net.i2p.router.transport.udp

## Class OutboundMessageState

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

- All Implemented Interfaces:
    CDPQEntry, CDQEntry, PQEntry

      class OutboundMessageState
      extends Object
      implements CDPQEntry

  Maintain the outbound fragmentation for resending, for a single message. All methods are thread-safe.

- - ### Field Summary

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

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `OutboundMessageState(I2PAppContext context, I2NPMessage msg, PeerState peer)` "injected" message from the establisher.
    `OutboundMessageState(I2PAppContext context, OutNetMessage m, PeerState peer)` Normal constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `acked(ACKBitfield bitfield)` Ack all the fragments in the ack list.
    `boolean` | `acked(int fragmentNum)` Ack this fragment number.
    `void` | `clearNACKs()`
    `void` | `drop()` For CDQ
    `int` | `fragmentSize(int fragmentNum)` The size in bytes of the fragment.
    `long` | `getEnqueueTime()` For CDQ
    `int` | `getFragmentCount()` How many fragments in the message.
    `long` | `getLifetime()`
    `int` | `getMaxSends()` The max number of sends for any fragment.
    `OutNetMessage` | `getMessage()`
    `long` | `getMessageId()`
    `int` | `getMessageSize()` The size of the I2NP message.
    `int` | `getMinSendSize()` The minimum number of bytes we can send, which is the smallest unacked fragment we will send next.
    `int` | `getNACKs()`
    `PeerState` | `getPeer()`
    `int` | `getPriority()` For CDPQ
    `int` | `getPushCount()` The number of times we've pushed some fragments.
    `int` | `getSendSize(int max)` How many bytes we can send under the max given.
    `long` | `getSeqNum()` For CDPQ
    `int` | `getUnackedFragments()`
    `int` | `getUnackedSize()` As of 0.9.49, includes packet overhead
    `int` | `getVersion()`
    `boolean` | `hasUnsentFragments()` Is any fragment unsent?
    `int` | `incrementNACKs()`
    `boolean` | `isComplete()`
    `boolean` | `isExpired()`
    `boolean` | `isExpired(long now)`
    `boolean` | `needsSending(int fragment)`
    `int` | `push(List<PacketBuilder.Fragment> toSend)` Add fragments up to the number of bytes allowed by setAllowedSendBytes() Side effects: Clears setAllowedSendBytes.
    `void` | `setEnqueueTime(long now)` For CDQ
    `void` | `setSeqNum(long num)` For CDPQ
    `String` | `toString()`
    `int` | `writeFragment(byte[] out, int outOffset, int fragmentNum)` Write a part of the the message onto the specified buffer.

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

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

- - ### Field Detail

    - #### MAX_MSG_SIZE

          public static final int MAX_MSG_SIZE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### OutboundMessageState

          public OutboundMessageState(I2PAppContext context,
                                      I2NPMessage msg,
                                      PeerState peer)

      "injected" message from the establisher. Called from UDPTransport.
      Throws:
        `IllegalArgumentException` - if too big or if msg or peer is null

    - #### OutboundMessageState

          public OutboundMessageState(I2PAppContext context,
                                      OutNetMessage m,
                                      PeerState peer)

      Normal constructor. Called from OutboundMessageFragments.
      Throws:
        `IllegalArgumentException` - if too big or if msg or peer is null

  - ### Method Detail

    - #### acked

          public boolean acked(ACKBitfield bitfield)

      Ack all the fragments in the ack list.
      Returns:
        true if the message was completely ACKed

    - #### acked

          public boolean acked(int fragmentNum)

      Ack this fragment number. For SSU 2 only.
      Returns:
        true if the message was completely ACKed

    - #### clearNACKs

          public void clearNACKs()

    - #### drop

          public void drop()

      For CDQ
      Specified by:
        `drop` in interface `CDQEntry`

    - #### fragmentSize

          public int fragmentSize(int fragmentNum)

      The size in bytes of the fragment. Does NOT include any SSU overhead (SSU2 is 3 for all fragments, + 5 for followon fragments)
      Parameters:
        `fragmentNum` - the number of the fragment
      Returns:
        the size of the fragment specified by the number

    - #### getEnqueueTime

          public long getEnqueueTime()

      For CDQ
      Specified by:
        `getEnqueueTime` in interface `CDQEntry`

    - #### getFragmentCount

          public int getFragmentCount()

      How many fragments in the message.

    - #### getLifetime

          public long getLifetime()

    - #### getMaxSends

          public int getMaxSends()

      The max number of sends for any fragment. As of 0.9.49, may be less than getPushCount() if we pushed only some fragments

    - #### getMessage

          public OutNetMessage getMessage()

    - #### getMessageId

          public long getMessageId()

    - #### getMessageSize

          public int getMessageSize()

      The size of the I2NP message. Does not include any SSU overhead.

    - #### getMinSendSize

          public int getMinSendSize()

      The minimum number of bytes we can send, which is the smallest unacked fragment we will send next. Includes packet overhead.
      Returns:
        0 to total size

    - #### getNACKs

          public int getNACKs()

    - #### getPeer

          public PeerState getPeer()

    - #### getPriority

          public int getPriority()

      For CDPQ
      Specified by:
        `getPriority` in interface `PQEntry`
      Returns:
        OutNetMessage priority or 1000 for injected

    - #### getPushCount

          public int getPushCount()

      The number of times we've pushed some fragments. As of 0.9.49, may be greater than getMaxSends() if we pushed only some fragments.

    - #### getSendSize

          public int getSendSize(int max)

      How many bytes we can send under the max given. Side effect: if applicable, amount to send will be saved for the push() call. Note: With multiple fragments, this will allocate only the fragments with the lowest push count. Example: If push counts are 1 1 1 0 0, this will only return the size of the last two fragments, even if any of the first three need to be retransmitted. Includes packet overhead.
      Parameters:
        `max` - the maximum number of bytes we can send, including packet overhead
      Returns:
        0 to max bytes

    - #### getSeqNum

          public long getSeqNum()

      For CDPQ
      Specified by:
        `getSeqNum` in interface `PQEntry`

    - #### getUnackedFragments

          public int getUnackedFragments()

      Returns:
        count of unacked fragments

    - #### getUnackedSize

          public int getUnackedSize()

      As of 0.9.49, includes packet overhead

    - #### getVersion

          public int getVersion()

    - #### hasUnsentFragments

          public boolean hasUnsentFragments()

      Is any fragment unsent?

    - #### incrementNACKs

          public int incrementNACKs()

      Returns:
        new value

    - #### isComplete

          public boolean isComplete()

    - #### isExpired

          public boolean isExpired()

    - #### isExpired

          public boolean isExpired(long now)

    - #### needsSending

          public boolean needsSending(int fragment)

      Returns:
        true if the fragment has not been ACKed

    - #### push

          public int push(List<PacketBuilder.Fragment> toSend)

      Add fragments up to the number of bytes allowed by setAllowedSendBytes() Side effects: Clears setAllowedSendBytes. Increments pushCount. Increments maxSends if applicable. Note: With multiple fragments, this will send only the fragments with the lowest push count. Example: If push counts are 1 1 1 0 0, this will only send the last two fragments, even if any of the first three need to be retransmitted.
      Parameters:
        `toSend` - out parameter
      Returns:
        the number of Fragments added

    - #### setEnqueueTime

          public void setEnqueueTime(long now)

      For CDQ
      Specified by:
        `setEnqueueTime` in interface `CDQEntry`

    - #### setSeqNum

          public void setSeqNum(long num)

      For CDPQ
      Specified by:
        `setSeqNum` in interface `PQEntry`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### writeFragment

          public int writeFragment(byte[] out,
                                   int outOffset,
                                   int fragmentNum)

      Write a part of the the message onto the specified buffer.
      Parameters:
        `out` - target to write
        `outOffset` - into outOffset to begin writing
        `fragmentNum` - fragment to write (0 indexed)
      Returns:
        bytesWritten, NOT including packet overhead