### Plain packet ¶

Plain packet contains either the whole file, or file request (freq), or transition packet or exec message. It is called "plain", because it contains plaintext, but plain packets would never be stored on your hard drive.

                HEADER
    +--------------------------------------+--...---+
    | MAGIC | TYPE | NICE | PATHLEN | PATH | PAYLOAD|
    +--------------------------------------+--...---+

| XDR type | Value
--- | --- | ---
Magic number | 8-byte, fixed length opaque data | `N N C P P 0x00 0x00 0x03`

Payload type

unsigned integer

0. file (file transmission)
1. freq (file request)
2. exec (compressed exec)
3. trns (transition)
4. exec-fat (uncompressed exec)
5. area (multicast area message)
6. ack (receipt acknowledgement)

Niceness | unsigned integer | 1-255, preferred packet niceness level
Path length | unsigned integer | actual length of path field’s payload

Path

255 byte, fixed length opaque data

Depending on packet’s type, path holds:

- UTF-8 encoded destination path for file transfer
- UTF-8 encoded source path for file request
- UTF-8 encoded, zero byte separated, exec’s arguments
- Node’s id the transition packet must be relayed on
- Multicast area’s id
- Packet’s id (its Merkle Tree Hashing hash)

Path has fixed size because of hiding its actual length – it is valuable metadata. Payload is appended to the header – it is not stored as XDR field, because XDR has no ability to pass more than 4 GiB of opaque data. Moreover most XDR libraries store fields in the memory in practice.

Depending on the packet’s type, payload could store:

- File contents
- Destination path for freq
- Optionally Zstandard compressed exec body
- Whole encrypted packet we need to relay on
- Multicast area message wrap with another encrypted packet inside
- Nothing, if it is acknowledgement packet

Also depending on packet’s type, niceness level means:

- Preferable niceness level for files sent by freq
- `$NNCP_NICE` variable’s value passed during CfgExec invocation.

So plain packets can hold following paths and payloads:

`file`

        +--------------- PATH ---------------+   +---- PAYLOAD ---+
       /                                      \ /                  \
      +----------------------------------------+---------------...--+
      | FILENAME  | 0x00 ... variable ... 0x00 |    FILE CONTENTS   |
      +----------------------------------------+---------------...--+
       \         /
         PATHLEN

`freq`

        +--------------- PATH ---------------+   +---- PAYLOAD ---+
       /                                      \ /                  \
      +----------------------------------------+---------------...--+
      | FILENAME  | 0x00 ... variable ... 0x00 |       FILENAME     |
      +----------------------------------------+---------------...--+
       \         /
         PATHLEN

`exec`

        +------------------------- PATH ----------------------------+   +---- PAYLOAD ---+
       /                                                             \ /                  \
      +---------------------------------------------------------------+---------------...--+
      |  HANDLE 0x00 | ARG0 0x00 ARG1 ...| 0x00 ... variable ... 0x00 |     ZSTD DATA      |
      +---------------------------------------------------------------+---------------...--+
       \                                /
        +-------- PATHLEN -------------+

`exec-fat`

        +------------------------- PATH ----------------------------+   +---- PAYLOAD ---+
       /                                                             \ /                  \
      +---------------------------------------------------------------+---------------...--+
      |  HANDLE 0x00 | ARG0 0x00 ARG1 ...| 0x00 ... variable ... 0x00 |        DATA        |
      +---------------------------------------------------------------+---------------...--+
       \                                /
        +-------- PATHLEN -------------+

`trns`

        +------- PATH ---------+   +---- PAYLOAD ---+
       /                        \ /                  \
      +--------------------------+---------------...--+
      |  NODE ID | 0x00 ... 0x00 |  ENCRYPTED PACKET  |
      +--------------------------+---------------...--+
       \        /
         PATHLEN

`area`

        +------- PATH ---------+   +---- PAYLOAD ---+
       /                        \ /                  \
      +--------------------------+---------------...--+
      |  AREA ID | 0x00 ... 0x00 |  ENCRYPTED PACKET  |
      +--------------------------+---------------...--+
       \        /
         PATHLEN

  See also encrypted area packet.

`ack`

        +------- PATH --------+
       /                       \
      +-------------------------+
      |  PKT ID | 0x00 ... 0x00 |
      +-------------------------+
       \       /
        PATHLEN