| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.Crypto.PeerRecord
Description
Peer routing records (RFC 0003).
A PeerRecord is a self-certified statement of a peer's dialable addresses, distributed inside a LibP2P.Crypto.SignedEnvelope (RFC 0002). Consumers verify the envelope signature and that the signing key derives the peer id named in the record, giving third-party-relayable address information that cannot be forged.
Wire format (go-libp2p corepeerpb/peer_record.proto):
message PeerRecord {
message AddressInfo { bytes multiaddr = 1; }
bytes peer_id = 1;
uint64 seq = 2;
repeated AddressInfo addresses = 3;
}Envelope parameters (go-libp2p corepeerrecord.go — note the RFC
0003 draft text uses different strings; the deployed go-libp2p values
are authoritative for interop):
- domain:
libp2p-peer-record - payload type: the raw multicodec bytes
0x03 0x01(multicodec table namelibp2p-peer-record)
Synopsis
- data PeerRecord = PeerRecord {
- prPeerId :: !ByteString
- prSeq :: !Word64
- prAddresses :: ![ByteString]
- timestampSeq :: IO Word64
- encodePeerRecord :: PeerRecord -> ByteString
- decodePeerRecord :: ByteString -> Either String PeerRecord
- peerRecordEnvelopeDomain :: ByteString
- peerRecordEnvelopePayloadType :: ByteString
- sealPeerRecord :: KeyPair -> PeerRecord -> Either String SignedEnvelope
- openPeerRecordEnvelope :: ByteString -> Either String (SignedEnvelope, PeerRecord)
Record type
data PeerRecord Source #
A routing record: which addresses a peer claims to be reachable at.
Constructors
| PeerRecord | |
Fields
| |
Instances
| Show PeerRecord Source # | |
Defined in LibP2P.Crypto.PeerRecord Methods showsPrec :: Int -> PeerRecord -> ShowS # show :: PeerRecord -> String # showList :: [PeerRecord] -> ShowS # | |
| Eq PeerRecord Source # | |
Defined in LibP2P.Crypto.PeerRecord | |
timestampSeq :: IO Word64 Source #
A timestamp-based, strictly monotonic sequence number: the current
Unix time in nanoseconds, bumped past the previous value if the clock
has not advanced (mirrors go-libp2p peer.TimestampSeq).
Protobuf codec
encodePeerRecord :: PeerRecord -> ByteString Source #
Encode a PeerRecord to protobuf wire format. Proto3 default values (empty peer_id, zero seq) are omitted, matching go-libp2p's encoder.
decodePeerRecord :: ByteString -> Either String PeerRecord Source #
Decode a PeerRecord from protobuf wire format.
Envelope integration
peerRecordEnvelopeDomain :: ByteString Source #
Domain separation string for peer-record envelopes
(go-libp2p PeerRecordEnvelopeDomain).
peerRecordEnvelopePayloadType :: ByteString Source #
Envelope payload type: the libp2p-peer-record multicodec bytes
(go-libp2p PeerRecordEnvelopePayloadType).
sealPeerRecord :: KeyPair -> PeerRecord -> Either String SignedEnvelope Source #
Seal a PeerRecord into a SignedEnvelope with the given identity key. The caller is responsible for the record's peer id matching the key (a mismatched record still seals, but no verifier will accept it).
openPeerRecordEnvelope :: ByteString -> Either String (SignedEnvelope, PeerRecord) Source #
Open an encoded peer-record envelope: decode it, check the payload type, verify the signature under the peer-record domain, decode the record, and require that the envelope's key derives the peer id the record claims. Any failure rejects the envelope.