net.i2p.router.transport.ntcp
Class EstablishState

java.lang.Object
  extended by net.i2p.router.transport.ntcp.EstablishState

 class EstablishState
extends Object

Handle the 4-phase establishment, which is as follows:


 Alice                   contacts                      Bob
 =========================================================

 Message 1 (Session Request):
  X+(H(X) xor Bob.identHash)----------------------------->

 Message 2 (Session Created):
  <----------------------------------------Y+E(H(X+Y)+tsB, sk, Y[239:255])

 Message 3 (Session Confirm A):
  E(sz+Alice.identity+tsA+padding+S(X+Y+Bob.identHash+tsA+tsB), sk, hX_xor_Bob.identHash[16:31])--->

 Message 4 (Session Confirm B):
  <----------------------E(S(X+Y+Alice.identHash+tsA+tsB)+padding, sk, prev)

  Key:

    X, Y: 256 byte DH keys
    H(): 32 byte SHA256 Hash
    E(data, session key, IV): AES256 Encrypt
    S(): 40 byte DSA Signature
    tsA, tsB: timestamps (4 bytes, seconds since epoch)
    sk: 32 byte Session key
    sz: 2 byte size of Alice identity to follow

 
Alternately, when Bob receives a connection, it could be a check connection (perhaps prompted by Bob asking for someone to verify his listener). check connections are formatted per isCheckInfo() NOTE: Check info is unused.


Field Summary
protected  net.i2p.router.transport.ntcp.EstablishState.State _state
           
static net.i2p.router.transport.ntcp.EstablishState.FailedEstablishState FAILED
           
static net.i2p.router.transport.ntcp.EstablishState.VerifiedEstablishState VERIFIED
           
 
Constructor Summary
EstablishState(RouterContext ctx, NTCPTransport transport, NTCPConnection con)
           
 
Method Summary
 void close(String reason, Exception e)
          Release resources on timeout.
 String getError()
           
 Exception getException()
           
 byte[] getExtraBytes()
          if complete, this will contain any bytes received as part of the handshake that were after the actual handshake.
 boolean getFailedBySkew()
          Was this connection failed because of clock skew?
 boolean isComplete()
          If synchronized on this, fails with deadlocks from all over via CSFI.isEstablished().
 boolean isCorrupt()
          did the handshake fail for some reason?
 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

VERIFIED

public static final net.i2p.router.transport.ntcp.EstablishState.VerifiedEstablishState VERIFIED

FAILED

public static final net.i2p.router.transport.ntcp.EstablishState.FailedEstablishState FAILED

_state

protected net.i2p.router.transport.ntcp.EstablishState.State _state
Constructor Detail

EstablishState

public EstablishState(RouterContext ctx,
                      NTCPTransport transport,
                      NTCPConnection con)
Method Detail

receive

public void receive(ByteBuffer src)
parse the contents of the buffer as part of the handshake. if the handshake is completed and there is more data remaining, the data are copieed out so that the next read will be the (still encrypted) remaining data (available from getExtraBytes) All data must be copied out of the buffer as Reader.processRead() will return it to the pool.


getFailedBySkew

public boolean getFailedBySkew()
Was this connection failed because of clock skew?


isCorrupt

public boolean isCorrupt()
did the handshake fail for some reason?


isComplete

public boolean isComplete()
If synchronized on this, fails with deadlocks from all over via CSFI.isEstablished(). Also CSFI.getFramedAveragePeerClockSkew().

Returns:
is the handshake complete and valid?

prepareOutbound

public void prepareOutbound()
We are Alice. We are establishing an outbound connection, so prepare ourselves by queueing up the write of the first part of the handshake This method sends message #1 to Bob.


getExtraBytes

public byte[] getExtraBytes()
if complete, this will contain any bytes received as part of the handshake that were after the actual handshake. This may return null.


close

public void close(String reason,
                  Exception e)
Release resources on timeout.

Parameters:
e - may be null
Since:
0.9.16

getError

public String getError()

getException

public Exception getException()

toString

public String toString()
Overrides:
toString in class Object