net.i2p.router.transport.ntcp

## Class OutboundNTCP2State

- java.lang.Object
- - net.i2p.router.transport.ntcp.OutboundNTCP2State

- All Implemented Interfaces:
    EstablishState

      class OutboundNTCP2State
      extends Object
      implements EstablishState

  NTCP 2 only. We are Alice. Also contains static constants and methods used by InboundEstablishState for NTCP2. Does not extend EstablishBase.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `IV_SIZE`
    `static int` | `KEY_SIZE`
    `static int` | `MAC_SIZE`
    `static long` | `MAX_SKEW` in SECONDS
    `static int` | `MSG1_SIZE` 64
    `static int` | `MSG2_SIZE`
    `static int` | `MSG3P1_SIZE` 48
    `static int` | `OPTIONS1_SIZE`
    `static int` | `OPTIONS2_SIZE`
    `static int` | `TOTAL1_MAX` one less than 288 byte NTCP1 msg 1
    `static byte[]` | `ZEROKEY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `OutboundNTCP2State(RouterContext ctx, NTCPTransport transport, NTCPConnection con)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close(String reason, Exception e)` Release resources on timeout.
    `protected void` | `fail(String reason)`
    `protected void` | `fail(String reason, Exception e)`
    `protected void` | `fail(String reason, Exception e, boolean bySkew)`
    `(package private) static byte[][]` | `generateSipHashKeys(RouterContext ctx, HandshakeState state)` KDF for SipHash
    `int` | `getVersion()` Get the NTCP version
    `boolean` | `isComplete()` Don't synchronize this, deadlocks all over.
    `boolean` | `isCorrupt()` did the handshake fail for some reason?
    `boolean` | `isInitialState()` Check if the connection is in initial state and ready for prepareOutbound()
    `boolean` | `isPrepareOutboundCalled()` Check if the connection is in a state where prepareOutbound() has already been called to avoid duplicate calls that cause IllegalStateException
    `void` | `prepareOutbound()` We are Alice.
    `void` | `receive(ByteBuffer src)` Parse the contents of the buffer as part of the handshake.
    `String` | `toString()`

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

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

- - ### Field Detail

    - #### IV_SIZE

          public static final int IV_SIZE

      See Also:
        Constant Field Values

    - #### KEY_SIZE

          public static final int KEY_SIZE

      See Also:
        Constant Field Values

    - #### MAC_SIZE

          public static final int MAC_SIZE

      See Also:
        Constant Field Values

    - #### MAX_SKEW

          public static final long MAX_SKEW

      in SECONDS
      See Also:
        Constant Field Values

    - #### MSG1_SIZE

          public static final int MSG1_SIZE

      64
      See Also:
        Constant Field Values

    - #### MSG2_SIZE

          public static final int MSG2_SIZE

      See Also:
        Constant Field Values

    - #### MSG3P1_SIZE

          public static final int MSG3P1_SIZE

      48
      See Also:
        Constant Field Values

    - #### OPTIONS1_SIZE

          public static final int OPTIONS1_SIZE

      See Also:
        Constant Field Values

    - #### OPTIONS2_SIZE

          public static final int OPTIONS2_SIZE

      See Also:
        Constant Field Values

    - #### TOTAL1_MAX

          public static final int TOTAL1_MAX

      one less than 288 byte NTCP1 msg 1
      See Also:
        Constant Field Values

    - #### ZEROKEY

          public static final byte[] ZEROKEY

  - ### Constructor Detail

    - #### OutboundNTCP2State

          public OutboundNTCP2State(RouterContext ctx,
                                    NTCPTransport transport,
                                    NTCPConnection con)

      Throws:
        `IllegalArgumentException` - on bad address in the con

  - ### Method Detail

    - #### close

          public void close(String reason,
                            Exception e)

      Release resources on timeout.
      Specified by:
        `close` in interface `EstablishState`
      Parameters:
        `e` - may be null

    - #### fail

          protected void fail(String reason)

    - #### fail

          protected void fail(String reason,
                              Exception e)

    - #### fail

          protected void fail(String reason,
                              Exception e,
                              boolean bySkew)

    - #### generateSipHashKeys

          static byte[][] generateSipHashKeys(RouterContext ctx,
                                              HandshakeState state)

      KDF for SipHash
      Returns:
        rv[0] is sip_ab, rv[1] is sip_ba

    - #### getVersion

          public int getVersion()

      Get the NTCP version
      Specified by:
        `getVersion` in interface `EstablishState`
      Returns:
        2

    - #### isComplete

          public boolean isComplete()

      Don't synchronize this, deadlocks all over.
      Specified by:
        `isComplete` in interface `EstablishState`
      Returns:
        is the handshake complete and valid?

    - #### isCorrupt

          public boolean isCorrupt()

      did the handshake fail for some reason?
      Specified by:
        `isCorrupt` in interface `EstablishState`

    - #### isInitialState

          public boolean isInitialState()

      Check if the connection is in initial state and ready for prepareOutbound()

    - #### isPrepareOutboundCalled

          public boolean isPrepareOutboundCalled()

      Check if the connection is in a state where prepareOutbound() has already been called to avoid duplicate calls that cause IllegalStateException

    - #### prepareOutbound

          public void prepareOutbound()

      We are Alice. We are establishing an outbound connection, so prepare ourselves by writing the first message in the handshake. Encrypt X and write X, the options block, and the padding. Save last half of encrypted X as IV for message 2 AES.
      Specified by:
        `prepareOutbound` in interface `EstablishState`
      Throws:
        `IllegalStateException`

    - #### receive

          public void receive(ByteBuffer src)

      Parse the contents of the buffer as part of the handshake. All data must be copied out of the buffer as Reader.processRead() will return it to the pool.
      Specified by:
        `receive` in interface `EstablishState`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`