java.lang.Object
net.i2p.data.i2np.I2NPMessageHandler
Handle messages from router to router. This class is NOT threadsafe.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextThe context the messages are read for.private I2NPMessageThe message read last, reused between reads.private final LogLogger for this class.Constructor Summary
ConstructorsConstructorDescriptionI2NPMessageHandler(I2PAppContext context) Message handler for reading and writing I2NP messages.Method Summary
All MethodsModifier and TypeMethodDescriptionlastRead()Clear the last message read from a byte array with an offset.readMessage(byte[] data) Read an I2NPMessage from the byte array and return the fully populated object.intreadMessage(byte[] data, int offset) Result is retrieved withlastRead().intreadMessage(byte[] data, 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.
Field Details
_log
Logger for this class._context
The context the messages are read for._lastRead
The message read last, reused between reads.
Constructor Details
I2NPMessageHandler
Message handler for reading and writing I2NP messages.- Parameters:
context- router context supplying the app context and this handler's Log
Method Details
lastRead
Clear the last message read from a byte array with an offset.- Returns:
- the last I2NP message read, or null if none is pending; the call clears it
readMessage
Read an I2NPMessage from the byte array and return the fully populated object.- Parameters:
data- the buffer holding the serialized message- Returns:
- the fully populated message
- Throws:
I2NPMessageException- if there is a problem handling the particular message - if it is an unknown type or has improper formatting, etc.
readMessage
Result is retrieved withlastRead().- Parameters:
data- the buffer holding the serialized messageoffset- the index in data at which the message starts- Returns:
- the number of bytes read from data
- Throws:
I2NPMessageException- on an unknown type or body
readMessage
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.Result is retrieved with lastRead().
- Parameters:
data- the buffer holding the serialized messageoffset- the index in data at which the message startsmaxLen- read no more than this many bytes from data starting at offset, even if it is longer must be at least 16- Returns:
- the number of bytes read from data
- Throws:
I2NPMessageException- on an unknown type or body