Package net.i2p.router.transport.udp
Class EstablishmentManager
java.lang.Object
net.i2p.router.transport.udp.EstablishmentManager
Coordinate the establishment of new sessions - both inbound and outbound.
This has its own thread to add packets to the packet queue when necessary,
as well as to drop any failed establishment attempts.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
static final int
Kill any inbound that takes more than this One round trip (Created-Confirmed) Note: could be two round trips for SSU2 with retrystatic final long
the relay tag is a 4-byte field in the protocolstatic final int
max before receiving a response to a single message during outbound establishment -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addOutboundToken
(RemoteHostId peer, long token, long expires) Remember a token that can be used later to connect to the peervoid
establish
(OutNetMessage msg) Send the message to its specified recipient by establishing a connection with them and sending it off.(package private) InboundEstablishState
getInboundState
(RemoteHostId from) Grab the active establishing stategetInboundToken
(RemoteHostId peer) Get a token that can be used later for the peer to connect to usgetInboundToken
(RemoteHostId peer, long expiration) Get a token that can be used later for the peer to connect to usA database store message with our router info(package private) OutboundEstablishState
getOutboundState
(RemoteHostId from) Grab the active establishing statelong
getOutboundToken
(RemoteHostId peer) Get a token to connect to the peervoid
ipChanged
(boolean isIPv6) Remove our tokens for this lengthboolean
isInboundTokenValid
(RemoteHostId peer, long token) Is the token from this peer valid?(package private) boolean
isValid
(byte[] ip, int port) Are IP and port valid? This is only for checking the relay response.void
Remove all tokens(package private) PeerState
A data packet arrived on an outbound connection being established, which means its complete (yay!).(package private) void
receiveHolePunch
(InetAddress from, int fromPort) Called from UDPReceiver.(package private) void
receiveHolePunch
(RemoteHostId id, UDPPacket packet) Called from PacketHandler.(package private) void
receiveRelayResponse
(PeerState2 bob, long nonce, int code, byte[] data) We are Alice, we sent a RelayRequest to Bob and got a RelayResponse back.(package private) void
receiveRelayResponse
(RemoteHostId bob, UDPPacketReader reader) We are Alice, we sent a RelayRequest to Bob and got a response back.(package private) void
receiveRetry
(OutboundEstablishState2 state, UDPPacket packet) Got a Retry (in response to our outbound SessionRequest or TokenRequest) SSU 2 only.(package private) void
receiveSessionConfirmed
(InboundEstablishState2 state, UDPPacket packet) got a SessionConfirmed (should only happen as part of an inbound establishment) SSU 2 only.(package private) void
receiveSessionConfirmed
(RemoteHostId from, InboundEstablishState state, UDPPacketReader reader) got a SessionConfirmed (should only happen as part of an inbound establishment) SSU 1 only.(package private) void
receiveSessionCreated
(OutboundEstablishState2 state, UDPPacket packet) Got a SessionCreated (in response to our outbound SessionRequest) SSU 2 only.(package private) void
receiveSessionCreated
(RemoteHostId from, OutboundEstablishState state, UDPPacketReader reader) Got a SessionCreated (in response to our outbound SessionRequest) SSU 1 only.(package private) void
Got a SessionDestroy - maybe during an inbound establish? TODO - PacketHandler won't look up inbound establishes As this packet was essentially unauthenticated (i.e.(package private) void
receiveSessionDestroy
(RemoteHostId from, OutboundEstablishState state) Got a SessionDestroy during outbound establish SSU 1 or 2(package private) void
receiveSessionDestroy
(RemoteHostId from, PeerState state) Got a SessionDestroy on an established conn SSU 1 or 2(package private) void
receiveSessionOrTokenRequest
(RemoteHostId from, InboundEstablishState2 state, UDPPacket packet) Got a SessionRequest OR a TokenRequest (initiates an inbound establishment) SSU 2 only.(package private) void
receiveSessionRequest
(RemoteHostId from, InboundEstablishState state, UDPPacketReader reader) Got a SessionRequest (initiates an inbound establishment) SSU 1 only.boolean
Should we allow another inbound establishment? Used to throttle outbound hole punches.void
shutdown()
void
startup()
-
Field Details
-
MAX_IB_ESTABLISH_TIME
public static final int MAX_IB_ESTABLISH_TIMEKill any inbound that takes more than this One round trip (Created-Confirmed) Note: could be two round trips for SSU2 with retry- See Also:
-
OB_MESSAGE_TIMEOUT
public static final int OB_MESSAGE_TIMEOUTmax before receiving a response to a single message during outbound establishment- See Also:
-
IB_TOKEN_EXPIRATION
public static final long IB_TOKEN_EXPIRATION- See Also:
-
MAX_TAG_VALUE
public static final long MAX_TAG_VALUEthe relay tag is a 4-byte field in the protocol- See Also:
-
-
Constructor Details
-
EstablishmentManager
-
-
Method Details
-
startup
public void startup() -
shutdown
public void shutdown() -
getInboundState
Grab the active establishing state- Returns:
- null if none
-
getOutboundState
Grab the active establishing state- Returns:
- null if none
-
establish
Send the message to its specified recipient by establishing a connection with them and sending it off. This call does not block, and on failure, the message is failed. Note - if we go back to multiple PacketHandler threads, this may need more locking. -
shouldAllowInboundEstablishment
public boolean shouldAllowInboundEstablishment()Should we allow another inbound establishment? Used to throttle outbound hole punches.- Since:
- 0.9.2
-
receiveSessionRequest
Got a SessionRequest (initiates an inbound establishment) SSU 1 only.- Parameters:
state
- as looked up in PacketHandler, but probably null unless retransmitted
-
receiveSessionOrTokenRequest
void receiveSessionOrTokenRequest(RemoteHostId from, InboundEstablishState2 state, UDPPacket packet) Got a SessionRequest OR a TokenRequest (initiates an inbound establishment) SSU 2 only.- Parameters:
state
- as looked up in PacketHandler, but null unless retransmitted or retry sentpacket
- header decrypted only- Since:
- 0.9.54
-
receiveSessionConfirmed
void receiveSessionConfirmed(RemoteHostId from, InboundEstablishState state, UDPPacketReader reader) got a SessionConfirmed (should only happen as part of an inbound establishment) SSU 1 only.- Parameters:
state
- as looked up in PacketHandler, if null is probably retransmitted
-
receiveSessionConfirmed
got a SessionConfirmed (should only happen as part of an inbound establishment) SSU 2 only.- Parameters:
state
- non-nullpacket
- header decrypted only- Since:
- 0.9.54
-
receiveSessionCreated
Got a SessionCreated (in response to our outbound SessionRequest) SSU 1 only.- Parameters:
state
- as looked up in PacketHandler, if null is probably retransmitted
-
receiveSessionCreated
Got a SessionCreated (in response to our outbound SessionRequest) SSU 2 only.- Parameters:
state
- non-nullpacket
- header decrypted only- Since:
- 0.9.54
-
receiveRetry
Got a Retry (in response to our outbound SessionRequest or TokenRequest) SSU 2 only.- Since:
- 0.9.54
-
receiveSessionDestroy
Got a SessionDestroy on an established conn SSU 1 or 2- Since:
- 0.8.1
-
receiveSessionDestroy
Got a SessionDestroy during outbound establish SSU 1 or 2- Since:
- 0.8.1
-
receiveSessionDestroy
Got a SessionDestroy - maybe during an inbound establish? TODO - PacketHandler won't look up inbound establishes As this packet was essentially unauthenticated (i.e. intro key, not session key) we just log it as it could be spoofed. SSU 1 or 2- Since:
- 0.8.1
-
receiveData
A data packet arrived on an outbound connection being established, which means its complete (yay!). This is a blocking call, more than I'd like...- Returns:
- the new PeerState
-
getOurInfo
A database store message with our router info- Returns:
- non-null
- Since:
- 0.9.24 split from sendOurInfo(), public since 0.9.55 for UDPTransport
-
receiveRelayResponse
We are Alice, we sent a RelayRequest to Bob and got a response back. SSU 1 only. -
receiveRelayResponse
We are Alice, we sent a RelayRequest to Bob and got a RelayResponse back. Time and version already checked by caller. SSU 2 only.- Parameters:
data
- including nonce, including token if code == 0- Since:
- 0.9.55
-
receiveHolePunch
Called from UDPReceiver. Accelerate response to RelayResponse if we haven't sent it yet. SSU 1 only.- Since:
- 0.9.15
-
receiveHolePunch
Called from PacketHandler. Accelerate response to RelayResponse if we haven't sent it yet. SSU 2 only.- Parameters:
id
- non-nullpacket
- header already decrypted- Since:
- 0.9.55
-
isValid
boolean isValid(byte[] ip, int port) Are IP and port valid? This is only for checking the relay response. Allow IPv6 as of 0.9.50. Refuse anybody in the same /16- Since:
- 0.9.3, pkg private since 0.9.45 for PacketBuider
-
addOutboundToken
Remember a token that can be used later to connect to the peer- Parameters:
token
- nonzero- Since:
- 0.9.54
-
getOutboundToken
Get a token to connect to the peer- Returns:
- 0 if none available
- Since:
- 0.9.54
-
ipChanged
public void ipChanged(boolean isIPv6) Remove our tokens for this length- Since:
- 0.9.54
-
portChanged
public void portChanged()Remove all tokens- Since:
- 0.9.54
-
getInboundToken
Get a token that can be used later for the peer to connect to us- Since:
- 0.9.54
-
getInboundToken
Get a token that can be used later for the peer to connect to us- Parameters:
expiration
- time from now- Since:
- 0.9.55
-
isInboundTokenValid
Is the token from this peer valid?- Returns:
- valid
- Since:
- 0.9.54
-