class InboundEstablishState extends EstablishBase implements NTCP2Payload.PayloadCallback
This class manages the complete inbound NTCP 2 connection lifecycle:
State transitions:
IB_INIT -> IB_NTCP2_INIT -> IB_NTCP2_GOT_X -> IB_NTCP2_GOT_PADDING
-> IB_NTCP2_SENT_Y -> IB_NTCP2_GOT_RI -> VERIFIED
Threading: All methods are synchronized. Caller must hold locks when invoking methods that modify state.
EstablishBase.State_con, _context, _log, _peerSkew, _prevEncrypted, _received, _state, _stateLock, _transport, _X, _Y, AES_SIZE, FAILED, MAX_RI_SIZE, MIN_RI_SIZE, STATES_DONE, VERIFIED, XY_SIZE| Constructor and Description |
|---|
InboundEstablishState(RouterContext ctx,
NTCPTransport transport,
NTCPConnection con) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
fail(String reason,
Exception e,
boolean bySkew)
Handles handshake failure by transitioning to CORRUPT state and cleaning up.
|
int |
getVersion()
Returns the NTCP protocol version this state machine handles.
|
void |
gotDateTime(long time)
Illegal during handshake - date/time is only in the options, not a separate payload.
|
void |
gotI2NP(I2NPMessage msg)
Illegal during handshake - I2NP messages are only in the data phase.
|
void |
gotOptions(byte[] options,
boolean isHandshake)
Receives and validates Alice's option preferences from message 3.
|
void |
gotPadding(int paddingLength,
int frameLength)
Receives padding information from message 3.
|
void |
gotRI(RouterInfo ri,
boolean isHandshake,
boolean flood)
Validates Alice's RouterInfo and extracts the static key for comparison.
|
void |
gotTermination(int reason,
long lastReceived)
Illegal during handshake - termination is only valid after connection is established.
|
void |
gotUnknown(int type,
int len)
Illegal during handshake - unknown payload types should not appear.
|
static String |
parseReason(int reasonCode)
Converts a termination reason code to a human-readable string.
|
void |
receive(ByteBuffer src)
Entry point for receiving data on an inbound NTCP connection.
|
protected void |
releaseBufs(boolean isVerified)
Releases buffers and resources held by this state machine.
|
_x, changeState, close, fail, fail, isComplete, isCorrupt, prefix, prepareOutbound, toStringpublic InboundEstablishState(RouterContext ctx, NTCPTransport transport, NTCPConnection con)
protected void fail(String reason, Exception e, boolean bySkew)
Overrides the base implementation to additionally destroy the Noise handshake state for security.
fail in class EstablishBasereason - the failure reason stringe - the exception that caused the failure, or nullbySkew - true if failure was due to clock skew (suppresses stat collection)public int getVersion()
getVersion in interface EstablishStategetVersion in class EstablishBasepublic void gotDateTime(long time)
gotDateTime in interface NTCP2Payload.PayloadCallbacktime - the timestamppublic void gotI2NP(I2NPMessage msg)
gotI2NP in interface NTCP2Payload.PayloadCallbackmsg - the I2NP messagepublic void gotOptions(byte[] options,
boolean isHandshake)
Parses the options byte array into an NTCP2Options object containing negotiated parameters like congestion control and flags.
gotOptions in interface NTCP2Payload.PayloadCallbackoptions - the options byte array from AliceisHandshake - always true; indicates this is during handshake processingpublic void gotPadding(int paddingLength,
int frameLength)
NTCP 2 padding is handled differently - the actual padding data is not separately tracked in this implementation.
gotPadding in interface NTCP2Payload.PayloadCallbackpaddingLength - the length of padding in the frameframeLength - the total length of the frame including paddingpublic void gotRI(RouterInfo ri, boolean isHandshake, boolean flood) throws DataFormatException
This is a PayloadCallback method invoked during message 3 processing.
Validations performed:
Side effects:
gotRI in interface NTCP2Payload.PayloadCallbackri - Alice's RouterInfo from message 3isHandshake - always true; indicates this is during handshake processingflood - true if the RouterInfo should be flooded to the networkDataFormatException - if validation fails (bad sig, no static key,
key mismatch, IP mismatch, banned, etc.)public void gotTermination(int reason,
long lastReceived)
gotTermination in interface NTCP2Payload.PayloadCallbackreason - the termination reason codelastReceived - the number of bytes received when termination occurredpublic void gotUnknown(int type,
int len)
gotUnknown in interface NTCP2Payload.PayloadCallbacktype - the unknown payload typelen - the payload lengthpublic static String parseReason(int reasonCode)
Reason codes are defined in NTCPConnection and used in termination messages to indicate why a connection failed.
reasonCode - the numeric reason code from NTCPConnectionpublic void receive(ByteBuffer src)
Delegates to receiveInbound() for actual processing. All data is copied out of the buffer as Reader.processRead() will return it to the pool.
If there are additional data in the buffer after the handshake is complete, this EstablishState is responsible for passing it to NTCPConnection.
receive in interface EstablishStatereceive in class EstablishBasesrc - the ByteBuffer containing received data; caller must not modify positionprotected void releaseBufs(boolean isVerified)
Must be called exactly once when the handshake completes (success or failure). Caller must hold synchronization.
Actions:
releaseBufs in class EstablishBaseisVerified - true if handshake succeeded; false if it failed