Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
cbc6e69e
Unverified
提交
cbc6e69e
authored
9月 14, 2018
作者:
Steven Allen
提交者:
GitHub
9月 14, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5457 from overbool/feat/command/add-connection-direction
feat(command): add connection direction
上级
041e771d
daf6fbd3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
7 行删除
+30
-7
swarm.go
core/commands/swarm.go
+30
-7
没有找到文件。
core/commands/swarm.go
浏览文件 @
cbc6e69e
...
...
@@ -62,6 +62,7 @@ var swarmPeersCmd = &cmds.Command{
cmdkit
.
BoolOption
(
"verbose"
,
"v"
,
"display all extra information"
),
cmdkit
.
BoolOption
(
"streams"
,
"Also list information about open streams for each peer"
),
cmdkit
.
BoolOption
(
"latency"
,
"Also list information about latency to each peer"
),
cmdkit
.
BoolOption
(
"direction"
,
"Also list information about the direction of connection"
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
...
...
@@ -79,14 +80,13 @@ var swarmPeersCmd = &cmds.Command{
verbose
,
_
,
_
:=
req
.
Option
(
"verbose"
)
.
Bool
()
latency
,
_
,
_
:=
req
.
Option
(
"latency"
)
.
Bool
()
streams
,
_
,
_
:=
req
.
Option
(
"streams"
)
.
Bool
()
direction
,
_
,
_
:=
req
.
Option
(
"direction"
)
.
Bool
()
conns
:=
n
.
PeerHost
.
Network
()
.
Conns
()
var
out
connInfos
for
_
,
c
:=
range
conns
{
pid
:=
c
.
RemotePeer
()
addr
:=
c
.
RemoteMultiaddr
()
ci
:=
connInfo
{
Addr
:
addr
.
String
(),
Peer
:
pid
.
Pretty
(),
...
...
@@ -100,6 +100,11 @@ var swarmPeersCmd = &cmds.Command{
}
*/
if
verbose
||
direction
{
// set direction
ci
.
Direction
=
c
.
Stat
()
.
Direction
}
if
verbose
||
latency
{
lat
:=
n
.
Peerstore
.
LatencyEWMA
(
pid
)
if
lat
==
0
{
...
...
@@ -146,6 +151,11 @@ var swarmPeersCmd = &cmds.Command{
if
info
.
Latency
!=
""
{
fmt
.
Fprintf
(
buf
,
" %s"
,
info
.
Latency
)
}
if
info
.
Direction
!=
inet
.
DirUnknown
{
fmt
.
Fprintf
(
buf
,
" %s"
,
directionString
(
info
.
Direction
))
}
fmt
.
Fprintln
(
buf
)
for
_
,
s
:=
range
info
.
Streams
{
...
...
@@ -168,11 +178,12 @@ type streamInfo struct {
}
type
connInfo
struct
{
Addr
string
Peer
string
Latency
string
Muxer
string
Streams
[]
streamInfo
Addr
string
Peer
string
Latency
string
Muxer
string
Direction
inet
.
Direction
Streams
[]
streamInfo
}
func
(
ci
*
connInfo
)
Less
(
i
,
j
int
)
bool
{
...
...
@@ -203,6 +214,18 @@ func (ci connInfos) Swap(i, j int) {
ci
.
Peers
[
i
],
ci
.
Peers
[
j
]
=
ci
.
Peers
[
j
],
ci
.
Peers
[
i
]
}
// directionString transfers to string
func
directionString
(
d
inet
.
Direction
)
string
{
switch
d
{
case
inet
.
DirInbound
:
return
"inbound"
case
inet
.
DirOutbound
:
return
"outbound"
default
:
return
""
}
}
var
swarmAddrsCmd
=
&
cmds
.
Command
{
Helptext
:
cmdkit
.
HelpText
{
Tagline
:
"List known addresses. Useful for debugging."
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论