java.lang.Object
net.i2p.router.MessageHistory
Logs router message traffic for debugging and network analysis. Records inbound and outbound messages with timestamps when enabled, providing detailed traffic history for troubleshooting.
This is always instantiated in context and WriteJob runs every minute, (except on Android, we don't set up the WriteJob) but unless router.keepHistory=true it does nothing. It generates a LARGE log file.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classJob reopening the history file.private classJob writing the queued entries to the file.Field Summary
Modifier and TypeFieldDescriptionprivate final RouterContextThe router context.private booleanTrue while logging is enabled.private booleanTrue to pause the writes briefly.private booleanTrue until the first write completes.private StringThe file the entries are written to.private StringThe router hash, written into each entry.private final LogLogger for the message history.private final MessageHistory.ReinitializeJobJob reopening the history file.The entries not yet written to the file.private final MessageHistory.WriteJobJob writing the queued entries.static final StringDefault file name for the message history log.private static final intEntries forcing a write to the file.private static final byte[]The platform line separator bytes.static final StringConfig property determining whether we want to debug with the message history - default false.static final StringConfig property determining where we want to log the message history, if we're keeping one.private static final longWrite out the message history once per minute, if not sooner.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate voidResponsible for adding the entry, flushing if necessary.voidWe banlisted the peer.voiddroppedFragmentedMessage(long messageId, String status) Note that a fragmented message was dropped.voiddroppedInboundMessage(long messageId, Hash from, String info) Note that an inbound message was dropped.voiddroppedOtherMessage(I2NPMessage message, Hash from) We received another message we weren't waiting for and don't know how to handle.voiddroppedTunnelDataMessageUnknown(long msgId, long tunnelId) Note that a data message for an unknown tunnel was dropped.voiddroppedTunnelGatewayMessageUnknown(long msgId, long tunnelId) Note that a gateway message for an unknown tunnel was dropped.voiddroppedTunnelMessage(TunnelId id, long msgId, Date expiration, Hash from) We don't know about the given tunnel, so we are dropping a message sent to us by the given router.private voidWrite out any unwritten entries, and clear the pending list.voidfragmentMessage(long messageId, int numFragments, int totalLength, List<Long> messageIds, Object tunnel, String msg) Note that a message was split into fragments.voidfragmentMessage(long messageId, int numFragments, int totalLength, List<Long> messageIds, String msg) Note that a message was split into fragments.booleangetDoLog()Whether the history logging is turned on.(package private) StringHistory file name.private static final StringPrettify the hash by doing a base64 and returning the first 6 characters.private final StringReturns the prefix naming this router.private final StringgetTime(long when) Formats a time for a history entry.voidinitialize(boolean forceReinitialize) Initialize the message history according to the router's configuration.voidmessageProcessingError(long messageId, String messageType, String error) There was an error processing the given message that was received.voidreceiveMessage(String messageType, long messageId, long expiration, boolean isValid) Note that we just received a message with no known origin.voidreceiveMessage(String messageType, long messageId, long expiration, Hash from, boolean isValid) Note that we just received a message from the peer.voidreceivePayloadMessage(long messageId) Receive a payload message to distribute to a client.voidreceiveTunnelFragment(long messageId, int fragmentId, Object status) Note that we received a fragment of a tunneled message.voidreceiveTunnelFragmentComplete(long messageId) Note that all fragments of a tunneled message were received.voidreplyTimedOut(OutNetMessage sentMessage) The message wanted a reply but no reply came in the time expected.voidsendMessage(String messageType, long messageId, long expiration, Hash peer, boolean sentOk, String info) We just sent a message to the peer.voidsendPayloadMessage(long messageId, boolean successfullySent, long timeToSend) Note that the sending of a payload message completed (successfully or as a failure).voidshutdown()Shutdown the message history.voidtunnelDispatched(long messageId, long innerMessageId, long tunnelId, String type) Note that a message was dispatched to a tunnel.voidtunnelDispatched(long messageId, long tunnelId, long toTunnel, Hash toPeer, String type) Note that a message was dispatched to a tunnel.voidtunnelDispatched(long messageId, long tunnelId, String type) Note that a message was dispatched to a tunnel.voidtunnelDispatched(String info) Note that a message was dispatched to a tunnel.voidtunnelFailed(TunnelId tunnel) The local router has detected a failure in the given tunnel.voidtunnelJoined(String state, HopConfig tunnel) The local router has joined the given tunnel operating in the given state.voidtunnelJoined(String state, TunnelInfo tunnel) The local router has joined the given tunnel operating in the given state.voidtunnelParticipantRejected(Hash peer, String msg) Note that a router rejected our request to participate in a tunnel.voidtunnelRejected(Hash peer, TunnelId tunnel, Hash replyThrough, String reason) The peer did not accept the tunnel join for the given reason.voidtunnelRequestTimedOut(Hash peer, TunnelId tunnel) The peer did not accept the tunnel join for the given reason (this may be because of a timeout or an explicit refusal).voidtunnelValid(TunnelInfo tunnel, long timeToTest) Note that we have reason to believe that the given tunnel is valid, since we could do something through it in the given amount of time.voidWe unbanlisted the peer.private voidReads the logging settings from the config.voidwrap(String bodyMessageType, long bodyMessageId, String containerMessageType, long containerMessageId) Note that we're wrapping the given message within another message (via tunnel/garlic).private voidActually write the specified entries.
Field Details
_log
Logger for the message history._context
The router context._unwrittenEntries
_historyFile
The file the entries are written to._localIdent
The router hash, written into each entry._doLog
private volatile boolean _doLogTrue while logging is enabled._doPause
private volatile boolean _doPauseTrue to pause the writes briefly._reinitializeJob
Job reopening the history file._writeJob
Job writing the queued entries._firstPass
private volatile boolean _firstPassTrue until the first write completes.NL
private static final byte[] NLThe platform line separator bytes.FLUSH_SIZE
private static final int FLUSH_SIZEEntries forcing a write to the file.- See Also:
PROP_KEEP_MESSAGE_HISTORY
Config property determining whether we want to debug with the message history - default false.- See Also:
PROP_MESSAGE_HISTORY_FILENAME
Config property determining where we want to log the message history, if we're keeping one.- See Also:
DEFAULT_MESSAGE_HISTORY_FILENAME
Default file name for the message history log.- See Also:
WRITE_DELAY
private static final long WRITE_DELAYWrite out the message history once per minute, if not sooner.- See Also:
Constructor Details
MessageHistory
Message history for the given context.- Parameters:
context- the router context
Method Details
shutdown
public void shutdown()Shutdown the message history.getDoLog
public boolean getDoLog()Whether the history logging is turned on.- Returns:
- true if the entries are being logged
getFilename
updateSettings
private void updateSettings()Reads the logging settings from the config.initialize
public void initialize(boolean forceReinitialize) Initialize the message history according to the router's configuration. Call this whenever the router identity changes.- Parameters:
forceReinitialize- whether to force reinit
tunnelJoined
The local router has joined the given tunnel operating in the given state.- Parameters:
state- {"free inbound", "allocated inbound", "inactive inbound", "outbound", "participant", "pending"}tunnel- the tunnel that was joined; a null value logs nothing
tunnelJoined
The local router has joined the given tunnel operating in the given state.- Parameters:
state- {"free inbound", "allocated inbound", "inactive inbound", "outbound", "participant", "pending"}tunnel- the tunnel that was joined; a null value logs nothing
tunnelDispatched
Note that a message was dispatched to a tunnel.- Parameters:
info- description of what was dispatched, logged verbatim
tunnelDispatched
Note that a message was dispatched to a tunnel.- Parameters:
messageId- the message IDtunnelId- the tunnel IDtype- the message type being sent
tunnelDispatched
public void tunnelDispatched(long messageId, long tunnelId, long toTunnel, Hash toPeer, String type) Note that a message was dispatched to a tunnel.- Parameters:
messageId- the message IDtunnelId- the tunnel IDtoTunnel- the ID of the tunnel the message is being forwarded totoPeer- the gateway peer, which may be null for a null-hop tunneltype- the message type being sent
tunnelDispatched
Note that a message was dispatched to a tunnel.- Parameters:
messageId- the message IDinnerMessageId- the inner message IDtunnelId- the tunnel IDtype- the message type being sent
tunnelFailed
The local router has detected a failure in the given tunnel.- Parameters:
tunnel- the tunnel that failed; a null value logs nothing
tunnelValid
Note that we have reason to believe that the given tunnel is valid, since we could do something through it in the given amount of time.- Parameters:
tunnel- tunnel in questiontimeToTest- milliseconds to verify the tunnel
tunnelRejected
The peer did not accept the tunnel join for the given reason.- Parameters:
peer- the router that rejected the jointunnel- the tunnel whose join was refusedreplyThrough- the reply-through routerreason- the reason reported by the rejecting router
tunnelParticipantRejected
tunnelRequestTimedOut
droppedTunnelMessage
We don't know about the given tunnel, so we are dropping a message sent to us by the given router.- Parameters:
id- tunnel ID we received a message formsgId- the ID of the dropped messageexpiration- the absolute time the dropped message was due to expirefrom- peer that sent us this message (if known)
droppedOtherMessage
We received another message we weren't waiting for and don't know how to handle.- Parameters:
message- the unexpected message that arrivedfrom- the peer that sent it, or null if the sender is unknown
droppedInboundMessage
replyTimedOut
The message wanted a reply but no reply came in the time expected.- Parameters:
sentMessage- message sent that didn't receive a reply
messageProcessingError
There was an error processing the given message that was received.- Parameters:
messageId- the ID of the message whose processing failedmessageType- type of message receivederror- error message related to the processing of the message
banlist
unbanlist
We unbanlisted the peer.- Parameters:
peer- the peer removed from the banlist
sendMessage
public void sendMessage(String messageType, long messageId, long expiration, Hash peer, boolean sentOk, String info) We just sent a message to the peer.- Parameters:
messageType- class name for the message object (e.g. DatabaseFindNearestMessage, TunnelMessage, etc)messageId- the unique message id of the message being sent (not including any tunnel or garlic wrapped message ids)expiration- the expiration for the message sentpeer- router that the message was sent tosentOk- whether the message was sent successfullyinfo- extra detail appended to the log line
receiveMessage
public void receiveMessage(String messageType, long messageId, long expiration, Hash from, boolean isValid) Note that we just received a message from the peer.- Parameters:
messageType- class name for the message object (e.g. DatabaseFindNearestMessage, TunnelMessage, etc)messageId- the unique message id of the message received (not including any tunnel or garlic wrapped message ids)expiration- the expiration for the message receivedfrom- router that the message was sent from (or null if we don't know)isValid- whether the message is valid (non duplicates, etc)
receiveMessage
Note that we just received a message with no known origin.- Parameters:
messageType- class name for the message object (e.g. DatabaseFindNearestMessage, TunnelMessage, etc)messageId- the unique message id of the message receivedexpiration- the expiration for the message receivedisValid- whether the message is valid (non duplicates, etc)
wrap
public void wrap(String bodyMessageType, long bodyMessageId, String containerMessageType, long containerMessageId) Note that we're wrapping the given message within another message (via tunnel/garlic).- Parameters:
bodyMessageType- class name for the message contained (e.g. DatabaseFindNearestMessage, DataMessage, etc)bodyMessageId- the unique message id of the messagecontainerMessageType- class name for the message containing the body message (e.g. TunnelMessage, GarlicMessage, etc)containerMessageId- the unique message id of the message
receivePayloadMessage
public void receivePayloadMessage(long messageId) Receive a payload message to distribute to a client.- Parameters:
messageId- the ID of the payload message received
sendPayloadMessage
public void sendPayloadMessage(long messageId, boolean successfullySent, long timeToSend) Note that the sending of a payload message completed (successfully or as a failure).- Parameters:
messageId- message that the payload message was sent insuccessfullySent- whether the message was delivered to the peer successfullytimeToSend- how long it took to send the message
receiveTunnelFragment
Note that we received a fragment of a tunneled message.- Parameters:
messageId- message ID the fragment belongs tofragmentId- the index of this fragment within the message, not a message IDstatus- status object for the fragment
receiveTunnelFragmentComplete
public void receiveTunnelFragmentComplete(long messageId) Note that all fragments of a tunneled message were received.- Parameters:
messageId- message ID that completed
droppedFragmentedMessage
Note that a fragmented message was dropped.- Parameters:
messageId- message ID droppedstatus- the reason it was dropped
fragmentMessage
public void fragmentMessage(long messageId, int numFragments, int totalLength, List<Long> messageIds, String msg) Note that a message was split into fragments.- Parameters:
messageId- message ID fragmentednumFragments- number of fragmentstotalLength- total length of the messagemessageIds- the fragment message IDsmsg- extra text appended to the entry, or null to omit it
fragmentMessage
public void fragmentMessage(long messageId, int numFragments, int totalLength, List<Long> messageIds, Object tunnel, String msg) Note that a message was split into fragments.- Parameters:
messageId- message ID fragmentednumFragments- number of fragmentstotalLength- total length of the messagemessageIds- the fragment message IDstunnel- tunnel the fragments were sent onmsg- extra text appended to the entry, or null to omit it
droppedTunnelDataMessageUnknown
public void droppedTunnelDataMessageUnknown(long msgId, long tunnelId) Note that a data message for an unknown tunnel was dropped.- Parameters:
msgId- message ID droppedtunnelId- tunnel ID the message was for
droppedTunnelGatewayMessageUnknown
public void droppedTunnelGatewayMessageUnknown(long msgId, long tunnelId) Note that a gateway message for an unknown tunnel was dropped.- Parameters:
msgId- message ID droppedtunnelId- tunnel ID the message was for
getName
Prettify the hash by doing a base64 and returning the first 6 characters.- Parameters:
router- the router hash to prettify, may be null- Returns:
- the first 6 characters of the hash in base64 form, or "UNKNOWN" if the hash is null and "INVALID" if it cannot be encoded
getPrefix
getTime
Formats a time for a history entry.- Parameters:
when- the time to format- Returns:
- the formatted text
addEntry
Responsible for adding the entry, flushing if necessary. This is the only thing that adds to _unwrittenEntries.- Parameters:
entry- the log entry line to add, ignored if null
flushEntries
private void flushEntries()Write out any unwritten entries, and clear the pending list.writeEntries
private void writeEntries()Actually write the specified entries.