feat: add protocol list to ipfs id
Steven Allen committed
May 27, 2020 at 14:56 UTC
dd47364e24f6177352d50ee70e46f36b2bab24e1
1 file changed
+8
core/commands/id.go
+8
@@ -36,6 +36,7 @@ type IdOutput struct {
36
Addresses []string
37
AgentVersion string
38
ProtocolVersion string
39
+ Protocols []string
40
}
41
42
const (
@@ -123,6 +124,7 @@ EXAMPLE:
124
output = strings.Replace(output, "<pver>", out.ProtocolVersion, -1)
125
output = strings.Replace(output, "<pubkey>", out.PublicKey, -1)
126
output = strings.Replace(output, "<addrs>", strings.Join(out.Addresses, "\n"), -1)
127
+ output = strings.Replace(output, "<protocols>", strings.Join(out.Protocols, "\n"), -1)
128
output = strings.Replace(output, "\\n", "\n", -1)
129
output = strings.Replace(output, "\\t", "\t", -1)
130
fmt.Fprint(w, output)
@@ -166,6 +168,11 @@ func printPeer(ps pstore.Peerstore, p peer.ID) (interface{}, error) {
168
info.Addresses = append(info.Addresses, a.String())
169
}
170
171
+ protocols, _ := ps.GetProtocols(p) // don't care about errors here.
172
+ for _, p := range protocols {
173
+ info.Protocols = append(info.Protocols, string(p))
174
+ }
175
+
176
if v, err := ps.Get(p, "ProtocolVersion"); err == nil {
177
if vs, ok := v.(string); ok {
178
info.ProtocolVersion = vs
@@ -200,6 +207,7 @@ func printSelf(node *core.IpfsNode) (interface{}, error) {
207
for _, a := range addrs {
208
info.Addresses = append(info.Addresses, a.String())
209
}
210
+ info.Protocols = node.PeerHost.Mux().Protocols()
211
}
212
info.ProtocolVersion = identify.LibP2PVersion
213
info.AgentVersion = version.UserAgent