Package net.i2p.data.i2np
Class FastI2NPMessageImpl
java.lang.Object
net.i2p.data.i2np.I2NPMessageImpl
net.i2p.data.i2np.FastI2NPMessageImpl
- All Implemented Interfaces:
I2NPMessage
- Direct Known Subclasses:
DatabaseLookupMessage
,DatabaseSearchReplyMessage
,DatabaseStoreMessage
,DataMessage
,DeliveryStatusMessage
,GarlicMessage
,TunnelDataMessage
,TunnelGatewayMessage
,UnknownI2NPMessage
public abstract class FastI2NPMessageImpl extends I2NPMessageImpl
Ignore, but save, the SHA-256 checksum in the full 16-byte header when read in.
Use the same checksum when writing out.
This is a savings for NTCP in,
and for NTCP-in to NTCP-out for TunnelDataMessages.
It's also a savings for messages embedded in other messages.
Note that SSU does not use the SHA-256 checksum.
Subclasses must take care to set _hasChecksum to false to invalidate it
if the message payload changes between reading and writing.
It isn't clear where, if anywhere, we actually need to send a checksum.
For point-to-point messages over NTCP where we know the router version
of the peer, we could add a method to skip checksum generation.
For end-to-end I2NP messages embedded in a Garlic, TGM, etc...
we would need a flag day.
- Since:
- 0.8.12
-
Nested Class Summary
Nested classes/interfaces inherited from class net.i2p.data.i2np.I2NPMessageImpl
I2NPMessageImpl.Builder
-
Field Summary
Fields Modifier and Type Field Description protected byte
_checksum
protected boolean
_hasChecksum
Fields inherited from class net.i2p.data.i2np.I2NPMessageImpl
_context, _expiration, _log, CHECKSUM_LENGTH, DEFAULT_EXPIRATION_MS, HEADER_LENGTH
-
Constructor Summary
Constructors Constructor Description FastI2NPMessageImpl(I2PAppContext context)
-
Method Summary
Modifier and Type Method Description int
readBytes(byte[] data, int type, int offset, int maxLen)
Ignore, but save, the checksum, to be used later if necessary.int
toByteArray(byte[] buffer)
If available, use the previously-computed or previously-read checksum for speedprotected int
toByteArrayWithSavedChecksum(byte[] buffer)
Use a previously-computed checksum for speedMethods inherited from class net.i2p.data.i2np.I2NPMessageImpl
calculateWrittenLength, createMessage, fromRawByteArray, fromRawByteArrayNTCP2, getMessageExpiration, getMessageSize, getRawMessageSize, getUniqueId, readBytes, readBytes, readMessage, registerBuilder, setMessageExpiration, setUniqueId, toByteArray, toByteArray, toRawByteArray, toRawByteArrayNTCP2, writeBytes, writeMessageBody
-
Field Details
-
_checksum
protected byte _checksum -
_hasChecksum
protected boolean _hasChecksum
-
-
Constructor Details
-
Method Details
-
readBytes
Ignore, but save, the checksum, to be used later if necessary.- Specified by:
readBytes
in interfaceI2NPMessage
- Overrides:
readBytes
in classI2NPMessageImpl
- Parameters:
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 < 0data
- the data, may or may not include the typetype
- the message type or -1 if we should read it hereoffset
- where to start starting at type if type is < 0 (16 byte header) starting at ID if type is >= 0 (15 byte header)- Returns:
- total length of the message
- Throws:
IllegalStateException
- if called twice, to protect saved checksumI2NPMessageException
- if there is no valid message
-
toByteArray
public int toByteArray(byte[] buffer)If available, use the previously-computed or previously-read checksum for speed- Specified by:
toByteArray
in interfaceI2NPMessage
- Overrides:
toByteArray
in classI2NPMessageImpl
- Returns:
- the length written
-
toByteArrayWithSavedChecksum
protected int toByteArrayWithSavedChecksum(byte[] buffer)Use a previously-computed checksum for speed
-