class PeerState extends Object
Modifier and Type | Field and Description |
---|---|
static int |
INIT_RTT |
static int |
LARGE_MTU
IPv4 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_MTU |
static int |
MAX_MTU
Max of IPv4 and IPv6 max MTUs
|
static int |
MIN_IPV6_MTU
IPv6/UDP header is 48 bytes, so we want MTU % 16 == 0.
|
static int |
MIN_MTU
IPv4 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_WIDTH
how many packets will be considered within the retransmission rate calculation
|
Constructor and Description |
---|
PeerState(RouterContext ctx,
UDPTransport transport,
byte[] remoteIP,
int remotePort,
Hash remotePeer,
boolean isInbound) |
Modifier and Type | Method and Description |
---|---|
boolean |
acked(ACKBitfield bitfield)
A partial ACK was received.
|
boolean |
acked(long messageId)
A full ACK was received.
|
void |
add(OutboundMessageState state)
TODO should this use a queue, separate from the list of msgs pending an ack?
TODO bring back tail drop?
TODO priority queue? (we don't implement priorities in SSU now)
TODO backlog / pushback / block instead of dropping? Can't really block here.
|
void |
adjustClockSkew(long skew)
Update the moving-average clock skew based on the current difference.
|
List<OutboundMessageState> |
allocateSend()
Pick one or more messages we want to send and allocate them out of our window
High usage -
OutboundMessageFragments.getNextVolley() calls this 2nd, if finishMessages() returned > 0.
|
void |
changePort(int newPort)
Caller should sync; UDPTransport must remove and add to peersByRemoteHost map
|
void |
dataReceived() |
void |
dropOutbound()
drop all outbound messages
|
void |
ECNReceived()
We received a backoff request, so cut our send window.
|
int |
expireInboundMessages()
Expire partially received inbound messages, returning how many are still pending.
|
(package private) void |
fetchPartialACKs(List<ACKBitfield> rv) |
int |
finishMessages()
Expire / complete any outbound messages
High usage -
OutboundMessageFragments.getNextVolley() calls this 1st.
|
int |
fragmentSize()
how much payload data can we shove in there?
|
long |
getClockSkew()
How far off is the remote peer from our clock, in milliseconds?
A positive number means our clock is ahead of theirs.
|
int |
getConcurrentSends() |
int |
getConcurrentSendWindow() |
int |
getConsecutiveFailedSends()
how many seconds have we sent packets without any ACKs received?
|
int |
getConsecutiveSendRejections() |
SessionKey |
getCurrentCipherKey()
The AES key used to encrypt/decrypt packets, set only after the
connection is established.
|
List<Long> |
getCurrentFullACKs()
Grab a list of message ids (Long) that we want to send to the remote
peer, regardless of the packet size, but don't remove it from our
"want to send" list.
|
SessionKey |
getCurrentMACKey()
The AES key used to verify packets, set only after the connection is
established.
|
long |
getCurrentReceiveSecond()
what is the current receive second, for congestion control?
|
List<Long> |
getCurrentResendACKs()
Grab a list of message ids (Long) that we want to send to the remote
peer, regardless of the packet size, but don't remove it from our
"want to send" list.
|
boolean |
getCurrentSecondECNReceived()
Deprecated.
unused, ECNs are never sent, always returns false
|
long |
getInactivityTime() |
Map<Long,InboundMessageState> |
getInboundMessages()
Fetch the internal id (Long) to InboundMessageState for incomplete inbound messages.
|
long |
getIntroducerTime()
the last time we used them as an introducer, or 0
|
long |
getKeyEstablishedTime()
when were the current cipher and MAC keys established/rekeyed?
|
long |
getLastACKSend()
when did we last send an ACK to the peer?
|
long |
getLastReceiveTime()
when did we last receive a packet from them?
|
long |
getLastSendFullyTime()
when did we last send them a message that was ACKed?
|
long |
getLastSendOrPingTime()
Latest of last sent, last ACK, last ping
|
long |
getLastSendTime()
when did we last send them a packet?
|
boolean |
getMayDisconnect() |
int |
getMessagesReceived()
I2NP messages received.
|
int |
getMessagesSent()
I2NP messages sent.
|
int |
getMTU()
what is the largest packet we can send to the peer?
|
SessionKey |
getNextCipherKey()
The pending AES key for encrypting/decrypting packets if we are
rekeying the connection, or null if we are not in the process
of rekeying.
|
int |
getNextDelay()
High usage -
OutboundMessageFragments.getNextVolley() calls this 3rd, if allocateSend() returned null.
|
SessionKey |
getNextMACKey()
The pending AES key for verifying packets if we are rekeying the
connection, or null if we are not in the process of rekeying.
|
int |
getOutboundMessageCount() |
int |
getPacketsReceived()
avg number of packets retransmitted for every 100 packets
|
int |
getPacketsReceivedDuplicate() |
int |
getPacketsRetransmitted() |
int |
getPacketsTransmitted() |
int |
getReceiveBps() |
int |
getReceiveMTU()
Estimate how large the other side's MTU is.
|
(package private) RemoteHostId |
getRemoteHostId() |
byte[] |
getRemoteIP()
what IP is the peer sending and receiving packets on?
|
InetAddress |
getRemoteIPAddress() |
Hash |
getRemotePeer()
The peer are we talking to.
|
int |
getRemotePort()
what port is the peer sending and receiving packets on?
|
int |
getRTO()
how soon should we retransmit an unacked packet?
|
int |
getRTT()
how long does it usually take to get a message ACKed?
|
int |
getRTTDeviation()
how skewed are the measured RTTs?
|
int |
getSendBps()
return the smoothed send transfer rate
|
int |
getSendWindowBytes()
how many bytes should we send to the peer in a second
|
int |
getSendWindowBytesRemaining()
how many bytes can we send to the peer in the current second
|
int |
getSlowStartThreshold()
public void setMTU(int mtu) {
_mtu = mtu;
_mtuLastChecked = _context.clock().now();
}
|
long |
getTheyRelayToUsAs()
If they have offered to serve as an introducer to us, this is the tag
we can use to publish that fact.
|
UDPTransport |
getTransport()
Convenience for OutboundMessageState so it can fail itself
|
long |
getWantedACKSendSince() |
long |
getWeRelayToThemAs()
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
|
int |
incrementConsecutiveFailedSends() |
boolean |
isBacklogged() |
boolean |
isInbound() |
boolean |
isIPv6() |
void |
loadFrom(PeerState oldPeer)
Transfer the basic activity/state from the old peer to the current peer
|
void |
messageFullyReceived(Long messageId,
int bytes)
We received the message specified completely.
|
void |
messagePartiallyReceived() |
void |
messageRetransmitted(int packets)
we are resending a packet, so lets jack up the rto
|
void |
packetReceived(int size) |
void |
packetsTransmitted(int packets) |
void |
removeACKMessage(Long messageId)
The ack was sent.
|
List<ACKBitfield> |
retrieveACKBitfields()
Deprecated.
unused
|
List<ACKBitfield> |
retrieveACKBitfields(boolean alwaysIncludeRetransmissions)
See above.
|
void |
setCurrentCipherKey(SessionKey key)
The AES key used to encrypt/decrypt packets, set only after the
connection is established.
|
void |
setCurrentMACKey(SessionKey key)
The AES key used to verify packets, set only after the connection is
established.
|
void |
setCurrentReceiveSecond(long sec)
what is the current receive second, for congestion control?
|
void |
setHisMTU(int mtu) |
void |
setIntroducerTime()
set the last time we used them as an introducer to now
|
void |
setKeyEstablishedTime(long when)
Deprecated.
unused
|
void |
setLastACKSend(long when)
Deprecated.
unused
|
void |
setLastPingTime(long when)
Note ping sent.
|
void |
setLastReceiveTime(long when)
when did we last receive a packet from them?
|
void |
setLastSendTime(long when)
when did we last send them a packet?
|
void |
setMayDisconnect()
Sets to true.
|
void |
setNextCipherKey(SessionKey key)
Deprecated.
unused
|
void |
setNextMACKey(SessionKey key)
Deprecated.
unused
|
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.
|
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
|
String |
toString() |
boolean |
unsentACKThresholdReached()
Are we out of room to send all the current unsent acks in a single packet?
This is a huge threshold (134 for small MTU and 255 for large MTU)
that is rarely if ever exceeded in practice.
|
static final long RETRANSMISSION_PERIOD_WIDTH
public static final int MIN_MTU
public static final int MIN_IPV6_MTU
public static final int MAX_IPV6_MTU
public static final int LARGE_MTU
public static final int MAX_MTU
public static final int INIT_RTT
public PeerState(RouterContext ctx, UDPTransport transport, byte[] remoteIP, int remotePort, Hash remotePeer, boolean isInbound)
public void changePort(int newPort)
public Hash getRemotePeer()
public SessionKey getCurrentMACKey()
public SessionKey getCurrentCipherKey()
public SessionKey getNextMACKey()
public SessionKey getNextCipherKey()
public long getKeyEstablishedTime()
public long getClockSkew()
public long getCurrentReceiveSecond()
public long getLastSendTime()
public long getLastSendFullyTime()
public long getLastReceiveTime()
public int getConsecutiveFailedSends()
@Deprecated public boolean getCurrentSecondECNReceived()
public int getSendWindowBytes()
public int getSendWindowBytesRemaining()
public byte[] getRemoteIP()
public InetAddress getRemoteIPAddress()
public int getRemotePort()
public long getWeRelayToThemAs()
public long getTheyRelayToUsAs()
public int getMTU()
public int getReceiveMTU()
public void setCurrentMACKey(SessionKey key)
public void setCurrentCipherKey(SessionKey key)
@Deprecated public void setNextMACKey(SessionKey key)
@Deprecated public void setNextCipherKey(SessionKey key)
@Deprecated public void setKeyEstablishedTime(long when)
public void adjustClockSkew(long skew)
skew
- milliseconds, NOT adjusted for RTT.public void setCurrentReceiveSecond(long sec)
public void setLastSendTime(long when)
public void setLastReceiveTime(long when)
public void setLastPingTime(long when)
public long getLastSendOrPingTime()
public int getSendBps()
public int getReceiveBps()
public int incrementConsecutiveFailedSends()
public long getInactivityTime()
public void setWeRelayToThemAs(long tag)
tag
- 1 to Integer.MAX_VALUE, or 0 if relaying disabledpublic void setTheyRelayToUsAs(long tag)
tag
- 1 to Integer.MAX_VALUE, or 0 if relaying disabledpublic int getSlowStartThreshold()
public int getConcurrentSends()
public int getConcurrentSendWindow()
public int getConsecutiveSendRejections()
public boolean isInbound()
public boolean isIPv6()
public long getIntroducerTime()
public void setIntroducerTime()
public void messageFullyReceived(Long messageId, int bytes)
bytes
- if less than or equal to zero, message is a duplicate.public void messagePartiallyReceived()
public Map<Long,InboundMessageState> getInboundMessages()
public int expireInboundMessages()
public List<Long> getCurrentFullACKs()
public List<Long> getCurrentResendACKs()
public void removeACKMessage(Long messageId)
@Deprecated public List<ACKBitfield> retrieveACKBitfields()
public List<ACKBitfield> retrieveACKBitfields(boolean alwaysIncludeRetransmissions)
void fetchPartialACKs(List<ACKBitfield> rv)
rv
- out parameter, populated with true partial ACKBitfields.
no full bitfields are included.public void setHisMTU(int mtu)
public void messageRetransmitted(int packets)
public void packetsTransmitted(int packets)
public int getRTT()
public int getRTO()
public int getRTTDeviation()
public int getMessagesSent()
public int getMessagesReceived()
public int getPacketsTransmitted()
public int getPacketsRetransmitted()
public int getPacketsReceived()
public int getPacketsReceivedDuplicate()
public void packetReceived(int size)
size
- not including IP header, UDP header, MAC or IVpublic void ECNReceived()
public void dataReceived()
public long getLastACKSend()
@Deprecated public void setLastACKSend(long when)
public long getWantedACKSendSince()
public boolean unsentACKThresholdReached()
RemoteHostId getRemoteHostId()
public void add(OutboundMessageState state)
public void dropOutbound()
public int getOutboundMessageCount()
public void setMayDisconnect()
public boolean getMayDisconnect()
public int finishMessages()
public List<OutboundMessageState> allocateSend()
public int getNextDelay()
public boolean isBacklogged()
public int fragmentSize()
public boolean acked(long messageId)
public boolean acked(ACKBitfield bitfield)
public void loadFrom(PeerState oldPeer)
oldPeer
- non-nullpublic UDPTransport getTransport()