net.i2p.router.transport.udp

## Class InboundMessageState

- java.lang.Object
- - net.i2p.router.transport.udp.InboundMessageState

- All Implemented Interfaces:
    CDQEntry

      class InboundMessageState
      extends Object
      implements CDQEntry

  Hold the raw data fragments of an inbound message.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `MAX_FRAGMENTS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `InboundMessageState(RouterContext ctx, long messageId, Hash from)` Constructs a new InboundMessageState with no fragments.
    `InboundMessageState(RouterContext ctx, long messageId, Hash from, byte[] data, int off, int len, int fragmentNum, boolean isLast)` Constructs and initializes by receiving one fragment.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `ACKBitfield` | `createACKBitfield()` Creates a bitfield representing received fragments.
    `void` | `drop()` Drops and releases resources.
    `int` | `getCompleteSize()` Returns the total size of the complete message in bytes.
    `long` | `getEnqueueTime()` Gets the enqueue time.
    `int` | `getFragmentCount()` Returns number of fragments received or expected.
    `ByteArray[]` | `getFragments()` Returns the array of fragments, throws if already released.
    `Hash` | `getFrom()` Returns the Hash of the sender.
    `long` | `getLifetime()` Returns the message lifetime in milliseconds.
    `long` | `getMessageId()` Returns the message ID.
    `boolean` | `hasFragment(int fragmentNum)` Returns whether the specified fragment has been received.
    `boolean` | `isComplete()` Returns true if all fragments up to last have been received.
    `boolean` | `isExpired()` Returns true if message has expired (received more than 10s ago).
    `boolean` | `receiveFragment(byte[] data, int off, int len, int fragmentNum, boolean isLast)` Receives and stores a fragment.
    `void` | `releaseResources()` Releases all cached fragments and marks this state as released.
    `void` | `setEnqueueTime(long now)` Sets enqueue time for queueing.
    `String` | `toString()` Returns a string summary of this message state.

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

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

- - ### Field Detail

    - #### MAX_FRAGMENTS

          public static final int MAX_FRAGMENTS

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### InboundMessageState

          public InboundMessageState(RouterContext ctx,
                                     long messageId,
                                     Hash from)

      Constructs a new InboundMessageState with no fragments.

    - #### InboundMessageState

          public InboundMessageState(RouterContext ctx,
                                     long messageId,
                                     Hash from,
                                     byte[] data,
                                     int off,
                                     int len,
                                     int fragmentNum,
                                     boolean isLast)
                              throws DataFormatException

      Constructs and initializes by receiving one fragment.
      Throws:
        `DataFormatException` - if fragment is invalid

  - ### Method Detail

    - #### createACKBitfield

          public ACKBitfield createACKBitfield()

      Creates a bitfield representing received fragments.

    - #### drop

          public void drop()

      Drops and releases resources.
      Specified by:
        `drop` in interface `CDQEntry`

    - #### getCompleteSize

          public int getCompleteSize()

      Returns the total size of the complete message in bytes.
      Throws:
        `IllegalStateException` - if message incomplete or released

    - #### getEnqueueTime

          public long getEnqueueTime()

      Gets the enqueue time.
      Specified by:
        `getEnqueueTime` in interface `CDQEntry`

    - #### getFragmentCount

          public int getFragmentCount()

      Returns number of fragments received or expected.

    - #### getFragments

          public ByteArray[] getFragments()

      Returns the array of fragments, throws if already released.

    - #### getFrom

          public Hash getFrom()

      Returns the Hash of the sender.

    - #### getLifetime

          public long getLifetime()

      Returns the message lifetime in milliseconds.

    - #### getMessageId

          public long getMessageId()

      Returns the message ID.

    - #### hasFragment

          public boolean hasFragment(int fragmentNum)

      Returns whether the specified fragment has been received.

    - #### isComplete

          public boolean isComplete()

      Returns true if all fragments up to last have been received.

    - #### isExpired

          public boolean isExpired()

      Returns true if message has expired (received more than 10s ago).

    - #### receiveFragment

          public boolean receiveFragment(byte[] data,
                                         int off,
                                         int len,
                                         int fragmentNum,
                                         boolean isLast)
                                  throws DataFormatException

      Receives and stores a fragment.
      Returns:
        true if successful, false if corrupt or invalid
      Throws:
        `DataFormatException`

    - #### releaseResources

          public void releaseResources()

      Releases all cached fragments and marks this state as released.

    - #### setEnqueueTime

          public void setEnqueueTime(long now)

      Sets enqueue time for queueing.
      Specified by:
        `setEnqueueTime` in interface `CDQEntry`

    - #### toString

          public String toString()

      Returns a string summary of this message state.
      Overrides:
        `toString` in class `Object`