public class PeerState extends Object
| Modifier and Type | Field and Description |
|---|---|
protected RouterContext | _contextThe router context. |
protected boolean | _deadHave we migrated away from this peer to another newer one? |
protected Object | _inboundLockLock for inbound operations |
protected ConcurrentMap<Long,InboundMessageState> | _inboundMessageslist of InboundMessageState for active message |
protected boolean | _isInboundIs it inbound? |
protected long | _keyEstablishedTimethe key establishment time |
protected long | _lastACKSendWhen did we last send ACKs to the peer? |
protected Log | _logThe log. |
protected int | _mtuWhat is the largest packet we can currently send to the peer? |
protected int | _packetsReceivedDuplicateHow many duplicate packets were received within the last RETRANSMISSION_PERIOD_WIDTH packets. |
protected RemoteHostId | _remoteHostIdcached RemoteHostId, used to find the peerState by remote info |
protected byte[] | _remoteIPwhat IP is the peer sending and receiving packets on? |
protected InetAddress | _remoteIPAddresscached IP address |
protected Hash | _remotePeerThe peer are we talking to. |
protected int | _remotePortwhat port is the peer sending and receiving packets on? |
protected int | _rttCurrent round trip time estimate. |
protected UDPTransport | _transportThe UDP transport. |
protected long | _wantACKSendSinceWhen did we decide we need to ACK to this peer? |
static int | DEFAULT_MTUDefault MTU |
static int | LARGE_MTUIPv4 Max MTU
based on measurements, 1350 fits nearly all reasonably small I2NP messages
(larger I2NP messages may be up to 1900B-4500B, which isn't going to fit
into a live network MTU anyway)
TODO
VTBM is 2646, it would be nice to fit in two large
2646 / 2 = 1323
1323 + 74 + 46 + 1 + (4 * 9) = 1480
So why not make it 1492 (old ethernet is 1492, new is 1500)
Changed to 1492 in 0.8.9
BUT through 0.8.11,
Size estimate was bad, actual packet was up to 48 bytes bigger
To be figured out. |
static int | MAX_IPV6_MTUthe maximum IPv6 MTU |
static int | MAX_MTUMax of IPv4 and IPv6 max MTUs |
static int | MIN_IPV6_MTUIPv6/UDP header is 48 bytes, so we want MTU % 16 == 0. |
static int | MIN_MTUIPv4 Min MTU
596 gives us 588 IP byes, 568 UDP bytes, and with an SSU data message,
522 fragment bytes, which is enough to send a tunnel data message in 2
packets. |
(package private) static long | RETRANSMISSION_PERIOD_WIDTHhow many packets will be considered within the retransmission rate calculation |
| Modifier | Constructor and Description |
|---|---|
protected | PeerState(RouterContext ctx,
UDPTransport transport,
InetSocketAddress addr,
Hash remotePeer,
boolean isInbound,
int rtt)For SSU2 |
| Modifier and Type | Method and Description |
|---|---|
protected boolean | acked(PacketBuilder.Fragment f)An ACK of a fragment was received. |
(package private) void | add(OutboundMessageState state)Add an outbound message state to the queue. |
(package private) void | adjustClockSkew(long skew)Update the moving-average clock skew based on the current difference. |
(package private) void | changePort(int newPort)Change the remote port. |
(package private) void | clearWantedACKSendSince()All acks have been sent - SSU 1 only, see override |
(package private) void | dataReceived()Same as setLastReceivedTime(now) |
(package private) void | dropOutbound()drop all outbound messages |
(package private) void | ECNReceived()Cut our send window as a congestion/backoff response. |
(package private) int | expireInboundMessages()Expire partially received inbound messages, returning how many are still pending. |
(package private) List<OutboundMessageState> | finishAndAllocate(long now)Replaces the two-pass pattern of finishMessages() + allocateSend() with a single pass
through _outboundMessages. |
(package private) int | fragmentOverhead()Packet overhead plus room for acks |
(package private) int | fragmentSize()how much payload data can we shove in there? |
static int | getAckFrequency()Current ACK frequency. |
static long[] | getAggregateStats(Collection<PeerState> peers)Compute aggregate transport stats across all peers for tuner visibility. |
long | getClockSkew()clock skew. |
static int | getClockSkewFudge()clock skew fudge factor. |
int | getConcurrentSends()Concurrent sends count. |
int | getConcurrentSendWindow()Concurrent send window. |
int | getConsecutiveFailedSends()Consecutive failed sends count. |
int | getConsecutiveSendRejections()Consecutive send rejections count. |
long | getInactivityTime()Inactivity time. |
(package private) Map<Long,InboundMessageState> | getInboundMessages()Fetch the internal id (Long) to InboundMessageState for incomplete inbound messages. |
static int | getInitConcurrentMsgs()initial concurrent messages per peer. |
static int | getInitRTO()initial RTO for new peers. |
(package private) long | getIntroducerTime()Last introducer time. |
long | getKeyEstablishedTime()when the cipher and MAC keys were established. |
long | getLastACKSend()when we last sent an ACK. |
long | getLastReceiveTime()Last receive time. |
long | getLastSendFullyTime()Last send fully time. |
(package private) long | getLastSendOrPingTime()latest of last sent, last ACK, last ping. |
long | getLastSendTime()Last send time. |
static int | getMaxConcurrentMessages()Max concurrent messages per peer. |
static int | getMaxRTO()maximum RTO ceiling. |
static int | getMaxSendWindow()max send window (CWIN). |
boolean | getMayDisconnect()whether we may disconnect. |
int | getMessagesReceived()I2NP messages received. |
int | getMessagesSent()I2NP messages sent - does not include duplicates. |
static int | getMinConcurrentMsgs()minimum concurrent messages per peer. |
static int | getMinRTO()minimum RTO floor. |
int | getMTU()Maximum transmission unit. |
(package private) int | getNextDelay(long now)Uses cached oldest lifetime from the most recent finishAndAllocate() pass. |
int | getOutboundMessageCount()Outbound message count. |
static long | getOutboundMsgExpiration()Bridge to OutboundMessageState.getMessageExpiration for Tuner (different package). |
int | getPacketsReceived()Packets received count. |
int | getPacketsReceivedDuplicate()Packets received duplicate count. |
int | getPacketsRetransmitted()Packets retransmitted count. |
int | getPacketsTransmitted()Packets transmitted count. |
static int | getPostRTOWindowMTUs()post-RTO-collapse window restart size. |
int | getReceiveBps(long now)receive Bps estimate. |
int | getReceiveMTU()receive MTU estimate. |
RemoteHostId | getRemoteHostId()remote host ID. |
byte[] | getRemoteIP()Remote IP address bytes. |
InetAddress | getRemoteIPAddress()cached remote IP address. |
Hash | getRemotePeer()remote peer hash. |
int | getRemotePort()Remote port. |
int | getRTO()retransmission timeout. |
int | getRTT()round trip time. |
int | getRTTDeviation()RTT deviation. |
int | getSendBps(long now)The Westwood+ bandwidth estimate |
int | getSendWindowBytes()send window bytes. |
int | getSendWindowBytesRemaining()Send window bytes remaining. |
static long | getSentMessagesCleanTime()Bridge to PeerState2.sentMessagesCleanTime for Tuner (different package). |
int | getSlowStartThreshold()Slow start threshold. |
long | getTheyRelayToUsAs()tag they relay to us as. |
(package private) UDPTransport | getTransport()Convenience for OutboundMessageState so it can fail itself |
int | getVersion()peer SSU version. |
long | getWeRelayToThemAs()tag we relay to them as. |
(package private) boolean | hasOutbound()After a finishAndAllocate() pass, reports whether any outbound messages remain. |
(package private) boolean | highestSeqNumAcked(long highest)Enter or leave fast retransmit mode, and adjust SST and window variables accordingly. |
(package private) int | incrementConsecutiveFailedSends()Increment consecutive failed sends. |
boolean | isBacklogged() |
boolean | isInbound()Whether this is an inbound connection. |
boolean | isIPv6()Whether the connection uses IPv6. |
static void | loadConfig(RouterContext ctx)Load configurable UDP transport parameters from router.config. |
(package private) void | loadFrom(PeerState oldPeer)Transfer the basic activity/state from the old peer to the current peer
SSU 1 or 2. |
(package private) void | messageFullyReceived(Long messageId,
int bytes)We received the message specified completely. |
(package private) void | messagePartiallyReceived()We received a partial message, or we want to send some acks. |
protected void | messagePartiallyReceived(long now)We received a partial message, or we want to send some acks. |
(package private) void | messageRetransmitted(int packets,
int maxPktSz)Handle a message retransmission. |
(package private) void | packetReceived(int size)Record a received packet. |
(package private) void | packetsTransmitted(int packets)Record that packets were transmitted. |
static void | setAckFrequency(int freq)ACK frequency. |
(package private) void | setHisMTU(int mtu)Remote peer's MTU. |
static void | setInitConcurrentMsgs(int msgs)Initial concurrent messages per peer (called by Tuner). |
static void | setInitRTO(int ms)Initial RTO for new peers (called by Tuner). |
(package private) void | setIntroducerTime()Record the last time we used them as an introducer. |
(package private) void | setLastPingTime(long when)Last ping time. |
(package private) void | setLastReceiveTime(long when)Last receive time. |
(package private) void | setLastSendTime(long when)Last send time. |
static void | setMaxConcurrentMessages(int max)Max concurrent messages per peer (called by Tuner). |
static void | setMaxRTO(int ms)Maximum RTO ceiling (called by Tuner). |
static void | setMaxSendWindow(int bytes)Max send window / CWIN (called by Tuner). |
void | setMayDisconnect()May disconnect to true. |
static void | setMinConcurrentMsgs(int msgs)Minimum concurrent messages per peer (called by Tuner). |
static void | setMinRTO(int ms)Minimum RTO floor (called by Tuner). |
static void | setOutboundMsgExpiration(long ms)Bridge to OutboundMessageState.setMessageExpiration for Tuner (different package). |
static void | setPostRTOWindowMTUs(int mtus)Send-window restart size after an RTO-timeout collapse (called by Tuner). |
static void | setSentMessagesCleanTime(long ms)Bridge to PeerState2.setSentMessagesCleanTime for Tuner (different package). |
(package private) void | setTheyRelayToUsAs(long tag)If they have offered to serve as an introducer to us, this is the tag we can use to publish that fact. |
(package private) void | setWeRelayToThemAs(long tag)If we are serving as an introducer to them, this is the the tag that they can publish that,
when presented to us, will cause us to send a relay introduction to the current peer |
protected boolean | shouldRequestImmediateAck()SSU 2 only |
String | toString()String representation. |
protected final RouterContext _context
protected volatile boolean _dead
protected final Object _inboundLock
protected final ConcurrentMap<Long,InboundMessageState> _inboundMessages
protected final boolean _isInbound
protected final long _keyEstablishedTime
protected volatile long _lastACKSend
protected final Log _log
protected volatile int _mtu
protected volatile int _packetsReceivedDuplicate
protected volatile RemoteHostId _remoteHostId
protected final byte[] _remoteIP
protected volatile InetAddress _remoteIPAddress
protected final Hash _remotePeer
protected volatile int _remotePort
protected volatile int _rtt
protected final UDPTransport _transport
protected volatile long _wantACKSendSince
public static final int DEFAULT_MTU
public static final int LARGE_MTU
public static final int MAX_IPV6_MTU
public static final int MAX_MTU
public static final int MIN_IPV6_MTU
public static final int MIN_MTU
static final long RETRANSMISSION_PERIOD_WIDTH
protected PeerState(RouterContext ctx, UDPTransport transport, InetSocketAddress addr, Hash remotePeer, boolean isInbound, int rtt)
protected boolean acked(PacketBuilder.Fragment f)
void add(OutboundMessageState state)
state - the outbound message state to addvoid adjustClockSkew(long skew)
skew - milliseconds, NOT adjusted for RTT.void changePort(int newPort)
newPort - the new port numbervoid clearWantedACKSendSince()
void dataReceived()
void dropOutbound()
void ECNReceived()
limitSending) to throttle
the peer while the path is unverified. Despite the name, explicit ECN
signalling is not implemented; this is the backoff hook.int expireInboundMessages()
List<OutboundMessageState> finishAndAllocate(long now)
now - current timeint fragmentOverhead()
int fragmentSize()
public static int getAckFrequency()
public static long[] getAggregateStats(Collection<PeerState> peers)
peers - collection of active peer statespublic long getClockSkew()
public static int getClockSkewFudge()
public int getConcurrentSends()
public int getConcurrentSendWindow()
public int getConsecutiveFailedSends()
public int getConsecutiveSendRejections()
public long getInactivityTime()
Map<Long,InboundMessageState> getInboundMessages()
public static int getInitConcurrentMsgs()
public static int getInitRTO()
long getIntroducerTime()
public long getKeyEstablishedTime()
public long getLastACKSend()
public long getLastReceiveTime()
public long getLastSendFullyTime()
long getLastSendOrPingTime()
public long getLastSendTime()
public static int getMaxConcurrentMessages()
public static int getMaxRTO()
public static int getMaxSendWindow()
public boolean getMayDisconnect()
public int getMessagesReceived()
public int getMessagesSent()
public static int getMinConcurrentMsgs()
public static int getMinRTO()
public int getMTU()
int getNextDelay(long now)
now - what time it is nowpublic int getOutboundMessageCount()
public static long getOutboundMsgExpiration()
public int getPacketsReceived()
public int getPacketsReceivedDuplicate()
public int getPacketsRetransmitted()
public int getPacketsTransmitted()
public static int getPostRTOWindowMTUs()
public int getReceiveBps(long now)
now - the current timepublic int getReceiveMTU()
public RemoteHostId getRemoteHostId()
public byte[] getRemoteIP()
public InetAddress getRemoteIPAddress()
public Hash getRemotePeer()
public int getRemotePort()
public int getRTO()
public int getRTT()
public int getRTTDeviation()
public int getSendBps(long now)
now - the current timepublic int getSendWindowBytes()
public int getSendWindowBytesRemaining()
public static long getSentMessagesCleanTime()
public int getSlowStartThreshold()
public long getTheyRelayToUsAs()
UDPTransport getTransport()
public int getVersion()
public long getWeRelayToThemAs()
boolean hasOutbound()
boolean highestSeqNumAcked(long highest)
highest - the highest sequence number that was ackedint incrementConsecutiveFailedSends()
public boolean isBacklogged()
public boolean isInbound()
public boolean isIPv6()
public static void loadConfig(RouterContext ctx)
ctx - router context for property accessvoid loadFrom(PeerState oldPeer)
oldPeer - non-nullvoid messageFullyReceived(Long messageId, int bytes)
messageId - the message IDbytes - if less than or equal to zero, message is a duplicate.void messagePartiallyReceived()
protected void messagePartiallyReceived(long now)
now - the current timevoid messageRetransmitted(int packets,
int maxPktSz)packets - the number of packets retransmittedmaxPktSz - the maximum packet sizevoid packetReceived(int size)
size - not including IP header, UDP header, MAC or IVvoid packetsTransmitted(int packets)
public static void setAckFrequency(int freq)
freq - new ACK frequency (bounded 50-300)void setHisMTU(int mtu)
mtu - the MTU to setpublic static void setInitConcurrentMsgs(int msgs)
msgs - initial concurrent messages, clamped 16-256public static void setInitRTO(int ms)
ms - initial RTO in ms, clamped 250-2000void setIntroducerTime()
void setLastPingTime(long when)
when - the time to setvoid setLastReceiveTime(long when)
when - the time to setvoid setLastSendTime(long when)
when - the time to setpublic static void setMaxConcurrentMessages(int max)
max - the max concurrent messages to setpublic static void setMaxRTO(int ms)
ms - maximum RTO in ms, clamped 10000-120000public static void setMaxSendWindow(int bytes)
bytes - max send window in bytes, clamped 32KB-1MBpublic void setMayDisconnect()
public static void setMinConcurrentMsgs(int msgs)
msgs - minimum concurrent messages, clamped 8-128public static void setMinRTO(int ms)
ms - minimum RTO in ms, clamped 250-2000public static void setOutboundMsgExpiration(long ms)
ms - the expiration in mspublic static void setPostRTOWindowMTUs(int mtus)
mtus - number of MTUs, clamped 1-4 (1 = RFC 5681 loss window)public static void setSentMessagesCleanTime(long ms)
ms - the clean time in msvoid setTheyRelayToUsAs(long tag)
tag - 1 to Integer.MAX_VALUE, or 0 if relaying disabledvoid setWeRelayToThemAs(long tag)
tag - 1 to Integer.MAX_VALUE, or 0 if relaying disabledprotected boolean shouldRequestImmediateAck()