Skip to content

Commit

Permalink
feat: add protocol list to ipfs id
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Jun 3, 2020
1 parent 388df45 commit 9f678a1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/commands/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type IdOutput struct {
Addresses []string
AgentVersion string
ProtocolVersion string
Protocols []string
}

const (
Expand Down Expand Up @@ -123,6 +124,7 @@ EXAMPLE:
output = strings.Replace(output, "<pver>", out.ProtocolVersion, -1)
output = strings.Replace(output, "<pubkey>", out.PublicKey, -1)
output = strings.Replace(output, "<addrs>", strings.Join(out.Addresses, "\n"), -1)
output = strings.Replace(output, "<protocols>", strings.Join(out.Protocols, "\n"), -1)
output = strings.Replace(output, "\\n", "\n", -1)
output = strings.Replace(output, "\\t", "\t", -1)
fmt.Fprint(w, output)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9f678a1

Please sign in to comment.