public class PeerState2 extends PeerState implements SSU2Payload.PayloadCallback, SSU2Bitfield.Callback, SSU2Sender
| Modifier and Type | Field and Description |
|---|---|
static int | DEFAULT_MTUDEFAULT_MTU. |
static int | DEFAULT_SSU_IPV4_MTUDEFAULT_SSU_IPV4_MTU. |
static int | DEFAULT_SSU_IPV6_MTUDEFAULT_SSU_IPV6_MTU. |
static int | MAX_MTUMAX_MTU. |
static int | MAX_SSU_IPV4_MTUMAX_SSU_IPV4_MTU. |
static int | MAX_SSU_IPV6_MTUMAX_SSU_IPV6_MTU. |
static int | MIN_MLKEM768_IPV4_MTUMIN_MLKEM768_IPV4_MTU. |
static int | MIN_MLKEM768_IPV6_MTUMIN_MLKEM768_IPV6_MTU. |
static int | MIN_MTUMIN_MTU. |
static int | MIN_SSU_IPV4_MTUMIN_SSU_IPV4_MTU. |
static int | MIN_SSU_IPV6_MTUMIN_SSU_IPV6_MTU. |
_context, _dead, _inboundLock, _inboundMessages, _isInbound, _keyEstablishedTime, _lastACKSend, _log, _mtu, _packetsReceivedDuplicate, _remoteHostId, _remoteIP, _remoteIPAddress, _remotePeer, _remotePort, _rtt, _transport, _wantACKSendSince, LARGE_MTU, MAX_IPV6_MTU, MIN_IPV6_MTU, RETRANSMISSION_PERIOD_WIDTH| Constructor and Description |
|---|
PeerState2(RouterContext ctx,
UDPTransport transport,
InetSocketAddress remoteAddress,
Hash remotePeer,
boolean isInbound,
int rtt,
CipherState sendCha,
CipherState rcvCha,
long sendID,
long rcvID,
byte[] sendHdrKey1,
byte[] sendHdrKey2,
byte[] rcvHdrKey2)If inbound, caller MUST immediately call setWeRelayToThemAs() (if nonzero) and sendAck0(). |
| Modifier and Type | Method and Description |
|---|---|
void | bitSet(long pktNum)Callback from SSU2Bitfield.forEachAndNot(). |
(package private) void | changeAddress(RemoteHostId id)Caller should sync; UDPTransport must remove and add to peersByRemoteHost map |
(package private) void | clearWantedACKSendSince()All acks have been sent. |
(package private) void | confirmedPacketsSent(byte[][] data)Note that we just sent the SessionConfirmed packets
and save them for retransmission. |
(package private) void | dropOutbound()Overridden to also clear sent-but-unacked fragments and cancel ACKTimer. |
(package private) List<OutboundMessageState> | finishAndAllocate(long now)Single-pass combined cleanup + send allocation, overriding the base class
to incorporate SSU2-specific _sentMessages cleanup and SessionConfirmed
retransmit logic. |
(package private) int | fragmentOverhead()Packet overhead
This is 5 bytes too high for first or only fragment,
because the 9 byte I2NP header is included in that fragment. |
(package private) int | fragmentSize()how much payload data can we shove in there?
This is 5 bytes too low for first or only fragment,
because the 9 byte I2NP header is included in that fragment. |
void | fragmentsSent(long pktNum,
int length,
List<PacketBuilder.Fragment> fragments)Record the mapping of packet number to what fragments were in it,
so we can process acks. |
SSU2Bitfield | getAckedMessages() |
(package private) int | getDestroyReason() |
byte | getFlags()Flag byte to be sent in header |
long | getNextPacketNumber()Next outbound packet number,
starts at 1 for Alice (0 is Session Confirmed) and 0 for Bob |
protected long | getNextPacketNumberNoThrow()For PeerStateDestroyed only, after we are dead |
(package private) byte[] | getOurIP()As received in the Address Block in the handshake,
or subsequently in the data phase. |
(package private) int | getOurPort()As received in the Address Block in the handshake,
or subsequently in the data phase. |
(package private) CipherState | getRcvCipher() |
(package private) long | getRcvConnID()The connection ID we expect to receive packets with. |
(package private) byte[] | getRcvHeaderEncryptKey1()The first header encryption key for received packets. |
(package private) byte[] | getRcvHeaderEncryptKey2()The second header encryption key for received packets. |
SSU2Bitfield | getReceivedMessages() |
CipherState | getSendCipher()Caller must sync on returned object when encrypting |
long | getSendConnID() |
byte[] | getSendHeaderEncryptKey1() |
byte[] | getSendHeaderEncryptKey2() |
static long | getSentMessagesCleanTime() |
int | getVersion()peer SSU version. |
void | gotACK(long ackThru,
int acks,
byte[] ranges)gotACK. |
void | gotAddress(byte[] ip,
int port)gotAddress. |
void | gotDateTime(long time)gotDateTime. |
void | gotFragment(byte[] data,
int off,
int len,
long messageId,
int frag,
boolean isLast)gotFragment. |
void | gotI2NP(I2NPMessage msg)gotI2NP. |
void | gotOptions(byte[] options,
boolean isHandshake)gotOptions. |
void | gotPathChallenge(RemoteHostId from,
byte[] data)gotPathChallenge. |
void | gotPathResponse(RemoteHostId from,
byte[] data)gotPathResponse. |
void | gotPeerTest(int msg,
int status,
Hash h,
byte[] data)gotPeerTest. |
void | gotRelayIntro(Hash aliceHash,
byte[] data)gotRelayIntro. |
void | gotRelayRequest(byte[] data)gotRelayRequest. |
void | gotRelayResponse(int status,
byte[] data)gotRelayResponse. |
void | gotRelayTag(long tag)gotRelayTag. |
void | gotRelayTagRequest()gotRelayTagRequest. |
void | gotRI(RouterInfo ri,
boolean isHandshake,
boolean flood)gotRI. |
void | gotRIFragment(byte[] data,
boolean isHandshake,
boolean flood,
boolean isGzipped,
int frag,
int totalFrags)gotRIFragment. |
void | gotTermination(int reason,
long count)gotTermination. |
void | gotToken(long token,
long expires)gotToken. |
(package private) boolean | isDead() |
protected void | messagePartiallyReceived(long now)Overridden to use our version of ACKTimer |
(package private) void | receivePacket(RemoteHostId from,
UDPPacket packet)From different than expected source IP/port |
(package private) void | receivePacket(UDPPacket packet) |
(package private) void | sendAck0()Send immediate ACK 0 of Session Confirmed. |
int | sentMessagesSize() |
void | setDestroyReason(int reason) |
(package private) void | setOurAddress(byte[] ip,
int port)For initialization by IES2/OES2 only. |
static void | setSentMessagesCleanTime(long ms)Set sent-messages cleanup interval. |
acked, add, adjustClockSkew, changePort, dataReceived, ECNReceived, expireInboundMessages, getAckFrequency, getAggregateStats, getClockSkew, getClockSkewFudge, getConcurrentSends, getConcurrentSendWindow, getConsecutiveFailedSends, getConsecutiveSendRejections, getInactivityTime, getInboundMessages, getInitConcurrentMsgs, getInitRTO, getIntroducerTime, getKeyEstablishedTime, getLastACKSend, getLastReceiveTime, getLastSendFullyTime, getLastSendOrPingTime, getLastSendTime, getMaxConcurrentMessages, getMaxRTO, getMaxSendWindow, getMayDisconnect, getMessagesReceived, getMessagesSent, getMinConcurrentMsgs, getMinRTO, getMTU, getNextDelay, getOutboundMessageCount, getOutboundMsgExpiration, getPacketsReceived, getPacketsReceivedDuplicate, getPacketsRetransmitted, getPacketsTransmitted, getPostRTOWindowMTUs, getReceiveBps, getReceiveMTU, getRemoteHostId, getRemoteIP, getRemoteIPAddress, getRemotePeer, getRemotePort, getRTO, getRTT, getRTTDeviation, getSendBps, getSendWindowBytes, getSendWindowBytesRemaining, getSlowStartThreshold, getTheyRelayToUsAs, getTransport, getWeRelayToThemAs, hasOutbound, highestSeqNumAcked, incrementConsecutiveFailedSends, isBacklogged, isInbound, isIPv6, loadConfig, loadFrom, messageFullyReceived, messagePartiallyReceived, messageRetransmitted, packetReceived, packetsTransmitted, setAckFrequency, setHisMTU, setInitConcurrentMsgs, setInitRTO, setIntroducerTime, setLastPingTime, setLastReceiveTime, setLastSendTime, setMaxConcurrentMessages, setMaxRTO, setMaxSendWindow, setMayDisconnect, setMinConcurrentMsgs, setMinRTO, setOutboundMsgExpiration, setPostRTOWindowMTUs, setTheyRelayToUsAs, setWeRelayToThemAs, shouldRequestImmediateAck, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetMTU, getRemoteHostId, getRemoteIPAddress, getRemotePort, isIPv6public static final int DEFAULT_MTU
public static final int DEFAULT_SSU_IPV4_MTU
public static final int DEFAULT_SSU_IPV6_MTU
public static final int MAX_MTU
public static final int MAX_SSU_IPV4_MTU
public static final int MAX_SSU_IPV6_MTU
public static final int MIN_MLKEM768_IPV4_MTU
public static final int MIN_MLKEM768_IPV6_MTU
public static final int MIN_MTU
public static final int MIN_SSU_IPV4_MTU
public static final int MIN_SSU_IPV6_MTU
public PeerState2(RouterContext ctx, UDPTransport transport, InetSocketAddress remoteAddress, Hash remotePeer, boolean isInbound, int rtt, CipherState sendCha, CipherState rcvCha, long sendID, long rcvID, byte[] sendHdrKey1, byte[] sendHdrKey2, byte[] rcvHdrKey2)
rtt - from the EstablishState, or 0 if not availablepublic void bitSet(long pktNum)
bitSet in interface SSU2Bitfield.Callbackvoid changeAddress(RemoteHostId id)
void clearWantedACKSendSince()
clearWantedACKSendSince in class PeerStatevoid confirmedPacketsSent(byte[][] data)
void dropOutbound()
dropOutbound in class PeerStateList<OutboundMessageState> finishAndAllocate(long now)
finishAndAllocate in class PeerStatenow - current timeint fragmentOverhead()
fragmentOverhead in class PeerStateint fragmentSize()
fragmentSize in class PeerStatepublic void fragmentsSent(long pktNum,
int length,
List<PacketBuilder.Fragment> fragments)fragmentsSent in interface SSU2Senderlength - including ip/udp header, for logging onlypktNum - packet number, @param length fragment length, @param fragments fragment listpublic SSU2Bitfield getAckedMessages()
getAckedMessages in interface SSU2Senderint getDestroyReason()
public byte getFlags()
getFlags in interface SSU2Senderpublic long getNextPacketNumber()
throws IOExceptiongetNextPacketNumber in interface SSU2SenderIOExceptionprotected long getNextPacketNumberNoThrow()
byte[] getOurIP()
int getOurPort()
CipherState getRcvCipher()
long getRcvConnID()
byte[] getRcvHeaderEncryptKey1()
byte[] getRcvHeaderEncryptKey2()
public SSU2Bitfield getReceivedMessages()
getReceivedMessages in interface SSU2Senderpublic CipherState getSendCipher()
getSendCipher in interface SSU2Senderpublic long getSendConnID()
getSendConnID in interface SSU2Senderpublic byte[] getSendHeaderEncryptKey1()
getSendHeaderEncryptKey1 in interface SSU2Senderpublic byte[] getSendHeaderEncryptKey2()
getSendHeaderEncryptKey2 in interface SSU2Senderpublic static long getSentMessagesCleanTime()
public int getVersion()
PeerStategetVersion in class PeerStatepublic void gotACK(long ackThru,
int acks,
byte[] ranges)gotACK in interface SSU2Payload.PayloadCallbackackThru - highest contiguous sequence number acknowledgedacks - number of additional acknowledgments beyond ackThruranges - null if nonepublic void gotAddress(byte[] ip,
int port)gotAddress in interface SSU2Payload.PayloadCallbackip - IP address bytesport - port numberpublic void gotDateTime(long time)
gotDateTime in interface SSU2Payload.PayloadCallbacktime - time in milliseconds since epochpublic void gotFragment(byte[] data,
int off,
int len,
long messageId,
int frag,
boolean isLast)
throws DataFormatExceptiongotFragment in interface SSU2Payload.PayloadCallbackdata - buffer containing fragment dataoff - offset in datalen - length of data to copymessageId - unique message identifierfrag - fragment number (0-based)isLast - whether this is the last fragmentDataFormatExceptionpublic void gotI2NP(I2NPMessage msg)
gotI2NP in interface SSU2Payload.PayloadCallbackmsg - the parsed I2NP messagepublic void gotOptions(byte[] options,
boolean isHandshake)gotOptions in interface SSU2Payload.PayloadCallbackoptions - the option dataisHandshake - true only for message 3 part 2public void gotPathChallenge(RemoteHostId from, byte[] data)
gotPathChallenge in interface SSU2Payload.PayloadCallbackfrom - null if unknownpublic void gotPathResponse(RemoteHostId from, byte[] data)
gotPathResponse in interface SSU2Payload.PayloadCallbackfrom - null if unknownpublic void gotPeerTest(int msg,
int status,
Hash h,
byte[] data)gotPeerTest in interface SSU2Payload.PayloadCallbackmsg - 1-7status - 0 = accept, 1-255 = rejecth - Alice or Charlie hash for msg 2 and 4, null for msg 1, 3, 5-7data - excludes flag, includes signaturepublic void gotRelayIntro(Hash aliceHash, byte[] data)
gotRelayIntro in interface SSU2Payload.PayloadCallbackaliceHash - hash of the introducerdata - excludes flag, includes signaturepublic void gotRelayRequest(byte[] data)
gotRelayRequest in interface SSU2Payload.PayloadCallbackdata - excludes flag, includes signaturepublic void gotRelayResponse(int status,
byte[] data)gotRelayResponse in interface SSU2Payload.PayloadCallbackstatus - 0 = accept, 1-255 = rejectdata - excludes flag, includes signaturepublic void gotRelayTag(long tag)
gotRelayTag in interface SSU2Payload.PayloadCallbacktag - the relay tagpublic void gotRelayTagRequest()
gotRelayTagRequest in interface SSU2Payload.PayloadCallbackpublic void gotRI(RouterInfo ri, boolean isHandshake, boolean flood) throws DataFormatException
gotRI in interface SSU2Payload.PayloadCallbackri - will already be validatedisHandshake - true only for message 3 part 2flood - true if this is a floodfill routerDataFormatExceptionpublic void gotRIFragment(byte[] data,
boolean isHandshake,
boolean flood,
boolean isGzipped,
int frag,
int totalFrags)gotRIFragment in interface SSU2Payload.PayloadCallbackdata - is first gzipped and then fragmentedisHandshake - true only for message 3 part 2flood - true if this is a floodfill routerisGzipped - true if the data is gzippedfrag - fragment number (0-based)totalFrags - total number of fragmentspublic void gotTermination(int reason,
long count)gotTermination in interface SSU2Payload.PayloadCallbackreason - termination reason codecount - in theory could wrap around to negative, but very unlikelypublic void gotToken(long token,
long expires)gotToken in interface SSU2Payload.PayloadCallbacktoken - the token valueexpires - token expiration time in millisecondsboolean isDead()
protected void messagePartiallyReceived(long now)
messagePartiallyReceived in class PeerStatenow - the current timevoid receivePacket(RemoteHostId from, UDPPacket packet)
from - source addresspacket - fully encrypted, header and body decryption will be done herevoid receivePacket(UDPPacket packet)
packet - fully encrypted, header and body decryption will be done herevoid sendAck0()
public int sentMessagesSize()
public void setDestroyReason(int reason)
setDestroyReason in interface SSU2Senderreason - destroy reasonvoid setOurAddress(byte[] ip,
int port)public static void setSentMessagesCleanTime(long ms)
ms - cleanup interval in ms, clamped to [2000, 300000]