java.lang.Object
net.i2p.router.crypto.ratchet.RatchetPayload
Ratchet payload generation and parsing.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAcknowledgment block for ratchet payload.static classAcknowledgment request block for ratchet payload.static classBase class for blocks to be transmitted.static classTimestamp block for ratchet payload synchronization and timing.static classGarlic clove block for embedding I2NP messages in ratchet payload.static classNext session key block for ratchet key exchange operations.static classOptions block for ratchet protocol configuration and negotiation.static classPadding block for ratchet payload size alignment and obfuscation.static interfaceFor all callbacks, recommend throwing exceptions only from the handshake.static classPacket number block for ratchet payload.static classTermination block for ratchet session closure with reason codes.Field Summary
Modifier and TypeFieldDescriptionprivate static final intBlock type of the ack.private static final intBlock type of the ack request.private static final intBlock type of the date and time.private static final intBlock type of the garlic clove.static final intBlock header size in bytes.private static final intBlock type of the message number.private static final intBlock type of the next ratchet key.private static final intBlock type of the session options.private static final intBlock type of the padding.private static final intBlock type of the termination reason.Constructor Summary
ConstructorsModifierConstructorDescriptionprivateUtility class with static methods only, not instantiable.Method Summary
Modifier and TypeMethodDescriptionstatic intprocessPayload(I2PAppContext ctx, RatchetPayload.PayloadCallback cb, byte[] payload, int off, int length, boolean isHandshake) Process a ratchet payload, calling the callback for each block found.private static voidtoInt4(byte[] target, int offset, int value) Big endian.static intwritePayload(byte[] payload, int off, List<RatchetPayload.Block> blocks) Write blocks to a payload buffer.
Field Details
BLOCK_HEADER_SIZE
BLOCK_DATETIME
private static final int BLOCK_DATETIMEBlock type of the date and time.- See Also:
BLOCK_TERMINATION
private static final int BLOCK_TERMINATIONBlock type of the termination reason.- See Also:
BLOCK_OPTIONS
private static final int BLOCK_OPTIONSBlock type of the session options.- See Also:
BLOCK_MSGNUM
private static final int BLOCK_MSGNUMBlock type of the message number.- See Also:
BLOCK_NEXTKEY
private static final int BLOCK_NEXTKEYBlock type of the next ratchet key.- See Also:
BLOCK_ACK
BLOCK_ACKREQ
BLOCK_GARLIC
BLOCK_PADDING
Constructor Details
RatchetPayload
private RatchetPayload()Utility class with static methods only, not instantiable.
Method Details
processPayload
public static int processPayload(I2PAppContext ctx, RatchetPayload.PayloadCallback cb, byte[] payload, int off, int length, boolean isHandshake) throws IOException, DataFormatException Process a ratchet payload, calling the callback for each block found.- Parameters:
ctx- the I2P app contextcb- the payload callbackpayload- the frame holding the encoded blocks, read from off for length bytesoff- the offset into the payloadlength- the number of payload bytes to scan, from off to the end of the frameisHandshake- true for handshake messages- Returns:
- the number of blocks processed
- Throws:
IOException- on I/O errorDataFormatException- on data format error
writePayload
Write blocks to a payload buffer.- Parameters:
payload- writes to it starting at offoff- the starting offsetblocks- the blocks to write, in order, each with its own header- Returns:
- the new offset
toInt4
private static void toInt4(byte[] target, int offset, int value) Big endian. Same asDataHelper.toLong(int, long)for 4 bytes, but allows a negative value.- Parameters:
target- the buffer the 4 big endian bytes are written intooffset- the index of the first of the 4 bytes in targetvalue- the value to encode, negative values included- Throws:
ArrayIndexOutOfBoundsException- if offset is negative or the 4 bytes at offset run past the end of target