Skip to content

Commit 2f6be1a

Browse files
fix: help text and comments
1 parent b20cfc1 commit 2f6be1a

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

core/commands/swarm.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ const (
6464

6565
var swarmPeeringCmd = &cmds.Command{
6666
Helptext: cmds.HelpText{
67-
Tagline: "modify the peering service.",
67+
Tagline: "Modify the peering subsystem.",
6868
ShortDescription: `
69-
'ipfs swarm peering' is a tool to manupulate the peering service.
70-
Peers in the peering service is maintained to be connected, reconnected
69+
'ipfs swarm peering' manages the peering subsystem.
70+
Peers in the peering subsystem is maintained to be connected, reconnected
7171
on disconnect with a back-off.
7272
`,
7373
},
@@ -80,13 +80,13 @@ on disconnect with a back-off.
8080

8181
var swarmPeeringAddCmd = &cmds.Command{
8282
Helptext: cmds.HelpText{
83-
Tagline: "add peers into the peering service.",
83+
Tagline: "Add peers into the peering subsystem.",
8484
ShortDescription: `
85-
'ipfs swarm peering add' adds peers into the peering service.
85+
'ipfs swarm peering add' will add the new address to the peering subsystem as one that should always be connected to.
8686
`,
8787
},
8888
Arguments: []cmds.Argument{
89-
cmds.StringArg("address", true, true, "address of peer to add into the PeeringService"),
89+
cmds.StringArg("address", true, true, "address of peer to add into the peering subsystem"),
9090
},
9191
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
9292
addrs := make([]ma.Multiaddr, len(req.Arguments))
@@ -128,16 +128,17 @@ var swarmPeeringAddCmd = &cmds.Command{
128128

129129
var swarmPeeringLsCmd = &cmds.Command{
130130
Helptext: cmds.HelpText{
131-
Tagline: "list peers registered in the peering service.",
131+
Tagline: "List peers registered in the peering subsystem.",
132132
ShortDescription: `
133-
'ipfs swarm peering ls' lists peers registered in the peering service.`,
133+
'ipfs swarm peering ls' lists the peers that are registered in the peering subsystem and to which the daemon is always connected.
134+
`,
134135
},
135136
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
136137
node, err := cmdenv.GetNode(env)
137138
if err != nil {
138139
return err
139140
}
140-
peers := node.Peering.ListPeer()
141+
peers := node.Peering.ListPeers()
141142
return cmds.EmitOnce(res, addrInfos{Peers: peers})
142143
},
143144
Type: addrInfos{},
@@ -160,13 +161,13 @@ type addrInfos struct {
160161

161162
var swarmPeeringRmCmd = &cmds.Command{
162163
Helptext: cmds.HelpText{
163-
Tagline: "remove a peer from the peering service.",
164+
Tagline: "Remove a peer from the peering subsystem.",
164165
ShortDescription: `
165-
'ipfs swarm peering rm' removes peers from the peering service.
166+
'ipfs swarm peering rm' will remove the given ID from the peering subsystem and remove it from the always-on connection.
166167
`,
167168
},
168169
Arguments: []cmds.Argument{
169-
cmds.StringArg("ID", true, true, "ID of peer to remove from PeeringService"),
170+
cmds.StringArg("ID", true, true, "ID of peer to remove from the peering subsystem"),
170171
},
171172
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
172173
node, err := cmdenv.GetNode(env)

peering/peering.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ func (ps *PeeringService) AddPeer(info peer.AddrInfo) {
220220
handler.setAddrs(info.Addrs)
221221
} else {
222222
logger.Infow("peer added", "peer", info.ID, "addrs", info.Addrs)
223-
// in case ps.host is null this line results in a panic.
224223
ps.host.ConnManager().Protect(info.ID, connmgrTag)
225224

226225
handler = &peerHandler{
@@ -245,16 +244,11 @@ func (ps *PeeringService) AddPeer(info peer.AddrInfo) {
245244

246245
// ListPeers lists peers in the peering service.
247246
func (ps *PeeringService) ListPeers() []peer.AddrInfo {
248-
out := make([]peer.AddrInfo, len(ps.peers))
249-
c := 0
250-
for k, v := range ps.peers {
251-
outAddrs := make([]multiaddr.Multiaddr, len(v.addrs))
252-
copy(out_addrs, v.addrs)
253-
out[c] = peer.AddrInfo{
254-
ID: k,
255-
Addrs: out_addrs,
256-
}
257-
c++
247+
out := make([]peer.AddrInfo, 0, len(ps.peers))
248+
for id, addrs := range ps.peers {
249+
ai := peer.AddrInfo{ID: id}
250+
ai.Addrs = append(ai.Addrs, addrs.addrs...)
251+
out = append(out, ai)
258252
}
259253
return out
260254
}

peering/peering_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestPeeringService(t *testing.T) {
3939

4040
// peer 1 -> 2
4141
ps1.AddPeer(peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
42-
require.Contains(t, ps1.ListPeer(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
42+
require.Contains(t, ps1.ListPeers(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
4343

4444
// We haven't started so we shouldn't have any peers.
4545
require.Never(t, func() bool {
@@ -110,7 +110,7 @@ func TestPeeringService(t *testing.T) {
110110

111111
// Unprotect 2 from 1.
112112
ps1.RemovePeer(h2.ID())
113-
require.NotContains(t, ps1.ListPeer(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
113+
require.NotContains(t, ps1.ListPeers(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
114114

115115
// Trim connections.
116116
h1.ConnManager().TrimOpenConns(ctx)
@@ -129,9 +129,9 @@ func TestPeeringService(t *testing.T) {
129129

130130
// Until added back
131131
ps1.AddPeer(peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
132-
require.Contains(t, ps1.ListPeer(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
132+
require.Contains(t, ps1.ListPeers(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
133133
ps1.AddPeer(peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()})
134-
require.Contains(t, ps1.ListPeer(), peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()})
134+
require.Contains(t, ps1.ListPeers(), peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()})
135135
t.Logf("wait for h1 to connect to h2 and h3 again")
136136
require.Eventually(t, func() bool {
137137
return h1.Network().Connectedness(h2.ID()) == network.Connected
@@ -146,9 +146,9 @@ func TestPeeringService(t *testing.T) {
146146

147147
// Adding and removing should work after stopping.
148148
ps1.AddPeer(peer.AddrInfo{ID: h4.ID(), Addrs: h4.Addrs()})
149-
require.Contains(t, ps1.ListPeer(), peer.AddrInfo{ID: h4.ID(), Addrs: h4.Addrs()})
149+
require.Contains(t, ps1.ListPeers(), peer.AddrInfo{ID: h4.ID(), Addrs: h4.Addrs()})
150150
ps1.RemovePeer(h2.ID())
151-
require.NotContains(t, ps1.ListPeer(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
151+
require.NotContains(t, ps1.ListPeers(), peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
152152
}
153153

154154
func TestNextBackoff(t *testing.T) {

0 commit comments

Comments
 (0)