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:
bool
: Encoded as 0x00 or 0x01 if the value is true or false, respectively.uint8
: Encoded as a single byte in the range 0x00-0xff.uint16
: Encoded as two big-endian bytes in the range 0x0000-0xffff.uint32
: Encoded as four big-endian bytes in the range 0x00000000-0xffffffffuint64
: Encoded as eight big-endian bytes in the range 0x0000000000000000-0xffffffffffffffff.string
: Encoded as a UTF-8 []byte.[N]T
: Encoded as the concatenation of the encoding of T.[]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:
time.Time
: Encoded as auint32
UNIX timestamp.crypto.Signature
: Encoded as[65]byte
.crypto.Hash
: Encoded as[32]byte
.net.IP
: Encoded as[16]byte
. Note that while the encoding scheme supports IPv6, DDRP does not currently support IPv6.