From 3aa86f8ed9602b86ed65ae4b9ddca3a97e1471e7 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 29 May 2020 18:47:21 -0700 Subject: [PATCH] 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. --- core/commands/id.go | 8 +++++++- test/sharness/t0140-swarm.sh | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/commands/id.go b/core/commands/id.go index dc4363e64..ae9d97d52 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -154,7 +154,13 @@ func printPeer(ps pstore.Peerstore, p peer.ID) (interface{}, error) { info.PublicKey = base64.StdEncoding.EncodeToString(pkb) } - for _, a := range ps.Addrs(p) { + addrInfo := ps.PeerInfo(p) + addrs, err := peer.AddrInfoToP2pAddrs(&addrInfo) + if err != nil { + return nil, err + } + + for _, a := range addrs { info.Addresses = append(info.Addresses, a.String()) } diff --git a/test/sharness/t0140-swarm.sh b/test/sharness/t0140-swarm.sh index 77e2af1b0..1468c560a 100755 --- a/test/sharness/t0140-swarm.sh +++ b/test/sharness/t0140-swarm.sh @@ -123,6 +123,17 @@ test_expect_success "/p2p addresses work" ' [ $(ipfsi 0 swarm peers | wc -l) -eq 1 ] ' +test_expect_success "ipfs id is consistent for node 0" ' + ipfsi 1 id "$(iptb attr get 0 id)" > 1see0 && + ipfsi 0 id > 0see0 && + test_cmp 1see0 0see0 +' +test_expect_success "ipfs id is consistent for node 1" ' + ipfsi 0 id "$(iptb attr get 1 id)" > 0see1 && + ipfsi 1 id > 1see1 && + test_cmp 0see1 1see1 +' + test_expect_success "stopping cluster" ' iptb stop '