- All Known Implementing Classes:
DatabaseLookupMessage, DatabaseSearchReplyMessage, DatabaseStoreMessage, DataMessage, DeliveryStatusMessage, FastI2NPMessageImpl, GarlicMessage, I2NPMessageImpl, OutboundTunnelBuildReplyMessage, ShortTunnelBuildMessage, ShortTunnelBuildReplyMessage, TunnelBuildMessage, TunnelBuildMessageBase, TunnelBuildReplyMessage, TunnelDataMessage, TunnelGatewayMessage, UnknownI2NPMessage, VariableTunnelBuildMessage, VariableTunnelBuildReplyMessage
public interface I2NPMessage
Base interface for all I2NP messages
Note: No longer extends DataStructure as of 0.9.48.
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long4 bytes unsigned.static final intNominal limit, actual max is much less.Method Summary
All MethodsModifier and TypeMethodDescriptionlongDate after which the message should be dropped (and the associated uniqueId forgotten).intHow large the message is, including any checksums, i.e.intHow large the raw message is with the short 5 byte header.intgetType()Return the unique identifier for this type of I2NP message, as defined in the I2NP spec.longUnique message id, optionally XORed with the given value.longgetUniqueId(long msgIDBloomXor) Replay resistant message ID optionally, the caller may pass a msgIDBloomXor value, and the return value will be Xor'ed with that value.intreadBytes(byte[] data, int type, int offset) Read the body into the data structures, after the initial type byte, using the current class's format as defined by the I2NP specification.intreadBytes(byte[] data, int type, int offset, int maxLen) Read the body into the data structures, after the initial type byte, using the current class's format as defined by the I2NP specification.voidreadMessage(byte[] data, int offset, int dataSize, int type) Read the body into the data structures, after the initial type byte and the uniqueId / expiration, using the current class's format as defined by the I2NP specification.voidreadMessage(byte[] data, int offset, int dataSize, int type, I2NPMessageHandler handler) Read the message fields from the byte array, dispatching them to the given handler.voidsetMessageExpiration(long exp) Expiration for this message, assigned when written.voidsetUniqueId(long id) Unique id for this message, assigned when written.byte[]Serialize the message, header included, into a new array.inttoByteArray(byte[] buffer) Write the message to the buffer, returning the new offset (NOT the length).inttoByteArray(byte[] buffer, int off) Write the message to the buffer, returning the new offset (NOT the length).inttoRawByteArray(byte[] buffer) Write the message to the buffer, returning the new offset (NOT the length).inttoRawByteArrayNTCP2(byte[] buffer, int off) Write the message to the buffer, returning the new offset (NOT the length).
Field Details
MAX_ID_VALUE
MAX_SIZE
static final int MAX_SIZENominal limit, actual max is much less. See website docs for further restrictions due to various overhead and limitations in encryption, fragmentation, and the transports.- See Also:
Method Details
readBytes
Read the body into the data structures, after the initial type byte, using the current class's format as defined by the I2NP specification.- Parameters:
data- the full serialized message, header includedtype- I2NP message type. If less than zero, read the type from dataoffset- where to start starting at type if type is < 0 (16 byte header) starting at ID if type is >= 0 (15 byte header)- Returns:
- size of the message read (including headers)
- Throws:
I2NPMessageException- if there is no valid message
readBytes
Read the body into the data structures, after the initial type byte, using the current class's format as defined by the I2NP specification.- Parameters:
data- the data, may or may not include the typetype- I2NP message type. If less than zero, read the type from dataoffset- where to start starting at type if type is < 0 (16 byte header) starting at ID if type is >= 0 (15 byte header)maxLen- read no more than this many bytes from data starting at offset, even if it is longer This includes the type byte only if type < 0- Returns:
- size of the message read (including headers)
- Throws:
I2NPMessageException- if there is no valid message
readMessage
Read the body into the data structures, after the initial type byte and the uniqueId / expiration, using the current class's format as defined by the I2NP specification.Implementations must not read more than dataSize, or throw I2NPMessageException or IndexOutOfBoundsException if they do.
- Parameters:
data- data to read fromoffset- where to start in the data arraydataSize- how long into the data to readtype- I2NP message type- Throws:
I2NPMessageException- if the stream doesn't contain a valid message that this class can read.
readMessage
void readMessage(byte[] data, int offset, int dataSize, int type, I2NPMessageHandler handler) throws I2NPMessageException Read the message fields from the byte array, dispatching them to the given handler. The base implementation ignores the handler and behaves asreadMessage(byte[], int, int, int); subclasses that deliver the message asynchronously override this.- Parameters:
data- the buffer holding the message, header includedoffset- where to start in the data arraydataSize- how long into the data to readtype- I2NP message typehandler- the target for the message the buffer contains- Throws:
I2NPMessageException- if the stream doesn't contain a valid message that this class can read.
getType
int getType()Return the unique identifier for this type of I2NP message, as defined in the I2NP spec.- Returns:
- the message type number, as defined in the I2NP spec
getUniqueId
long getUniqueId(long msgIDBloomXor) Replay resistant message ID optionally, the caller may pass a msgIDBloomXor value, and the return value will be Xor'ed with that value. Passing a msgIDBloomXor value of 0 will result in the original ID being returned, instead of passing 0 use the no-arg version.- Parameters:
msgIDBloomXor- value to XOR the id with, or 0 for the id unchanged- Returns:
- the unique id
getUniqueId
long getUniqueId()Unique message id, optionally XORed with the given value.- Returns:
- the unique id
setUniqueId
void setUniqueId(long id) Unique id for this message, assigned when written.- Parameters:
id- the unique id to attach to this message
getMessageExpiration
long getMessageExpiration()Date after which the message should be dropped (and the associated uniqueId forgotten).- Returns:
- the message expiration
setMessageExpiration
void setMessageExpiration(long exp) Expiration for this message, assigned when written.- Parameters:
exp- the expiration as milliseconds since the epoch, which is also when the peer should stop forwarding the message
getMessageSize
int getMessageSize()How large the message is, including any checksums, i.e. full 16 byte header.- Returns:
- the size in bytes of the message with the full NTCP 1 header
getRawMessageSize
int getRawMessageSize()How large the raw message is with the short 5 byte header.- Returns:
- the size in bytes of the message with the short SSU header
toByteArray
byte[] toByteArray()Serialize the message, header included, into a new array.- Returns:
- a new array holding the whole message, full 16 byte header included
toByteArray
int toByteArray(byte[] buffer) Write the message to the buffer, returning the new offset (NOT the length). the data is formatted so as to be self contained, with the type, size, expiration, unique id, as well as a checksum bundled along. Full 16 byte header for NTCP 1.- Parameters:
buffer- the destination array, which must have room forgetMessageSize()bytes- Returns:
- the new offset (NOT the length)
toByteArray
int toByteArray(byte[] buffer, int off) Write the message to the buffer, returning the new offset (NOT the length). the data is formatted so as to be self contained, with the type, size, expiration, unique id, as well as a checksum bundled along. Full 16 byte header for NTCP 1.- Parameters:
buffer- the destination array, which must have room forgetMessageSize()bytes fromoffonoff- the offset to start writing at- Returns:
- the new offset (NOT the length)
toRawByteArray
int toRawByteArray(byte[] buffer) Write the message to the buffer, returning the new offset (NOT the length). the data is is not self contained - it does not include the size, unique id, or any checksum, but does include the type and expiration. Short 5 byte header for SSU.- Parameters:
buffer- the destination array, written from index 0, which must have room forgetRawMessageSize()bytes- Returns:
- the length written
toRawByteArrayNTCP2
int toRawByteArrayNTCP2(byte[] buffer, int off) Write the message to the buffer, returning the new offset (NOT the length). the data is is not self contained - it does not include the size, unique id, or any checksum, but does include the type and expiration. Short 9 byte header for NTCP 2.- Parameters:
buffer- the destination array, which must have room forgetRawMessageSize()bytes fromoffonoff- the offset to start writing at- Returns:
- the new offset (NOT the length)