fix(commands): print consistent addresses in ipfs id
Consistently append `/p2p/QmMyId` to addresses when calling `ipfs id Me` and `ipfs id NotMe`. Fixes https://github.com/ipfs/go-ipfs/issues/7378.
Steven Allen committed
May 29, 2020 at 18:47 UTC
3aa86f8ed9602b86ed65ae4b9ddca3a97e1471e7
2 files changed
+18
-1
core/commands/id.go
+7
-1
@@ -154,7 +154,13 @@ func printPeer(ps pstore.Peerstore, p peer.ID) (interface{}, error) {
154
info.PublicKey = base64.StdEncoding.EncodeToString(pkb)
155
}
156
157
- for _, a := range ps.Addrs(p) {
157
+ addrInfo := ps.PeerInfo(p)
158
+ addrs, err := peer.AddrInfoToP2pAddrs(&addrInfo)
159
+ if err != nil {
160
+ return nil, err
161
+ }
162
+
163
+ for _, a := range addrs {
164
info.Addresses = append(info.Addresses, a.String())
165
}
166
test/sharness/t0140-swarm.sh
+11
@@ -123,6 +123,17 @@ test_expect_success "/p2p addresses work" '
123
[ $(ipfsi 0 swarm peers | wc -l) -eq 1 ]
124
'
125
126
+test_expect_success "ipfs id is consistent for node 0" '
127
+ ipfsi 1 id "$(iptb attr get 0 id)" > 1see0 &&
128
+ ipfsi 0 id > 0see0 &&
129
+ test_cmp 1see0 0see0
130
+'
131
+test_expect_success "ipfs id is consistent for node 1" '
132
+ ipfsi 0 id "$(iptb attr get 1 id)" > 0see1 &&
133
+ ipfsi 1 id > 1see1 &&
134
+ test_cmp 0see1 1see1
135
+'
136
+
137
test_expect_success "stopping cluster" '
138
iptb stop
139
'