From 2f6be1a675af0802c07c3c84ccfc320ffef46fa6 Mon Sep 17 00:00:00 2001 From: Takashi Matsuda Date: Wed, 18 Aug 2021 21:07:34 +0900 Subject: [PATCH] fix: help text and comments --- core/commands/swarm.go | 25 +++++++++++++------------ peering/peering.go | 16 +++++----------- peering/peering_test.go | 12 ++++++------ 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/core/commands/swarm.go b/core/commands/swarm.go index 220801bf72cb..6c4e7ac1bdbc 100644 --- a/core/commands/swarm.go +++ b/core/commands/swarm.go @@ -64,10 +64,10 @@ const ( var swarmPeeringCmd = &cmds.Command{ Helptext: cmds.HelpText{ - Tagline: "modify the peering service.", + Tagline: "Modify the peering subsystem.", ShortDescription: ` -'ipfs swarm peering' is a tool to manupulate the peering service. -Peers in the peering service is maintained to be connected, reconnected +'ipfs swarm peering' manages the peering subsystem. +Peers in the peering subsystem is maintained to be connected, reconnected on disconnect with a back-off. `, }, @@ -80,13 +80,13 @@ on disconnect with a back-off. var swarmPeeringAddCmd = &cmds.Command{ Helptext: cmds.HelpText{ - Tagline: "add peers into the peering service.", + Tagline: "Add peers into the peering subsystem.", ShortDescription: ` -'ipfs swarm peering add' adds peers into the peering service. +'ipfs swarm peering add' will add the new address to the peering subsystem as one that should always be connected to. `, }, Arguments: []cmds.Argument{ - cmds.StringArg("address", true, true, "address of peer to add into the PeeringService"), + cmds.StringArg("address", true, true, "address of peer to add into the peering subsystem"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { addrs := make([]ma.Multiaddr, len(req.Arguments)) @@ -128,16 +128,17 @@ var swarmPeeringAddCmd = &cmds.Command{ var swarmPeeringLsCmd = &cmds.Command{ Helptext: cmds.HelpText{ - Tagline: "list peers registered in the peering service.", + Tagline: "List peers registered in the peering subsystem.", ShortDescription: ` -'ipfs swarm peering ls' lists peers registered in the peering service.`, +'ipfs swarm peering ls' lists the peers that are registered in the peering subsystem and to which the daemon is always connected. +`, }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { node, err := cmdenv.GetNode(env) if err != nil { return err } - peers := node.Peering.ListPeer() + peers := node.Peering.ListPeers() return cmds.EmitOnce(res, addrInfos{Peers: peers}) }, Type: addrInfos{}, @@ -160,13 +161,13 @@ type addrInfos struct { var swarmPeeringRmCmd = &cmds.Command{ Helptext: cmds.HelpText{ - Tagline: "remove a peer from the peering service.", + Tagline: "Remove a peer from the peering subsystem.", ShortDescription: ` -'ipfs swarm peering rm' removes peers from the peering service. +'ipfs swarm peering rm' will remove the given ID from the peering subsystem and remove it from the always-on connection. `, }, Arguments: []cmds.Argument{ - cmds.StringArg("ID", true, true, "ID of peer to remove from PeeringService"), + cmds.StringArg("ID", true, true, "ID of peer to remove from the peering subsystem"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { node, err := cmdenv.GetNode(env) diff --git a/peering/peering.go b/peering/peering.go index 796167a91e78..3146769a02a0 100644 --- a/peering/peering.go +++ b/peering/peering.go @@ -220,7 +220,6 @@ func (ps *PeeringService) AddPeer(info peer.AddrInfo) { handler.setAddrs(info.Addrs) } else { logger.Infow("peer added", "peer", info.ID, "addrs", info.Addrs) - // in case ps.host is null this line results in a panic. ps.host.ConnManager().Protect(info.ID, connmgrTag) handler = &peerHandler{ @@ -245,16 +244,11 @@ func (ps *PeeringService) AddPeer(info peer.AddrInfo) { // ListPeers lists peers in the peering service. func (ps *PeeringService) ListPeers() []peer.AddrInfo { - out := make([]peer.AddrInfo, len(ps.peers)) - c := 0 - for k, v := range ps.peers { - outAddrs := make([]multiaddr.Multiaddr, len(v.addrs)) - copy(out_addrs, v.addrs) - out[c] = peer.AddrInfo{ - ID: k, - Addrs: out_addrs, - } - c++ + out := make([]peer.AddrInfo, 0, len(ps.peers)) + for id, addrs := range ps.peers { + ai := peer.AddrInfo{ID: id} + ai.Addrs = append(ai.Addrs, addrs.addrs...) + out = append(out, ai) } return out } diff --git a/peering/peering_test.go b/peering/peering_test.go index 8d4d4ae2578a..cf91e637c75e 100644 --- a/peering/peering_test.go +++ b/peering/peering_test.go @@ -39,7 +39,7 @@ func TestPeeringService(t *testing.T) { // peer 1 -> 2 ps1.AddPeer(peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}) - require.Contains(t, ps1.ListPeer(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}) + require.Contains(t, ps1.ListPeers(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}) // We haven't started so we shouldn't have any peers. require.Never(t, func() bool { @@ -110,7 +110,7 @@ func TestPeeringService(t *testing.T) { // Unprotect 2 from 1. ps1.RemovePeer(h2.ID()) - require.NotContains(t, ps1.ListPeer(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}) + require.NotContains(t, ps1.ListPeers(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}) // Trim connections. h1.ConnManager().TrimOpenConns(ctx) @@ -129,9 +129,9 @@ func TestPeeringService(t *testing.T) { // Until added back ps1.AddPeer(peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}) - require.Contains(t, ps1.ListPeer(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}) + require.Contains(t, ps1.ListPeers(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}) ps1.AddPeer(peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()}) - require.Contains(t, ps1.ListPeer(), peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()}) + require.Contains(t, ps1.ListPeers(), peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()}) t.Logf("wait for h1 to connect to h2 and h3 again") require.Eventually(t, func() bool { return h1.Network().Connectedness(h2.ID()) == network.Connected @@ -146,9 +146,9 @@ func TestPeeringService(t *testing.T) { // Adding and removing should work after stopping. ps1.AddPeer(peer.AddrInfo{ID: h4.ID(), Addrs: h4.Addrs()}) - require.Contains(t, ps1.ListPeer(), peer.AddrInfo{ID: h4.ID(), Addrs: h4.Addrs()}) + require.Contains(t, ps1.ListPeers(), peer.AddrInfo{ID: h4.ID(), Addrs: h4.Addrs()}) ps1.RemovePeer(h2.ID()) - require.NotContains(t, ps1.ListPeer(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}) + require.NotContains(t, ps1.ListPeers(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}) } func TestNextBackoff(t *testing.T) {