RouterFragmentHandler
class FragmentHandler
extends java.lang.Object
When the gateway wants to deliver data through the tunnel, it first gathers zero or more I2NP messages, selects how much padding will be used, fragments it across the necessary number of 1KB tunnel messages, and decides how each I2NP message should be handled by the tunnel endpoint, encoding that data into the raw tunnel payload:
Note that the padding, if any, must be before the instruction/message pairs. there is no provision for padding at the end.
The instructions are encoded with a single control byte, followed by any necessary additional information. The first bit 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.
With the first (leftmost or MSB) bit being 0, the instructions are:
bit 0: is follow on fragment? (1 = true, 0 = false, must be 0) bits 1-2: delivery type (0x0 = LOCAL, 0x01 = TUNNEL, 0x02 = ROUTER) bit 3: delay included? (1 = true, 0 = false) (unimplemented) bit 4: fragmented? (1 = true, 0 = false) bit 5: extended options? (1 = true, 0 = false) (unimplemented) bits 6-7: reserved
bit 0: type (0 = strict, 1 = randomized) bits 1-7: delay exponent (2^value minutes)
= a 1 byte option size (in bytes) = that many bytes
If the first bit being 1, the instructions are:
bit 0: is follow on fragment? (1 = true, 0 = false, must be 1) bits 1-6: fragment number bit 7: is last? (1 = true, 0 = false)
The I2NP message is encoded in its standard form, and the preprocessed payload must be padded to a multiple of 16 bytes. The total size, including the tunnel ID and IV, is 1028 bytes.
修飾子とタイプ | クラス | 説明 |
---|---|---|
static interface |
FragmentHandler.DefragmentedReceiver |
Receive messages out of the tunnel endpoint.
|
修飾子とタイプ | フィールド | 説明 |
---|---|---|
protected RouterContext |
_context |
|
protected Log |
_log |
|
(package private) static byte |
MASK_EXTENDED |
are there follow up headers? UNIMPLEMENTED
|
(package private) static byte |
MASK_FRAGMENTED |
is this the first of a fragmented message?
|
(package private) static byte |
MASK_IS_SUBSEQUENT |
is this a follw up byte?
|
(package private) static byte |
MASK_TYPE |
how should this be delivered.
|
(package private) static long |
MAX_DEFRAGMENT_TIME |
don't wait more than 60s to defragment the partial message
|
(package private) static short |
TYPE_LOCAL |
|
(package private) static short |
TYPE_ROUTER |
|
(package private) static short |
TYPE_TUNNEL |
|
(package private) static short |
TYPE_UNDEF |
コンストラクタ | 説明 |
---|---|
FragmentHandler(RouterContext context,
FragmentHandler.DefragmentedReceiver receiver) |
修飾子とタイプ | メソッド | 説明 |
---|---|---|
int |
getCompleteCount() |
|
int |
getFailedCount() |
|
protected void |
noteCompletion(long messageId) |
|
protected void |
noteFailure(long messageId,
java.lang.String status) |
|
protected void |
noteReception(long messageId,
int fragmentId,
java.lang.Object status) |
|
void |
receiveTunnelMessage(byte[] preprocessed,
int offset,
int length) |
Receive the raw preprocessed message at the endpoint, parsing out each
of the fragments, using those to fill various FragmentedMessages, and
sending the resulting I2NPMessages where necessary.
|
protected final RouterContext _context
protected final Log _log
static long MAX_DEFRAGMENT_TIME
static final byte MASK_IS_SUBSEQUENT
static final byte MASK_TYPE
static final byte MASK_FRAGMENTED
static final byte MASK_EXTENDED
static final short TYPE_LOCAL
static final short TYPE_TUNNEL
static final short TYPE_ROUTER
static final short TYPE_UNDEF
public FragmentHandler(RouterContext context, FragmentHandler.DefragmentedReceiver receiver)
public void receiveTunnelMessage(byte[] preprocessed, int offset, int length)
public int getCompleteCount()
public int getFailedCount()
protected void noteReception(long messageId, int fragmentId, java.lang.Object status)
protected void noteCompletion(long messageId)
protected void noteFailure(long messageId, java.lang.String status)