Skip to content

Commit

Permalink
fix: help text and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TakashiMatsuda committed Aug 18, 2021
1 parent b20cfc1 commit 2f6be1a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
25 changes: 13 additions & 12 deletions core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
`,
},
Expand All @@ -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))
Expand Down Expand Up @@ -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{},
Expand All @@ -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)
Expand Down
16 changes: 5 additions & 11 deletions peering/peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions peering/peering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 2f6be1a

Please sign in to comment.