java.lang.Object
net.i2p.router.transport.udp.OutboundEstablishState
- Direct Known Subclasses:
OutboundEstablishState2
Data for a new connection being established, where we initiated the connection with a remote peer. In other words, we are Alice and they are Bob.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumStates for outbound SSU session establishment.Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]Alice's IP.protected intAlice's port.protected byte[]Bob's IP.protected intBob's port.protected final RouterContextThe router context.protected OutboundEstablishState.OutboundStateCurrent state.protected final longEstablish begin time.protected longLast send time.protected final LogLogger.protected longNext send time.protected longReceived relay tag.protected RemoteHostIdRemote host ID.protected final RouterIdentityRemote peer.protected intRequest sent count.protected longRequest sent time.protected intRound trip time.protected static final longMax delay including backoff (15 seconds).protected static final longFlat delay between all retransmits (no exponential backoff).Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedOutboundEstablishState(RouterContext ctx, RemoteHostId claimedAddress, RemoteHostId remoteHostId, RouterIdentity remotePeer, boolean needIntroduction, SessionKey introKey, UDPAddress addr) For SSU2.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidaddMessage(OutNetMessage msg) Queue a message to be sent after the session is established.booleancomplete()Mark as complete.voidNote that we just sent the SessionConfirmed packet.voidWe have received a real data packet, so we're done establishing.voidfail()The SessionCreated validation failed.(package private) RemoteHostIdThis will never be a hash-based address.longWhen we sent the first SessionConfirmed packet.longTime the establish began.Bob's introduction key, as published in the netdb.longIntroduction nonce, or -1 if unset.longWhen we sent the first RelayRequest packet.longHow long have we been trying to establish this session?longgetLifetime(long now) How long have we been trying to establish this session?Next queued message.longThe next time a message should be sent.byte[]IP address reported by the peer.intPort reported by the peer.longRelay tag received from the introducer.longTime the signed-on packet was received.Remote address of the peer.(package private) RemoteHostIdThis should be what the state is currently indexed by in the _outboundStates table.Remote router identity.longWhen we sent the first SessionRequest packet.(package private) intgetRTT()Round-trip time estimate.byte[]The remote side (Bob) - note that in some places he's called Charlie.intThe remote side (Bob) - note that in some places he's called Charlie.longTime the signed-on packet was sent.getState()Current outbound handshake state.intVersion of the SSU protocol in use.booleanWhether the state machine has already scheduled a resend.voidintroduced(byte[] bobIP, int bobPort) This changes the remoteHostId from a hash-based one or possibly incorrect IP/port to what the introducer told us.voidRecord that the introduction failed.voidNote that we just sent the RelayRequest packet.booleanAre we allowed to send extended options to this peer?booleanIs the first message queued our own DatabaseStoreMessage?booleanShould we ask this peer to be an introducer for us? Ignored unless allowExtendedOptions is true.protected voidCall from synchronized method only.(package private) booleanAccelerate response to RelayResponse if we haven't sent it yet.voidNote that we just sent the SessionRequest packet.voidsetIntroNonce(long nonce) Introduction nonce.toString()String representation.booleanBlocking call (run in the establisher thread) to determine if the session was created properly.
Field Details
_context
The router context._log
Logger._bobIP
protected byte[] _bobIPBob's IP._bobPort
protected int _bobPortBob's port._aliceIP
protected byte[] _aliceIPAlice's IP._alicePort
protected int _alicePortAlice's port._receivedRelayTag
protected long _receivedRelayTagReceived relay tag._establishBegin
protected final long _establishBeginEstablish begin time._lastSend
protected long _lastSendLast send time._nextSend
protected long _nextSendNext send time._remoteHostId
Remote host ID._remotePeer
Remote peer._currentState
Current state._requestSentCount
protected int _requestSentCountRequest sent count._requestSentTime
protected long _requestSentTimeRequest sent time._rtt
protected int _rttRound trip time.RETRANSMIT_DELAY
protected static final long RETRANSMIT_DELAYFlat delay between all retransmits (no exponential backoff). Handshake packets are tiny (~200B) and infrequent per-peer, so the bandwidth cost of flat retransmission is negligible. The OB_MESSAGE_TIMEOUT (2.5s) bounds total retransmits per establishment phase.Was 1000ms with exponential doubling (max gap 16s). Reduced to 500ms, now 200ms for sub-100ms message delivery.
MAX_DELAY
protected static final long MAX_DELAYMax delay including backoff (15 seconds).- See Also:
Constructor Details
OutboundEstablishState
protected OutboundEstablishState(RouterContext ctx, RemoteHostId claimedAddress, RemoteHostId remoteHostId, RouterIdentity remotePeer, boolean needIntroduction, SessionKey introKey, UDPAddress addr) For SSU2.- Parameters:
ctx- the router contextclaimedAddress- the claimed address from the netdbremoteHostId- the remote host IDremotePeer- the remote peer identityneedIntroduction- whether introduction is neededintroKey- the introduction keyaddr- the UDP address
Method Details
getVersion
public int getVersion()Version of the SSU protocol in use.- Returns:
- the protocol version
getState
Current outbound handshake state.- Returns:
- the current outbound state
complete
public boolean complete()Mark as complete.- Returns:
- whether it was previously complete
getRemoteAddress
setIntroNonce
public void setIntroNonce(long nonce) Introduction nonce.- Parameters:
nonce- the introduction nonce
getIntroNonce
public long getIntroNonce()Introduction nonce, or -1 if unset.- Returns:
- the nonce, or -1
isExtendedOptionsAllowed
public boolean isExtendedOptionsAllowed()Are we allowed to send extended options to this peer?- Returns:
- true if allowed
needIntroduction
public boolean needIntroduction()Should we ask this peer to be an introducer for us? Ignored unless allowExtendedOptions is true.- Returns:
- true if introduction is needed
getRTT
int getRTT()Round-trip time estimate.- Returns:
- round-trip time in milliseconds, measured during the handshake
addMessage
Queue a message to be sent after the session is established.- Parameters:
msg- the message to queue
isFirstMessageOurDSM
public boolean isFirstMessageOurDSM()Is the first message queued our own DatabaseStoreMessage?- Returns:
- true if the first queued message is our DSM
getNextQueuedMessage
Next queued message.- Returns:
- the next queued message, or null if none
getRemoteIdentity
getIntroKey
Bob's introduction key, as published in the netdb.- Returns:
- the intro key
getSentIP
public byte[] getSentIP()The remote side (Bob) - note that in some places he's called Charlie. Warning - may change after introduction. May be null before introduction.- Returns:
- the sent IP, or null
getSentPort
public int getSentPort()The remote side (Bob) - note that in some places he's called Charlie. Warning - may change after introduction. May be -1 before introduction.- Returns:
- the sent port, or -1
validateSessionCreated
public boolean validateSessionCreated()Blocking call (run in the establisher thread) to determine if the session was created properly. If it wasn't, all the SessionCreated remnants are dropped (perhaps they were spoofed, etc) so that we can receive another oneGenerates session key and mac key.
- Returns:
- true if valid
fail
public void fail()The SessionCreated validation failed.getReceivedRelayTag
public long getReceivedRelayTag()Relay tag received from the introducer.- Returns:
- the received relay tag
getSentSignedOnTime
public long getSentSignedOnTime()Time the signed-on packet was sent.- Returns:
- the sent signed-on time
getReceivedSignedOnTime
public long getReceivedSignedOnTime()Time the signed-on packet was received.- Returns:
- the received signed-on time
getReceivedIP
public byte[] getReceivedIP()IP address reported by the peer.- Returns:
- the received IP
getReceivedPort
public int getReceivedPort()Port reported by the peer.- Returns:
- the received port
confirmedPacketsSent
public void confirmedPacketsSent()Note that we just sent the SessionConfirmed packet.getConfirmedSentTime
public long getConfirmedSentTime()When we sent the first SessionConfirmed packet.- Returns:
- the time, or 0 if not yet sent
requestSent
public void requestSent()Note that we just sent the SessionRequest packet.getRequestSentTime
public long getRequestSentTime()When we sent the first SessionRequest packet.- Returns:
- the time, or 0 if not yet sent
introSent
public void introSent()Note that we just sent the RelayRequest packet.getIntroSentTime
public long getIntroSentTime()When we sent the first RelayRequest packet.- Returns:
- the time, or 0 if not yet sent
introductionFailed
public void introductionFailed()Record that the introduction failed.introduced
public void introduced(byte[] bobIP, int bobPort) This changes the remoteHostId from a hash-based one or possibly incorrect IP/port to what the introducer told us. All params are for the remote end (NOT the introducer) and must have been validated already.- Parameters:
bobIP- the remote IPbobPort- the remote port
receiveHolePunch
boolean receiveHolePunch()Accelerate response to RelayResponse if we haven't sent it yet.- Returns:
- true if we should send the SessionRequest now
getLifetime
public long getLifetime()How long have we been trying to establish this session?- Returns:
- the lifetime in milliseconds
getLifetime
public long getLifetime(long now) How long have we been trying to establish this session?- Parameters:
now- the current time- Returns:
- the lifetime in milliseconds
getEstablishBeginTime
public long getEstablishBeginTime()Time the establish began.- Returns:
- the establish begin time
getNextSendTime
public long getNextSendTime()The next time a message should be sent.- Returns:
- 0 at initialization (to force sending session request), rcv time after receiving a packet, send time + delay after sending a packet (including session request)
hasRetried
public boolean hasRetried()Whether the state machine has already scheduled a resend.Derived rather than counted: the first send stamps
_lastSendwith the same clock reading as_establishBegin, so a strictly later stamp means a subsequent send. This is what lets the establishment deadline be extended only once retransmission has genuinely failed, instead of holding every attempt - the overwhelming majority of which are a peer that is simply not there - to the longer budget.- Returns:
- true if anything has been sent since the state was created
getRemoteHostId
RemoteHostId getRemoteHostId()This should be what the state is currently indexed by in the _outboundStates table. Beware - During introduction, this is a router hash. After introduced() is called, this is set to the IP/port the introducer told us.- Returns:
- non-null
getClaimedAddress
RemoteHostId getClaimedAddress()This will never be a hash-based address. This is the 'claimed' (unverified) address from the netdb, or null. It is not changed after introduction. Use getRemoteHostId() for the verified address.- Returns:
- may be null
dataReceived
public void dataReceived()We have received a real data packet, so we're done establishing.packetReceived
protected void packetReceived()Call from synchronized method only.toString