Skip to content

Core format

anire edited this page May 12, 2020 · 11 revisions

This is a description of the transit-independent, extensible PearDrop protocol.

Packet types

All offsets are in big endian, and offsets and lengths are in bytes. Multi-byte payloads are to be coded in big endian.

In bitfields, offsets are in little endian, and offsets and lengths are in bits.

Advertisement packet

Maximum length: 128 bytes

From: sender

To: advertise

Offset Length Type Name Description
0x0 0x1 u8 exts_len Number of extensions this packet contains.
0x1 max 0x7c [Extension; ext_len] exts The extensions in this packet. Maximum 125 bytes total.
0x20 0x1 u8 name_len Length of the name of the advertised file. Maximum 125 bytes.
0x21 name_len &str name Name of the advertised file. Maximum length of 125 bytes.
0x49 0x1 u8 mt_len Length of the mimetype of the advertised file. Maximum 125 bytes.
0x4a mt_len &str mimetype MIME type of the advertised file. Maximum length of 125 bytes.

AdFlags bitfield

Reserved for extensions.

Sender packet

Maximum length: 4096 bytes

From: sender

To: single receiver

Offset Length Type Name Description
0x0 0x1 u8 ext_len Number of extensions this packet contains.
0x1 max 0xff7 [Extension; ext_len] exts The extensions in this packet. Maximum 4087 bytes total.
0xff7 0x8 u64 len Length of the data.

Receiver acknowledge packet

Maximum length: 128 bytes

From: receiver

To: sender

Offset Length Type Name Description
0x0 4 bits ReceiverAcknowledgeType type Type of the packet being acknowledged.
4 bits 4 bits u4 exts_len Number of extensions. Maximum of 32 entries.
0x1 max 0x1f [Extension; ext_len] exts The extensions in this packet. Maximum 31 bytes total.

Data packet

No maximum length. This should be the length specified in the sender packet.

This should be sent over a reliable stream protocol (like TCP), or properly chunked otherwise.

This packet simply consists of the data and nothing else.

Common types

Extension trait

Reserved for extensions. All sub-structs must have these fields at the start:

Offset Length Type Name Description
0x0 0x1 ExtType type Type of this extension.
0x1 0x1 u8 len Length of this entire structure.

ExtType enum

Must fit in a u8. Reserved for extensions.

Handshake

Sender     Receiver(s)     Receiver
   ------------->
   advertisement

   <----------------------------
   acknowledge: advertisement

   <--------------------------->
   (optional) extension pre-handshakes

   ---------------------------->
   sender packet

   <----------------------------
   acknowledge: sender

   <--------------------------->
   (optional) extension post-handshakes

   ---------------------------->
   data packet

   <----------------------------
   acknowledge: data

   transfer complete :)
Clone this wiki locally