java.lang.Object
net.i2p.router.transport.udp.OutboundEstablishState
Direct Known Subclasses:
OutboundEstablishState2

class OutboundEstablishStateextends Object
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.
  • Field Details

    • _context

      protected final RouterContext _context
      The router context.
    • _log

      protected final Log _log
      Logger.
    • _bobIP

      protected byte[] _bobIP
      Bob's IP.
    • _bobPort

      protected int _bobPort
      Bob's port.
    • _aliceIP

      protected byte[] _aliceIP
      Alice's IP.
    • _alicePort

      protected int _alicePort
      Alice's port.
    • _receivedRelayTag

      protected long _receivedRelayTag
      Received relay tag.
    • _establishBegin

      protected final long _establishBegin
      Establish begin time.
    • _lastSend

      protected long _lastSend
      Last send time.
    • _nextSend

      protected long _nextSend
      Next send time.
    • _remoteHostId

      protected RemoteHostId _remoteHostId
      Remote host ID.
    • _remotePeer

      protected final RouterIdentity _remotePeer
      Remote peer.
    • _currentState

      protected OutboundEstablishState.OutboundState _currentState
      Current state.
    • _requestSentCount

      protected int _requestSentCount
      Request sent count.
    • _requestSentTime

      protected long _requestSentTime
      Request sent time.
    • _rtt

      protected int _rtt
      Round trip time.
    • RETRANSMIT_DELAY

      protected static final long RETRANSMIT_DELAY
      Flat 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_DELAY
      Max 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 context
      claimedAddress - the claimed address from the netdb
      remoteHostId - the remote host ID
      remotePeer - the remote peer identity
      needIntroduction - whether introduction is needed
      introKey - the introduction key
      addr - 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

      public UDPAddress getRemoteAddress()
      Remote address of the peer.
      Returns:
      the remote address
    • 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

      public void addMessage(OutNetMessage msg)
      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

      public OutNetMessage getNextQueuedMessage()
      Next queued message.
      Returns:
      the next queued message, or null if none
    • getRemoteIdentity

      public RouterIdentity getRemoteIdentity()
      Remote router identity.
      Returns:
      the remote identity
    • getIntroKey

      public SessionKey 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 one

      Generates 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 IP
      bobPort - 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 _lastSend with 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

      public String toString()
      String representation.
      Overrides:
      toString in class Object