net.i2p.router.tunnel
Class FragmentHandler

java.lang.Object
  extended by net.i2p.router.tunnel.FragmentHandler
Direct Known Subclasses:
RouterFragmentHandler

public class FragmentHandler
extends java.lang.Object

Handle fragments at the endpoint of a tunnel, peeling off fully completed I2NPMessages when they arrive, and dropping fragments if they take too long to arrive. From tunnel-alt.html:

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:

If the first bit being 1, the instructions are:

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.


Nested Class Summary
static interface FragmentHandler.DefragmentedReceiver
          Receive messages out of the tunnel endpoint.
 
Field Summary
protected  RouterContext _context
           
protected  Log _log
           
(package private) static byte MASK_EXTENDED
          are there follow up headers?
(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
          LOCAL isn't explicitly used anywhere, because the code knows that it is 0
(package private) static short TYPE_ROUTER
           
(package private) static short TYPE_TUNNEL
           
 
Constructor Summary
FragmentHandler(RouterContext context, FragmentHandler.DefragmentedReceiver receiver)
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_context

protected RouterContext _context

_log

protected Log _log

MAX_DEFRAGMENT_TIME

static long MAX_DEFRAGMENT_TIME
don't wait more than 60s to defragment the partial message


MASK_IS_SUBSEQUENT

static final byte MASK_IS_SUBSEQUENT
is this a follw up byte?

See Also:
Constant Field Values

MASK_TYPE

static final byte MASK_TYPE
how should this be delivered. shift this 5 the right and get TYPE_*

See Also:
Constant Field Values

MASK_FRAGMENTED

static final byte MASK_FRAGMENTED
is this the first of a fragmented message?

See Also:
Constant Field Values

MASK_EXTENDED

static final byte MASK_EXTENDED
are there follow up headers? UNIMPLEMENTED

See Also:
Constant Field Values

TYPE_LOCAL

static final short TYPE_LOCAL
LOCAL isn't explicitly used anywhere, because the code knows that it is 0

See Also:
Constant Field Values

TYPE_TUNNEL

static final short TYPE_TUNNEL
See Also:
Constant Field Values

TYPE_ROUTER

static final short TYPE_ROUTER
See Also:
Constant Field Values
Constructor Detail

FragmentHandler

public FragmentHandler(RouterContext context,
                       FragmentHandler.DefragmentedReceiver receiver)
Method Detail

receiveTunnelMessage

public 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. The received fragments are all verified.


getCompleteCount

public int getCompleteCount()

getFailedCount

public int getFailedCount()

noteReception

protected void noteReception(long messageId,
                             int fragmentId,
                             java.lang.Object status)

noteCompletion

protected void noteCompletion(long messageId)

noteFailure

protected void noteFailure(long messageId,
                           java.lang.String status)