net.i2p.router.transport.udp

## Class OutboundEstablishState2

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

- All Implemented Interfaces:
    SSU2Payload.PayloadCallback

      class OutboundEstablishState2
      extends OutboundEstablishState
      implements SSU2Payload.PayloadCallback

  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. SSU2 only.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `OutboundEstablishState2.IntroState` Per-introducer introduction states

    - ### Nested classes/interfaces inherited from class net.i2p.router.transport.udp.OutboundEstablishState

      `OutboundEstablishState.OutboundState`

  - ### Field Summary

    - ### Fields inherited from class net.i2p.router.transport.udp.OutboundEstablishState

      `_aliceIP, _alicePort, _bobIP, _bobPort, _context, _currentState, _establishBegin, _lastSend, _log, _nextSend, _receivedRelayTag, _remoteHostId, _remotePeer, _requestSentCount, _requestSentTime, _rtt, RETRANSMIT_DELAY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `OutboundEstablishState2(RouterContext ctx, UDPTransport transport, RemoteHostId claimedAddress, RemoteHostId remoteHostId, RouterIdentity remotePeer, boolean needIntroduction, SessionKey introKey, RouterAddress ra, UDPAddress addr)` Prepare to start a new handshake with the given peer.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `PeerState2` | `confirmedPacketsSent(UDPPacket[] packets)` note that we just sent the SessionConfirmed packets and save them for retransmission
    `int` | `countIntroducers()`
    `void` | `fail()` Overridden to destroy the handshake state
    `HandshakeState` | `getHandshakeState()`
    `OutboundEstablishState2.IntroState` | `getIntroState(Hash h)`
    `int` | `getMTU()` What is the largest packet we can send to the peer? Only used for Session Confirmed packets.
    `EstablishmentManager.Token` | `getNextToken()`
    `PeerState2` | `getPeerState()`
    `long` | `getRcvConnID()`
    `byte[]` | `getRcvHeaderEncryptKey1()`
    `byte[]` | `getRcvHeaderEncryptKey2()`
    `byte[]` | `getRcvRetryHeaderEncryptKey2()`
    `UDPPacket` | `getRetransmitSessionRequestPacket()`
    `long` | `getSendConnID()`
    `byte[]` | `getSendHeaderEncryptKey1()`
    `byte[]` | `getSendHeaderEncryptKey2()`
    `InetSocketAddress` | `getSentAddress()`
    `long` | `getToken()`
    `int` | `getVersion()`
    `void` | `gotACK(long ackThru, int acks, byte[] ranges)`
    `void` | `gotAddress(byte[] ip, int port)`
    `void` | `gotDateTime(long time)`
    `void` | `gotFragment(byte[] data, int off, int len, long messageId, int frag, boolean isLast)` Data must be copied out in this method.
    `void` | `gotI2NP(I2NPMessage msg)`
    `void` | `gotOptions(byte[] options, boolean isHandshake)`
    `void` | `gotPathChallenge(RemoteHostId from, byte[] data)`
    `void` | `gotPathResponse(RemoteHostId from, byte[] data)`
    `void` | `gotPeerTest(int msg, int status, Hash h, byte[] data)`
    `void` | `gotRelayIntro(Hash aliceHash, byte[] data)`
    `void` | `gotRelayRequest(byte[] data)`
    `void` | `gotRelayResponse(int status, byte[] data)`
    `void` | `gotRelayTag(long tag)`
    `void` | `gotRelayTagRequest()`
    `void` | `gotRI(RouterInfo ri, boolean isHandshake, boolean flood)`
    `void` | `gotRIFragment(byte[] data, boolean isHandshake, boolean flood, boolean isGzipped, int frag, int totalFrags)`
    `void` | `gotTermination(int reason, long count)`
    `void` | `gotToken(long token, long expires)`
    `void` | `introduced(byte[] ip, int port, long token)` After introduction
    `void` | `introSent(Hash h)` A relay request was sent to the SSU2 introducer specified
    `(package private) boolean` | `receiveHolePunch()` Overridden because we don't have to wait for Relay Response first.
    `void` | `receiveRetry(UDPPacket packet)`
    `void` | `receiveSessionCreated(UDPPacket packet)`
    `void` | `requestSent(DatagramPacket pkt)` note that we just sent the SessionRequest packet and save it for retransmission
    `void` | `setIntroState(Hash h, OutboundEstablishState2.IntroState state)` Set the current state for the SSU2 introducer specified
    `void` | `tokenRequestSent(DatagramPacket packet)` Note that we just sent a token request packet.
    `String` | `toString()`
    `boolean` | `validateSessionCreated()` Blocking call (run in the establisher thread) to determine if the session was created properly.

    - ### Methods inherited from class net.i2p.router.transport.udp.OutboundEstablishState

      `addMessage, complete, confirmedPacketsSent, dataReceived, getClaimedAddress, getConfirmedSentTime, getEstablishBeginTime, getIntroKey, getIntroNonce, getIntroSentTime, getLifetime, getLifetime, getNextQueuedMessage, getNextSendTime, getReceivedIP, getReceivedPort, getReceivedRelayTag, getReceivedSignedOnTime, getRemoteAddress, getRemoteHostId, getRemoteIdentity, getRequestSentTime, getRTT, getSentIP, getSentPort, getSentSignedOnTime, getState, introduced, introductionFailed, introSent, isExtendedOptionsAllowed, isFirstMessageOurDSM, needIntroduction, packetReceived, requestSent, setIntroNonce`

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

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

- - ### Constructor Detail

    - #### OutboundEstablishState2

          public OutboundEstablishState2(RouterContext ctx,
                                         UDPTransport transport,
                                         RemoteHostId claimedAddress,
                                         RemoteHostId remoteHostId,
                                         RouterIdentity remotePeer,
                                         boolean needIntroduction,
                                         SessionKey introKey,
                                         RouterAddress ra,
                                         UDPAddress addr)
                                  throws IllegalArgumentException

      Prepare to start a new handshake with the given peer. Caller must then check getState() and build a Token Request or Session Request to send to the peer.
      Parameters:
        `claimedAddress` - an IP/port based RemoteHostId, or null if unknown
        `remoteHostId` - non-null, == claimedAddress if direct, or a hash-based one if indirect
        `remotePeer` - must have supported sig type
        `needIntroduction` - should we ask Bob to be an introducer for us? ignored unless allowExtendedOptions is true
        `introKey` - Bob's introduction key, as published in the netdb
        `addr` - non-null
      Throws:
        `IllegalArgumentException`

  - ### Method Detail

    - #### confirmedPacketsSent

          public PeerState2 confirmedPacketsSent(UDPPacket[] packets)

      note that we just sent the SessionConfirmed packets and save them for retransmission
      Returns:
        the new PeerState2, may also be retrieved from getPeerState()

    - #### countIntroducers

          public int countIntroducers()

    - #### fail

          public void fail()

      Overridden to destroy the handshake state
      Overrides:
        `fail` in class `OutboundEstablishState`

    - #### getHandshakeState

          public HandshakeState getHandshakeState()

    - #### getIntroState

          public OutboundEstablishState2.IntroState getIntroState(Hash h)

      Returns:
        non-null current state for the SSU2 introducer specified, or INTRO_STATE_INVALID if peer is not an SSU2 introducer

    - #### getMTU

          public int getMTU()

      What is the largest packet we can send to the peer? Only used for Session Confirmed packets. Session Request is very small.

    - #### getNextToken

          public EstablishmentManager.Token getNextToken()

      Returns:
        may be null

    - #### getPeerState

          public PeerState2 getPeerState()

      Returns:
        null if we have not sent the session confirmed

    - #### getRcvConnID

          public long getRcvConnID()

    - #### getRcvHeaderEncryptKey1

          public byte[] getRcvHeaderEncryptKey1()

    - #### getRcvHeaderEncryptKey2

          public byte[] getRcvHeaderEncryptKey2()

      Returns:
        null before Session Request is sent (i.e. we sent a Token Request first)

    - #### getRcvRetryHeaderEncryptKey2

          public byte[] getRcvRetryHeaderEncryptKey2()

    - #### getRetransmitSessionRequestPacket

          public UDPPacket getRetransmitSessionRequestPacket()

      Returns:
        null if not sent or already got the session created

    - #### getSendConnID

          public long getSendConnID()

    - #### getSendHeaderEncryptKey1

          public byte[] getSendHeaderEncryptKey1()

    - #### getSendHeaderEncryptKey2

          public byte[] getSendHeaderEncryptKey2()

    - #### getSentAddress

          public InetSocketAddress getSentAddress()

    - #### getToken

          public long getToken()

    - #### getVersion

          public int getVersion()

      Overrides:
        `getVersion` in class `OutboundEstablishState`

    - #### gotACK

          public void gotACK(long ackThru,
                             int acks,
                             byte[] ranges)

      Specified by:
        `gotACK` in interface `SSU2Payload.PayloadCallback`
        `ranges` - null if none

    - #### gotAddress

          public void gotAddress(byte[] ip,
                                 int port)

      Specified by:
        `gotAddress` in interface `SSU2Payload.PayloadCallback`

    - #### gotDateTime

          public void gotDateTime(long time)

      Specified by:
        `gotDateTime` in interface `SSU2Payload.PayloadCallback`

    - #### gotFragment

          public void gotFragment(byte[] data,
                                  int off,
                                  int len,
                                  long messageId,
                                  int frag,
                                  boolean isLast)
                           throws DataFormatException

      Description copied from interface: `SSU2Payload.PayloadCallback`
      Data must be copied out in this method. Data starts at the 9 byte header for fragment 0.
      Specified by:
        `gotFragment` in interface `SSU2Payload.PayloadCallback`
        `off` - offset in data
        `len` - length of data to copy
      Throws:
        `DataFormatException`

    - #### gotI2NP

          public void gotI2NP(I2NPMessage msg)

      Specified by:
        `gotI2NP` in interface `SSU2Payload.PayloadCallback`

    - #### gotOptions

          public void gotOptions(byte[] options,
                                 boolean isHandshake)

      Specified by:
        `gotOptions` in interface `SSU2Payload.PayloadCallback`
        `isHandshake` - true only for message 3 part 2

    - #### gotPathChallenge

          public void gotPathChallenge(RemoteHostId from,
                                       byte[] data)

      Specified by:
        `gotPathChallenge` in interface `SSU2Payload.PayloadCallback`
      Parameters:
        `from` - null if unknown

    - #### gotPathResponse

          public void gotPathResponse(RemoteHostId from,
                                      byte[] data)

      Specified by:
        `gotPathResponse` in interface `SSU2Payload.PayloadCallback`
      Parameters:
        `from` - null if unknown

    - #### gotPeerTest

          public void gotPeerTest(int msg,
                                  int status,
                                  Hash h,
                                  byte[] data)

      Specified by:
        `gotPeerTest` in interface `SSU2Payload.PayloadCallback`
      Parameters:
        `msg` - 1-7
        `status` - 0 = accept, 1-255 = reject
        `h` - Alice or Charlie hash for msg 2 and 4, null for msg 1, 3, 5-7
        `data` - excludes flag, includes signature

    - #### gotRelayIntro

          public void gotRelayIntro(Hash aliceHash,
                                    byte[] data)

      Specified by:
        `gotRelayIntro` in interface `SSU2Payload.PayloadCallback`
        `data` - excludes flag, includes signature

    - #### gotRelayRequest

          public void gotRelayRequest(byte[] data)

      Specified by:
        `gotRelayRequest` in interface `SSU2Payload.PayloadCallback`
      Parameters:
        `data` - excludes flag, includes signature

    - #### gotRelayResponse

          public void gotRelayResponse(int status,
                                       byte[] data)

      Specified by:
        `gotRelayResponse` in interface `SSU2Payload.PayloadCallback`
      Parameters:
        `status` - 0 = accept, 1-255 = reject
        `data` - excludes flag, includes signature

    - #### gotRelayTag

          public void gotRelayTag(long tag)

      Specified by:
        `gotRelayTag` in interface `SSU2Payload.PayloadCallback`

    - #### gotRelayTagRequest

          public void gotRelayTagRequest()

      Specified by:
        `gotRelayTagRequest` in interface `SSU2Payload.PayloadCallback`

    - #### gotRI

          public void gotRI(RouterInfo ri,
                            boolean isHandshake,
                            boolean flood)
                     throws DataFormatException

      Specified by:
        `gotRI` in interface `SSU2Payload.PayloadCallback`
      Parameters:
        `ri` - will already be validated
        `isHandshake` - 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:
        `gotRIFragment` in interface `SSU2Payload.PayloadCallback`
      Parameters:
        `data` - is first gzipped and then fragmented
        `isHandshake` - true only for message 3 part 2

    - #### gotTermination

          public void gotTermination(int reason,
                                     long count)

      Specified by:
        `gotTermination` in interface `SSU2Payload.PayloadCallback`
        `count` - in theory could wrap around to negative, but very unlikely

    - #### gotToken

          public void gotToken(long token,
                               long expires)

      Specified by:
        `gotToken` in interface `SSU2Payload.PayloadCallback`

    - #### introduced

          public void introduced(byte[] ip,
                                 int port,
                                 long token)

      After introduction

    - #### introSent

          public void introSent(Hash h)

      A relay request was sent to the SSU2 introducer specified

    - #### receiveHolePunch

          boolean receiveHolePunch()

      Overridden because we don't have to wait for Relay Response first.
      Overrides:
        `receiveHolePunch` in class `OutboundEstablishState`
      Returns:
        true if we should send the SessionRequest now

    - #### receiveRetry

          public void receiveRetry(UDPPacket packet)
                            throws GeneralSecurityException

      Throws:
        `GeneralSecurityException`

    - #### receiveSessionCreated

          public void receiveSessionCreated(UDPPacket packet)
                                     throws GeneralSecurityException

      Throws:
        `GeneralSecurityException`

    - #### requestSent

          public void requestSent(DatagramPacket pkt)

      note that we just sent the SessionRequest packet and save it for retransmission

    - #### setIntroState

          public void setIntroState(Hash h,
                                    OutboundEstablishState2.IntroState state)

      Set the current state for the SSU2 introducer specified

    - #### tokenRequestSent

          public void tokenRequestSent(DatagramPacket packet)

      Note that we just sent a token request packet. and save them for retransmission

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `OutboundEstablishState`

    - #### validateSessionCreated

          public boolean validateSessionCreated()

      Description copied from class: `OutboundEstablishState`
      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.
      Overrides:
        `validateSessionCreated` in class `OutboundEstablishState`
      Returns:
        true if valid