From dd1093f4382dbddc9efb04541756e98c903b6f07 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 27 May 2020 14:52:31 -0700 Subject: [PATCH 1/4] fix: use connect instead of findpeer so we ensure we actually connect Otherwise, the ID is going to be incorrect. Note: technically, the previous logic didn't need to connect to the target peer to complete. However, I'm fine dropping that capability in favor of more up-to-date information. --- core/commands/id.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/commands/id.go b/core/commands/id.go index ae9d97d52b3..0dc782d876b 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -97,15 +97,17 @@ EXAMPLE: return errors.New(offlineIdErrorMessage) } - p, err := n.Routing.FindPeer(req.Context, id) - if err == kb.ErrLookupFailure { + // We need to actually connect to run identify. + err = n.PeerHost.Connect(req.Context, peer.AddrInfo{ID: id}) + switch err { + case nil: + case kb.ErrLookupFailure: return errors.New(offlineIdErrorMessage) - } - if err != nil { + default: return err } - output, err := printPeer(n.Peerstore, p.ID) + output, err := printPeer(n.Peerstore, id) if err != nil { return err } From dd47364e24f6177352d50ee70e46f36b2bab24e1 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 27 May 2020 14:56:28 -0700 Subject: [PATCH 2/4] feat: add protocol list to ipfs id --- core/commands/id.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/commands/id.go b/core/commands/id.go index 0dc782d876b..2b6f54c6de7 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -36,6 +36,7 @@ type IdOutput struct { Addresses []string AgentVersion string ProtocolVersion string + Protocols []string } const ( @@ -123,6 +124,7 @@ EXAMPLE: output = strings.Replace(output, "", out.ProtocolVersion, -1) output = strings.Replace(output, "", out.PublicKey, -1) output = strings.Replace(output, "", strings.Join(out.Addresses, "\n"), -1) + output = strings.Replace(output, "", strings.Join(out.Protocols, "\n"), -1) output = strings.Replace(output, "\\n", "\n", -1) output = strings.Replace(output, "\\t", "\t", -1) fmt.Fprint(w, output) @@ -166,6 +168,11 @@ func printPeer(ps pstore.Peerstore, p peer.ID) (interface{}, error) { info.Addresses = append(info.Addresses, a.String()) } + protocols, _ := ps.GetProtocols(p) // don't care about errors here. + for _, p := range protocols { + info.Protocols = append(info.Protocols, string(p)) + } + if v, err := ps.Get(p, "ProtocolVersion"); err == nil { if vs, ok := v.(string); ok { info.ProtocolVersion = vs @@ -200,6 +207,7 @@ func printSelf(node *core.IpfsNode) (interface{}, error) { for _, a := range addrs { info.Addresses = append(info.Addresses, a.String()) } + info.Protocols = node.PeerHost.Mux().Protocols() } info.ProtocolVersion = identify.LibP2PVersion info.AgentVersion = version.UserAgent From d6b94360e2c7b63593e71775bc05a8c77268f82a Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Sat, 8 Aug 2020 21:38:34 -0400 Subject: [PATCH 3/4] fix: sort protocols returned by ipfs id --- core/commands/id.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/commands/id.go b/core/commands/id.go index 2b6f54c6de7..9268514db90 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "sort" "strings" version "github.com/ipfs/go-ipfs" @@ -172,6 +173,7 @@ func printPeer(ps pstore.Peerstore, p peer.ID) (interface{}, error) { for _, p := range protocols { info.Protocols = append(info.Protocols, string(p)) } + sort.Strings(info.Protocols) if v, err := ps.Get(p, "ProtocolVersion"); err == nil { if vs, ok := v.(string); ok { @@ -208,6 +210,7 @@ func printSelf(node *core.IpfsNode) (interface{}, error) { info.Addresses = append(info.Addresses, a.String()) } info.Protocols = node.PeerHost.Mux().Protocols() + sort.Strings(info.Protocols) } info.ProtocolVersion = identify.LibP2PVersion info.AgentVersion = version.UserAgent From 34c0e5c0f60118dcb8fd3b7fd24d627483a07589 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Sat, 8 Aug 2020 21:39:18 -0400 Subject: [PATCH 4/4] fix: sort addresses returned by ipfs id --- core/commands/id.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/commands/id.go b/core/commands/id.go index 9268514db90..af6f3470d77 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -168,6 +168,7 @@ func printPeer(ps pstore.Peerstore, p peer.ID) (interface{}, error) { for _, a := range addrs { info.Addresses = append(info.Addresses, a.String()) } + sort.Strings(info.Addresses) protocols, _ := ps.GetProtocols(p) // don't care about errors here. for _, p := range protocols { @@ -209,6 +210,7 @@ func printSelf(node *core.IpfsNode) (interface{}, error) { for _, a := range addrs { info.Addresses = append(info.Addresses, a.String()) } + sort.Strings(info.Addresses) info.Protocols = node.PeerHost.Mux().Protocols() sort.Strings(info.Protocols) }