java.lang.Object
net.i2p.data.i2np.I2NPMessageImpl
net.i2p.data.i2np.TunnelBuildMessageBase
- All Implemented Interfaces:
I2NPMessage
- Direct Known Subclasses:
TunnelBuildMessage, TunnelBuildReplyMessage
Base for TBM, TBRM, VTBM, VTBRM Retrofitted over them. There's really no difference between the build and build reply.
TBM and VBTM (but not TBRM and VTBRM?) messages are modified in-place by doing a single setRecord(), and retransmitted. Therefore they are NOT good candidates to use FastI2NPMessageImpl; the checksum would have to be invalidated with every setRecord(). Which we could do in TBM and VTBM but not TBRM and VTBRM, but keep it simple for now.
Nested Class Summary
Nested classes/interfaces inherited from class I2NPMessageImpl
I2NPMessageImpl.BuilderModifier and TypeClassDescriptionstatic interfaceInterface for extending the types of messages handled - unused.Field Summary
FieldsModifier and TypeFieldDescriptionprotected EncryptedBuildRecord[]The encrypted records, one per hop, or null until readMessage().static final intMaximum number of records in any tunnel build message (8 hops).protected intNumber of records in _records, zero if not yet set.static final intSize in bytes of one encrypted record: 16 byte IV + 512 byte payload.Fields inherited from class I2NPMessageImpl
_context, _expiration, _log, CHECKSUM_LENGTH, DEFAULT_EXPIRATION_MS, HEADER_LENGTHModifier and TypeFieldDescriptionprotected final I2PAppContextApplication context this message belongs to.protected longExpiration time in milliseconds since the epoch, as an I2P Date.protected final LogLog for the message class, taken from the context's log manager.static final intNumber of checksum bytes the message header carries.static final longDefault lifetime of an unsent message, one minute in milliseconds.static final intI2NP message header size in bytes.Fields inherited from interface I2NPMessage
MAX_ID_VALUE, MAX_SIZEModifier and TypeFieldDescriptionstatic final long4 bytes unsigned.static final intNominal limit, actual max is much less.Constructor Summary
ConstructorsModifierConstructorDescriptionTunnelBuildMessageBase(I2PAppContext context) Create with the default number of records.protectedTunnelBuildMessageBase(I2PAppContext context, int records) Leaves the count to be set by readMessage().Method Summary
All MethodsModifier and TypeMethodDescriptionprotected intWritten length of the message body: one record size per record.getRecord(int index) Build record at the given index, may be null.intHow many encrypted build records this message carries, which sets both the length of every hop record array and the tunnel's depth.voidreadMessage(byte[] data, int offset, int dataSize, int type) Read the records from a byte array.voidsetRecord(int index, EncryptedBuildRecord record) Store a build record.protected intwriteMessageBody(byte[] out, int curIndex) Write the records to the output array, starting at the given index.Methods inherited from class I2NPMessageImpl
createMessage, fromRawByteArray, fromRawByteArrayNTCP2, getMessageExpiration, getMessageSize, getRawMessageSize, getUniqueId, getUniqueId, readBytes, readBytes, readMessage, setMessageExpiration, setUniqueId, toByteArray, toByteArray, toByteArray, toRawByteArray, toRawByteArrayNTCP2Modifier and TypeMethodDescriptionstatic I2NPMessagecreateMessage(I2PAppContext context, int type) Yes, this is fairly ugly, but its the only place it ever happens.static I2NPMessagefromRawByteArray(I2PAppContext ctx, byte[] buffer, int offset, int len, I2NPMessageHandler handler) Read the message with a short 5-byte header.static I2NPMessagefromRawByteArrayNTCP2(I2PAppContext ctx, byte[] buffer, int offset, int len, I2NPMessageHandler handler) Read the message with a short 9-byte header.longDate after which the message should be dropped (and the associated uniqueId forgotten).intSerialized message size, including the 16-byte header.intThe raw header consists of a one-byte type and a 4-byte expiration in seconds only.longUnique id for this message, lazily initialized when negative.longgetUniqueId(long msgIDBloomXor) Replay resistant message Id.intreadBytes(byte[] data, int type, int offset) Read the header, then read the rest into buffer, then call readMessage in the implemented message type.intreadBytes(byte[] data, int type, int offset, int maxLen) Limit the max to read from the data buffer, so that we can use a large buffer but prevent the reader from reading off the end.voidreadMessage(byte[] data, int offset, int dataSize, int type, I2NPMessageHandler handler) Read the message fields from the byte array, ignoring the handler.voidsetMessageExpiration(long exp) The expiration is set to one minute from now in the constructor but it can be overridden here.voidsetUniqueId(long id) The ID is set to a random value when written but it can be overridden here.byte[]The message serialized into a new byte array.inttoByteArray(byte[] buffer) Write the message to the buffer, returning the number of bytes written.inttoByteArray(byte[] buffer, int off) Write the message to the buffer, returning the new offset (NOT the length).inttoRawByteArray(byte[] buffer) Write the message with a short 5-byte header.inttoRawByteArrayNTCP2(byte[] buffer, int off) Write the message to the buffer, returning the new offset (NOT the length).Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface I2NPMessage
getTypeModifier and TypeMethodDescriptionintgetType()Return the unique identifier for this type of I2NP message, as defined in the I2NP spec.
Field Details
_records
The encrypted records, one per hop, or null until readMessage().RECORD_COUNT
protected int RECORD_COUNTNumber of records in _records, zero if not yet set.MAX_RECORD_COUNT
public static final int MAX_RECORD_COUNTMaximum number of records in any tunnel build message (8 hops).- See Also:
RECORD_SIZE
public static final int RECORD_SIZESize in bytes of one encrypted record: 16 byte IV + 512 byte payload.- See Also:
Constructor Details
TunnelBuildMessageBase
Create with the default number of records.- Parameters:
context- the application context the message is read and written under
TunnelBuildMessageBase
Leaves the count to be set by readMessage().- Parameters:
context- the application context the message is read and written underrecords- the number of records to preallocate, up to MAX_RECORD_COUNT; zero
Method Details
setRecord
Store a build record.- Parameters:
index- the zero-based position of the record in the record arrayrecord- may be null
getRecord
Build record at the given index, may be null.- Parameters:
index- the zero-based position of the record in the record array- Returns:
- may be null
getRecordCount
public int getRecordCount()How many encrypted build records this message carries, which sets both the length of every hop record array and the tunnel's depth.- Returns:
- the number of records, from 0 to MAX_RECORD_COUNT
calculateWrittenLength
protected int calculateWrittenLength()Written length of the message body: one record size per record.- Specified by:
calculateWrittenLengthin classI2NPMessageImpl- Returns:
- the number of bytes the body will occupy once serialized
readMessage
public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException Read the records from a byte array.- 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.
writeMessageBody
Write the records to the output array, starting at the given index.- Specified by:
writeMessageBodyin classI2NPMessageImpl- Parameters:
out- the buffer to serialize the body intocurIndex- the offset into out at which to begin writing; leave room for the signature where the header format calls for one- Returns:
- the index into the array after the last byte written (NOT the length)
- Throws:
I2NPMessageException- if the body cannot be serialized into out, because it is too small or a field is unserializable