net.i2p.data.i2np
Interface I2NPMessage

All Superinterfaces:
DataStructure
All Known Implementing Classes:
DatabaseLookupMessage, DatabaseSearchReplyMessage, DatabaseStoreMessage, DataMessage, DeliveryStatusMessage, FastI2NPMessageImpl, GarlicMessage, I2NPMessageImpl, TunnelBuildMessage, TunnelBuildMessageBase, TunnelBuildReplyMessage, TunnelDataMessage, TunnelGatewayMessage, UnknownI2NPMessage, VariableTunnelBuildMessage, VariableTunnelBuildReplyMessage

public interface I2NPMessage
extends DataStructure

Base interface for all I2NP messages

Author:
jrandom

Field Summary
static long MAX_ID_VALUE
          4 bytes unsigned
static int MAX_SIZE
          Nominal limit, actual max is much less.
 
Method Summary
 long getMessageExpiration()
          Date after which the message should be dropped (and the associated uniqueId forgotten)
 int getMessageSize()
          How large the message is, including any checksums, i.e.
 int getRawMessageSize()
          How large the raw message is with the short 5 byte header
 int getType()
          Return the unique identifier for this type of I2NP message, as defined in the I2NP spec
 long getUniqueId()
          Replay resistant message ID
 int readBytes(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
 int readBytes(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
 int readBytes(InputStream in, int type, byte[] buffer)
          Deprecated. unused
 void readMessage(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
 void readMessage(byte[] data, int offset, int dataSize, int type, I2NPMessageHandler handler)
           
 void setMessageExpiration(long exp)
           
 void setUniqueId(long id)
           
 int toByteArray(byte[] buffer)
          write the message to the buffer, returning the number of bytes written.
 int toRawByteArray(byte[] buffer)
          write the message to the buffer, returning the number of bytes written.
 
Methods inherited from interface net.i2p.data.DataStructure
calculateHash, fromBase64, fromByteArray, readBytes, toBase64, toByteArray, writeBytes
 

Field Detail

MAX_ID_VALUE

static final long MAX_ID_VALUE
4 bytes unsigned

See Also:
Constant Field Values

MAX_SIZE

static final int MAX_SIZE
Nominal 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:
Constant Field Values
Method Detail

readBytes

int readBytes(InputStream in,
              int type,
              byte[] buffer)
              throws I2NPMessageException,
                     IOException
Deprecated. unused

Read the body into the data structures, after the initial type byte, using the current class's format as defined by the I2NP specification Unused - All transports provide encapsulation and so we have byte arrays available.

Parameters:
in - stream to read from starting at type if type is < 0 (16 byte header) starting at ID if type is >= 0 (15 byte header)
type - I2NP message type. If less than zero, read the type from data
buffer - scratch buffer to be used when reading and parsing
Returns:
size of the message read (including headers)
Throws:
I2NPMessageException - if the stream doesn't contain a valid message that this class can read.
IOException - if there is a problem reading from the stream

readBytes

int readBytes(byte[] data,
              int type,
              int offset)
              throws I2NPMessageException
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
type - I2NP message type. If less than zero, read the type from data
offset - 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
IOException - if there is a problem reading from the stream

readBytes

int readBytes(byte[] data,
              int type,
              int offset,
              int maxLen)
              throws I2NPMessageException
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 type
type - I2NP message type. If less than zero, read the type from data
offset - 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
IOException - if there is a problem reading from the stream
Since:
0.8.12

readMessage

void readMessage(byte[] data,
                 int offset,
                 int dataSize,
                 int type)
                 throws I2NPMessageException
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

Parameters:
data - data to read from
offset - where to start in the data array
dataSize - how long into the data to read
type - I2NP message type
Throws:
I2NPMessageException - if the stream doesn't contain a valid message that this class can read.
IOException - if there is a problem reading from the stream

readMessage

void readMessage(byte[] data,
                 int offset,
                 int dataSize,
                 int type,
                 I2NPMessageHandler handler)
                 throws I2NPMessageException
Throws:
I2NPMessageException

getType

int getType()
Return the unique identifier for this type of I2NP message, as defined in the I2NP spec


getUniqueId

long getUniqueId()
Replay resistant message ID


setUniqueId

void setUniqueId(long id)

getMessageExpiration

long getMessageExpiration()
Date after which the message should be dropped (and the associated uniqueId forgotten)


setMessageExpiration

void setMessageExpiration(long exp)

getMessageSize

int getMessageSize()
How large the message is, including any checksums, i.e. full 16 byte header


getRawMessageSize

int getRawMessageSize()
How large the raw message is with the short 5 byte header


toByteArray

int toByteArray(byte[] buffer)
write the message to the buffer, returning the number of bytes written. 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.


toRawByteArray

int toRawByteArray(byte[] buffer)
write the message to the buffer, returning the number of bytes written. 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.