| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.Discovery.Rendezvous.Message
Contents
Description
Rendezvous protocol messages (specsrendezvousREADME.md).
Wire format (specsrendezvousREADME.md §Protobuf, proto2):
message Message {
enum MessageType { REGISTER = 0; REGISTER_RESPONSE = 1;
UNREGISTER = 2; DISCOVER = 3; DISCOVER_RESPONSE = 4; }
enum ResponseStatus { OK = 0; E_INVALID_NAMESPACE = 100;
E_INVALID_SIGNED_PEER_RECORD = 101; E_INVALID_TTL = 102;
E_INVALID_COOKIE = 103; E_NOT_AUTHORIZED = 200;
E_INTERNAL_ERROR = 300; E_UNAVAILABLE = 400; }
message Register { optional string ns = 1; optional bytes
signedPeerRecord = 2; optional uint64 ttl = 3; }
message RegisterResponse{ optional ResponseStatus status = 1;
optional string statusText = 2;
optional uint64 ttl = 3; }
message Unregister { optional string ns = 1; }
message Discover { optional string ns = 1; optional uint64 limit = 2;
optional bytes cookie = 3; }
message DiscoverResponse{ repeated Register registrations = 1;
optional bytes cookie = 2;
optional ResponseStatus status = 3;
optional string statusText = 4; }
optional MessageType type = 1;
optional Register register = 2; ... DiscoverResponse discoverResponse = 6;
}Uses proto3-wire for protobuf encoding/decoding. On the wire the message is varint-length-delimited; the framing lives in LibP2P.Discovery.Rendezvous (encodeFramedMessage / readFramedMessage).
Synopsis
- data RendezvousMessage
- = RMRegister !Text !ByteString !(Maybe Word64)
- | RMRegisterResponse !ResponseStatus !(Maybe Text) !(Maybe Word64)
- | RMUnregister !Text
- | RMDiscover !(Maybe Text) !DiscoverLimit !ByteString
- | RMDiscoverResponse ![RegistrationInfo] !ByteString !ResponseStatus !(Maybe Text)
- data RegistrationInfo = RegistrationInfo {
- riNamespace :: !Text
- riPeerRecord :: !ByteString
- riTTL :: !Word64
- data ResponseStatus
- data DiscoverLimit
- encodeRendezvousMessage :: RendezvousMessage -> ByteString
- decodeRendezvousMessage :: ByteString -> Either ParseError RendezvousMessage
- maxRendezvousMessageSize :: Int
Message types
data RendezvousMessage Source #
A rendezvous message (specsrendezvousREADME.md §Protobuf).
The five wire message types are separate constructors; the envelope
type discriminator (field 1) is checked on decode and set on
encode, so a decoded message never disagrees with its type field.
Constructors
| RMRegister !Text !ByteString !(Maybe Word64) | A |
| RMRegisterResponse !ResponseStatus !(Maybe Text) !(Maybe Word64) | A |
| RMUnregister !Text | An |
| RMDiscover !(Maybe Text) !DiscoverLimit !ByteString | A |
| RMDiscoverResponse ![RegistrationInfo] !ByteString !ResponseStatus !(Maybe Text) | A |
Instances
| Show RendezvousMessage Source # | |
Defined in LibP2P.Discovery.Rendezvous.Message Methods showsPrec :: Int -> RendezvousMessage -> ShowS # show :: RendezvousMessage -> String # showList :: [RendezvousMessage] -> ShowS # | |
| Eq RendezvousMessage Source # | |
Defined in LibP2P.Discovery.Rendezvous.Message Methods (==) :: RendezvousMessage -> RendezvousMessage -> Bool # (/=) :: RendezvousMessage -> RendezvousMessage -> Bool # | |
data RegistrationInfo Source #
One registration as carried in a DISCOVER response: the namespace it was registered under, its signed peer record (RFC 0003 envelope), and the TTL it was registered with.
Constructors
| RegistrationInfo | |
Fields
| |
Instances
| Show RegistrationInfo Source # | |
Defined in LibP2P.Discovery.Rendezvous.Message Methods showsPrec :: Int -> RegistrationInfo -> ShowS # show :: RegistrationInfo -> String # showList :: [RegistrationInfo] -> ShowS # | |
| Eq RegistrationInfo Source # | |
Defined in LibP2P.Discovery.Rendezvous.Message Methods (==) :: RegistrationInfo -> RegistrationInfo -> Bool # (/=) :: RegistrationInfo -> RegistrationInfo -> Bool # | |
data ResponseStatus Source #
Response status codes (specsrendezvousREADME.md §Protobuf).
Constructors
| StatusOK | |
| StatusInvalidNamespace | |
| StatusInvalidSignedPeerRecord | |
| StatusInvalidTTL | |
| StatusInvalidCookie | |
| StatusNotAuthorized | |
| StatusInternalError | |
| StatusUnavailable | |
| StatusUnknown !Word64 | Unrecognized code; preserved for forward compat |
Instances
| Show ResponseStatus Source # | |
Defined in LibP2P.Discovery.Rendezvous.Message Methods showsPrec :: Int -> ResponseStatus -> ShowS # show :: ResponseStatus -> String # showList :: [ResponseStatus] -> ShowS # | |
| Eq ResponseStatus Source # | |
Defined in LibP2P.Discovery.Rendezvous.Message Methods (==) :: ResponseStatus -> ResponseStatus -> Bool # (/=) :: ResponseStatus -> ResponseStatus -> Bool # | |
data DiscoverLimit Source #
Discovery limit: absent (rendezvous point default applies) or an explicit maximum (possibly 0). Both are meaningful on the wire: a rendezvous point with zero registrations to hand out still answers OK with an empty list, so an absent limit must not be conflated with "zero".
Constructors
| LimitDefault | No limit given; rendezvous point applies its default |
| LimitExact !Word64 | Explicit limit, possibly 0 |
Instances
| Show DiscoverLimit Source # | |
Defined in LibP2P.Discovery.Rendezvous.Message Methods showsPrec :: Int -> DiscoverLimit -> ShowS # show :: DiscoverLimit -> String # showList :: [DiscoverLimit] -> ShowS # | |
| Eq DiscoverLimit Source # | |
Defined in LibP2P.Discovery.Rendezvous.Message Methods (==) :: DiscoverLimit -> DiscoverLimit -> Bool # (/=) :: DiscoverLimit -> DiscoverLimit -> Bool # | |
Codec
encodeRendezvousMessage :: RendezvousMessage -> ByteString Source #
Encode a rendezvous message to protobuf wire format. The message type (field 1) is always written; exactly one submessage (fields 2-6) is written, matching the discriminator. Submessage fields that coincide with a proto3 default (empty bytes, status OK code 0) are written explicitly where the spec's response semantics need them (status, ttl), matching go-libp2p's encoder, and omitted elsewhere.
decodeRendezvousMessage :: ByteString -> Either ParseError RendezvousMessage Source #
Decode a rendezvous message from protobuf wire format.
The type discriminator (field 1) selects which submessage shape is parsed; a message whose discriminator names no known type is a decode error rather than a partial guess.
maxRendezvousMessageSize :: Int Source #
Maximum rendezvous message size: 1 MiB. Signed peer records are a few hundred bytes; registrations are bounded by the discovery limits (1000 per query by recommendation), so 1 MiB is far above anything legitimate. Rejecting larger messages before reading the payload keeps a hostile peer from pinning memory.