## net.i2p.client.streaming
Class Connection

    java.lang.Object
      net.i2p.client.streaming.Connection

    public class Connection

extends java.lang.Object

Maintain the state controlling a streaming connection between two destinations.

Nested Class Summary
`(package private) class` `Connection.ConEvent` fired to reschedule event notification

Field Summary
`static int` `DISCONNECT_TIMEOUT` wait up to 5 minutes after disconnection so we can ack/close packets
`(package private) static int` `FAST_RETRANSMIT_THRESHOLD` If we have been explicitly NACKed three times, retransmit the packet even if there are other packets in flight.
`static long` `MAX_RESEND_DELAY`
`static int` `MAX_WINDOW_SIZE` lets be sane- no more than 64 packets in the air in each dir
`static long` `MIN_RESEND_DELAY`

Constructor Summary
`Connection(I2PAppContext ctx, ConnectionManager manager, SchedulerChooser chooser, PacketQueue queue, ConnectionPacketHandler handler)`
`Connection(I2PAppContext ctx, ConnectionManager manager, SchedulerChooser chooser, PacketQueue queue, ConnectionPacketHandler handler, ConnectionOptions opts)`

Method Summary
`(package private) void` `ackImmediately()`
`(package private) java.util.List` `ackPackets(long ackThrough, long[] nacks)`
`(package private) void` `closeReceived()`
`(package private) void` `congestionOccurred()`
`(package private) void` `disconnect(boolean cleanDisconnect)`
`(package private) void` `disconnect(boolean cleanDisconnect, boolean removeFromConMgr)`
`(package private) void` `disconnectComplete()`
`(package private) void` `eventOccurred()`
`long` `getAckedPackets()` how many packets have we sent and the other side has ACKed?
`long` `getCloseReceivedOn()`
`long` `getCloseSentOn()`
`long` `getCongestionWindowEnd()`
`java.lang.String` `getConnectionError()`
`SimpleTimer.TimedEvent` `getConnectionEvent()`
`long` `getCreatedOn()`
`long` `getDisconnectScheduledOn()`
`boolean` `getHardDisconnected()`
`long` `getHighestAckedThrough()`
`MessageInputStream` `getInputStream()` stream that the local peer receives data on
`boolean` `getIsConnected()`
`long` `getLastActivityOn()`
`int` `getLastCongestionSeenAt()`
`long` `getLastSendId()` what was the last packet Id sent to the peer?
`long` `getLastSendTime()` when did we last send anything to the peer?
`long` `getLifetime()`
`long` `getLifetimeBytesReceived()`
`long` `getLifetimeBytesSent()`
`long` `getLifetimeDupMessagesReceived()`
`long` `getLifetimeDupMessagesSent()`
`long` `getNextOutboundPacketNum()`
`long` `getNextSendTime()` Time when the scheduler next want to send a packet, or -1 if never.
`ConnectionOptions` `getOptions()`
`MessageOutputStream` `getOutputStream()` stream that the local peer sends data to the remote peer on
`ConnectionPacketHandler` `getPacketHandler()`
`long` `getReceiveStreamId()` stream the peer sends data to us on.
`Destination` `getRemotePeer()` who are we talking with
`boolean` `getResetReceived()`
`boolean` `getResetSent()`
`long` `getResetSentOn()`
`long` `getSendStreamId()` what stream do we send data to the peer on?
`I2PSession` `getSession()`
`I2PSocketFull` `getSocket()`
`int` `getUnackedPacketsReceived()`
`int` `getUnackedPacketsSent()` how many packets have we sent but not yet received an ACK for?
`void` `incrementBytesReceived(int bytes)`
`void` `incrementBytesSent(int bytes)`
`void` `incrementDupMessagesReceived(int msgs)`
`void` `incrementDupMessagesSent(int msgs)`
`void` `incrementUnackedPacketsReceived()`
`(package private) void` `packetReceived()`
`(package private) boolean` `packetSendChoke(long timeoutMs)` Block until there is an open outbound packet slot or the write timeout expires.
`(package private) void` `resetReceived()`
`(package private) void` `sendAvailable()` Flush any data that we can
`(package private) void` `sendPacket(PacketLocal packet)`
`(package private) void` `sendReset()` got a packet we shouldn't have, send 'em a reset
`void` `setCloseReceivedOn(long when)`
`void` `setCloseSentOn(long when)`
`void` `setCongestionWindowEnd(long endMsg)`
`void` `setConnectionError(java.lang.String err)`
`void` `setHighestAckedThrough(long msgNum)`
`void` `setLastSendId(long id)`
`void` `setLastSendTime(long when)`
`void` `setNextSendTime(long when)`
`void` `setOptions(ConnectionOptions opts)`
`void` `setReceiveStreamId(long id)`
`void` `setRemotePeer(Destination peer)`
`void` `setSendStreamId(long id)`
`void` `setSocket(I2PSocketFull socket)`
`java.lang.String` `toString()`
`(package private) void` `waitForConnect()` wait until a connection is made or the connection fails within the timeout period, setting the error accordingly.
`(package private) void` `windowAdjusted()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### MAX_RESEND_DELAY

    public static final long MAX_RESEND_DELAY

See Also:
  Constant Field Values

### MIN_RESEND_DELAY

    public static final long MIN_RESEND_DELAY

See Also:
  Constant Field Values

### DISCONNECT_TIMEOUT

    public static int DISCONNECT_TIMEOUT

  wait up to 5 minutes after disconnection so we can ack/close packets

### MAX_WINDOW_SIZE

    public static final int MAX_WINDOW_SIZE

  lets be sane- no more than 64 packets in the air in each dir

  See Also:
    Constant Field Values

### FAST_RETRANSMIT_THRESHOLD

    static final int FAST_RETRANSMIT_THRESHOLD

  If we have been explicitly NACKed three times, retransmit the packet even if there are other packets in flight.

  See Also:
    Constant Field Values

Constructor Detail

### Connection

    public Connection(I2PAppContext ctx,
                      ConnectionManager manager,
                      SchedulerChooser chooser,
                      PacketQueue queue,
                      ConnectionPacketHandler handler)

### Connection

    public Connection(I2PAppContext ctx,
                      ConnectionManager manager,
                      SchedulerChooser chooser,
                      PacketQueue queue,
                      ConnectionPacketHandler handler,
                      ConnectionOptions opts)

Method Detail

### getNextOutboundPacketNum

    public long getNextOutboundPacketNum()

### closeReceived

    void closeReceived()

### packetSendChoke

    boolean packetSendChoke(long timeoutMs)

  Block until there is an open outbound packet slot or the write timeout expires.

  Returns:
    true if the packet should be sent

### windowAdjusted

    void windowAdjusted()

### ackImmediately

    void ackImmediately()

### sendReset

    void sendReset()

  got a packet we shouldn't have, send 'em a reset

### sendAvailable

    void sendAvailable()

  Flush any data that we can

### sendPacket

    void sendPacket(PacketLocal packet)

### ackPackets

    java.util.List ackPackets(long ackThrough,
                              long[] nacks)

### eventOccurred

    void eventOccurred()

### resetReceived

    void resetReceived()

### getResetReceived

    public boolean getResetReceived()

### getIsConnected

    public boolean getIsConnected()

### getHardDisconnected

    public boolean getHardDisconnected()

### getResetSent

    public boolean getResetSent()

### getResetSentOn

    public long getResetSentOn()

### getDisconnectScheduledOn

    public long getDisconnectScheduledOn()

### disconnect

    void disconnect(boolean cleanDisconnect)

### disconnect

    void disconnect(boolean cleanDisconnect,
                    boolean removeFromConMgr)

### disconnectComplete

    void disconnectComplete()

### getRemotePeer

    public Destination getRemotePeer()

  who are we talking with

### setRemotePeer

    public void setRemotePeer(Destination peer)

### getSendStreamId

    public long getSendStreamId()

  what stream do we send data to the peer on?

### setSendStreamId

    public void setSendStreamId(long id)

### getReceiveStreamId

    public long getReceiveStreamId()

  stream the peer sends data to us on. (may be null)

### setReceiveStreamId

    public void setReceiveStreamId(long id)

### getLastSendTime

    public long getLastSendTime()

  when did we last send anything to the peer?

### setLastSendTime

    public void setLastSendTime(long when)

### getLastSendId

    public long getLastSendId()

  what was the last packet Id sent to the peer?

### setLastSendId

    public void setLastSendId(long id)

### getOptions

    public ConnectionOptions getOptions()

### setOptions

    public void setOptions(ConnectionOptions opts)

### getSession

    public I2PSession getSession()

### getSocket

    public I2PSocketFull getSocket()

### setSocket

    public void setSocket(I2PSocketFull socket)

### getConnectionError

    public java.lang.String getConnectionError()

### setConnectionError

    public void setConnectionError(java.lang.String err)

### getLifetime

    public long getLifetime()

### getPacketHandler

    public ConnectionPacketHandler getPacketHandler()

### getLifetimeBytesSent

    public long getLifetimeBytesSent()

### getLifetimeBytesReceived

    public long getLifetimeBytesReceived()

### getLifetimeDupMessagesSent

    public long getLifetimeDupMessagesSent()

### getLifetimeDupMessagesReceived

    public long getLifetimeDupMessagesReceived()

### incrementBytesSent

    public void incrementBytesSent(int bytes)

### incrementDupMessagesSent

    public void incrementDupMessagesSent(int msgs)

### incrementBytesReceived

    public void incrementBytesReceived(int bytes)

### incrementDupMessagesReceived

    public void incrementDupMessagesReceived(int msgs)

### getNextSendTime

    public long getNextSendTime()

  Time when the scheduler next want to send a packet, or -1 if never. This should be set when we want to send on timeout, for instance, or want to delay an ACK.

### setNextSendTime

    public void setNextSendTime(long when)

### getAckedPackets

    public long getAckedPackets()

  how many packets have we sent and the other side has ACKed?

### getCreatedOn

    public long getCreatedOn()

### getCloseSentOn

    public long getCloseSentOn()

### setCloseSentOn

    public void setCloseSentOn(long when)

### getCloseReceivedOn

    public long getCloseReceivedOn()

### setCloseReceivedOn

    public void setCloseReceivedOn(long when)

### incrementUnackedPacketsReceived

    public void incrementUnackedPacketsReceived()

### getUnackedPacketsReceived

    public int getUnackedPacketsReceived()

### getUnackedPacketsSent

    public int getUnackedPacketsSent()

  how many packets have we sent but not yet received an ACK for?

### getCongestionWindowEnd

    public long getCongestionWindowEnd()

### setCongestionWindowEnd

    public void setCongestionWindowEnd(long endMsg)

### getHighestAckedThrough

    public long getHighestAckedThrough()

### setHighestAckedThrough

    public void setHighestAckedThrough(long msgNum)

### getLastActivityOn

    public long getLastActivityOn()

### getLastCongestionSeenAt

    public int getLastCongestionSeenAt()

### congestionOccurred

    void congestionOccurred()

### packetReceived

    void packetReceived()

### waitForConnect

    void waitForConnect()

  wait until a connection is made or the connection fails within the timeout period, setting the error accordingly.

### getInputStream

    public MessageInputStream getInputStream()

  stream that the local peer receives data on

### getOutputStream

    public MessageOutputStream getOutputStream()

  stream that the local peer sends data to the remote peer on

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### getConnectionEvent

    public SimpleTimer.TimedEvent getConnectionEvent()