net.i2p.router.tunnel

## Class FragmentedMessage

- java.lang.Object
- - net.i2p.router.tunnel.FragmentedMessage

-     class FragmentedMessage
      extends Object

  Gather fragments of I2NPMessages at a tunnel endpoint, making them available for reading when complete. Warning - this is all unsynchronized here - receivers must implement synchronization

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FragmentedMessage(I2PAppContext ctx, long messageId)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `failed()`
    `int` | `getCompleteSize()`
    `SimpleTimer2.TimedEvent` | `getExpireEvent()` used in the fragment handler so we can cancel the expire event on success
    `int` | `getFragmentCount()`
    `long` | `getLifetime()` how long has this fragmented message been alive?
    `long` | `getMessageId()`
    `boolean` | `getReleased()`
    `long` | `getReleasedAfter()`
    `Hash` | `getTargetRouter()`
    `TunnelId` | `getTargetTunnel()`
    `boolean` | `isComplete()` have we received all of the fragments?
    `boolean` | `receive(byte[] payload, int offset, int length, boolean isLast, Hash toRouter, TunnelId toTunnel)` Receive the first fragment (#0) and related metadata.
    `boolean` | `receive(int fragmentNum, byte[] payload, int offset, int length, boolean isLast)` Receive a followup fragment, though one of these may arrive at the endpoint prior to the fragment # 0.
    `void` | `setExpireEvent(SimpleTimer2.TimedEvent evt)`
    `byte[]` | `toByteArray()`
    `String` | `toString()` toString

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### FragmentedMessage

          public FragmentedMessage(I2PAppContext ctx,
                                   long messageId)

  - ### Method Detail

    - #### failed

          public void failed()

    - #### getCompleteSize

          public int getCompleteSize()

    - #### getExpireEvent

          public SimpleTimer2.TimedEvent getExpireEvent()

      used in the fragment handler so we can cancel the expire event on success

    - #### getFragmentCount

          public int getFragmentCount()

    - #### getLifetime

          public long getLifetime()

      how long has this fragmented message been alive?

    - #### getMessageId

          public long getMessageId()

    - #### getReleased

          public boolean getReleased()

    - #### getReleasedAfter

          public long getReleasedAfter()

    - #### getTargetRouter

          public Hash getTargetRouter()

    - #### getTargetTunnel

          public TunnelId getTargetTunnel()

    - #### isComplete

          public boolean isComplete()

      have we received all of the fragments?

    - #### receive

          public boolean receive(byte[] payload,
                                 int offset,
                                 int length,
                                 boolean isLast,
                                 Hash toRouter,
                                 TunnelId toTunnel)

      Receive the first fragment (#0) and related metadata. This may not be the first one to arrive at the endpoint however.
      Parameters:
        `payload` - data for the fragment non-null
        `offset` - index into the payload where the fragment data starts (past headers/etc)
        `length` - how much past the offset should we snag?
        `isLast` - is this the last fragment in the message?
        `toRouter` - what router is this destined for (may be null)
        `toTunnel` - what tunnel is this destined for (may be null)

    - #### receive

          public boolean receive(int fragmentNum,
                                 byte[] payload,
                                 int offset,
                                 int length,
                                 boolean isLast)

      Receive a followup fragment, though one of these may arrive at the endpoint prior to the fragment # 0.
      Parameters:
        `fragmentNum` - sequence number within the message (1 - 63)
        `payload` - data for the fragment non-null
        `offset` - index into the payload where the fragment data starts (past headers/etc)
        `length` - how much past the offset should we snag?
        `isLast` - is this the last fragment in the message?

    - #### setExpireEvent

          public void setExpireEvent(SimpleTimer2.TimedEvent evt)

    - #### toByteArray

          public byte[] toByteArray()

    - #### toString

          public String toString()

      toString
      Overrides:
        `toString` in class `Object`