java.lang.Object
net.i2p.router.crypto.ratchet.RatchetSKM.OutboundSession
- Enclosing class:
RatchetSKM
The state for a crypto session to a single public key.
Constructor Summary
ConstructorsConstructorDescriptionOutboundSession(PublicKey target, Destination d, SessionKey key, HandshakeState state, ReplyCallback callback) Outbound session for the given target.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidackRequested(int id, int n) Queue the ACK for one ratchet tag to be sent back.intNumber of tags remaining in acked tag sets.Consume the next available tag and advance.intexpireCallbacks(long now) Drop reply callbacks whose expiration has passed.intexpireTags(long now) Expire old tags, returning the number of tag sets removed.(package private) voidFirst tag was received for this inbound (ES) tagset.The session key stored at construction; never updated afterwards.Destination for the current session's far end.longWhen this session was established.Original outbound state, null for inbound.longFurthest away tag set expiration date, after which all of the tags will have expired.longONLY updated for inbound NS/NSR/ES tag used.longNOT updated for inbound except for NSR and first ES tag used.(package private) List<RatchetTagSet> This is used only by renderStatusHTML().The far-end public key this session talks to.voidProcess a Next Session Key message, validating the ID sequence before advancing the ratchet to the new tag set key.voidreceivedACK(int id, int n) Run and remove the callback registered for the ACKed tag, if any.voidregisterCallback(int id, int n, ReplyCallback callback) Register the callback to run when the ACK for one ratchet tag arrives; a live callback for the same tag is not replaced.booleanregisterTimer(Destination d, SimpleTimer2.TimedEvent timer) A timer that we will cancel when we send something.(package private) voidtagConsumed(RatchetTagSet set) A tag was received for this inbound (ES) tagset.(package private) voidupdateSession(HandshakeState state, ReplyCallback callback, SplitKeys split) Inbound or outbound.
Constructor Details
OutboundSession
public OutboundSession(PublicKey target, Destination d, SessionKey key, HandshakeState state, ReplyCallback callback) Outbound session for the given target.- Parameters:
target- the far-end public key this session talks tod- may be nullkey- may be nullstate- the completed handshake state, source of the chaining key and the role that decides the tagset directioncallback- may be null. Always null for IB.
Method Details
updateSession
Inbound or outbound. Checks state.getRole() to determine. For outbound (NSR rcvd by Alice), sets session to transition to ES mode outbound. For inbound (NSR sent by Bob), sets up inbound ES tagset.- Parameters:
state- the handshake state to advance, whose role decides the directioncallback- only for inbound (NSR sent by Bob), may be nullsplit- the NSR split keys - new root chaining key ck plus the per-direction session keys k_ab and k_ba
nextKeyReceived
Process a Next Session Key message, validating the ID sequence before advancing the ratchet to the new tag set key.- Parameters:
key- the received next-session-key message
tagConsumed
A tag was received for this inbound (ES) tagset.- Parameters:
set- the inbound tagset
firstTagConsumed
First tag was received for this inbound (ES) tagset. Find the corresponding outbound (ES) tagset in _unackedTagSets, move it to _tagSets, and remove all others from _unackedTagSets.Note: We do NOT remove remaining inbound tags from _inboundTagSets here. The addTags() sliding window in consume() already handles tag lifecycle — generating new tags ahead and trimming old ones via
RatchetSKM.expireTag(RatchetSessionTag, RatchetTagSet). Purging all tags on first consumption broke subsequent ES decryptions because Alice's retransmitted SYNs (using pre-generated tags 1-N) could no longer be found in _inboundTagSets.- Parameters:
set- the inbound tagset
getTagSets
List<RatchetTagSet> getTagSets()This is used only by renderStatusHTML(). It includes both acked and unacked RatchetTagSets.- Returns:
- list of RatchetTagSet objects
getTarget
The far-end public key this session talks to.- Returns:
- the target key, set at construction
getHandshakeState
Original outbound state, null for inbound.- Returns:
- the handshake state
getCurrentKey
The session key stored at construction; never updated afterwards.- Returns:
- the key, or null if the session was created without one
getEstablishedDate
public long getEstablishedDate()When this session was established.- Returns:
- creation time in ms
getLastUsedDate
public long getLastUsedDate()NOT updated for inbound except for NSR and first ES tag used.- Returns:
- the last used date
getLastReceivedDate
public long getLastReceivedDate()ONLY updated for inbound NS/NSR/ES tag used.- Returns:
- the last received date
expireTags
public int expireTags(long now) Expire old tags, returning the number of tag sets removed.- Parameters:
now- current time in ms, tag sets expiring at or before it are removed- Returns:
- the number of tag sets removed
consumeNext
Consume the next available tag and advance.- Returns:
- the next tag with its key, rotation keys and pending acks, or null if the session or tag set has expired or drained
registerTimer
A timer that we will cancel when we send something. Side effect - binds this session to the supplied destination.- Parameters:
d- the far-end Destination for this PublicKey if known, or nulltimer- the ack timer to hold, cancelled when this session sends; ignored if a timer is already registered- Returns:
- true if registered
getDestination
Destination for the current session's far end.- Returns:
- the far-end Destination for this PublicKey, or null
availableTags
public int availableTags()Number of tags remaining in acked tag sets.- Returns:
- the total number of tags in acked RatchetTagSets
getLastExpirationDate
public long getLastExpirationDate()Furthest away tag set expiration date, after which all of the tags will have expired.- Returns:
- the last expiration date
registerCallback
Register the callback to run when the ACK for one ratchet tag arrives; a live callback for the same tag is not replaced.- Parameters:
id- tag set ID the ACK is forn- tag index within the tag setcallback- callback to run on ACK
receivedACK
public void receivedACK(int id, int n) Run and remove the callback registered for the ACKed tag, if any.- Parameters:
id- tag set ID the ACK is forn- tag index within the tag set
ackRequested
public void ackRequested(int id, int n) Queue the ACK for one ratchet tag to be sent back.- Parameters:
id- tag set ID being ACKedn- tag index within the tag set
expireCallbacks
public int expireCallbacks(long now) Drop reply callbacks whose expiration has passed.- Parameters:
now- current time in ms- Returns:
- the number of callbacks removed