1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-03 04:37:30 +08:00

Merge pull request #3484 from ipfs/fix/pubsub-peers-cmd

cmd/pubsub: fix peers command topic filtering
This commit is contained in:
Jeromy Johnson
2016-12-09 12:08:45 -08:00
committed by GitHub
2 changed files with 30 additions and 9 deletions

View File

@ -274,9 +274,11 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
var PubsubPeersCmd = &cmds.Command{ var PubsubPeersCmd = &cmds.Command{
Helptext: cmds.HelpText{ Helptext: cmds.HelpText{
Tagline: "List all peers we are currently pubsubbing with.", Tagline: "List peers we are currently pubsubbing with.",
ShortDescription: ` ShortDescription: `
ipfs pubsub peers lists out the pubsub peers you are currently connected to. ipfs pubsub peers with no arguments lists out the pubsub peers you are
currently connected to. If given a topic, it will list connected
peers who are subscribed to the named topic.
This is an experimental feature. It is not intended in its current state This is an experimental feature. It is not intended in its current state
to be used in a production environment. to be used in a production environment.
@ -284,6 +286,9 @@ to be used in a production environment.
To use, the daemon must be run with '--enable-pubsub-experiment'. To use, the daemon must be run with '--enable-pubsub-experiment'.
`, `,
}, },
Arguments: []cmds.Argument{
cmds.StringArg("topic", false, false, "topic to list connected peers of"),
},
Run: func(req cmds.Request, res cmds.Response) { Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode() n, err := req.InvocContext().GetNode()
if err != nil { if err != nil {
@ -302,8 +307,13 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
return return
} }
var topic string
if len(req.Arguments()) == 1 {
topic = req.Arguments()[0]
}
var out []string var out []string
for _, p := range n.Floodsub.ListPeers("") { for _, p := range n.Floodsub.ListPeers(topic) {
out = append(out, p.Pretty()) out = append(out, p.Pretty())
} }
res.SetOutput(&stringList{out}) res.SetOutput(&stringList{out})

View File

@ -32,16 +32,27 @@ test_expect_success 'pubsub' '
echo > wait echo > wait
fi fi
) & ) &
'
# wait until ipfs pubsub sub is ready to do work test_expect_success "wait until ipfs pubsub sub is ready to do work" '
sleep 1 && sleep 1
'
# publish something test_expect_success "can see peer subscribed to testTopic" '
ipfsi 1 pubsub pub testTopic "testOK" &> pubErr && ipfsi 1 pubsub peers testTopic > peers_out
'
# wait until `echo > wait` executed test_expect_success "output looks good" '
echo $PEERID_0 > peers_exp &&
test_cmp peers_exp peers_out
'
test_expect_success "publish something" '
ipfsi 1 pubsub pub testTopic "testOK" &> pubErr
'
test_expect_success "wait until echo > wait executed" '
cat wait && cat wait &&
test_cmp pubErr empty && test_cmp pubErr empty &&
test_cmp expected actual test_cmp expected actual
' '