Protocol Specification - rubdos/libap2p GitHub Wiki
Message format
Communication through the libap2p protocol goes message wise. Node A can send any type of message at any time (for now) to node B. Idem vice versa. A message consists of a header (8 bytes) and content (variable length). They are sent directly after eachother. After message construction (see Message Data), the total length is specified and the flags are determined. The header is sent on a TCP port (usually 120xx) and messagedata follows.
Message Header
Before a message is sent, a header is constructed and sent. A header contains 8 bytes:
4 bytes: an unsigned 32 bits integer, the message length.
1 byte : flags 1
1 byte : flags 2
1 byte : encryption flags
1 byte : compression flags
Message Length
The message length specifies how many, exactly, bytes will be sent in the message data. An unsigned 32-bit integer gives us 4.295 GB (gigabytes) (exactly 4.294.967.294 bytes) of max message length. Compression included ofcourse.
Flags
The flags don't have a use yet. I said YET. It's for being extensible. Library implementation should forget about the flags right now. One could use it for storing protocol version or so, but not yet in the protocol. Stable libap2p version will specify it.
Encryption flags
1 byte: 0000 0000 (0): No encryption
0000 0001 (1): RSA encryption. This will use the key previously send in the HELLO message.
Compression flags
1 byte: 0000 0000 (0): No compression
0000 0001 (1): GZIP compression
Message data
Data consists of a XML file. If compression is specified, it is applied around the whole XML. If encryption is specified, it is around the whole compressed xml.