public class PeerState extends Object
Modifier and Type | Field and Description |
---|---|
protected RouterContext |
_context |
protected boolean |
_dead
have we migrated away from this peer to another newer one?
|
protected Map<Long,InboundMessageState> |
_inboundMessages
list of InboundMessageState for active message
|
protected boolean |
_isInbound
is it inbound?
|
protected long |
_keyEstablishedTime |
protected long |
_lastACKSend
when did we last send ACKs to the peer?
|
protected Log |
_log |
protected int |
_mtu
what is the largest packet we can currently send to the peer?
|
protected int |
_packetsReceivedDuplicate
how many dup packets were received within the last RETRANSMISSION_PERIOD_WIDTH packets
|
protected RemoteHostId |
_remoteHostId
cached RemoteHostId, used to find the peerState by remote info
|
protected byte[] |
_remoteIP
what IP is the peer sending and receiving packets on?
|
protected InetAddress |
_remoteIPAddress
cached IP address
|
protected Hash |
_remotePeer
The peer are we talking to.
|
protected int |
_remotePort
what port is the peer sending and receiving packets on?
|
protected int |
_rtt
current round trip time estimate
|
protected UDPTransport |
_transport |
protected long |
_wantACKSendSince
when did we decide we need to ACK to this peer?
|
protected static int |
ACK_FREQUENCY
how frequently do we want to send ACKs to a peer?
|
protected static int |
CLOCK_SKEW_FUDGE |
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
|
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)
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.
|
(package private) void |
adjustClockSkew(long skew)
Update the moving-average clock skew based on the current difference.
|
(package private) List<OutboundMessageState> |
allocateSend(long now)
Pick one or more messages we want to send and allocate them out of our window
Adjusts the retransmit timer if necessary.
|
(package private) void |
changePort(int newPort)
Caller should sync; UDPTransport must remove and add to peersByRemoteHost map
|
(package private) void |
clearWantedACKSendSince()
All acks have been sent.
|
(package private) void |
dataReceived()
Same as setLastReceivedTime(now)
|
(package private) void |
dropOutbound()
drop all outbound messages
|
(package private) void |
ECNReceived()
We received a backoff request, so cut our send window.
|
(package private) int |
expireInboundMessages()
Expire partially received inbound messages, returning how many are still pending.
|
(package private) int |
finishMessages(long now)
Expire / complete any outbound messages
High usage -
OutboundMessageFragments.getNextVolley() calls this 1st.
|
(package private) int |
fragmentOverhead()
Packet overhead plus room for acks
|
(package private) 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()
2nd stat in CWND column, otherwise unused,
candidate for removal
|
int |
getConcurrentSendWindow()
3rd stat in CWND column, otherwise unused,
candidate for removal
|
int |
getConsecutiveFailedSends()
how many seconds have we sent packets without any ACKs received?
|
int |
getConsecutiveSendRejections()
4th stat in CWND column, otherwise unused,
candidate for removal
|
long |
getInactivityTime() |
(package private) Map<Long,InboundMessageState> |
getInboundMessages()
Fetch the internal id (Long) to InboundMessageState for incomplete inbound messages.
|
(package private) 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?
This is the connection uptime.
|
long |
getLastACKSend()
when did we last send an ACK to the peer?
|
long |
getLastReceiveTime()
When did we last receive a packet from them?
Set for data, relay, and peer test, but not acks, pings, or termination
|
long |
getLastSendFullyTime()
when did we last send them a message that was ACKed?
|
(package private) long |
getLastSendOrPingTime()
Latest of last sent, last ACK, last ping
|
long |
getLastSendTime()
When did we last send them a packet?
Set for data, relay, and peer test, but not acks, pings, or termination
|
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?
|
(package private) int |
getNextDelay(long now)
High usage -
OutboundMessageFragments.getNextVolley() calls this 3rd, if allocateSend() returned null.
|
int |
getOutboundMessageCount() |
int |
getPacketsReceived() |
int |
getPacketsReceivedDuplicate() |
int |
getPacketsRetransmitted() |
int |
getPacketsTransmitted() |
int |
getReceiveBps(long now)
An approximation, for display only
|
int |
getReceiveMTU()
Estimate how large the other side's MTU is.
|
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(long now)
The Westwood+ bandwidth estimate
|
int |
getSendWindowBytes()
how many bytes should we send to the peer in a second
1st stat in CWND column, otherwise unused,
candidate for removal
|
int |
getSendWindowBytesRemaining()
how many bytes can we send to the peer in the current second
|
int |
getSlowStartThreshold()
stat in SST column, otherwise unused,
candidate for removal
|
long |
getTheyRelayToUsAs()
If they have offered to serve as an introducer to us, this is the tag
we can use to publish that fact.
|
(package private) UDPTransport |
getTransport()
Convenience for OutboundMessageState so it can fail itself
|
int |
getVersion() |
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
|
(package private) boolean |
highestSeqNumAcked(long highest)
Enter or leave fast retransmit mode, and adjust
SST and window variables accordingly.
|
(package private) int |
incrementConsecutiveFailedSends() |
boolean |
isBacklogged() |
boolean |
isInbound() |
boolean |
isIPv6() |
(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)
we are resending a packet, so lets jack up the rto
|
(package private) void |
packetReceived(int size) |
(package private) void |
packetsTransmitted(int packets) |
(package private) void |
setHisMTU(int mtu) |
(package private) void |
setIntroducerTime()
set the last time we used them as an introducer to now
|
(package private) void |
setLastPingTime(long when)
Note ping sent.
|
(package private) void |
setLastReceiveTime(long when)
When did we last receive a packet from them?
Set for data, relay, and peer test, but not acks, pings, or termination
|
(package private) void |
setLastSendTime(long when)
When did we last send them a packet?
Set for data, relay, and peer test, but not acks, pings, or termination
|
void |
setMayDisconnect()
Sets to true.
|
(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() |
protected final RouterContext _context
protected final Log _log
protected final Hash _remotePeer
protected final long _keyEstablishedTime
protected volatile long _lastACKSend
protected volatile long _wantACKSendSince
protected final byte[] _remoteIP
protected volatile InetAddress _remoteIPAddress
protected volatile int _remotePort
protected volatile RemoteHostId _remoteHostId
protected int _mtu
protected int _rtt
static final long RETRANSMISSION_PERIOD_WIDTH
protected int _packetsReceivedDuplicate
protected final Map<Long,InboundMessageState> _inboundMessages
protected final UDPTransport _transport
protected volatile boolean _dead
protected final boolean _isInbound
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
protected static final int ACK_FREQUENCY
protected static final int CLOCK_SKEW_FUDGE
protected PeerState(RouterContext ctx, UDPTransport transport, InetSocketAddress addr, Hash remotePeer, boolean isInbound, int rtt)
public int getVersion()
void changePort(int newPort)
public Hash getRemotePeer()
public long getKeyEstablishedTime()
public long getClockSkew()
public long getLastSendTime()
public long getLastSendFullyTime()
public long getLastReceiveTime()
public int getConsecutiveFailedSends()
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()
void adjustClockSkew(long skew)
skew
- milliseconds, NOT adjusted for RTT.void setLastSendTime(long when)
void setLastReceiveTime(long when)
void setLastPingTime(long when)
long getLastSendOrPingTime()
public int getSendBps(long now)
public int getReceiveBps(long now)
int incrementConsecutiveFailedSends()
public long getInactivityTime()
void setWeRelayToThemAs(long tag)
tag
- 1 to Integer.MAX_VALUE, or 0 if relaying disabledvoid 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()
long getIntroducerTime()
void setIntroducerTime()
void messageFullyReceived(Long messageId, int bytes)
bytes
- if less than or equal to zero, message is a duplicate.void messagePartiallyReceived()
protected void messagePartiallyReceived(long now)
Map<Long,InboundMessageState> getInboundMessages()
int expireInboundMessages()
void setHisMTU(int mtu)
void messageRetransmitted(int packets, int maxPktSz)
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()
void packetReceived(int size)
size
- not including IP header, UDP header, MAC or IVvoid ECNReceived()
void dataReceived()
public long getLastACKSend()
void clearWantedACKSendSince()
public RemoteHostId getRemoteHostId()
void add(OutboundMessageState state)
void dropOutbound()
public int getOutboundMessageCount()
public void setMayDisconnect()
public boolean getMayDisconnect()
int finishMessages(long now)
List<OutboundMessageState> allocateSend(long now)
int getNextDelay(long now)
now
- what time it is nowpublic boolean isBacklogged()
int fragmentSize()
int fragmentOverhead()
protected boolean acked(PacketBuilder.Fragment f)
boolean highestSeqNumAcked(long highest)
highest
- the highest sequence number that was ackedprotected boolean shouldRequestImmediateAck()
void loadFrom(PeerState oldPeer)
oldPeer
- non-nullUDPTransport getTransport()