@cryptotaxi247 / kubo / commits / f104b8ae5

cmd/pubsub: fix peers command topic filtering

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Dec 7, 2016 at 16:44 UTC f104b8ae57fcbcc56770c4b3d78ca87e6de33de0
2 files changed +30 -9
core/commands/pubsub.go
+13 -3
@@ -274,9 +274,11 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
274
275 var PubsubPeersCmd = &cmds.Command{
276 Helptext: cmds.HelpText{
277 - Tagline: "List all peers we are currently pubsubbing with.",
277 + Tagline: "List peers we are currently pubsubbing with.",
278 ShortDescription: `
279 -ipfs pubsub peers lists out the pubsub peers you are currently connected to.
279 +ipfs pubsub peers with no arguments lists out the pubsub peers you are
280 +currently connected to. If given a topic, it will list connected
281 +peers who are subscribed to the named topic.
282
283 This is an experimental feature. It is not intended in its current state
284 to be used in a production environment.
@@ -284,6 +286,9 @@ to be used in a production environment.
286 To use, the daemon must be run with '--enable-pubsub-experiment'.
287 `,
288 },
289 + Arguments: []cmds.Argument{
290 + cmds.StringArg("topic", false, false, "topic to list connected peers of"),
291 + },
292 Run: func(req cmds.Request, res cmds.Response) {
293 n, err := req.InvocContext().GetNode()
294 if err != nil {
@@ -302,8 +307,13 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
307 return
308 }
309
310 + var topic string
311 + if len(req.Arguments()) == 1 {
312 + topic = req.Arguments()[0]
313 + }
314 +
315 var out []string
306 - for _, p := range n.Floodsub.ListPeers("") {
316 + for _, p := range n.Floodsub.ListPeers(topic) {
317 out = append(out, p.Pretty())
318 }
319 res.SetOutput(&stringList{out})
test/sharness/t0180-pubsub.sh
+17 -6
@@ -32,16 +32,27 @@ test_expect_success 'pubsub' '
32 echo > wait
33 fi
34 ) &
35 +'
36
36 - # wait until ipfs pubsub sub is ready to do work
37 - sleep 1 &&
37 +test_expect_success "wait until ipfs pubsub sub is ready to do work" '
38 + sleep 1
39 +'
40
39 - # publish something
40 - ipfsi 1 pubsub pub testTopic "testOK" &> pubErr &&
41 +test_expect_success "can see peer subscribed to testTopic" '
42 + ipfsi 1 pubsub peers testTopic > peers_out
43 +'
44
42 - # wait until `echo > wait` executed
43 - cat wait &&
45 +test_expect_success "output looks good" '
46 + echo $PEERID_0 > peers_exp &&
47 + test_cmp peers_exp peers_out
48 +'
49 +
50 +test_expect_success "publish something" '
51 + ipfsi 1 pubsub pub testTopic "testOK" &> pubErr
52 +'
53
54 +test_expect_success "wait until echo > wait executed" '
55 + cat wait &&
56 test_cmp pubErr empty &&
57 test_cmp expected actual
58 '