Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
4a029c73
提交
4a029c73
authored
11月 03, 2016
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add stream listings as swarm peers flag
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
上级
ec212209
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
97 行增加
和
15 行删除
+97
-15
swarm.go
core/commands/swarm.go
+95
-13
package.json
package.json
+2
-2
没有找到文件。
core/commands/swarm.go
浏览文件 @
4a029c73
...
...
@@ -54,9 +54,9 @@ var swarmPeersCmd = &cmds.Command{
`
,
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"verbose"
,
"v"
,
"Also display latency along with peer information in the following form: "
+
"<peer address> <latency>
"
),
cmds
.
BoolOption
(
"verbose"
,
"v"
,
"display all extra information"
),
cmds
.
BoolOption
(
"streams"
,
"Also list information about open streams for each peer"
),
cmds
.
BoolOption
(
"latency"
,
"Also list information about latency to each peer
"
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
...
...
@@ -73,27 +73,109 @@ var swarmPeersCmd = &cmds.Command{
}
verbose
,
_
,
_
:=
req
.
Option
(
"verbose"
)
.
Bool
()
latency
,
_
,
_
:=
req
.
Option
(
"latency"
)
.
Bool
()
streams
,
_
,
_
:=
req
.
Option
(
"streams"
)
.
Bool
()
conns
:=
n
.
PeerHost
.
Network
()
.
Conns
()
addrs
:=
make
([]
string
,
len
(
conns
))
for
i
,
c
:=
range
conns
{
var
out
connInfos
for
_
,
c
:=
range
conns
{
pid
:=
c
.
RemotePeer
()
addr
:=
c
.
RemoteMultiaddr
()
if
verbose
{
addrs
[
i
]
=
fmt
.
Sprintf
(
"%s/ipfs/%s %s"
,
addr
,
pid
.
Pretty
(),
n
.
Peerstore
.
LatencyEWMA
(
pid
))
}
else
{
addrs
[
i
]
=
fmt
.
Sprintf
(
"%s/ipfs/%s"
,
addr
,
pid
.
Pretty
())
ci
:=
connInfo
{
Addr
:
addr
.
String
(),
Peer
:
pid
.
Pretty
(),
}
if
verbose
||
latency
{
ci
.
Latency
=
n
.
Peerstore
.
LatencyEWMA
(
pid
)
.
String
()
}
if
verbose
||
streams
{
strs
,
err
:=
c
.
GetStreams
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
for
_
,
s
:=
range
strs
{
ci
.
Streams
=
append
(
ci
.
Streams
,
streamInfo
{
Protocol
:
string
(
s
.
Protocol
())})
}
}
sort
.
Sort
(
&
ci
)
out
.
Peers
=
append
(
out
.
Peers
,
ci
)
}
sort
.
Sort
(
sort
.
StringSlice
(
addrs
)
)
res
.
SetOutput
(
&
stringList
{
addrs
}
)
sort
.
Sort
(
&
out
)
res
.
SetOutput
(
&
out
)
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
stringListMarshaler
,
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
ci
,
ok
:=
res
.
Output
()
.
(
*
connInfos
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"expected output type to be connInfos"
)
}
buf
:=
new
(
bytes
.
Buffer
)
for
_
,
info
:=
range
ci
.
Peers
{
fmt
.
Fprintf
(
buf
,
"%s/ipfs/%s"
,
info
.
Addr
,
info
.
Peer
)
if
info
.
Latency
!=
""
{
fmt
.
Fprintf
(
buf
,
" %s"
,
info
.
Latency
)
}
fmt
.
Fprintln
(
buf
)
for
_
,
s
:=
range
info
.
Streams
{
if
s
.
Protocol
==
""
{
s
.
Protocol
=
"<no protocol name>"
}
fmt
.
Fprintf
(
buf
,
" %s
\n
"
,
s
.
Protocol
)
}
}
return
buf
,
nil
},
},
Type
:
stringList
{},
Type
:
connInfos
{},
}
type
streamInfo
struct
{
Protocol
string
}
type
connInfo
struct
{
Addr
string
Peer
string
Latency
string
Streams
[]
streamInfo
}
func
(
ci
*
connInfo
)
Less
(
i
,
j
int
)
bool
{
return
ci
.
Streams
[
i
]
.
Protocol
<
ci
.
Streams
[
j
]
.
Protocol
}
func
(
ci
*
connInfo
)
Len
()
int
{
return
len
(
ci
.
Streams
)
}
func
(
ci
*
connInfo
)
Swap
(
i
,
j
int
)
{
ci
.
Streams
[
i
],
ci
.
Streams
[
j
]
=
ci
.
Streams
[
j
],
ci
.
Streams
[
i
]
}
type
connInfos
struct
{
Peers
[]
connInfo
}
func
(
ci
connInfos
)
Less
(
i
,
j
int
)
bool
{
return
ci
.
Peers
[
i
]
.
Addr
<
ci
.
Peers
[
j
]
.
Addr
}
func
(
ci
connInfos
)
Len
()
int
{
return
len
(
ci
.
Peers
)
}
func
(
ci
connInfos
)
Swap
(
i
,
j
int
)
{
ci
.
Peers
[
i
],
ci
.
Peers
[
j
]
=
ci
.
Peers
[
j
],
ci
.
Peers
[
i
]
}
var
swarmAddrsCmd
=
&
cmds
.
Command
{
...
...
package.json
浏览文件 @
4a029c73
...
...
@@ -52,9 +52,9 @@
"version"
:
"0.1.0"
},
{
"hash"
:
"Qm
QF3y5N5RcMaGUbSunmbnjhaFHP7uGDismvngkn8HJ1Xa
"
,
"hash"
:
"Qm
U6FqHBr1W5ajRrj4cr2SfGq1w8gq2LpS42JWRysEb3BK
"
,
"name"
:
"iptb"
,
"version"
:
"1.1.
1
"
"version"
:
"1.1.
2
"
},
{
"hash"
:
"QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论