Documentation ¶
Overview ¶
Package peer implements an object used to represent peers in the libp2p network.
This file contains Protobuf and JSON serialization/deserialization methods for peer IDs.
Index ¶
- Variables
- func AddrInfoToP2pAddrs(pi *AddrInfo) ([]ma.Multiaddr, error)
- func Encode(id ID) string
- func IDB58Encode(id ID) stringdeprecated
- func IDHexEncode(id ID) stringdeprecated
- func ToCid(id ID) cid.Cid
- type AddrInfo
- type ID
- func Decode(s string) (ID, error)
- func FromCid(c cid.Cid) (ID, error)
- func IDB58Decode(s string) (ID, error)deprecated
- func IDFromBytes(b []byte) (ID, error)
- func IDFromPrivateKey(sk ic.PrivKey) (ID, error)
- func IDFromPublicKey(pk ic.PubKey) (ID, error)
- func IDFromString(s string) (ID, error)
- func IDHexDecode(s string) (ID, error)deprecated
- func SplitAddr(m ma.Multiaddr) (transport ma.Multiaddr, id ID)
- func (id ID) ExtractPublicKey() (ic.PubKey, error)
- func (id ID) Loggable() map[string]interface{}
- func (id ID) Marshal() ([]byte, error)
- func (id ID) MarshalBinary() ([]byte, error)
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id ID) MarshalTo(data []byte) (n int, err error)
- func (id ID) MatchesPrivateKey(sk ic.PrivKey) bool
- func (id ID) MatchesPublicKey(pk ic.PubKey) bool
- func (id ID) Pretty() string
- func (id ID) ShortString() string
- func (id ID) Size() int
- func (id ID) String() string
- func (id *ID) Unmarshal(data []byte) (err error)
- func (id *ID) UnmarshalBinary(data []byte) error
- func (id *ID) UnmarshalJSON(data []byte) (err error)
- func (id *ID) UnmarshalText(data []byte) error
- func (id ID) Validate() error
- type IDSlice
- type Set
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyPeerID is an error for empty peer ID. ErrEmptyPeerID = errors.New("empty peer ID") // ErrNoPublicKey is an error for peer IDs that don't embed public keys ErrNoPublicKey = errors.New("public key is not embedded in peer ID") )
var AdvancedEnableInlining = true
AdvancedEnableInlining enables automatically inlining keys shorter than 42 bytes into the peer ID (using the "identity" multihash function).
WARNING: This flag will likely be set to false in the future and eventually be removed in favor of using a hash function specified by the key itself. See: https://github.com/libp2p/specs/issues/138
DO NOT change this flag unless you know what you're doing.
This currently defaults to true for backwards compatibility but will likely be set to false by default when an upgrade path is determined.
var ErrInvalidAddr = fmt.Errorf("invalid p2p multiaddr")
Functions ¶
func AddrInfoToP2pAddrs ¶
AddrInfoToP2pAddr converts an AddrInfo to a list of Multiaddrs.
func Encode ¶
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.
func IDB58Encode
deprecated
func IDHexEncode
deprecated
Types ¶
type AddrInfo ¶
AddrInfo is a small struct used to pass around a peer with a set of addresses (and later, keys?).
func AddrInfoFromP2pAddr ¶
AddrInfoFromP2pAddr converts a Multiaddr to an AddrInfo.
func AddrInfosFromP2pAddrs ¶
AddrInfosFromP2pAddrs converts a set of Multiaddrs to a set of AddrInfos.
func (AddrInfo) MarshalJSON ¶
func (*AddrInfo) UnmarshalJSON ¶
type ID ¶
type ID string
ID is a libp2p peer identity.
Peer IDs are derived by hashing a peer's public key and encoding the hash output as a multihash. See IDFromPublicKey for details.
func Decode ¶
Decode accepts an encoded peer ID and returns the decoded ID if the input is valid.
The encoded peer ID can either be a CID of a key or a raw multihash (identity or sha256-256).
func IDB58Decode
deprecated
func IDFromBytes ¶
IDFromBytes casts a byte slice to the ID type, and validates the value to make sure it is a multihash.
func IDFromPrivateKey ¶
IDFromPrivateKey returns the Peer ID corresponding to the secret key sk.
func IDFromPublicKey ¶
IDFromPublicKey returns the Peer ID corresponding to the public key pk.
func IDFromString ¶
IDFromString casts a string to the ID type, and validates the value to make sure it is a multihash.
func IDHexDecode
deprecated
func SplitAddr ¶
SplitAddr splits a p2p Multiaddr into a transport multiaddr and a peer ID.
* Returns a nil transport if the address only contains a /p2p part. * Returns a empty peer ID if the address doesn't contain a /p2p part.
func (ID) ExtractPublicKey ¶
ExtractPublicKey attempts to extract the public key from an ID
This method returns ErrNoPublicKey if the peer ID looks valid but it can't extract the public key.
func (ID) MarshalBinary ¶
BinaryMarshal returns the byte representation of the peer ID.
func (ID) MarshalJSON ¶
func (ID) MarshalText ¶
TextMarshal returns the text encoding of the ID.
func (ID) MatchesPrivateKey ¶
MatchesPrivateKey tests whether this ID was derived from the secret key sk.
func (ID) MatchesPublicKey ¶
MatchesPublicKey tests whether this ID was derived from the public key pk.
func (ID) ShortString ¶
String prints out the peer ID.
TODO(brian): ensure correctness at ID generation and enforce this by only exposing functions that generate IDs safely. Then any peer.ID type found in the codebase is known to be correct.
func (ID) Size ¶
Implements Gogo's proto.Sizer, but we omit the compile-time assertion to avoid introducing a hard dependency on gogo.
func (*ID) UnmarshalBinary ¶
BinaryUnmarshal sets the ID from its binary representation.
func (*ID) UnmarshalJSON ¶
func (*ID) UnmarshalText ¶
TextUnmarshal restores the ID from its text encoding.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
PeerSet is a threadsafe set of peers