net.i2p.router.transport.udp

## Class OutboundEstablishState

- java.lang.Object
- - net.i2p.router.transport.udp.OutboundEstablishState

- Direct Known Subclasses:
    OutboundEstablishState2

      class OutboundEstablishState
      extends 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.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `OutboundEstablishState.OutboundState` States for outbound SSU session establishment.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected byte[]` | `_aliceIP`
    `protected int` | `_alicePort`
    `protected byte[]` | `_bobIP`
    `protected int` | `_bobPort`
    `protected RouterContext` | `_context`
    `protected OutboundEstablishState.OutboundState` | `_currentState`
    `protected long` | `_establishBegin`
    `protected long` | `_lastSend`
    `protected Log` | `_log`
    `protected long` | `_nextSend`
    `protected long` | `_receivedRelayTag`
    `protected RemoteHostId` | `_remoteHostId`
    `protected RouterIdentity` | `_remotePeer`
    `protected int` | `_requestSentCount`
    `protected long` | `_requestSentTime`
    `protected int` | `_rtt`
    `protected static long` | `RETRANSMIT_DELAY` basic delay before backoff Transmissions at 0, 1.25, 3.75, 8.75 sec This should be a little longer than for inbound.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `OutboundEstablishState(RouterContext ctx, RemoteHostId claimedAddress, RemoteHostId remoteHostId, RouterIdentity remotePeer, boolean needIntroduction, SessionKey introKey, UDPAddress addr)` For SSU2

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addMessage(OutNetMessage msg)` Queue a message to be sent after the session is established.
    `boolean` | `complete()`
    `void` | `confirmedPacketsSent()` note that we just sent the SessionConfirmed packet
    `void` | `dataReceived()` we have received a real data packet, so we're done establishing
    `void` | `fail()` The SessionCreated validation failed
    `(package private) RemoteHostId` | `getClaimedAddress()` This will never be a hash-based address.
    `long` | `getConfirmedSentTime()`
    `long` | `getEstablishBeginTime()`
    `SessionKey` | `getIntroKey()` Bob's introduction key, as published in the netdb
    `long` | `getIntroNonce()`
    `long` | `getIntroSentTime()`
    `long` | `getLifetime()` how long have we been trying to establish this session?
    `long` | `getLifetime(long now)` how long have we been trying to establish this session?
    `OutNetMessage` | `getNextQueuedMessage()`
    `long` | `getNextSendTime()`
    `byte[]` | `getReceivedIP()`
    `int` | `getReceivedPort()`
    `long` | `getReceivedRelayTag()`
    `long` | `getReceivedSignedOnTime()`
    `UDPAddress` | `getRemoteAddress()`
    `(package private) RemoteHostId` | `getRemoteHostId()` This should be what the state is currently indexed by in the _outboundStates table.
    `RouterIdentity` | `getRemoteIdentity()`
    `long` | `getRequestSentTime()`
    `(package private) int` | `getRTT()`
    `byte[]` | `getSentIP()` The remote side (Bob) - note that in some places he's called Charlie.
    `int` | `getSentPort()` The remote side (Bob) - note that in some places he's called Charlie.
    `long` | `getSentSignedOnTime()`
    `OutboundEstablishState.OutboundState` | `getState()`
    `int` | `getVersion()`
    `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.
    `void` | `introductionFailed()`
    `void` | `introSent()` note that we just sent the RelayRequest packet
    `boolean` | `isExtendedOptionsAllowed()` Are we allowed to send extended options to this peer?
    `boolean` | `isFirstMessageOurDSM()` Is the first message queued our own DatabaseStoreMessage?
    `boolean` | `needIntroduction()` Should we ask this peer to be an introducer for us? Ignored unless allowExtendedOptions is true
    `protected void` | `packetReceived()` Call from synchronized method only
    `(package private) boolean` | `receiveHolePunch()` Accelerate response to RelayResponse if we haven't sent it yet.
    `void` | `requestSent()` note that we just sent the SessionRequest packet
    `void` | `setIntroNonce(long nonce)`
    `String` | `toString()`
    `boolean` | `validateSessionCreated()` Blocking call (run in the establisher thread) to determine if the session was created properly.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### _aliceIP

          protected byte[] _aliceIP

    - #### _alicePort

          protected int _alicePort

    - #### _bobIP

          protected byte[] _bobIP

    - #### _bobPort

          protected int _bobPort

    - #### _context

          protected final RouterContext _context

    - #### _currentState

          protected OutboundEstablishState.OutboundState _currentState

    - #### _establishBegin

          protected final long _establishBegin

    - #### _lastSend

          protected long _lastSend

    - #### _log

          protected final Log _log

    - #### _nextSend

          protected long _nextSend

    - #### _receivedRelayTag

          protected long _receivedRelayTag

    - #### _remoteHostId

          protected RemoteHostId _remoteHostId

    - #### _remotePeer

          protected final RouterIdentity _remotePeer

    - #### _requestSentCount

          protected int _requestSentCount

    - #### _requestSentTime

          protected long _requestSentTime

    - #### _rtt

          protected int _rtt

    - #### RETRANSMIT_DELAY

          protected static final long RETRANSMIT_DELAY

      basic delay before backoff Transmissions at 0, 1.25, 3.75, 8.75 sec This should be a little longer than for inbound.

  - ### Constructor Detail

    - #### OutboundEstablishState

          protected OutboundEstablishState(RouterContext ctx,
                                           RemoteHostId claimedAddress,
                                           RemoteHostId remoteHostId,
                                           RouterIdentity remotePeer,
                                           boolean needIntroduction,
                                           SessionKey introKey,
                                           UDPAddress addr)

      For SSU2

  - ### Method Detail

    - #### addMessage

          public void addMessage(OutNetMessage msg)

      Queue a message to be sent after the session is established.

    - #### complete

          public boolean complete()

      Returns:
        if previously complete

    - #### confirmedPacketsSent

          public void confirmedPacketsSent()

      note that we just sent the SessionConfirmed packet

    - #### dataReceived

          public void dataReceived()

      we have received a real data packet, so we're done establishing

    - #### fail

          public void fail()

      The SessionCreated validation failed

    - #### 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

    - #### getConfirmedSentTime

          public long getConfirmedSentTime()

      Returns:
        when we sent the first SessionConfirmed packet, or 0

    - #### getEstablishBeginTime

          public long getEstablishBeginTime()

    - #### getIntroKey

          public SessionKey getIntroKey()

      Bob's introduction key, as published in the netdb

    - #### getIntroNonce

          public long getIntroNonce()

      Returns:
        -1 if unset

    - #### getIntroSentTime

          public long getIntroSentTime()

      Returns:
        when we sent the first RelayRequest packet, or 0

    - #### getLifetime

          public long getLifetime()

      how long have we been trying to establish this session?

    - #### getLifetime

          public long getLifetime(long now)

      how long have we been trying to establish this session?

    - #### getNextQueuedMessage

          public OutNetMessage getNextQueuedMessage()

      Returns:
        null if none

    - #### getNextSendTime

          public long getNextSendTime()

      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)

    - #### getReceivedIP

          public byte[] getReceivedIP()

    - #### getReceivedPort

          public int getReceivedPort()

    - #### getReceivedRelayTag

          public long getReceivedRelayTag()

    - #### getReceivedSignedOnTime

          public long getReceivedSignedOnTime()

    - #### getRemoteAddress

          public UDPAddress getRemoteAddress()

      Returns:
        non-null

    - #### 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

    - #### getRemoteIdentity

          public RouterIdentity getRemoteIdentity()

    - #### getRequestSentTime

          public long getRequestSentTime()

      Returns:
        when we sent the first SessionRequest packet, or 0

    - #### getRTT

          int getRTT()

    - #### 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.

    - #### 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.

    - #### getSentSignedOnTime

          public long getSentSignedOnTime()

    - #### getState

          public OutboundEstablishState.OutboundState getState()

    - #### getVersion

          public int getVersion()

    - #### 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.

    - #### introductionFailed

          public void introductionFailed()

    - #### introSent

          public void introSent()

      note that we just sent the RelayRequest packet

    - #### isExtendedOptionsAllowed

          public boolean isExtendedOptionsAllowed()

      Are we allowed to send extended options to this peer?

    - #### isFirstMessageOurDSM

          public boolean isFirstMessageOurDSM()

      Is the first message queued our own DatabaseStoreMessage?

    - #### needIntroduction

          public boolean needIntroduction()

      Should we ask this peer to be an introducer for us? Ignored unless allowExtendedOptions is true

    - #### packetReceived

          protected void packetReceived()

      Call from synchronized method only

    - #### receiveHolePunch

          boolean receiveHolePunch()

      Accelerate response to RelayResponse if we haven't sent it yet.
      Returns:
        true if we should send the SessionRequest now

    - #### requestSent

          public void requestSent()

      note that we just sent the SessionRequest packet

    - #### setIntroNonce

          public void setIntroNonce(long nonce)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### 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