net.i2p.client.streaming.impl

## Class PacketLocal

- java.lang.Object
- - net.i2p.client.streaming.impl.Packet
  - - net.i2p.client.streaming.impl.PacketLocal

- All Implemented Interfaces:
    MessageOutputStream.WriteStatus

      class PacketLocal
      extends Packet
      implements MessageOutputStream.WriteStatus

  This is the class used for outbound packets. coordinate local attributes about a packet - send time, ack time, number of retries, etc.

- - ### Field Summary

    - ### Fields inherited from class net.i2p.client.streaming.impl.Packet

      `_nacks, _offlineSignature, _optionFrom, _optionSignature, _session, _transientExpires, _transientSigningPublicKey, DEFAULT_MAX_SIZE, FLAG_CLOSE, FLAG_DELAY_REQUESTED, FLAG_ECHO, FLAG_FROM_INCLUDED, FLAG_MAX_PACKET_SIZE_INCLUDED, FLAG_NO_ACK, FLAG_PROFILE_INTERACTIVE, FLAG_RESET, FLAG_SIGNATURE_INCLUDED, FLAG_SIGNATURE_OFFLINE, FLAG_SIGNATURE_REQUESTED, FLAG_SYNCHRONIZE, MAX_DELAY_REQUEST, MAX_PAYLOAD_SIZE, MAX_STREAM_ID, MIN_DELAY_CHOKE, SEND_DELAY_CHOKE, STREAM_ID_UNKNOWN`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PacketLocal(I2PAppContext ctx, Destination to, Connection con)` bound to a connection
    `PacketLocal(I2PAppContext ctx, Destination to, I2PSession session)` not bound to a connection

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `ackReceived()`
    `void` | `cancelled()`
    `StringBuilder` | `formatAsString()`
    `int` | `getAckTime()` how long after packet creation was it acked?
    `Connection` | `getConnection()`
    `long` | `getCreatedOn()`
    `long` | `getLastSend()`
    `long` | `getLifetime()`
    `int` | `getNACKs()` Warning: This is different than getNacks() in super
    `int` | `getNumSends()`
    `int` | `getTimeout()` Used by PacketQueue to feed an expiration to the router.
    `Destination` | `getTo()`
    `void` | `incrementNACKs()` Will force a fast restransmit on the 3rd call (FAST_RETRANSMIT_THRESHOLD) but only if it's the lowest unacked (see Connection.ResendPacketEvent)
    `void` | `incrementSends()`
    `void` | `logTCPDump()` Generate a pcap/tcpdump-compatible format, so we can use standard debugging tools.
    `void` | `setOptionalFrom()` This sets the from field in the packet to the Destination for the session provided in the constructor.
    `void` | `setTimeout(int timeout)`
    `boolean` | `shouldSign()`
    `void` | `waitForAccept(int maxWaitMs)` Blocks until outbound window is not full.
    `void` | `waitForCompletion(int maxWaitMs)` block until the packet is acked from the far end
    `boolean` | `writeAccepted()` Returns true if the write was accepted by the outbound queue.
    `boolean` | `writeFailed()` Returns true if the write operation failed.
    `int` | `writeSignedPacket(byte[] buffer, int offset)` Sign and write the packet to the buffer (starting at the offset) and return the number of bytes written.
    `boolean` | `writeSuccessful()` Returns true if the write operation succeeded.

    - ### Methods inherited from class net.i2p.client.streaming.impl.Packet

      `acquirePayload, getAckThrough, getLocalPort, getNacks, getOptionalDelay, getOptionalFrom, getOptionalMaxSize, getOptionalSignature, getPayload, getPayloadSize, getReceiveStreamId, getRemotePort, getResendDelay, getSendStreamId, getSequenceNum, getSession, getTransientSPK, isFlagSet, logTCPDump, readPacket, releasePayload, setAckThrough, setFlag, setFlag, setLocalPort, setNacks, setOptionalDelay, setOptionalMaxSize, setOptionalSignature, setPayload, setReceiveStreamId, setRemotePort, setResendDelay, setSendStreamId, setSequenceNum, toId, toString, verifySignature, verifySignature, writePacket, writePacket`

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

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

- - ### Constructor Detail

    - #### PacketLocal

          public PacketLocal(I2PAppContext ctx,
                             Destination to,
                             Connection con)

      bound to a connection

    - #### PacketLocal

          public PacketLocal(I2PAppContext ctx,
                             Destination to,
                             I2PSession session)

      not bound to a connection

  - ### Method Detail

    - #### ackReceived

          public void ackReceived()

    - #### cancelled

          public void cancelled()

    - #### formatAsString

          public StringBuilder formatAsString()

      Overrides:
        `formatAsString` in class `Packet`

    - #### getAckTime

          public int getAckTime()

      how long after packet creation was it acked?
      Returns:
        how long after packet creation the packet was ACKed in ms

    - #### getConnection

          public Connection getConnection()

      Returns:
        null if not bound

    - #### getCreatedOn

          public long getCreatedOn()

    - #### getLastSend

          public long getLastSend()

    - #### getLifetime

          public long getLifetime()

    - #### getNACKs

          public int getNACKs()

      Warning: This is different than getNacks() in super
      Returns:
        Number of times this packet has been nacked

    - #### getNumSends

          public int getNumSends()

    - #### getTimeout

          public int getTimeout()

      Used by PacketQueue to feed an expiration to the router.
      Returns:
        time from now, not absolute time. May be zero if unset.

    - #### getTo

          public Destination getTo()

    - #### incrementNACKs

          public void incrementNACKs()

      Will force a fast restransmit on the 3rd call (FAST_RETRANSMIT_THRESHOLD) but only if it's the lowest unacked (see Connection.ResendPacketEvent)

    - #### incrementSends

          public void incrementSends()

    - #### logTCPDump

          public void logTCPDump()

      Generate a pcap/tcpdump-compatible format, so we can use standard debugging tools.

    - #### setOptionalFrom

          public void setOptionalFrom()

      This sets the from field in the packet to the Destination for the session provided in the constructor. This also sets flag FLAG_FROM_INCLUDED. Also, as of 0.9.39, sets the offline signing data if supported by the session.

    - #### setTimeout

          public void setTimeout(int timeout)

      Parameters:
        `timeout` - time from now, not absolute time

    - #### shouldSign

          public boolean shouldSign()

    - #### waitForAccept

          public void waitForAccept(int maxWaitMs)
                             throws IOException,
                                    InterruptedException

      Blocks until outbound window is not full. See Connection.packetSendChoke().
      Specified by:
        `waitForAccept` in interface `MessageOutputStream.WriteStatus`
      Parameters:
        `maxWaitMs` - MessageOutputStream is the only caller, generally with -1
      Throws:
        `IOException` - if acceptance fails or times out
        `InterruptedException` - if waiting thread is interrupted

    - #### waitForCompletion

          public void waitForCompletion(int maxWaitMs)
                                 throws IOException,
                                        InterruptedException

      block until the packet is acked from the far end
      Specified by:
        `waitForCompletion` in interface `MessageOutputStream.WriteStatus`
      Parameters:
        `maxWaitMs` - maximum wait time in milliseconds (-1 means wait forever)
      Throws:
        `IOException` - if write fails or times out
        `InterruptedException` - if waiting thread is interrupted

    - #### writeAccepted

          public boolean writeAccepted()

      Description copied from interface: `MessageOutputStream.WriteStatus`
      Returns true if the write was accepted by the outbound queue.
      Specified by:
        `writeAccepted` in interface `MessageOutputStream.WriteStatus`
      Returns:
        true if accepted, false otherwise

    - #### writeFailed

          public boolean writeFailed()

      Description copied from interface: `MessageOutputStream.WriteStatus`
      Returns true if the write operation failed.
      Specified by:
        `writeFailed` in interface `MessageOutputStream.WriteStatus`
      Returns:
        true if failed, false otherwise

    - #### writeSignedPacket

          public int writeSignedPacket(byte[] buffer,
                                       int offset)
                                throws IllegalStateException

      Sign and write the packet to the buffer (starting at the offset) and return the number of bytes written.
      Parameters:
        `buffer` - data to be written
        `offset` - starting point in the buffer
      Returns:
        Count of bytes written
      Throws:
        `IllegalStateException` - if there is data missing or otherwise b0rked

    - #### writeSuccessful

          public boolean writeSuccessful()

      Description copied from interface: `MessageOutputStream.WriteStatus`
      Returns true if the write operation succeeded.
      Specified by:
        `writeSuccessful` in interface `MessageOutputStream.WriteStatus`
      Returns:
        true if successful, false otherwise