Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 1.78 KB

pip-001.rst

File metadata and controls

53 lines (40 loc) · 1.78 KB

PIP-1: Messaging

Table of Contents

This document will outline the protocol DDRP nodes uses to exchange messages on the wire. Its inspiration is Lightning's BOLT-1. The protocol is transport- agnostic, though we will describe the canonical TCP transport layer in a later PIP.

All data fields are unsigned big-endian unless otherwise specified.

Message fields are encoded and decoded in-order according to their type and the message's schema. A message's structure must be known beforehand in order to encode or decode it - hence the addition of the type field in the message envelope.

The below list outlines how primitives types are encoded:

  1. bool: Encoded as 0x00 or 0x01 if the value is true or false, respectively.
  2. uint8: Encoded as a single byte in the range 0x00-0xff.
  3. uint16: Encoded as two big-endian bytes in the range 0x0000-0xffff.
  4. uint32: Encoded as four big-endian bytes in the range 0x00000000-0xffffffff
  5. uint64: Encoded as eight big-endian bytes in the range 0x0000000000000000-0xffffffffffffffff.
  6. string: Encoded as a UTF-8 []byte.
  7. [N]T: Encoded as the concatenation of the encoding of T.
  8. []T: Encoded as a binary.Uvarint length prefix followed by the concatenation of the encoding of T.

There are also a set of DDRP-specific well-known types with special encodings:

  1. time.Time: Encoded as a uint32 UNIX timestamp.
  2. crypto.Signature: Encoded as [65]byte.
  3. crypto.Hash: Encoded as [32]byte.
  4. net.IP: Encoded as [16]byte. Note that while the encoding scheme supports IPv6, DDRP does not currently support IPv6.