Files
i2p.www/www.i2p2/pages/i2np_spec.html
2010-07-26 18:46:54 +00:00

668 lines
18 KiB
HTML

{% extends "_layout.html" %}
{% block title %}I2NP Specification{% endblock %}
{% block content %}
<h1>I2P Network Protocol (I2NP) Specification</h1>
<p>
The I2P Network Protocol (I2NP),
which is sandwiched between I2CP and the various I2P transport protocols, manages the
routing and mixing of messages between routers, as well as the selection of what
transports to use when communicating with a peer for which there are multiple
common transports supported.
</p>
<h2 id="structures">Common structures</h2>
<h3 id="struct_header">I2NP message header</h3>
<h4>Description</h4>
<p>
Common header to all I2NP messages, which contains important information like an checksum, expiration date, etc.
</p>
<h4>Contents</h4>
<p>
1 byte <a href="common_structures_spec#type_Integer">Integer</a> specifying the type of this message, followed by an 4 byte <a href="common_structures_spec#type_Integer">Integer</a> specifying the message-id. After that there is an expiration <a href="common_structures_spec#type_Date">Date</a>, followed by an 2 byte <a href="common_structures_spec#type_Integer">Integer</a> specifying the length of the message payload, followed by an <a href="common_structures_spec#type_Hash">Hash</a>, which is truncated to the first byte. After that the actual message data follows.
</p>
<pre>
{% filter escape %}
+----+----+----+----+----+
|type| msg-id |
+----+----+----+----+----+----+----+----+
| expiration |
+----+----+----+----+----+----+----+----+
| size |chks|
+----+----+----+
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
type :: Integer
length -> 1 byte
purpose -> identifies the message type(see table below)
msg-id :: Integer
length -> 4 bytes
purpose -> uniquely identifies this message(for some time at least)
expiration :: Date
8 bytes
date this message will expire
size :: Integer
length -> 2 bytes
purpose -> length of the payload
chks :: Hash
length -> 1 byte
purpose -> checksum of the payload
SHA256 hash truncated to the first byte
data :: Data
length -> $size bytes
purpose -> actual message contents
{% endfilter %}
</pre>
<h3 id="struct_BuildRequestRecord">BuildRequestRecord</h3>
<h4>Description</h4>
<p>
One Record in a set of multiple records to request the creation of one hop in the tunnel. For more details see here.
</p>
<h4>Contents</h4>
<p>
<a href="common_structures_spec#type_TunnelId">TunnelId</a> to receive messages on, followed by the <a href="common_structures_spec#type_Hash">Hash</a> of our <a href="common_structures_spec#struct_RouterIdentity">RouterIdentity</a>. After that the <a href="common_structures_spec#type_TunnelId">TunnelId</a> and the <a href="common_structures_spec#type_Hash">Hash</a> of the next router's <a href="common_structures_spec#struct_RouterIdentity">RouterIdentity</a> follow.
</p>
<h4>Definition</h4>
<pre>
{% filter escape %}
Cleartext:
+----+----+----+----+----+----+----+----+
| receive_tunnel | our_ident |
+----+----+----+----+ +
| |
+ +
| |
+ +
| |
+ +----+----+----+----+
| | next_tunnel |
+----+----+----+----+----+----+----+----+
| next_ident |
+ +
| |
+ +
| |
+ +
| |
+----+----+----+----+----+----+----+----+
| layer_key |
+ +
| |
+ +
| |
+ +
| |
+----+----+----+----+----+----+----+----+
| iv_key |
+ +
| |
+ +
| |
+ +
| |
+----+----+----+----+----+----+----+----+
| reply_key |
+ +
| |
+ +
| |
+ +
| |
+----+----+----+----+----+----+----+----+
| reply_iv |
+ +
| |
+----+----+----+----+----+----+----+----+----+
|flag| request_time | send_message_id |
+----+----+----+----+----+----+----+----+----+
| padding...
+----+----+----+--//
encrypted:
+----+----+----+----+----+----+----+----+
| toPeer |
+ +
| |
+----+----+----+----+----+----+----+----+
| encrypted data ... |
+----+----+----+----+----+----+----+----+
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
unencrypted:
receive_tunnel :: TunnelId
length -> 4 bytes
our_ident :: Hash
length -> 32 bytes
next_tunnel :: TunnelId
length -> 4 bytes
next_ident :: Hash
length -> 32 bytes
layer_key :: SessionKey
length -> 32 bytes
iv_key :: SessionKey
length -> 32 bytes
reply_key :: SessionKey
length -> 32 bytes
reply_iv :: Integer
length -> 16 bytes
flag :: Integer
length -> 1 byte
request_time :: Integer
length -> 4 bytes
send_message_id :: Integer
length -> 4 bytes
padding :: Data
length -> 29 bytes
source -> random
encrypted:
toPeer :: Hash
length -> 16 bytes
encrypted_data :: ElGamal-2048 encrypted data
length -> 514
{% endfilter %}
</pre>
<h3 id="struct_BuildResponseRecord">BuildResponseRecord</h3>
<pre>
{% filter escape %}
unencrypted:
+----+----+----+----+----+----+----+----+
| random data... |
| |
+ +----+
| |ret |
+----+----+----+----+----+----+----+----+
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
unencrypted:
bytes 0-526: random data
byte 527 : reply
encrypted:
bytes 0-527: AES-encrypted record(note: same size as BuildRequestRecord!)
{% endfilter %}
</pre>
<h2 id="messages">Messages</h2>
<table border=1>
<tr>
<td>Message</td>
<td>Type</td>
</tr>
<tr>
<td><a href="#msg_DatabaseStore">DatabaseStore</a></td>
<td align="right">1</td>
</tr>
<tr>
<td><a href="#msg_DatabaseLookup">DatabaseLookup</a></td>
<td align="right">2</td>
</tr>
<tr>
<td><a href="#msg_DatabaseSearchReply">DatabaseSearchReply</a></td>
<td align="right">3</td>
</tr>
<tr>
<td><a href="#msg_DeliveryStatus">DeliveryStatus</a></td>
<td align="right">10</td>
</tr>
<tr>
<td><a href="#msg_Garlic">Garlic</a></td>
<td align="right">11</td>
</tr>
<tr>
<td><a href="#msg_TunnelData">TunnelData</a></td>
<td align="right">18</td>
</tr>
<tr>
<td><a href="#msg_TunnelGateway">TunnelGateway</a></td>
<td align="right">19</td>
</tr>
<tr>
<td><a href="#msg_Data">Data</a></td>
<td align="right">20</td>
</tr>
<tr>
<td><a href="#msg_TunnelBuild">TunnelBuild</a></td>
<td align="right">21</td>
</tr>
<tr>
<td><a href="#msg_TunnelBuildReply">TunnelBuildReply</a></td>
<td align="right">22</td>
</tr>
<tr>
<td><a href="#msg_VariableTunnelBuild">VariableTunnelBuild</a></td>
<td align="right">23</td>
</tr>
<tr>
<td><a href="#msg_VariableTunnelBuildReply">VariableTunnelBuildReply</a></td>
<td align="right">24</td>
</tr>
</table>
<h3 id="msg_DatabaseStore">DatabaseStore</h3>
<pre>
with reply token:
+----+----+----+----+----+----+----+----+
| SHA256 Hash as key |
+ +
| |
+ +
| |
+ +
| |
+----+----+----+----+----+----+----+----+
|type| reply token | reply tunnel-
+----+----+----+----+----+----+----+----+
Id | SHA256 of the gateway RouterInfo |
+----+ +
| |
+ +
| |
+ +
| |
+ +----+----+----+----+----+----+----+
| | data ...
+----+--------\\
with reply token == 0:
+----+----+----+----+----+----+----+----+
| SHA256 Hash as key |
+ +
| |
+ +
| |
+ +
| |
+----+----+----+----+----+----+----+----+
|type| reply token | data ...
+----+-------------------+---------\\
</pre>
<h4>Definition</h4>
<pre>
key:
32 bytes
SHA256 hash
type:
1 byte
type identifier
mapping:
0 RouterInfo
1 LeaseSet
reply token:
4 bytes
TODO: find out what this does
reply tunnelId:
4 bytes
only included if reply token > 0
TODO: what this tunnel information is needed for
reply gateway:
32 bytes
Hash of the routerInfo entry to reach the gateway
only included if reply token > 0
TODO: what this tunnel information is needed for
data:
rest of the message(could be anything)
</pre>
<h3 id="msg_DatabaseLookup">DatabaseLookup</h3>
<pre>
{% filter escape %}
if flag==TRUE
+----+----+----+----+----+----+----+----+
| SHA256 hash as the key to look up |
+ +
| |
+ +
| |
+ +
| |
+----+----+----+----+----+----+----+----+
| SHA256 hash of the routerInfo |
+ who is asking +
| |
+ +
| |
+ +
| |
+----+----+----+----+----+----+----+----+
|flag| reply tunnelId |size | |
+----+----+----+----+----+----+----+ +
| SHA256 of $key1 to exclude |
+ +
| |
+ +
| |
+ +----+
| | |
+----+----+----+----+----+----+----+ +
| SHA256 of $key2 to exclude |
....
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
key:
32 bytes
SHA256 hash of the object to lookup
from:
32 bytes
SHA256 hash of the routerInfo entry this request came from(and to which the reply should be sent)
flag:
1 byte
mapping:
0 FALSE => send reply directly
1 TRUE => send reply to some tunnel
reply tunnelId:
2 bytes
only included if flag==TRUE
tunnelId of the tunnel to send the reply to
size:
2 bytes
number of peers to exclude from the lookup(TODO: whatever this means)
excludedPeers:
rest of the message are $size SHA256 hashes of 32 bytes each(total $size*32 bytes)
{% endfilter %}
</pre>
<h3 id="msg_DatabaseSearchReply">DatabaseSearchReply</h3>
<pre>
{% filter escape %}
+----+----+----+----+----+----+----+----+
| SHA256 hash as query key |
+ +
| |
+ +
| |
+ +
| |
+----+----+----+----+----+----+----+----+
|num | peer hash $1 |
+----+ +
| |
+ +
| |
+ +
| |
+ +----+----+----+----+----+----+----+
| | |
+----+.... $num peer hashes
+ +----+----+----+----+----+----+----+
| | from |
+----+ +
| |
+ +
| |
+ +
| |
+ +----+----+----+----+----+----+----+
| |
+----+
{% endfilter %}
<h4>Definition</h4>
<pre>
{% filter escape %}
key:
32 bytes
SHA256 of the object being searched
num:
1 byte
number of peer hashes that follow
peer hash:
32 bytes
SHA256 of the RouterInfo that the other router thinks are close to the key
$num entries
from:
32 bytes
SHA256 of the RouterInfo of the router this reply was sent from
{% endfilter %}
</pre>
<h3 id="msg_DeliveryStatus">DeliveryStatus</h3>
<pre>
{% filter escape %}
+----+----+----+----+----+----+----+----+----+----+----+----+
|msg-id | arrival-time |
+----+----+----+----+----+----+----+----+----+----+----+----+
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
msg-id:
4 bytes
unique ID of the message we deliver the DeliveryStatus for(see common I2NP header for details)
arrival-time:
8 bytes
time the message was successfully delivered
{% endfilter %}
</pre>
<h3 id="msg_Garlic">Garlic</h3>
<pre>
{% filter escape %}
encrypted:
+----+----+----+----+----+----+----+----+
|length | tag |
+----+----+----+----+ +
| |
+ +
| |
+ +
| |
+ +----+----+----+----+
|
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
length:
4 bytes
number of bytes that follow
data:
$length bytes
elgamal en
{% endfilter %}
</pre>
<h3 id="msg_TunnelData">TunnelData</h3>
<pre>
{% filter escape %}
+----+----+----+----+----+----+----+----+
| tunnelId | data |
+----+----+----+----+ |
| |
| |
+----+----+----+----+----+----+----+----+
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
tunnelId:
4 bytes
identifies the tunnel this message is directed at
data:
1024 bytes
payload data.. fixed to 1024 bytes
{% endfilter %}
</pre>
<h3 id="msg_TunnelGateway">TunnelGateway</h3>
<pre>
{% filter escape %}
+----+----+----+----+----+----+--\\----+
| tunnelId | length | data...|
+----+----+----+----+----+----+--\\----+
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
tunnelId:
4 bytes
identifies the tunnel this message is directed at
length:
2 bytes
length of the payload
data:
$length bytes
actual payload of this message
{% endfilter %}
</pre>
{% endblock %}
<h3 id="msg_Data">Data</h3>
<pre>
{% filter escape %}
+----+----+----+----+----+---//--+
| length | data... |
+----+----+----+----+----+---//--+
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
length:
4 bytes
length of the payload
data:
$length bytes
actual payload of this message
{% endfilter %}
</pre>
<h3 id="msg_TunnelBuild">TunnelBuild</h3>
<pre>
{% filter escape %}
+----+----+----+----+----+----+----+----+
| Record 0 ... |
| |
+----+----+----+----+----+----+----+----+
| Record 1 ... |
.....
+----+----+----+----+----+----+----+----+
| Record 7 ... |
| |
+----+----+----+----+----+----+----+----+
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
Just 8 records attached together
Record size: 528 bytes
Total size: 8*528 = 4224 bytes
{% endfilter %}
</pre>
<h3 id="msg_TunnelBuildReply">TunnelBuildReply</h3>
<pre>
{% filter escape %}
same format as TunnelBuild message
{% endfilter %}
</pre>
<h3 id="msg_VariableTunnelBuild">VariableTunnelBuild</h3>
<pre>
{% filter escape %}
+----+----+----+----+----+----+----+----+
|num | ....
{% endfilter %}
</pre>
<h4>Definition</h4>
<pre>
{% filter escape %}
same format as TunnelBuildMessage, except for the addition of an "num" field in front and $num number of records instead of 8
{% endfilter %}
</pre>
<h3 id="msg_VariableTunnelBuildReply">VariableTunnelBuildReply</h3>
<pre>
{% filter escape %}
same format as VariableTunnelBuild message
{% endfilter %}
</pre>