class Connection extends Object
| Modifier and Type | Class and Description |
|---|---|
(package private) class | Connection.AckDupEventReusable event to send an ACK for a duplicate packet after a short delay. |
(package private) class | Connection.ConEventNotify waiters to reschedule the connection event. |
(package private) class | Connection.ResendPacketEventThis is not normally scheduled. |
(package private) class | Connection.RetransmitEventA single retransmit timer for all packets. |
| Modifier and Type | Field and Description |
|---|---|
static int | ABSOLUTE_MAX_WINDOWAbsolute ceiling on in-flight packets regardless of BDP estimate. |
static int | DEFAULT_CONNECT_TIMEOUTDefault connect timeout in milliseconds. |
(package private) static int | FAST_RETRANSMIT_THRESHOLDIf we have been explicitly NACKed three times, retransmit the packet even if
there are other packets in flight. |
static int | MAX_WINDOW_SIZE_DEFAULTDefault window size cap used when no per-connection or global override is set. |
| Constructor and Description |
|---|
Connection(I2PAppContext ctx,
ConnectionManager manager,
I2PSession session,
SchedulerChooser chooser,
SimpleTimer2 timer,
PacketQueue queue,
ConnectionPacketHandler handler,
ConnectionOptions opts,
boolean isInbound)Constructor for this connection. |
| Modifier and Type | Method and Description |
|---|---|
(package private) void | ackImmediately()Ack immediately. |
List<PacketLocal> | ackPackets(long ackThrough,
long[] nacks)Process the acks and nacks received in a packet. |
void | closeReceived()Notify that a close was received. |
void | disconnect(boolean cleanDisconnect)Must be called when we are done with this connection. |
void | disconnect(boolean cleanDisconnect,
boolean removeFromConMgr)Must be called when we are done with this connection. |
void | disconnectComplete()Must be called when we are done with this connection. |
(package private) void | eventOccurred()Notify the scheduler that an event occurred on this connection. |
(package private) Connection.AckDupEvent | getAckDupEvent()Schedule an event on our timer. |
long | getAckedPackets()How many packets have we sent and the other side has ACKed? |
long | getCloseReceivedOn()Timestamp when a close was received. |
long | getCloseSentOn()Timestamp when a close was sent. |
long | getCongestionWindowEnd()Congestion window end sequence number. |
String | getConnectionError()Connection error message, if any. |
ConnectionManager | getConnectionManager() |
(package private) static int | getConnectTimeoutMultiplier() |
long | getCreatedOn()Timestamp when this connection was created. |
long | getDisconnectScheduledOn()Timestamp when the disconnect was scheduled. |
static int | getDisconnectTimeout() |
static int | getGlobalMaxWindowSize() |
boolean | getHardDisconnected()Check if this connection has been hard-disconnected (via RESET). |
long | getHighestAckedThrough()Highest outbound packet we have received an ack for. |
MessageInputStream | getInputStream()Input stream that the local peer receives data on. |
boolean | getIsConnected()Always true at the start, even if we haven't gotten a reply on an
outbound connection. |
long | getLastActivityOn()Timestamp of the last send or receive activity. |
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()Lifetime of this connection in milliseconds. |
long | getLifetimeBytesReceived()Total bytes received on this connection. |
long | getLifetimeBytesSent()Total bytes sent on this connection. |
long | getLifetimeDupBytesSent()Total duplicate bytes sent on this connection. |
long | getLifetimeDupMessagesReceived()Total duplicate messages received on this connection. |
long | getLifetimeDupMessagesSent()Total duplicate messages sent on this connection. |
int | getLocalPort()Local port of this connection. |
(package private) static long | getMaxConnectTimeout() |
static int | getMaxResendDelay() |
static int | getMaxRetransmissionsStatic() |
static int | getMaxSynResendsStatic() |
static int | getMinResendDelay() |
long | getNextOutboundPacketNum()Next outbound packet sequence number. |
long | getNextSendTime()Time when the scheduler next want to send a packet, or -1 if
never. |
ConnectionOptions | getOptions()Retrieve the current ConnectionOptions. |
MessageOutputStream | getOutputStream()Output stream that the local peer sends data to the remote peer on. |
ConnectionPacketHandler | getPacketHandler()Packet handler for this connection. |
int | getPort()The remote port. |
long | getReceiveStreamId()The stream ID of a peer connection that sends data to us, or zero if unknown. |
Destination | getRemotePeer()Destination of the remote peer. |
SigningPublicKey | getRemoteSPK()The key to verify signatures with. |
boolean | getResetReceived()Check if a reset has been received on this connection. |
long | getResetReceivedOn()Timestamp when a reset was received. |
boolean | getResetSent()Check if a reset has been sent on this connection. |
long | getResetSentOn()Timestamp when a reset was sent. |
long | getSendStreamId()What stream do we send data to the peer on? |
I2PSession | getSession()I2P session for this connection. |
I2PSocketFull | getSocket()Socket associated with this connection. |
(package private) int | getSSThresh() |
int | getUnackedPacketsReceived()Count of unacked packets received. |
int | getUnackedPacketsSent()How many packets have we sent but not yet received an ACK for? |
Object | getWindowLock()For ConnectionPacketHandler.adjustWindow() |
void | incrementBytesReceived(int bytes)Increment the lifetime bytes received counter. |
void | incrementBytesSent(int bytes)Increment the lifetime bytes sent counter. |
void | incrementDupBytesSent(int bytes)Increment the lifetime duplicate bytes sent counter. |
void | incrementDupMessagesReceived(int msgs)Increment the lifetime duplicate messages received counter. |
void | incrementDupMessagesSent(int msgs)Increment the lifetime duplicate messages sent counter. |
void | incrementUnackedPacketsReceived()Increment the count of unacked packets received. |
boolean | isChoked()Is the other side choking us? |
boolean | isInbound()Check if this is an inbound connection. |
(package private) Connection.ResendPacketEvent | newResendPacketEvent(PacketLocal packet)A new ResendPacketEvent. |
void | notifyCloseSent()Called by CPH when a CLOSE packet is sent. |
void | notifyLastPacketAcked()Notify that a close that we sent, and all previous packets, were acked. |
(package private) void | packetReceived()Called when a packet is received on this connection. |
boolean | packetSendChoke(long timeoutMs)This doesn't "send a choke". |
void | resetReceived()Notify that a reset was received. |
void | scheduleConnectionEvent(long msToWait)Called from SchedulerImpl |
(package private) void | scheduleSoftFailureRetransmit()Trigger immediate retransmission of unacked packets after a soft failure
(e.g., tunnel expiry, no tunnels). |
(package private) void | sendAvailable()Flush any data that we can. |
(package private) void | sendPacket(PacketLocal packet)This sends all 'normal' packets (acks and data) for the first time. |
void | setChoked(boolean on)Choked state set by the other side. |
void | setChoking(boolean on)Choking state toward the other side. |
void | setCongestionWindowEnd(long endMsg)Congestion window end sequence number. |
void | setConnectionError(String err)Connection error message. |
(package private) static void | setConnectTimeoutMultiplier(int pct) |
static void | setGlobalMaxWindowSize(int val) |
static void | setMaxRetransmissions(int val) |
static void | setMaxSynResends(int val) |
void | setNextSendTime(long when)If the next send time is currently >= 0 (i.e. |
void | setOptions(ConnectionOptions opts)ConnectionOptions for this connection. |
void | setReceiveStreamId(long id)Stream ID that the peer sends data on. |
void | setRemotePeer(Destination peer)Remote peer of this connection, non-null. |
void | setRemoteTransientSPK(SigningPublicKey transientSPK)Transient signing public key of the remote peer. |
void | setSendStreamId(long id)Stream ID that we send data on. |
void | setSocket(I2PSocketFull socket)Socket associated with this connection. |
String | toString()Human-readable summary of this connection. |
void | updateShareOpts()Update shared options from the TCB cache. |
(package private) void | waitForConnect()Wait for the connection to be established, with the option's connectTimeout. |
(package private) void | waitForConnect(int timeoutMs)Wait for the connection to be established, but no longer than timeoutMs. |
(package private) void | windowAdjusted()Notify all threads waiting in packetSendChoke(). |
public static final int ABSOLUTE_MAX_WINDOW
public static final int DEFAULT_CONNECT_TIMEOUT
static final int FAST_RETRANSMIT_THRESHOLD
public static final int MAX_WINDOW_SIZE_DEFAULT
public Connection(I2PAppContext ctx, ConnectionManager manager, I2PSession session, SchedulerChooser chooser, SimpleTimer2 timer, PacketQueue queue, ConnectionPacketHandler handler, ConnectionOptions opts, boolean isInbound)
opts - may be nullvoid ackImmediately()
public List<PacketLocal> ackPackets(long ackThrough, long[] nacks)
Note: the returned list is a reused, internally-owned buffer
(_ackedList) that is cleared at the start of the next
ackPackets() call. Callers MUST fully consume it before the
next ack is processed. This is safe because acks are serialized on the
receive thread; do not retain a reference across calls.
public void closeReceived()
public void disconnect(boolean cleanDisconnect)
cleanDisconnect - if true, normal close; if false, send a RESETpublic void disconnect(boolean cleanDisconnect,
boolean removeFromConMgr)cleanDisconnect - if true, normal close; if false, send a RESETremoveFromConMgr - if true, enters TIME-WAIT if necessary.
if false, MUST call disconnectComplete() later.
Should always be true unless called from ConnectionManager.public void disconnectComplete()
void eventOccurred()
Connection.AckDupEvent getAckDupEvent()
public long getAckedPackets()
public long getCloseReceivedOn()
public long getCloseSentOn()
public long getCongestionWindowEnd()
public String getConnectionError()
public ConnectionManager getConnectionManager()
static int getConnectTimeoutMultiplier()
public long getCreatedOn()
public long getDisconnectScheduledOn()
public static int getDisconnectTimeout()
public static int getGlobalMaxWindowSize()
public boolean getHardDisconnected()
public long getHighestAckedThrough()
public MessageInputStream getInputStream()
public boolean getIsConnected()
public long getLastActivityOn()
public long getLastSendId()
public long getLastSendTime()
public long getLifetime()
public long getLifetimeBytesReceived()
public long getLifetimeBytesSent()
public long getLifetimeDupBytesSent()
public long getLifetimeDupMessagesReceived()
public long getLifetimeDupMessagesSent()
public int getLocalPort()
static long getMaxConnectTimeout()
public static int getMaxResendDelay()
public static int getMaxRetransmissionsStatic()
public static int getMaxSynResendsStatic()
public static int getMinResendDelay()
public long getNextOutboundPacketNum()
public long getNextSendTime()
public ConnectionOptions getOptions()
public MessageOutputStream getOutputStream()
public ConnectionPacketHandler getPacketHandler()
public int getPort()
public long getReceiveStreamId()
public Destination getRemotePeer()
public SigningPublicKey getRemoteSPK()
public boolean getResetReceived()
public long getResetReceivedOn()
public boolean getResetSent()
public long getResetSentOn()
public long getSendStreamId()
public I2PSession getSession()
public I2PSocketFull getSocket()
int getSSThresh()
public int getUnackedPacketsReceived()
public int getUnackedPacketsSent()
public Object getWindowLock()
public void incrementBytesReceived(int bytes)
bytes - number of bytes to addpublic void incrementBytesSent(int bytes)
bytes - number of bytes to addpublic void incrementDupBytesSent(int bytes)
bytes - number of duplicate bytes to addpublic void incrementDupMessagesReceived(int msgs)
msgs - number of duplicate messages to addpublic void incrementDupMessagesSent(int msgs)
msgs - number of duplicate messages to addpublic void incrementUnackedPacketsReceived()
public boolean isChoked()
public boolean isInbound()
Connection.ResendPacketEvent newResendPacketEvent(PacketLocal packet)
public void notifyCloseSent()
public void notifyLastPacketAcked()
void packetReceived()
public boolean packetSendChoke(long timeoutMs)
throws IOException,
InterruptedExceptionThe wait loop polls every 50ms (instead of 250ms) to reduce latency when an ACK arrives to free a window slot.
timeoutMs - 0 or negative means wait forever, 5 minutes maxIOExceptionInterruptedExceptionpublic void resetReceived()
public void scheduleConnectionEvent(long msToWait)
void scheduleSoftFailureRetransmit()
void sendAvailable()
void sendPacket(PacketLocal packet)
public void setChoked(boolean on)
on - true for chokedpublic void setChoking(boolean on)
on - true for chokingpublic void setCongestionWindowEnd(long endMsg)
endMsg - the new congestion window endpublic void setConnectionError(String err)
err - the error messagestatic void setConnectTimeoutMultiplier(int pct)
public static void setGlobalMaxWindowSize(int val)
public static void setMaxRetransmissions(int val)
public static void setMaxSynResends(int val)
public void setNextSendTime(long when)
public void setOptions(ConnectionOptions opts)
opts - ConnectionOptions non-nullpublic void setReceiveStreamId(long id)
id - 0 to 0xffffffffIllegalStateException - if already set to nonzeropublic void setRemotePeer(Destination peer)
peer - non-nullpublic void setRemoteTransientSPK(SigningPublicKey transientSPK)
transientSPK - null okpublic void setSendStreamId(long id)
id - 0 to 0xffffffffIllegalStateException - if already set to nonzeropublic void setSocket(I2PSocketFull socket)
socket - the socketpublic String toString()
public void updateShareOpts()
void waitForConnect()
void waitForConnect(int timeoutMs)
timeoutMs - max wait in ms; if <= 0 uses the connection option's connectTimeoutvoid windowAdjusted()