Package net.i2p.client.streaming.impl
Class Connection
- java.lang.Object
- 
- net.i2p.client.streaming.impl.Connection
 
- 
 class Connection extends Object Maintain the state controlling a streaming connection between two destinations.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description (package private) classConnection.ConEventfired to reschedule event notification(package private) classConnection.ResendPacketEventThis is not normally scheduled.(package private) classConnection.RetransmitEventA single retransmit timer for all packets.
 - 
Field SummaryFields Modifier and Type Field Description static intDEFAULT_CONNECT_TIMEOUTstatic intDISCONNECT_TIMEOUTWait up to 5 minutes after disconnection so we can ack/close packets.(package private) static intFAST_RETRANSMIT_THRESHOLDIf we have been explicitly NACKed three times, retransmit the packet even if there are other packets in flight.static intMAX_RESEND_DELAYstatic intMAX_WINDOW_SIZEstatic intMIN_RESEND_DELAY
 - 
Constructor SummaryConstructors Constructor Description Connection(I2PAppContext ctx, ConnectionManager manager, I2PSession session, SchedulerChooser chooser, SimpleTimer2 timer, PacketQueue queue, ConnectionPacketHandler handler, ConnectionOptions opts, boolean isInbound)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidackImmediately()List<PacketLocal>ackPackets(long ackThrough, long[] nacks)Process the acks and nacks received in a packetvoidcloseReceived()Notify that a close was received.voiddisconnect(boolean cleanDisconnect)Must be called when we are done with this connection.voiddisconnect(boolean cleanDisconnect, boolean removeFromConMgr)Must be called when we are done with this connection.voiddisconnectComplete()Must be called when we are done with this connection.(package private) voideventOccurred()longgetAckedPackets()how many packets have we sent and the other side has ACKed?longgetCloseReceivedOn()longgetCloseSentOn()longgetCongestionWindowEnd()StringgetConnectionError()ConnectionManagergetConnectionManager()longgetCreatedOn()longgetDisconnectScheduledOn()booleangetHardDisconnected()longgetHighestAckedThrough()MessageInputStreamgetInputStream()stream that the local peer receives data onbooleangetIsConnected()Always true at the start, even if we haven't gotten a reply on an outbound connection.longgetLastActivityOn()longgetLastSendId()What was the last packet Id sent to the peer?longgetLastSendTime()When did we last send anything to the peer?longgetLifetime()longgetLifetimeBytesReceived()longgetLifetimeBytesSent()longgetLifetimeDupMessagesReceived()longgetLifetimeDupMessagesSent()intgetLocalPort()longgetNextOutboundPacketNum()longgetNextSendTime()Time when the scheduler next want to send a packet, or -1 if never.ConnectionOptionsgetOptions()Retrieve the current ConnectionOptions.MessageOutputStreamgetOutputStream()stream that the local peer sends data to the remote peer onConnectionPacketHandlergetPacketHandler()intgetPort()The remote port.longgetReceiveStreamId()The stream ID of a peer connection that sends data to us, or zero if unknown.DestinationgetRemotePeer()who are we talking withSigningPublicKeygetRemoteSPK()The key to verify signatures with.booleangetResetReceived()booleangetResetSent()longgetResetSentOn()longgetSendStreamId()What stream do we send data to the peer on?I2PSessiongetSession()I2PSocketFullgetSocket()(package private) intgetSSThresh()intgetUnackedPacketsReceived()intgetUnackedPacketsSent()how many packets have we sent but not yet received an ACK for?voidincrementBytesReceived(int bytes)voidincrementBytesSent(int bytes)voidincrementDupMessagesReceived(int msgs)voidincrementDupMessagesSent(int msgs)voidincrementUnackedPacketsReceived()booleanisChoked()Is the other side choking us?booleanisInbound()(package private) Connection.ResendPacketEventnewResendPacketEvent(PacketLocal packet)A new ResendPacketEvent.voidnotifyCloseSent()Notify that a close was sent.voidnotifyLastPacketAcked()Notify that a close that we sent, and all previous packets, were acked.(package private) voidpacketReceived()booleanpacketSendChoke(long timeoutMs)This doesn't "send a choke".voidresetReceived()Notify that a reset was received.voidschedule(SimpleTimer.TimedEvent event, long msToWait)Schedule something on our timer.voidscheduleConnectionEvent(long msToWait)Called from SchedulerImpl(package private) voidsendAvailable()Flush any data that we can.(package private) voidsendPacket(PacketLocal packet)This sends all 'normal' packets (acks and data) for the first time.voidsetChoked(boolean on)Set or clear if we are being choked by the other side.voidsetChoking(boolean on)Set or clear if we are choking the other side.voidsetCongestionWindowEnd(long endMsg)voidsetConnectionError(String err)voidsetLastSendId(long id)Set the packet Id that was sent to a peer.voidsetNextSendTime(long when)If the next send time is currently >= 0 (i.e.voidsetOptions(ConnectionOptions opts)Set the ConnectionOptions.voidsetReceiveStreamId(long id)voidsetRemotePeer(Destination peer)voidsetRemoteTransientSPK(SigningPublicKey transientSPK)voidsetSendStreamId(long id)voidsetSocket(I2PSocketFull socket)StringtoString()voidupdateShareOpts()(package private) voidwaitForConnect()wait until a connection is made or the connection fails within the timeout period, setting the error accordingly.(package private) voidwindowAdjusted()Notify all threads waiting in packetSendChoke()
 
- 
- 
- 
Field Detail- 
MAX_RESEND_DELAYpublic static final int MAX_RESEND_DELAY - See Also:
- Constant Field Values
 
 - 
MIN_RESEND_DELAYpublic static final int MIN_RESEND_DELAY - See Also:
- Constant Field Values
 
 - 
DISCONNECT_TIMEOUTpublic static final int DISCONNECT_TIMEOUT Wait up to 5 minutes after disconnection so we can ack/close packets. Roughly equal to the TIME-WAIT time in RFC 793, where the recommendation is 4 minutes (2 * MSL)- See Also:
- Constant Field Values
 
 - 
DEFAULT_CONNECT_TIMEOUTpublic static final int DEFAULT_CONNECT_TIMEOUT - See Also:
- Constant Field Values
 
 - 
MAX_WINDOW_SIZEpublic static final int MAX_WINDOW_SIZE - See Also:
- Constant Field Values
 
 - 
FAST_RETRANSMIT_THRESHOLDstatic 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- 
Connectionpublic Connection(I2PAppContext ctx, ConnectionManager manager, I2PSession session, SchedulerChooser chooser, SimpleTimer2 timer, PacketQueue queue, ConnectionPacketHandler handler, ConnectionOptions opts, boolean isInbound) - Parameters:
- opts- may be null
 
 
- 
 - 
Method Detail- 
getSSThreshint getSSThresh() - Since:
- 0.9.46
 
 - 
getNextOutboundPacketNumpublic long getNextOutboundPacketNum() 
 - 
packetSendChokepublic boolean packetSendChoke(long timeoutMs) throws IOException, InterruptedExceptionThis doesn't "send a choke". Rather, it blocks if the outbound window is full, thus choking the sender that calls this. Block until there is an open outbound packet slot or the write timeout expires. PacketLocal is the only caller, generally with -1.- Parameters:
- timeoutMs- 0 or negative means wait forever, 5 minutes max
- Returns:
- true if the packet should be sent, false for a fatal error will return false after 5 minutes even if timeoutMs is <= 0.
- Throws:
- IOException
- InterruptedException
 
 - 
windowAdjustedvoid windowAdjusted() Notify all threads waiting in packetSendChoke()
 - 
ackImmediatelyvoid ackImmediately() 
 - 
sendAvailablevoid sendAvailable() Flush any data that we can. Non-blocking.
 - 
sendPacketvoid sendPacket(PacketLocal packet) This sends all 'normal' packets (acks and data) for the first time. Retransmits are done in ResendPacketEvent below. Resets, pings, and pongs are done elsewhere in this class, or in ConnectionManager or ConnectionHandler.
 - 
ackPacketspublic List<PacketLocal> ackPackets(long ackThrough, long[] nacks) Process the acks and nacks received in a packet- Returns:
- List of packets acked for the first time, or null if none
 
 - 
eventOccurredvoid eventOccurred() 
 - 
notifyCloseSentpublic void notifyCloseSent() Notify that a close was sent. Called by CPH. May be called multiple times... but shouldn't be.
 - 
closeReceivedpublic void closeReceived() Notify that a close was received. Called by CPH. May be called multiple times.
 - 
notifyLastPacketAckedpublic void notifyLastPacketAcked() Notify that a close that we sent, and all previous packets, were acked. Called by CPH. Only call this once.- Since:
- 0.9.9
 
 - 
resetReceivedpublic void resetReceived() Notify that a reset was received. May be called multiple times.
 - 
getResetReceivedpublic boolean getResetReceived() 
 - 
isInboundpublic boolean isInbound() 
 - 
getIsConnectedpublic boolean getIsConnected() Always true at the start, even if we haven't gotten a reply on an outbound connection. Only set to false on disconnect. For outbound, use getHighestAckedThrough() >= 0 also, to determine if the connection is up. In general, this is true until either: - CLOSE received and CLOSE sent and our CLOSE is acked - RESET received or sent - closed on the socket side
 - 
getHardDisconnectedpublic boolean getHardDisconnected() 
 - 
getResetSentpublic boolean getResetSent() 
 - 
getResetSentOnpublic long getResetSentOn() - Returns:
- 0 if not sent
 
 - 
getDisconnectScheduledOnpublic long getDisconnectScheduledOn() - Returns:
- 0 if not scheduled
 
 - 
disconnectpublic void disconnect(boolean cleanDisconnect) Must be called when we are done with this connection. Enters TIME-WAIT if necessary, and removes from connection manager. May be called multiple times. This closes the socket side. In normal operation, this is called when a CLOSE has been received, AND a CLOSE has been sent, AND EITHER: received close before sent close AND our CLOSE has been acked OR received close after sent close.- Parameters:
- cleanDisconnect- if true, normal close; if false, send a RESET
 
 - 
disconnectpublic void disconnect(boolean cleanDisconnect, boolean removeFromConMgr)Must be called when we are done with this connection. May be called multiple times. This closes the socket side. In normal operation, this is called when a CLOSE has been received, AND a CLOSE has been sent, AND EITHER: received close before sent close AND our CLOSE has been acked OR received close after sent close.- Parameters:
- cleanDisconnect- if true, normal close; if false, send a RESET
- removeFromConMgr- if true, enters TIME-WAIT if necessary. if false, MUST call disconnectComplete() later. Should always be true unless called from ConnectionManager.
 
 - 
disconnectCompletepublic void disconnectComplete() Must be called when we are done with this connection. Final disconnect. Remove from conn manager. May be called multiple times.
 - 
scheduleConnectionEventpublic void scheduleConnectionEvent(long msToWait) Called from SchedulerImpl- Since:
- 0.9.23 moved here so we can use our timer
 
 - 
schedulepublic void schedule(SimpleTimer.TimedEvent event, long msToWait) Schedule something on our timer.- Since:
- 0.9.23
 
 - 
getRemotePeerpublic Destination getRemotePeer() who are we talking with- Returns:
- peer Destination or null if unset
 
 - 
setRemotePeerpublic void setRemotePeer(Destination peer) - Parameters:
- peer- non-null
 
 - 
getRemoteSPKpublic SigningPublicKey getRemoteSPK() The key to verify signatures with. The transient SPK if previously received, else getRemotePeer().getSigningPublicKey() if previously received, else null.- Returns:
- peer Destination or null if unset
- Since:
- 0.9.39
 
 - 
setRemoteTransientSPKpublic void setRemoteTransientSPK(SigningPublicKey transientSPK) - Parameters:
- transientSPK- null ok
- Since:
- 0.9.39
 
 - 
getSendStreamIdpublic long getSendStreamId() What stream do we send data to the peer on?- Returns:
- non-global stream sending ID, or 0 if unknown
 
 - 
setSendStreamIdpublic void setSendStreamId(long id) - Parameters:
- id- 0 to 0xffffffff
- Throws:
- IllegalStateException- if already set to nonzero
 
 - 
getReceiveStreamIdpublic long getReceiveStreamId() The stream ID of a peer connection that sends data to us, or zero if unknown.- Returns:
- receive stream ID, or 0 if unknown
 
 - 
setReceiveStreamIdpublic void setReceiveStreamId(long id) - Parameters:
- id- 0 to 0xffffffff
- Throws:
- IllegalStateException- if already set to nonzero
 
 - 
getLastSendTimepublic long getLastSendTime() When did we last send anything to the peer?- Returns:
- Last time we sent data
 
 - 
getLastSendIdpublic long getLastSendId() What was the last packet Id sent to the peer?- Returns:
- The last sent packet ID
 
 - 
setLastSendIdpublic void setLastSendId(long id) Set the packet Id that was sent to a peer.- Parameters:
- id- The packet ID
 
 - 
getOptionspublic ConnectionOptions getOptions() Retrieve the current ConnectionOptions.- Returns:
- the current ConnectionOptions, non-null
 
 - 
setOptionspublic void setOptions(ConnectionOptions opts) Set the ConnectionOptions.- Parameters:
- opts- ConnectionOptions non-null
 
 - 
getConnectionManagerpublic ConnectionManager getConnectionManager() - Since:
- 0.9.21
 
 - 
getSessionpublic I2PSession getSession() 
 - 
getSocketpublic I2PSocketFull getSocket() 
 - 
setSocketpublic void setSocket(I2PSocketFull socket) 
 - 
getPortpublic int getPort() The remote port.- Returns:
- Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
- Since:
- 0.8.9
 
 - 
getLocalPortpublic int getLocalPort() - Returns:
- Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
- Since:
- 0.8.9
 
 - 
getConnectionErrorpublic String getConnectionError() 
 - 
setConnectionErrorpublic void setConnectionError(String err) 
 - 
getLifetimepublic long getLifetime() 
 - 
getPacketHandlerpublic ConnectionPacketHandler getPacketHandler() 
 - 
getLifetimeBytesSentpublic long getLifetimeBytesSent() 
 - 
getLifetimeBytesReceivedpublic long getLifetimeBytesReceived() 
 - 
getLifetimeDupMessagesSentpublic long getLifetimeDupMessagesSent() 
 - 
getLifetimeDupMessagesReceivedpublic long getLifetimeDupMessagesReceived() 
 - 
incrementBytesSentpublic void incrementBytesSent(int bytes) 
 - 
incrementDupMessagesSentpublic void incrementDupMessagesSent(int msgs) 
 - 
incrementBytesReceivedpublic void incrementBytesReceived(int bytes) 
 - 
incrementDupMessagesReceivedpublic void incrementDupMessagesReceived(int msgs) 
 - 
getNextSendTimepublic 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.- Returns:
- the next time the scheduler will want to send a packet, or -1 if never.
 
 - 
setNextSendTimepublic void setNextSendTime(long when) If the next send time is currently >= 0 (i.e. not "never"), this may make the next time sooner but will not make it later. If the next send time is currently < 0 (i.e. "never"), this will set it to the time specified, but not later than options.getSendAckDelay() from now (1000 ms)
 - 
setChokingpublic void setChoking(boolean on) Set or clear if we are choking the other side. If on is true or the value has changed, this will call ackImmediately().- Parameters:
- on- true for choking
- Since:
- 0.9.29
 
 - 
setChokedpublic void setChoked(boolean on) Set or clear if we are being choked by the other side.- Parameters:
- on- true for choked
- Since:
- 0.9.29
 
 - 
isChokedpublic boolean isChoked() Is the other side choking us?- Returns:
- if choked
- Since:
- 0.9.29
 
 - 
getAckedPacketspublic long getAckedPackets() how many packets have we sent and the other side has ACKed?- Returns:
- Count of how many packets ACKed.
 
 - 
getCreatedOnpublic long getCreatedOn() 
 - 
getCloseSentOnpublic long getCloseSentOn() - Returns:
- 0 if not sent
 
 - 
getCloseReceivedOnpublic long getCloseReceivedOn() - Returns:
- 0 if not received
 
 - 
updateShareOptspublic void updateShareOpts() 
 - 
incrementUnackedPacketsReceivedpublic void incrementUnackedPacketsReceived() 
 - 
getUnackedPacketsReceivedpublic int getUnackedPacketsReceived() 
 - 
getUnackedPacketsSentpublic int getUnackedPacketsSent() how many packets have we sent but not yet received an ACK for?- Returns:
- Count of packets in-flight.
 
 - 
getCongestionWindowEndpublic long getCongestionWindowEnd() 
 - 
setCongestionWindowEndpublic void setCongestionWindowEnd(long endMsg) 
 - 
getHighestAckedThroughpublic long getHighestAckedThrough() - Returns:
- the highest outbound packet we have recieved an ack for
 
 - 
getLastActivityOnpublic long getLastActivityOn() 
 - 
packetReceivedvoid packetReceived() 
 - 
waitForConnectvoid waitForConnect() wait until a connection is made or the connection fails within the timeout period, setting the error accordingly.
 - 
getInputStreampublic MessageInputStream getInputStream() stream that the local peer receives data on- Returns:
- the inbound message stream, non-null
 
 - 
getOutputStreampublic MessageOutputStream getOutputStream() stream that the local peer sends data to the remote peer on- Returns:
- the outbound message stream, non-null
 
 - 
newResendPacketEventConnection.ResendPacketEvent newResendPacketEvent(PacketLocal packet) A new ResendPacketEvent.- Since:
- 0.9.46
 
 
- 
 
-