Marten Seemann
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
4 additions and
14 deletions
-
core/peer/addrinfo.go
-
core/peer/addrinfo_test.go
-
core/peer/peer.go
-
core/peer/peer_serde.go
|
|
@ -86,7 +86,7 @@ func AddrInfoFromP2pAddr(m ma.Multiaddr) (*AddrInfo, error) { |
|
|
|
|
|
|
|
// AddrInfoToP2pAddrs converts an AddrInfo to a list of Multiaddrs.
|
|
|
|
func AddrInfoToP2pAddrs(pi *AddrInfo) ([]ma.Multiaddr, error) { |
|
|
|
p2ppart, err := ma.NewComponent("p2p", Encode(pi.ID)) |
|
|
|
p2ppart, err := ma.NewComponent("p2p", pi.ID.String()) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
@ -19,7 +19,7 @@ func init() { |
|
|
|
if err != nil { |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
maddrPeer = ma.StringCast("/p2p/" + Encode(testID)) |
|
|
|
maddrPeer = ma.StringCast("/p2p/" + testID.String()) |
|
|
|
maddrTpt = ma.StringCast("/ip4/127.0.0.1/tcp/1234") |
|
|
|
maddrFull = maddrTpt.Encapsulate(maddrPeer) |
|
|
|
} |
|
|
|
|
|
@ -145,16 +145,6 @@ func Decode(s string) (ID, error) { |
|
|
|
return FromCid(c) |
|
|
|
} |
|
|
|
|
|
|
|
// Encode encodes a peer ID as a string.
|
|
|
|
//
|
|
|
|
// At the moment, it base58 encodes the peer ID but, in the future, it will
|
|
|
|
// switch to encoding it as a CID by default.
|
|
|
|
//
|
|
|
|
// Deprecated: use id.String instead.
|
|
|
|
func Encode(id ID) string { |
|
|
|
return id.String() |
|
|
|
} |
|
|
|
|
|
|
|
// FromCid converts a CID to a peer ID, if possible.
|
|
|
|
func FromCid(c cid.Cid) (ID, error) { |
|
|
|
code := mc.Code(c.Type()) |
|
|
|
|
|
@ -45,7 +45,7 @@ func (id ID) Size() int { |
|
|
|
} |
|
|
|
|
|
|
|
func (id ID) MarshalJSON() ([]byte, error) { |
|
|
|
return json.Marshal(Encode(id)) |
|
|
|
return json.Marshal(id.String()) |
|
|
|
} |
|
|
|
|
|
|
|
func (id *ID) UnmarshalJSON(data []byte) (err error) { |
|
|
@ -59,7 +59,7 @@ func (id *ID) UnmarshalJSON(data []byte) (err error) { |
|
|
|
|
|
|
|
// MarshalText returns the text encoding of the ID.
|
|
|
|
func (id ID) MarshalText() ([]byte, error) { |
|
|
|
return []byte(Encode(id)), nil |
|
|
|
return []byte(id.String()), nil |
|
|
|
} |
|
|
|
|
|
|
|
// UnmarshalText restores the ID from its text encoding.
|
|
|
|