java.lang.Object
net.i2p.data.i2np.I2NPMessageImpl
net.i2p.data.i2np.FastI2NPMessageImpl
net.i2p.data.i2np.DatabaseLookupMessage
- All Implemented Interfaces:
I2NPMessage
Defines the message a router sends to another router to search for a key in the network database.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDatabase lookup type enumeration.Nested classes/interfaces inherited from class I2NPMessageImpl
I2NPMessageImpl.BuilderModifier and TypeClassDescriptionstatic interfaceInterface for extending the types of messages handled - unused.Field Summary
Modifier and TypeFieldDescriptionThis must be kept as a list to preserve the order and not break the checksum.private HashThe hash of the requester.private HashThe hash being looked up.private static final LogLogger for the lookup messages.private PublicKeyRatchet key to encrypt the reply to.private RatchetSessionTagRatchet tag identifying the reply.private SessionKeyKey to encrypt the reply with.private SessionTagTag identifying the reply.private TunnelIdTunnel id to reply through.private DatabaseLookupMessage.TypeThe record type the requester wants.private static final byteFlag that the reply is encrypted, unknown to old routers.private static final byteFlag that the reply uses a ratchet key, 0.9.46 or newer.private static final byteFlag that the reply goes through a tunnel.private static final byteType bits asking for any record.private static final byteType bits asking for an exploratory search.private static final byteType bits asking for a lease set.private static final byteMask of the record type bits.private static final byteType bits asking for a router info.private static final intInsanely big.static final intThe I2NP message type number identifying a database lookup.private static final StringIt's not supported until 0.9.7, but as of 0.9.6 we can specify the bit in the flags without the receiver rejecting the whole message as invalid.private static final StringOldest version understanding ratchet replies.static final booleanWhether a reply session may use ECIES X25519 keys, not just ElGamal.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, 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.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
ConstructorsConstructorDescriptionDatabaseLookupMessage(I2PAppContext context) Creates a database lookup message for the given context.DatabaseLookupMessage(I2PAppContext context, boolean locallyCreated) Lookup message for the given context.Method Summary
Modifier and TypeMethodDescriptionvoidaddDontIncludePeer(Hash peer) Add to the set.voidaddDontIncludePeers(Collection<Hash> peers) Add to the set.protected intCalculates the length of the message body.booleanCompares this message to another for equality of all fields.Collection of peers that a lookup reply should NOT include.getFrom()Contains the router who requested this lookup.The included session key or null if unset.The included session tag or null if unset.The included session key or null if unset.The included session tag or null if unset.Contains the tunnel ID a reply should be sent to.Defines the key being searched for.Defines the type of data being searched for.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.voidsetDontIncludePeers(Collection<Hash> peers) Replace the dontInclude set with this set.voidAssigns the router who requested this lookup.voidsetReplySession(PublicKey pubKey) Sets the reply session's ratchet public key.voidsetReplySession(SessionKey encryptKey, SessionTag encryptTag) Only worthwhile if sending reply via tunnel.voidsetReplySession(SessionKey encryptKey, RatchetSessionTag encryptTag) Sets the reply session for ratchet encryption; only once per message.voidsetReplyTunnel(TunnelId replyTunnel) Assigns the tunnel a reply should be sent to.voidsetSearchKey(Hash key) Assigns the key being searched for.voidDefines the type of data being searched for.(package private) static StringshortKey(DatabaseLookupMessage.Type type, Hash key) The search key as the house truncation - 8 base32 characters for a lease set, 6 base64 for anything else - bracketed so the console links it.static booleanDoes this router support encrypted replies?static booleanDoes this router support ratchet replies?Key material for lookup interop debugging only.toString()String form of the message, suitable for debugging.protected intwriteMessageBody(byte[] out, int curIndex) Writes the message body to the output array, returning the new 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
_log
Logger for the lookup messages.MESSAGE_TYPE
public static final int MESSAGE_TYPEThe I2NP message type number identifying a database lookup.- See Also:
_key
The hash being looked up._fromHash
The hash of the requester._replyTunnel
Tunnel id to reply through._dontIncludePeers
_replyKey
Key to encrypt the reply with._replyTag
Tag identifying the reply._ratchetReplyTag
Ratchet tag identifying the reply._ratchetPubKey
Ratchet key to encrypt the reply to._type
The record type the requester wants.USE_ECIES_FF
public static final boolean USE_ECIES_FFWhether a reply session may use ECIES X25519 keys, not just ElGamal.- See Also:
MAX_NUM_PEERS
private static final int MAX_NUM_PEERSInsanely big. Not much more than 1500 will fit in a message. Have to prevent a huge alloc on rcv of a malicious msg though.- See Also:
FLAG_TUNNEL
private static final byte FLAG_TUNNELFlag that the reply goes through a tunnel.- See Also:
FLAG_ENCRYPT
private static final byte FLAG_ENCRYPTFlag that the reply is encrypted, unknown to old routers.- See Also:
FLAG_TYPE_MASK
FLAG_TYPE_ANY
private static final byte FLAG_TYPE_ANYType bits asking for any record.- See Also:
FLAG_TYPE_LS
private static final byte FLAG_TYPE_LSType bits asking for a lease set.- See Also:
FLAG_TYPE_RI
private static final byte FLAG_TYPE_RIType bits asking for a router info.- See Also:
FLAG_TYPE_EXPL
private static final byte FLAG_TYPE_EXPLType bits asking for an exploratory search.- See Also:
FLAG_RATCHET
private static final byte FLAG_RATCHETFlag that the reply uses a ratchet key, 0.9.46 or newer.- See Also:
MIN_ENCRYPTION_VERSION
It's not supported until 0.9.7, but as of 0.9.6 we can specify the bit in the flags without the receiver rejecting the whole message as invalid.- See Also:
MIN_RATCHET_VERSION
Oldest version understanding ratchet replies.- See Also:
Constructor Details
DatabaseLookupMessage
Creates a database lookup message for the given context.- Parameters:
context- the application context the message is created for
DatabaseLookupMessage
Lookup message for the given context.- Parameters:
context- the application context the message is created forlocallyCreated- ignored; this constructor always behaves the same
Method Details
getSearchKey
setSearchKey
Assigns the key being searched for.- Parameters:
key- the key to look up, which may be set only once- Throws:
IllegalStateException- if key previously set, to protect saved checksum
getSearchType
Defines the type of data being searched for. Default ANY.- Returns:
- non-null
setSearchType
Defines the type of data being searched for. Default ANY. Must be ANY for queried routers 0.9.5 or lower, but there are few if any floodfills that old left, so not even worth checking.- Parameters:
type- non-null
getFrom
Contains the router who requested this lookup.- Returns:
- the hash of the router that requested this lookup
setFrom
Assigns the router who requested this lookup.- Parameters:
from- the requesting router, recorded once so a reply can be routed back to it- Throws:
IllegalStateException- if from previously set, to protect saved checksum
getReplyTunnel
Contains the tunnel ID a reply should be sent to.- Returns:
- the reply tunnel
setReplyTunnel
Assigns the tunnel a reply should be sent to.- Parameters:
replyTunnel- the tunnel any reply to this lookup should be sent through- Throws:
IllegalStateException- if tunnel previously set, to protect saved checksum
supportsEncryptedReplies
Does this router support encrypted replies?- Parameters:
to- null OK returns true as of 0.9.69- Returns:
- true if the router is new enough and its public key type can encrypt replies
supportsRatchetReplies
Does this router support ratchet replies?- Parameters:
to- null OK returns true as of 0.9.69- Returns:
- true if the router is new enough and its public key type supports ratchets
getReplyKey
The included session key or null if unset. If non-null, eithergetReplyTag()or getRatchetReplyTag() is non-null.- Returns:
- the reply key
getReplyTag
setReplySession
Only worthwhile if sending reply via tunnel.- Parameters:
encryptKey- non-nullencryptTag- non-null- Throws:
IllegalStateException- if key or tag previously set, to protect saved checksum
getRatchetReplyTag
The included session tag or null if unset.- Returns:
- the ratchet reply tag
setReplySession
Sets the reply session for ratchet encryption; only once per message.- Parameters:
encryptKey- non-nullencryptTag- non-null- Throws:
IllegalStateException- if key or tag previously set, to protect saved checksum
getRatchetPublicKey
The included session key or null if unset. Preliminary, not fully supported, see proposal 154.- Returns:
- the ratchet public key
setReplySession
Sets the reply session's ratchet public key. Preliminary, not fully supported, see proposal 154.- Parameters:
pubKey- non-null- Throws:
IllegalStateException- if key or tag previously set, to protect saved checksum
getDontIncludePeers
setDontIncludePeers
Replace the dontInclude set with this set. WARNING - makes a copy. Invalidates the checksum.- Parameters:
peers- may be null
addDontIncludePeer
Add to the set. Invalidates the checksum.- Parameters:
peer- non-null
addDontIncludePeers
Add to the set. Invalidates the checksum.- Parameters:
peers- non-null
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()Calculates the length of the message body.- Specified by:
calculateWrittenLengthin classI2NPMessageImpl- Returns:
- the number of bytes the body will occupy once serialized
writeMessageBody
Writes the message body to the output array, returning the new 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
public int getType()The message type.- Returns:
- the DatabaseLookupMessage message type constant
hashCode
equals
toString
String form of the message, suitable for debugging. The INFO form masks every hash to the house truncation and carries no key material; the full keys are DEBUG-only, as inBuildRequestRecord.toKeyString().shortKey
The search key as the house truncation - 8 base32 characters for a lease set, 6 base64 for anything else - bracketed so the console links it.- Parameters:
type- what is being searched for, deciding the encoding usedkey- the search key to truncate- Returns:
- the bracketed truncation, never null
toKeyString
Key material for lookup interop debugging only. Never log this at INFO or above. Starts with a newline and an asterisk for multi-line log entries.- Returns:
- the key material dump, never null