java.lang.Object
net.i2p.data.i2np.I2NPMessageImpl
net.i2p.data.i2np.FastI2NPMessageImpl
net.i2p.data.i2np.DatabaseStoreMessage
- All Implemented Interfaces:
I2NPMessage
Defines the message a router sends to another router to test the network database reachability, as well as the reply message sent back.
Could this even change the message length or corrupt things?
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
Modifier and TypeFieldDescriptionprivate byte[]Cached serialization of the message.private DatabaseEntryThe entry being stored.private HashThe key being stored.private booleanTrue if this message arrived as someone's reply.private HashGateway the reply should go back to.private longToken identifying the reply to send back.private TunnelIdTunnel the reply should go back through.static final intI2NP message type ID for a database store request.Fields inherited from class FastI2NPMessageImpl
_checksum, _hasChecksumModifier and TypeFieldDescriptionprotected byteOne-byte checksum.protected booleanWhether the message includes a checksum.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
ConstructorsConstructorDescriptionDatabaseStoreMessage(I2PAppContext context) Creates a new DatabaseStoreMessage.Method Summary
Public MethodsModifier and TypeMethodDescriptionprotected intCalculate the message body's length (not including the header and footer).booleanCompares this message to another for equality of all fields.getEntry()Defines the entry in the network database being stored.getKey()Defines the key in the network database being stored.booleanIf true, we received this by searching for it.The gateway to send the reply to, or null if no reply is requested.longIf a reply is desired, this token specifies the message ID that should be used for a DeliveryStatusMessage to be sent to the reply tunnel on the reply gateway.The tunnel to send the reply through, or null if no reply is requested.intgetType()The message type.inthashCode()Hash code calculated from the message fields.voidreadMessage(byte[] data, int offset, int dataSize, int type) Reads the message fields from the byte array.voidsetEntry(DatabaseEntry entry) This also sets the key.voidRecords that this message was received by searching for it.voidsetReplyGateway(Hash peer) Assigns the gateway to send the reply to.voidsetReplyToken(long token) Update the reply token.voidAssigns the tunnel to send the reply through.toString()String form of the message, suitable for debugging.protected intwriteMessageBody(byte[] out, int curIndex) Write the message body to the output array, starting at the given index.Methods inherited from class FastI2NPMessageImpl
readBytes, toByteArray, toByteArrayWithSavedChecksumModifier and TypeMethodDescriptionintreadBytes(byte[] data, int type, int offset, int maxLen) Ignore, but save, the checksum, to be used later if necessary.inttoByteArray(byte[] buffer) If available, use the previously-computed or previously-read checksum for speed.protected inttoByteArrayWithSavedChecksum(byte[] buffer) Use a previously-computed checksum for speed.Methods inherited from class I2NPMessageImpl
createMessage, fromRawByteArray, fromRawByteArrayNTCP2, getMessageExpiration, getMessageSize, getRawMessageSize, getUniqueId, getUniqueId, readBytes, readMessage, setMessageExpiration, setUniqueId, 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.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, 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).
Field Details
MESSAGE_TYPE
public static final int MESSAGE_TYPEI2NP message type ID for a database store request.- See Also:
_key
The key being stored._dbEntry
The entry being stored._byteCache
private byte[] _byteCacheCached serialization of the message._replyToken
private long _replyTokenToken identifying the reply to send back._replyTunnel
Tunnel the reply should go back through._replyGateway
Gateway the reply should go back to._receivedAsReply
private boolean _receivedAsReplyTrue if this message arrived as someone's reply.
Constructor Details
DatabaseStoreMessage
Creates a new DatabaseStoreMessage.- Parameters:
context- the I2P app context
Method Details
getKey
Defines the key in the network database being stored.- Returns:
- the key, or null if not set
getEntry
Defines the entry in the network database being stored.- Returns:
- the database entry
setEntry
This also sets the key.- Parameters:
entry- the entry to store- Throws:
IllegalStateException- if data previously set, to protect saved checksum
getReplyToken
public long getReplyToken()If a reply is desired, this token specifies the message ID that should be used for a DeliveryStatusMessage to be sent to the reply tunnel on the reply gateway.- Returns:
- positive reply token ID, or 0 if no reply is necessary.
setReplyToken
Update the reply token.- Parameters:
token- message ID to correlate a DeliveryStatusMessage with, 0 if no reply is needed- Throws:
IllegalArgumentException- if the token is out of range (min=0, max=I2NPMessage.MAX_ID_VALUE)
getReplyTunnel
The tunnel to send the reply through, or null if no reply is requested.- Returns:
- the reply tunnel, or null
setReplyTunnel
Assigns the tunnel to send the reply through.- Parameters:
id- the reply tunnel
getReplyGateway
The gateway to send the reply to, or null if no reply is requested.- Returns:
- the reply gateway, or null
setReplyGateway
Assigns the gateway to send the reply to.- Parameters:
peer- the reply gateway
getReceivedAsReply
public boolean getReceivedAsReply()If true, we received this by searching for it. Note that searches may query multiple peers in parallel; only the first reply may have this set, and a reply received after the reply job times out will not have this set. Default false.- Returns:
- the received as reply
setReceivedAsReply
public void setReceivedAsReply()Records that this message was received by searching for it.readMessage
public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException Reads the message fields from the 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.
calculateWrittenLength
protected int calculateWrittenLength()Calculate the message body's length (not including the header and footer).- Specified by:
calculateWrittenLengthin classI2NPMessageImpl- Returns:
- the length of the message body
- Throws:
IllegalStateException- if the entry is not set
writeMessageBody
Write the message body 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
getType
hashCode
equals
toString