peer

package
Version: v0.20.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2022 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 5 Imported by: 2,097

Documentation

Overview

Deprecated: This package has moved into go-libp2p as a sub-package: github.com/libp2p/go-libp2p/core/peer.

Package peer implements an object used to represent peers in the libp2p network.

Index

Constants

View Source
const PeerRecordEnvelopeDomain = peer.PeerRecordEnvelopeDomain

PeerRecordEnvelopeDomain is the domain string used for peer records contained in a Envelope. Deprecated: use github.com/libp2p/go-libp2p/core/peer.PeerRecordEnvelopeDomain instead

Variables

View Source
var (
	// ErrEmptyPeerID is an error for empty peer ID.
	// Deprecated: use github.com/libp2p/go-libp2p/core/peer.ErrEmptyPeerID instead
	ErrEmptyPeerID = peer.ErrEmptyPeerID
	// ErrNoPublicKey is an error for peer IDs that don't embed public keys
	// Deprecated: use github.com/libp2p/go-libp2p/core/peer.ErrNoPublicKey instead
	ErrNoPublicKey = peer.ErrNoPublicKey
)
View Source
var AdvancedEnableInlining = peer.AdvancedEnableInlining

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. Deprecated: use github.com/libp2p/go-libp2p/core/peer.AdvancedEnableInlining instead

View Source
var ErrInvalidAddr = peer.ErrInvalidAddr

Deprecated: use github.com/libp2p/go-libp2p/core/peer.ErrInvalidAddr instead

View Source
var PeerRecordEnvelopePayloadType = peer.PeerRecordEnvelopePayloadType

PeerRecordEnvelopePayloadType is the type hint used to identify peer records in a Envelope. Defined in https://github.com/multiformats/multicodec/blob/master/table.csv with name "libp2p-peer-record". Deprecated: use github.com/libp2p/go-libp2p/core/peer.PeerRecordEnvelopePayloadType instead

Functions

func AddrInfoToP2pAddrs

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

AddrInfoToP2pAddrs converts an AddrInfo to a list of Multiaddrs. Deprecated: use github.com/libp2p/go-libp2p/core/peer.AddrInfoToP2pAddrs instead

func Encode deprecated added in v0.3.0

func Encode(id ID) string

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 github.com/libp2p/go-libp2p/core/peer.Encode instead

func TimestampSeq added in v0.4.0

func TimestampSeq() uint64

TimestampSeq is a helper to generate a timestamp-based sequence number for a PeerRecord. Deprecated: use github.com/libp2p/go-libp2p/core/peer.TimestampSeq instead

func ToCid added in v0.3.0

func ToCid(id ID) cid.Cid

ToCid encodes a peer ID as a CID of the public key.

If the peer ID is invalid (e.g., empty), this will return the empty CID. Deprecated: use github.com/libp2p/go-libp2p/core/peer.ToCid instead

Types

type AddrInfo

type AddrInfo = peer.AddrInfo

AddrInfo is a small struct used to pass around a peer with a set of addresses (and later, keys?). Deprecated: use github.com/libp2p/go-libp2p/core/peer.AddrInfo instead

func AddrInfoFromP2pAddr

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

AddrInfoFromP2pAddr converts a Multiaddr to an AddrInfo. Deprecated: use github.com/libp2p/go-libp2p/core/peer.AddrInfoFromP2pAddr instead

func AddrInfoFromString added in v0.8.6

func AddrInfoFromString(s string) (*AddrInfo, error)

AddrInfoFromString builds an AddrInfo from the string representation of a Multiaddr Deprecated: use github.com/libp2p/go-libp2p/core/peer.AddrInfoFromString instead

func AddrInfosFromP2pAddrs

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

AddrInfosFromP2pAddrs converts a set of Multiaddrs to a set of AddrInfos. Deprecated: use github.com/libp2p/go-libp2p/core/peer.AddrInfosFromP2pAddrs instead

type ID

type ID = peer.ID

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. Deprecated: use github.com/libp2p/go-libp2p/core/peer.ID instead

func AddrInfosToIDs added in v0.9.0

func AddrInfosToIDs(pis []AddrInfo) []ID

AddrInfosToIDs extracts the peer IDs from the passed AddrInfos and returns them in-order. Deprecated: use github.com/libp2p/go-libp2p/core/peer.AddrInfosToIDs instead

func Decode added in v0.3.0

func Decode(s string) (ID, error)

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). Deprecated: use github.com/libp2p/go-libp2p/core/peer.Decode instead

func FromCid added in v0.3.0

func FromCid(c cid.Cid) (ID, error)

FromCid converts a CID to a peer ID, if possible. Deprecated: use github.com/libp2p/go-libp2p/core/peer.FromCid instead

func IDFromBytes

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. Deprecated: use github.com/libp2p/go-libp2p/core/peer.IDFromBytes instead

func IDFromPrivateKey

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

IDFromPrivateKey returns the Peer ID corresponding to the secret key sk. Deprecated: use github.com/libp2p/go-libp2p/core/peer.IDFromPrivateKey instead

func IDFromPublicKey

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

IDFromPublicKey returns the Peer ID corresponding to the public key pk. Deprecated: use github.com/libp2p/go-libp2p/core/peer.IDFromPublicKey instead

func SplitAddr

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. Deprecated: use github.com/libp2p/go-libp2p/core/peer.SplitAddr instead

type IDSlice

type IDSlice = peer.IDSlice

IDSlice for sorting peers. Deprecated: use github.com/libp2p/go-libp2p/core/peer.IDSlice instead

type PeerRecord deprecated added in v0.4.0

type PeerRecord = peer.PeerRecord

PeerRecord contains information that is broadly useful to share with other peers, either through a direct exchange (as in the libp2p identify protocol), or through a Peer Routing provider, such as a DHT.

Currently, a PeerRecord contains the public listen addresses for a peer, but this is expected to expand to include other information in the future.

PeerRecords are ordered in time by their Seq field. Newer PeerRecords must have greater Seq values than older records. The NewPeerRecord function will create a PeerRecord with a timestamp-based Seq value. The other PeerRecord fields should be set by the caller:

rec := peer.NewPeerRecord()
rec.PeerID = aPeerID
rec.Addrs = someAddrs

Alternatively, you can construct a PeerRecord struct directly and use the TimestampSeq helper to set the Seq field:

rec := peer.PeerRecord{PeerID: aPeerID, Addrs: someAddrs, Seq: peer.TimestampSeq()}

Failing to set the Seq field will not result in an error, however, a PeerRecord with a Seq value of zero may be ignored or rejected by other peers.

PeerRecords are intended to be shared with other peers inside a signed routing.Envelope, and PeerRecord implements the routing.Record interface to facilitate this.

To share a PeerRecord, first call Sign to wrap the record in a Envelope and sign it with the local peer's private key:

rec := &PeerRecord{PeerID: myPeerId, Addrs: myAddrs}
envelope, err := rec.Sign(myPrivateKey)

The resulting record.Envelope can be marshalled to a []byte and shared publicly. As a convenience, the MarshalSigned method will produce the Envelope and marshal it to a []byte in one go:

rec := &PeerRecord{PeerID: myPeerId, Addrs: myAddrs}
recordBytes, err := rec.MarshalSigned(myPrivateKey)

To validate and unmarshal a signed PeerRecord from a remote peer, "consume" the containing envelope, which will return both the routing.Envelope and the inner Record. The Record must be cast to a PeerRecord pointer before use:

envelope, untypedRecord, err := ConsumeEnvelope(envelopeBytes, PeerRecordEnvelopeDomain)
if err != nil {
  handleError(err)
  return
}
peerRec := untypedRecord.(*PeerRecord)

Deprecated: use github.com/libp2p/go-libp2p/core/peer.PeerRecord instead

func NewPeerRecord added in v0.4.0

func NewPeerRecord() *PeerRecord

NewPeerRecord returns a PeerRecord with a timestamp-based sequence number. The returned record is otherwise empty and should be populated by the caller. Deprecated: use github.com/libp2p/go-libp2p/core/peer.NewPeerRecord instead

func PeerRecordFromAddrInfo added in v0.4.0

func PeerRecordFromAddrInfo(info AddrInfo) *PeerRecord

PeerRecordFromAddrInfo creates a PeerRecord from an AddrInfo struct. The returned record will have a timestamp-based sequence number. Deprecated: use github.com/libp2p/go-libp2p/core/peer.PeerRecordFromAddrInfo instead

func PeerRecordFromProtobuf added in v0.5.2

func PeerRecordFromProtobuf(msg *pb.PeerRecord) (*PeerRecord, error)

PeerRecordFromProtobuf creates a PeerRecord from a protobuf PeerRecord struct. Deprecated: use github.com/libp2p/go-libp2p/core/peer.PeerRecordFromProtobuf instead

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL