Expand description
Wire protocol for hashtree WebRTC data exchange
Compatible with hashtree-ts wire format:
- Request: [0x00][msgpack: {h: bytes32, htl?: u8, q?: u64}]
- Response: [0x01][msgpack: {h: bytes32, d: bytes, i?: u32, n?: u32}]
- QuoteRequest: [0x02][msgpack: {h: bytes32, p: u64, t: u32, m?: string}]
- QuoteResponse: [0x03][msgpack: {h: bytes32, a: bool, q?: u64, p?: u64, t?: u32, m?: string}]
- Payment: [0x04][msgpack: {h: bytes32, q: u64, c: u32, p: u64, m?: string, tok: string}]
- PaymentAck: [0x05][msgpack: {h: bytes32, q: u64, c: u32, a: bool, e?: string}]
- Chunk: [0x06][msgpack: {h: bytes32, q: u64, c: u32, n: u32, p: u64, d: bytes}]
- PeerHints: [0x07][msgpack: {u: [WebRTC signaling endpoint URLs]}]
- PubsubInterest: [0x08][msgpack: {s: stream, sub: subscriber peer id, q: seq, a: active, htl?: u8}]
- PubsubFrame: [0x09][msgpack: {s: stream, q: seq, o: origin peer id, htl?: u8, d: bytes}]
- PubsubInventory:[0x0a][msgpack: {s: stream, q: seq, o: origin peer id, b: bytes, htl?: u8}]
- PubsubWant: [0x0b][msgpack: {s: stream, q: seq, o: origin peer id}]
Fragmented responses include i (index) and n (total), unfragmented omit them.
Structs§
- Data
Chunk - Quoted data chunk delivered after payment negotiation.
- Data
Payment - Payment message body for chunk-by-chunk settlement.
- Data
Payment Ack - Payment acknowledgement for quoted chunk settlement.
- Data
Quote Request - Quote request message body
- Data
Quote Response - Quote response message body
- Data
Request - Data request message body
- Data
Response - Data response message body
- Peer
Hints - Private signaling hints exchanged over an established peer link.
- Pubsub
Frame - Pubsub data frame delivered over mesh peer links.
- Pubsub
Interest - Pubsub interest advertisement.
- Pubsub
Inventory - Pubsub inventory announcement for inventory-first delivery.
- Pubsub
Want - Pubsub want request for inventory-first delivery.
Enums§
- Data
Message - Parsed data message
Constants§
- FRAGMENT_
SIZE - Fragment size for large data (32KB - safe limit for WebRTC)
- MSG_
TYPE_ CHUNK - MSG_
TYPE_ PAYMENT - MSG_
TYPE_ PAYMENT_ ACK - MSG_
TYPE_ PEER_ HINTS - MSG_
TYPE_ PUBSUB_ FRAME - MSG_
TYPE_ PUBSUB_ INTEREST - MSG_
TYPE_ PUBSUB_ INVENTORY - MSG_
TYPE_ PUBSUB_ WANT - MSG_
TYPE_ QUOTE_ REQUEST - MSG_
TYPE_ QUOTE_ RESPONSE - MSG_
TYPE_ REQUEST - Message type bytes (prefix before MessagePack body)
- MSG_
TYPE_ RESPONSE
Functions§
- bytes_
to_ hash - Convert bytes to Hash
- create_
fragment_ response - Create a fragmented response
- create_
pubsub_ frame - Create a pubsub data frame.
- create_
pubsub_ interest - Create a pubsub interest message.
- create_
pubsub_ inventory - Create a pubsub inventory announcement.
- create_
pubsub_ want - Create a pubsub want request.
- create_
quote_ request - Create a quote request.
- create_
quote_ response_ available - Create an accepted quote response.
- create_
quote_ response_ unavailable - Create a declined quote response.
- create_
request - Create a request
- create_
request_ with_ quote - Create a request that references a previously accepted quote.
- create_
response - Create an unfragmented response
- encode_
chunk - Encode a quoted data chunk to wire format.
- encode_
payment - Encode a payment message to wire format.
- encode_
payment_ ack - Encode a payment acknowledgement to wire format.
- encode_
peer_ hints - Encode private peer hints to wire format.
- encode_
pubsub_ frame - Encode a pubsub data frame to wire format.
- encode_
pubsub_ interest - Encode a pubsub interest to wire format.
- encode_
pubsub_ inventory - Encode a pubsub inventory announcement to wire format.
- encode_
pubsub_ want - Encode a pubsub want request to wire format.
- encode_
quote_ request - Encode a quote request message to wire format.
- encode_
quote_ response - Encode a quote response message to wire format.
- encode_
request - Encode a request message to wire format Uses named/map encoding for compatibility with hashtree-ts and to support optional fields
- encode_
response - Encode a response message to wire format Uses named/map encoding for compatibility with hashtree-ts and to support optional fields
- hash_
to_ bytes - Convert Hash to bytes
- hash_
to_ key - Convert hash bytes to hex string for use as map key
- is_
fragmented - Check if a response is fragmented
- parse_
message - Parse a wire format message