// printing self is special cased as we get values differently. func printSelf(node *core.IpfsNode) (interface{}, error) { info := new(IdOutput) info.ID = node.Identity.Pretty() if node.PrivateKey == nil { if err := node.LoadPrivateKey(); err != nil { return nil, err } } pk := node.PrivateKey.GetPublic() pkb, err := ic.MarshalPublicKey(pk) if err != nil { return nil, err } info.PublicKey = base64.StdEncoding.EncodeToString(pkb) if node.PeerHost != nil { for _, a := range node.PeerHost.Addrs() { s := a.String() + "/ipfs/" + info.ID info.Addresses = append(info.Addresses, s) } } info.ProtocolVersion = identify.LibP2PVersion info.AgentVersion = identify.ClientVersion return info, nil }
func printPeer(ps pstore.Peerstore, p peer.ID) (interface{}, error) { if p == "" { return nil, errors.New("Attempted to print nil peer!") } info := new(IdOutput) info.ID = p.Pretty() if pk := ps.PubKey(p); pk != nil { pkb, err := ic.MarshalPublicKey(pk) if err != nil { return nil, err } info.PublicKey = base64.StdEncoding.EncodeToString(pkb) } for _, a := range ps.Addrs(p) { info.Addresses = append(info.Addresses, a.String()) } if v, err := ps.Get(p, "ProtocolVersion"); err == nil { if vs, ok := v.(string); ok { info.ProtocolVersion = vs } } if v, err := ps.Get(p, "AgentVersion"); err == nil { if vs, ok := v.(string); ok { info.AgentVersion = vs } } return info, nil }