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
- Variables
- func AddrInfoToP2pAddrs(pi *AddrInfo) ([]ma.Multiaddr, error)
- func Encode(id ID) stringdeprecated
- func TimestampSeq() uint64
- func ToCid(id ID) cid.Cid
- type AddrInfo
- type ID
- func AddrInfosToIDs(pis []AddrInfo) []ID
- func Decode(s string) (ID, error)
- func FromCid(c cid.Cid) (ID, error)
- func IDFromBytes(b []byte) (ID, error)
- func IDFromPrivateKey(sk ic.PrivKey) (ID, error)
- func IDFromPublicKey(pk ic.PubKey) (ID, error)
- func SplitAddr(m ma.Multiaddr) (transport ma.Multiaddr, id ID)
- type IDSlice
- type PeerRecorddeprecated
Constants ¶
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 ¶
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 )
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
var ErrInvalidAddr = peer.ErrInvalidAddr
Deprecated: use github.com/libp2p/go-libp2p/core/peer.ErrInvalidAddr instead
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 ¶
AddrInfoToP2pAddrs converts an AddrInfo to a list of Multiaddrs. Deprecated: use github.com/libp2p/go-libp2p/core/peer.AddrInfoToP2pAddrs 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
Types ¶
type 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 ¶
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
AddrInfoFromString builds an AddrInfo from the string representation of a Multiaddr Deprecated: use github.com/libp2p/go-libp2p/core/peer.AddrInfoFromString instead
type 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
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
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
FromCid converts a CID to a peer ID, if possible. Deprecated: use github.com/libp2p/go-libp2p/core/peer.FromCid instead
func IDFromBytes ¶
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 ¶
IDFromPrivateKey returns the Peer ID corresponding to the secret key sk. Deprecated: use github.com/libp2p/go-libp2p/core/peer.IDFromPrivateKey instead
func IDFromPublicKey ¶
IDFromPublicKey returns the Peer ID corresponding to the public key pk. Deprecated: use github.com/libp2p/go-libp2p/core/peer.IDFromPublicKey instead
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. Deprecated: use github.com/libp2p/go-libp2p/core/peer.SplitAddr instead
type 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