go-libp2p-core: github.com/libp2p/go-libp2p-core/peer Index | Files

package peer

import "github.com/libp2p/go-libp2p-core/peer"

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

Package Files

addrinfo.go addrinfo_serde.go peer.go peer_serde.go set.go

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")

func AddrInfoToP2pAddrs Uses

func AddrInfoToP2pAddrs(pi *AddrInfo) ([]ma.Multiaddr, error)

AddrInfoToP2pAddr converts an AddrInfo to a list of Multiaddrs.

func IDB58Encode Uses

func IDB58Encode(id ID) string

IDB58Encode returns the base58-encoded multihash representation of the ID.

func IDHexEncode Uses

func IDHexEncode(id ID) string

IDHexEncode returns the hex-encoded multihash representation of the ID.

type AddrInfo Uses

type AddrInfo struct {
    ID    ID
    Addrs []ma.Multiaddr
}

AddrInfo is a small struct used to pass around a peer with a set of addresses (and later, keys?).

func AddrInfoFromP2pAddr Uses

func AddrInfoFromP2pAddr(m ma.Multiaddr) (*AddrInfo, error)

AddrInfoFromP2pAddr converts a Multiaddr to an AddrInfo.

func AddrInfosFromP2pAddrs Uses

func AddrInfosFromP2pAddrs(maddrs ...ma.Multiaddr) ([]AddrInfo, error)

AddrInfosFromP2pAddrs converts a set of Multiaddrs to a set of AddrInfos.

func (*AddrInfo) Loggable Uses

func (pi *AddrInfo) Loggable() map[string]interface{}

func (AddrInfo) MarshalJSON Uses

func (pi AddrInfo) MarshalJSON() ([]byte, error)

func (AddrInfo) String Uses

func (pi AddrInfo) String() string

func (*AddrInfo) UnmarshalJSON Uses

func (pi *AddrInfo) UnmarshalJSON(b []byte) error

type ID Uses

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 IDB58Decode Uses

func IDB58Decode(s string) (ID, error)

IDB58Decode accepts a base58-encoded multihash representing a peer ID and returns the decoded ID if the input is valid.

func IDFromBytes Uses

func IDFromBytes(b []byte) (ID, error)

IDFromBytes casts a byte slice to the ID type, and validates the value to make sure it is a multihash.

func IDFromPrivateKey Uses

func IDFromPrivateKey(sk ic.PrivKey) (ID, error)

IDFromPrivateKey returns the Peer ID corresponding to the secret key sk.

func IDFromPublicKey Uses

func IDFromPublicKey(pk ic.PubKey) (ID, error)

IDFromPublicKey returns the Peer ID corresponding to the public key pk.

func IDFromString Uses

func IDFromString(s string) (ID, error)

IDFromString casts a string to the ID type, and validates the value to make sure it is a multihash.

func IDHexDecode Uses

func IDHexDecode(s string) (ID, error)

IDHexDecode accepts a hex-encoded multihash representing a peer ID and returns the decoded ID if the input is valid.

func SplitAddr Uses

func SplitAddr(m ma.Multiaddr) (transport ma.Multiaddr, id ID)

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 Uses

func (id ID) ExtractPublicKey() (ic.PubKey, error)

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) Loggable Uses

func (id ID) Loggable() map[string]interface{}

Loggable returns a pretty peer ID string in loggable JSON format.

func (ID) Marshal Uses

func (id ID) Marshal() ([]byte, error)

func (ID) MarshalBinary Uses

func (id ID) MarshalBinary() ([]byte, error)

BinaryMarshal returns the byte representation of the peer ID.

func (ID) MarshalJSON Uses

func (id ID) MarshalJSON() ([]byte, error)

func (ID) MarshalText Uses

func (id ID) MarshalText() ([]byte, error)

TextMarshal returns the text encoding of the ID.

func (ID) MarshalTo Uses

func (id ID) MarshalTo(data []byte) (n int, err error)

func (ID) MatchesPrivateKey Uses

func (id ID) MatchesPrivateKey(sk ic.PrivKey) bool

MatchesPrivateKey tests whether this ID was derived from the secret key sk.

func (ID) MatchesPublicKey Uses

func (id ID) MatchesPublicKey(pk ic.PubKey) bool

MatchesPublicKey tests whether this ID was derived from the public key pk.

func (ID) Pretty Uses

func (id ID) Pretty() string

Pretty returns a base58-encoded string representation of the ID.

func (ID) ShortString Uses

func (id ID) ShortString() string

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 Uses

func (id ID) Size() int

Implements Gogo's proto.Sizer, but we omit the compile-time assertion to avoid introducing a hard dependency on gogo.

func (ID) String Uses

func (id ID) String() string

func (*ID) Unmarshal Uses

func (id *ID) Unmarshal(data []byte) (err error)

func (*ID) UnmarshalBinary Uses

func (id *ID) UnmarshalBinary(data []byte) error

BinaryUnmarshal sets the ID from its binary representation.

func (*ID) UnmarshalJSON Uses

func (id *ID) UnmarshalJSON(data []byte) (err error)

func (*ID) UnmarshalText Uses

func (id *ID) UnmarshalText(data []byte) error

TextUnmarshal restores the ID from its text encoding.

func (ID) Validate Uses

func (id ID) Validate() error

Validate checks if ID is empty or not.

type IDSlice Uses

type IDSlice []ID

IDSlice for sorting peers

func (IDSlice) Len Uses

func (es IDSlice) Len() int

func (IDSlice) Less Uses

func (es IDSlice) Less(i, j int) bool

func (IDSlice) Swap Uses

func (es IDSlice) Swap(i, j int)

type Set Uses

type Set struct {
    // contains filtered or unexported fields
}

PeerSet is a threadsafe set of peers

func NewLimitedSet Uses

func NewLimitedSet(size int) *Set

func NewSet Uses

func NewSet() *Set

func (*Set) Add Uses

func (ps *Set) Add(p ID)

func (*Set) Contains Uses

func (ps *Set) Contains(p ID) bool

func (*Set) Peers Uses

func (ps *Set) Peers() []ID

func (*Set) Size Uses

func (ps *Set) Size() int

func (*Set) TryAdd Uses

func (ps *Set) TryAdd(p ID) bool

TryAdd Attempts to add the given peer into the set. This operation can fail for one of two reasons: 1) The given peer is already in the set 2) The number of peers in the set is equal to size

Package peer imports 10 packages (graph) and is imported by 395 packages. Updated 2019-08-28. Refresh now. Tools for package owners.