Package net.i2p.router.transport.udp
Class PeerState2
java.lang.Object
net.i2p.router.transport.udp.PeerState
net.i2p.router.transport.udp.PeerState2
- All Implemented Interfaces:
SSU2Bitfield.Callback,SSU2Payload.PayloadCallback
public class PeerState2
extends PeerState
implements SSU2Payload.PayloadCallback, SSU2Bitfield.Callback
Contain all of the state about a UDP connection to a peer.
This is instantiated only after a connection is fully established.
Public only for UI peers page. Not a public API, not for external use.
SSU2 only.
- Since:
- 0.9.54
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intFields inherited from class net.i2p.router.transport.udp.PeerState
_context, _dead, _inboundMessages, _isInbound, _keyEstablishedTime, _lastACKSend, _log, _mtu, _packetsReceivedDuplicate, _remoteHostId, _remoteIP, _remoteIPAddress, _remotePeer, _remotePort, _rtt, _transport, _wantACKSendSince, ACK_FREQUENCY, CLOCK_SKEW_FUDGE, LARGE_MTU, MAX_IPV6_MTU, MIN_IPV6_MTU, RETRANSMISSION_PERIOD_WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionPeerState2(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) -
Method Summary
Modifier and TypeMethodDescription(package private) List<OutboundMessageState>allocateSend(long now) Overridden to retransmit SessionConfirmed alsovoidbitSet(long pktNum) Callback from SSU2Bitfield.forEachAndNot().(package private) voidCaller should sync; UDPTransport must remove and add to peersByRemoteHost map(package private) voidAll acks have been sent.(package private) voidconfirmedPacketsSent(byte[][] data) Note that we just sent the SessionConfirmed packets and save them for retransmission.(package private) voidSSU 1 only.(package private) intfinishMessages(long now) Overridden to expire unacked packets in _sentMessages.(package private) intPacket 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) inthow 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.(package private) voidfragmentsSent(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.(package private) SSU2BitfieldGrab 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.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.(package private) bytegetFlags()Flag byte to be sent in header(package private) longNext outbound packet number, starts at 1 for Alice (0 is Session Confirmed) and 0 for Bob(package private) byte[]getOurIP()(package private) int(package private) long(package private) byte[](package private) byte[](package private) SSU2Bitfield(package private) CipherStatecaller must sync on returned object when encrypting(package private) long(package private) byte[](package private) byte[]intvoidgotACK(long ackThru, int acks, byte[] ranges) voidgotAddress(byte[] ip, int port) voidgotDateTime(long time) voidgotFragment(byte[] data, int off, int len, long messageId, int frag, boolean isLast) Data must be copied out in this method.voidgotI2NP(I2NPMessage msg) voidgotOptions(byte[] options, boolean isHandshake) voidgotPathChallenge(RemoteHostId from, byte[] data) voidgotPathResponse(RemoteHostId from, byte[] data) voidgotPeerTest(int msg, int status, Hash h, byte[] data) voidgotRelayIntro(Hash aliceHash, byte[] data) voidgotRelayRequest(byte[] data) voidgotRelayResponse(int status, byte[] data) voidgotRelayTag(long tag) voidvoidgotRI(RouterInfo ri, boolean isHandshake, boolean flood) voidgotRIFragment(byte[] data, boolean isHandshake, boolean flood, boolean isGzipped, int frag, int totalFrags) voidgotTermination(int reason, long count) voidgotToken(long token, long expires) protected voidmessagePartiallyReceived(long now) Overridden to use our version of ACKTimer(package private) voidreceivePacket(RemoteHostId from, UDPPacket packet) From different than expected source IP/port(package private) voidreceivePacket(UDPPacket packet) (package private) voidremoveACKMessage(Long messageId) The ack was sent.(package private) voidsetOurAddress(byte[] ip, int port) Methods inherited from class net.i2p.router.transport.udp.PeerState
acked, acked, acked, add, adjustClockSkew, changePort, dataReceived, dropOutbound, ECNReceived, expireInboundMessages, getClockSkew, getConcurrentSends, getConcurrentSendWindow, getConsecutiveFailedSends, getConsecutiveSendRejections, getCurrentCipherKey, getCurrentMACKey, getInactivityTime, getInboundMessages, getIntroducerTime, getKeyEstablishedTime, getLastACKSend, getLastReceiveTime, getLastSendFullyTime, getLastSendOrPingTime, getLastSendTime, getMayDisconnect, getMessagesReceived, getMessagesSent, getMTU, getNextCipherKey, getNextDelay, getNextMACKey, getOutboundMessageCount, getPacketsReceived, getPacketsReceivedDuplicate, getPacketsRetransmitted, getPacketsTransmitted, getReceiveBps, getReceiveMTU, getRemoteHostId, getRemoteIP, getRemoteIPAddress, getRemotePeer, getRemotePort, getRTO, getRTT, getRTTDeviation, getSendBps, getSendWindowBytes, getSendWindowBytesRemaining, getSlowStartThreshold, getTheyRelayToUsAs, getTransport, getWeRelayToThemAs, highestSeqNumAcked, incrementConsecutiveFailedSends, isBacklogged, isInbound, isIPv6, loadFrom, messageFullyReceived, messagePartiallyReceived, messageRetransmitted, packetReceived, packetsTransmitted, setHisMTU, setIntroducerTime, setLastPingTime, setLastReceiveTime, setLastSendTime, setMayDisconnect, setTheyRelayToUsAs, setWeRelayToThemAs, shouldRequestImmediateAck, toString, unsentACKThresholdReached
-
Field Details
-
MIN_SSU_IPV4_MTU
public static final int MIN_SSU_IPV4_MTU- See Also:
-
MAX_SSU_IPV4_MTU
public static final int MAX_SSU_IPV4_MTU- See Also:
-
DEFAULT_SSU_IPV4_MTU
public static final int DEFAULT_SSU_IPV4_MTU- See Also:
-
MIN_SSU_IPV6_MTU
public static final int MIN_SSU_IPV6_MTU- See Also:
-
MAX_SSU_IPV6_MTU
public static final int MAX_SSU_IPV6_MTU- See Also:
-
DEFAULT_SSU_IPV6_MTU
public static final int DEFAULT_SSU_IPV6_MTU- See Also:
-
MIN_MTU
public static final int MIN_MTU- See Also:
-
MAX_MTU
public static final int MAX_MTU- See Also:
-
DEFAULT_MTU
public static final int DEFAULT_MTU- See Also:
-
-
Constructor Details
-
PeerState2
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) - Parameters:
rtt- from the EstablishState, or 0 if not available
-
-
Method Details
-
getVersion
public int getVersion()- Overrides:
getVersionin classPeerState
-
fragmentSize
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. Does NOT leave any room for acks with a full-size fragment.- Overrides:
fragmentSizein classPeerState- Returns:
- MTU - 68 (IPv4), MTU - 88 (IPv6)
-
fragmentOverhead
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. Does NOT leave any room for acks with a full-size fragment.- Overrides:
fragmentOverheadin classPeerState- Returns:
- 68 (IPv4), 88 (IPv6)
-
clearWantedACKSendSince
void clearWantedACKSendSince()All acks have been sent.- Overrides:
clearWantedACKSendSincein classPeerState
-
messagePartiallyReceived
protected void messagePartiallyReceived(long now) Overridden to use our version of ACKTimer- Overrides:
messagePartiallyReceivedin classPeerState
-
finishMessages
int finishMessages(long now) Overridden to expire unacked packets in _sentMessages. These will remain unacked if lost; fragments will be retransmitted in a new packet.- Overrides:
finishMessagesin classPeerState- Returns:
- number of active outbound messages remaining
-
allocateSend
Overridden to retransmit SessionConfirmed also- Overrides:
allocateSendin classPeerState- Returns:
- allocated messages to send (never empty), or null if no messages or no resources
-
getCurrentFullACKs
Description copied from class:PeerStateGrab 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. If the message id is transmitted to the peer, removeACKMessage(Long) should be called. The returned list contains acks not yet sent only. The caller should NOT transmit all of them all the time, even if there is room, or the packets will have way too much overhead. SSU 1 only.- Overrides:
getCurrentFullACKsin classPeerState- Returns:
- a new list, do as you like with it
-
getCurrentResendACKs
Description copied from class:PeerStateGrab 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. The returned list contains a random assortment of acks already sent. The caller should NOT transmit all of them all the time, even if there is room, or the packets will have way too much overhead. SSU 1 only.- Overrides:
getCurrentResendACKsin classPeerState- Returns:
- a new list, do as you like with it
-
removeACKMessage
Description copied from class:PeerStateThe ack was sent. Side effect - sets _lastACKSend SSU 1 only.- Overrides:
removeACKMessagein classPeerState
-
fetchPartialACKs
Description copied from class:PeerStateSSU 1 only.- Overrides:
fetchPartialACKsin classPeerState- Parameters:
rv- out parameter, populated with true partial ACKBitfields. no full bitfields are included.
-
getNextPacketNumber
long getNextPacketNumber()Next outbound packet number, starts at 1 for Alice (0 is Session Confirmed) and 0 for Bob -
getSendConnID
long getSendConnID() -
getRcvConnID
long getRcvConnID() -
getSendCipher
CipherState getSendCipher()caller must sync on returned object when encrypting -
getSendHeaderEncryptKey1
byte[] getSendHeaderEncryptKey1() -
getRcvHeaderEncryptKey1
byte[] getRcvHeaderEncryptKey1() -
getSendHeaderEncryptKey2
byte[] getSendHeaderEncryptKey2() -
getRcvHeaderEncryptKey2
byte[] getRcvHeaderEncryptKey2() -
setOurAddress
void setOurAddress(byte[] ip, int port) -
getOurIP
byte[] getOurIP() -
getOurPort
int getOurPort() -
getReceivedMessages
SSU2Bitfield getReceivedMessages() -
getAckedMessages
SSU2Bitfield getAckedMessages() -
receivePacket
- Parameters:
packet- fully encrypted, header and body decryption will be done here
-
receivePacket
From different than expected source IP/port- Parameters:
from- source addresspacket- fully encrypted, header and body decryption will be done here- Since:
- 0.9.55
-
gotDateTime
public void gotDateTime(long time) - Specified by:
gotDateTimein interfaceSSU2Payload.PayloadCallback
-
gotOptions
public void gotOptions(byte[] options, boolean isHandshake) - Specified by:
gotOptionsin interfaceSSU2Payload.PayloadCallback- Parameters:
isHandshake- true only for message 3 part 2
-
gotRI
- Specified by:
gotRIin interfaceSSU2Payload.PayloadCallback- Parameters:
ri- will already be validatedisHandshake- true only for message 3 part 2- Throws:
DataFormatException
-
gotRIFragment
public void gotRIFragment(byte[] data, boolean isHandshake, boolean flood, boolean isGzipped, int frag, int totalFrags) - Specified by:
gotRIFragmentin interfaceSSU2Payload.PayloadCallback- Parameters:
data- is first gzipped and then fragmentedisHandshake- true only for message 3 part 2
-
gotAddress
public void gotAddress(byte[] ip, int port) - Specified by:
gotAddressin interfaceSSU2Payload.PayloadCallback
-
gotRelayTagRequest
public void gotRelayTagRequest()- Specified by:
gotRelayTagRequestin interfaceSSU2Payload.PayloadCallback
-
gotRelayTag
public void gotRelayTag(long tag) - Specified by:
gotRelayTagin interfaceSSU2Payload.PayloadCallback
-
gotRelayRequest
public void gotRelayRequest(byte[] data) - Specified by:
gotRelayRequestin interfaceSSU2Payload.PayloadCallback- Parameters:
data- excludes flag, includes signature
-
gotRelayResponse
public void gotRelayResponse(int status, byte[] data) - Specified by:
gotRelayResponsein interfaceSSU2Payload.PayloadCallback- Parameters:
status- 0 = accept, 1-255 = rejectdata- excludes flag, includes signature
-
gotRelayIntro
- Specified by:
gotRelayIntroin interfaceSSU2Payload.PayloadCallback- Parameters:
data- excludes flag, includes signature
-
gotPeerTest
- Specified by:
gotPeerTestin interfaceSSU2Payload.PayloadCallback- Parameters:
msg- 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 signature
-
gotToken
public void gotToken(long token, long expires) - Specified by:
gotTokenin interfaceSSU2Payload.PayloadCallback
-
gotI2NP
- Specified by:
gotI2NPin interfaceSSU2Payload.PayloadCallback
-
gotFragment
public void gotFragment(byte[] data, int off, int len, long messageId, int frag, boolean isLast) throws DataFormatException Description copied from interface:SSU2Payload.PayloadCallbackData must be copied out in this method. Data starts at the 9 byte header for fragment 0.- Specified by:
gotFragmentin interfaceSSU2Payload.PayloadCallback- Parameters:
off- offset in datalen- length of data to copy- Throws:
DataFormatException
-
gotACK
public void gotACK(long ackThru, int acks, byte[] ranges) - Specified by:
gotACKin interfaceSSU2Payload.PayloadCallback- Parameters:
ranges- null if none
-
gotTermination
public void gotTermination(int reason, long count) - Specified by:
gotTerminationin interfaceSSU2Payload.PayloadCallback- Parameters:
count- in theory could wrap around to negative, but very unlikely
-
gotPathChallenge
- Specified by:
gotPathChallengein interfaceSSU2Payload.PayloadCallback- Parameters:
from- null if unknown
-
gotPathResponse
- Specified by:
gotPathResponsein interfaceSSU2Payload.PayloadCallback- Parameters:
from- null if unknown
-
changeAddress
Caller should sync; UDPTransport must remove and add to peersByRemoteHost map- Since:
- 0.9.56
-
fragmentsSent
Record the mapping of packet number to what fragments were in it, so we can process acks.- Parameters:
length- including ip/udp header, for logging only
-
bitSet
public void bitSet(long pktNum) Callback from SSU2Bitfield.forEachAndNot(). A new ack was received.- Specified by:
bitSetin interfaceSSU2Bitfield.Callback
-
confirmedPacketsSent
void confirmedPacketsSent(byte[][] data) Note that we just sent the SessionConfirmed packets and save them for retransmission. This is only called the first time. For retransmit see allocateSend() above. -
getFlags
byte getFlags()Flag byte to be sent in header- Since:
- 0.9.56
-