Skip to main content

Module protocol

Module protocol 

Source
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§

DataChunk
Quoted data chunk delivered after payment negotiation.
DataPayment
Payment message body for chunk-by-chunk settlement.
DataPaymentAck
Payment acknowledgement for quoted chunk settlement.
DataQuoteRequest
Quote request message body
DataQuoteResponse
Quote response message body
DataRequest
Data request message body
DataResponse
Data response message body
PeerHints
Private signaling hints exchanged over an established peer link.
PubsubFrame
Pubsub data frame delivered over mesh peer links.
PubsubInterest
Pubsub interest advertisement.
PubsubInventory
Pubsub inventory announcement for inventory-first delivery.
PubsubWant
Pubsub want request for inventory-first delivery.

Enums§

DataMessage
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