net.i2p.data.i2np
public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPMessage
Modifier and Type | Class and Description |
---|---|
static interface |
I2NPMessageImpl.Builder
interface for extending the types of messages handled - unused
|
Modifier and Type | Field and Description |
---|---|
protected I2PAppContext |
_context |
static int |
CHECKSUM_LENGTH |
static long |
DEFAULT_EXPIRATION_MS |
MAX_ID_VALUE, MAX_SIZE
Constructor and Description |
---|
I2NPMessageImpl(I2PAppContext context) |
Modifier and Type | Method and Description |
---|---|
protected abstract int |
calculateWrittenLength()
calculate the message body's length (not including the header and footer
|
static I2NPMessage |
createMessage(I2PAppContext context,
int type)
Yes, this is fairly ugly, but its the only place it ever happens.
|
static I2NPMessage |
fromRawByteArray(I2PAppContext ctx,
byte[] buffer,
int offset,
int len,
I2NPMessageHandler handler)
used by SSU only
|
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
|
int |
getRawMessageSize()
How large the raw message is
|
long |
getUniqueId()
Replay resistent message Id
|
int |
readBytes(byte[] data,
int type,
int offset)
Read the header, then read the rest into buffer, then call
readMessage in the implemented message type
|
void |
readBytes(InputStream in)
Deprecated.
Unused, why would you do this
|
int |
readBytes(InputStream in,
int type,
byte[] buffer)
Read the header, then read the rest into buffer, then call
readMessage in the implemented message type
|
void |
readMessage(byte[] data,
int offset,
int dataSize,
int type,
I2NPMessageHandler handler) |
static void |
registerBuilder(I2NPMessageImpl.Builder builder,
int type)
Deprecated.
unused
|
void |
setMessageExpiration(long exp) |
void |
setUniqueId(long id) |
byte[] |
toByteArray() |
int |
toByteArray(byte[] buffer)
write the message to the buffer, returning the number of bytes written.
|
int |
toRawByteArray(byte[] buffer)
used by SSU only
|
void |
writeBytes(OutputStream out)
Write out the data structure to the stream, using the format defined in the
I2P data structure specification.
|
protected abstract int |
writeMessageBody(byte[] out,
int curIndex)
write the message body to the output array, starting at the given index.
|
calculateHash, fromBase64, fromByteArray, read, toBase64
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getType, readMessage
calculateHash, fromBase64, fromByteArray, toBase64
protected I2PAppContext _context
public static final long DEFAULT_EXPIRATION_MS
public static final int CHECKSUM_LENGTH
public I2NPMessageImpl(I2PAppContext context)
public static final void registerBuilder(I2NPMessageImpl.Builder builder, int type)
public void readBytes(InputStream in) throws DataFormatException, IOException
readBytes
in interface DataStructure
in
- stream to read fromDataFormatException
- if the data is improperly formattedIOException
- if there was a problem reading the streampublic int readBytes(InputStream in, int type, byte[] buffer) throws I2NPMessageException, IOException
Specifically: 1 byte type (if caller didn't read already, as specified by the type param 4 byte ID 8 byte expiration 2 byte size 1 byte checksum size bytes of payload (read by readMessage() in implementation)
readBytes
in interface I2NPMessage
type
- the message type or -1 if we should read it herebuffer
- temp buffer to usein
- stream to read fromI2NPMessageException
- if the stream doesn't contain a valid message
that this class can read.IOException
- if there is a problem reading from the streampublic int readBytes(byte[] data, int type, int offset) throws I2NPMessageException, IOException
Specifically: 1 byte type (if caller didn't read already, as specified by the type param 4 byte ID 8 byte expiration 2 byte size 1 byte checksum size bytes of payload (read by readMessage() in implementation)
readBytes
in interface I2NPMessage
type
- the message type or -1 if we should read it hereI2NPMessageException
IOException
public void writeBytes(OutputStream out) throws DataFormatException, IOException
DataStructure
writeBytes
in interface DataStructure
out
- stream to write toDataFormatException
- if the data was incomplete or not yet ready to be writtenIOException
- if there was a problem writing to the streampublic long getUniqueId()
getUniqueId
in interface I2NPMessage
public void setUniqueId(long id)
setUniqueId
in interface I2NPMessage
public long getMessageExpiration()
getMessageExpiration
in interface I2NPMessage
public void setMessageExpiration(long exp)
setMessageExpiration
in interface I2NPMessage
public int getMessageSize()
I2NPMessage
getMessageSize
in interface I2NPMessage
public int getRawMessageSize()
I2NPMessage
getRawMessageSize
in interface I2NPMessage
public byte[] toByteArray()
toByteArray
in interface DataStructure
toByteArray
in class DataStructureImpl
public int toByteArray(byte[] buffer)
I2NPMessage
toByteArray
in interface I2NPMessage
protected abstract int calculateWrittenLength()
protected abstract int writeMessageBody(byte[] out, int curIndex) throws I2NPMessageException
I2NPMessageException
public int toRawByteArray(byte[] buffer)
toRawByteArray
in interface I2NPMessage
public void readMessage(byte[] data, int offset, int dataSize, int type, I2NPMessageHandler handler) throws I2NPMessageException, IOException
readMessage
in interface I2NPMessage
I2NPMessageException
IOException
public static I2NPMessage fromRawByteArray(I2PAppContext ctx, byte[] buffer, int offset, int len, I2NPMessageHandler handler) throws I2NPMessageException
I2NPMessageException
public static I2NPMessage createMessage(I2PAppContext context, int type) throws I2NPMessageException
I2NPMessageException