{% extends "global/layout.html" %} {% block title %}Tunnel Message Specification{% endblock %} {% block lastupdated %}February 2014{% endblock %} {% block accuratefor %}0.9.11{% endblock %} {% block content %}
This document specifies the format of tunnel messages. For general information about tunnels see the tunnel documentation.
A gateway preprocesses I2NP messages by fragmenting and combining them into tunnel messages.
While I2NP messages are variable size from 0 to almost 64 KB, tunnel messages are fixed-size, approximately 1 KB. Fixed message size restricts several types of attacks that are possible from observing message size.
After the tunnel messages are created, they are encrypted as described in the tunnel documentation.
The instructions are encoded with a single control byte, followed by any necessary additional information. The first bit (MSB) in that control byte determines how the remainder of the header is interpreted - if it is not set, the message is either not fragmented or this is the first fragment in the message. If it is set, this is a follow on fragment.
This specification is for Delivery Instructions inside Tunnel Messages only. Note that "Delivery Instructions" are also used inside Garlic Cloves, where the format is significantly different. See the I2NP documentation for details. Do NOT use the following specification for Garlic Clove Delivery Instructions!
If the MSB of the first byte is 0, this is an initial I2NP message fragment, or a complete (unfragmented) I2NP message, and the instructions are:
{% highlight lang='dataspec' %} +----+----+----+----+----+----+----+----+ |flag| Tunnel ID (opt) | | +----+----+----+----+----+ + | | + + | To Hash (optional) | + + | | + +--------------+ | |dly | Message +----+----+----+----+----+----+----+----+ ID (opt) |extended opts (opt)| size | +----+----+----+----+----+----+----+----+ {% endhighlight %}If the MSB of the first byte is 1, this is a follow-on fragment, and the instructions are:
{% highlight lang='dataspec' %} +----+----+----+----+----+----+----+ |frag| Message ID | size | +----+----+----+----+----+----+----+ {% endhighlight %}While the maximum I2NP message size is nominally 64 KB, the size is further constrained by the method of fragmenting I2NP messages into multiple 1 KB tunnel messages. The maximum number of fragments is 64, and the initial fragment may not be perfectly aligned at the start of a tunnel message. So the message must nominally fit in 63 fragments.
The maximum size of an initial fragment is 956 bytes (assuming TUNNEL delivery mode); the maximum size of a follow-on fragment is 996 bytes. Therefore the maximum size is approximately 956 + (62 * 996) = 62708 bytes, or 61.2 KB.