java.lang.Object
net.i2p.router.OutNetMessage
All Implemented Interfaces:
CDPQEntry, CDQEntry, PQEntry

public class OutNetMessageextends Object implements CDPQEntry
Wrap up an outbound I2NP message, along with the information associated with its delivery and jobs to be fired off if particular events occur.
  • Field Details

    • _context

      private final RouterContext _context
      The router context.
    • _target

      private final RouterInfo _target
      The peer the message goes to.
    • _message

      private final I2NPMessage _message
      The message to send.
    • _messageTypeId

      private final int _messageTypeId
      Type id of the message.
    • _messageId

      private final long _messageId
      Cached message ID, for use after we discard the message.
    • _messageSize

      private final int _messageSize
      Size of the message, in bytes.
    • _priority

      private final int _priority
      Send priority of the message.
    • _expiration

      private final long _expiration
      When the message is too old to send.
    • _onSend

      private Job _onSend
      Job run after a successful send.
    • _onFailedSend

      private Job _onFailedSend
      Job run after a failed send.
    • _onReply

      private ReplyJob _onReply
      Job run when the reply arrives.
    • _onFailedReply

      private Job _onFailedReply
      Job run when the reply fails.
    • _replySelector

      private MessageSelector _replySelector
      Selector matching the expected reply.
    • _failedTransports

      private List<String> _failedTransports
      The transports that failed to deliver this message. Copy-on-write, since the list is read - and formatted into log messages - on the send path of every transport while another transport may be recording a failure of its own at the same time.
    • _sendBegin

      private long _sendBegin
      When the send started, 0 until sent.
    • _created

      private long _created
      When the message was created.
    • _enqueueTime

      private long _enqueueTime
      When the message entered the send pool.
    • _transportQueued

      private long _transportQueued
      When the transport took the message.
    • _seqNum

      private long _seqNum
      Sequence id used to match the reply.
    • _shouldTimestamp

      private final boolean _shouldTimestamp
      True to record the send timing.
    • _timestamps

      private HashMap<String,Long> _timestamps
      For debugging, maps each event name to a timestamp (e.g. "begin sending", "handleOutbound", etc).
    • _timestampOrder

      private List<String> _timestampOrder
      Contains a list of timestamp event names in the order they were fired (some JVMs have less than 10ms resolution, so the Long above doesn't guarantee order).
    • PRIORITY_LOWEST

      public static final int PRIORITY_LOWEST
      Priorities, higher is higher priority. Lowest priority.
      See Also:
    • PRIORITY_MEDIUM

      public static final int PRIORITY_MEDIUM
      Medium priority.
      See Also:
    • PRIORITY_HIGHEST

      public static final int PRIORITY_HIGHEST
      Highest priority.
      See Also:
    • PRIORITY_BUILD_REPLY

      public static final int PRIORITY_BUILD_REPLY
      Build reply priority.
      See Also:
    • PRIORITY_EXPLORATORY

      public static final int PRIORITY_EXPLORATORY
      Exploratory priority.
      See Also:
    • PRIORITY_PARTICIPATING

      public static final int PRIORITY_PARTICIPATING
      Participating priority.
      See Also:
    • PRIORITY_MY_BUILD_REQUEST

      public static final int PRIORITY_MY_BUILD_REQUEST
      My build request priority.
      See Also:
    • PRIORITY_MY_DATA

      public static final int PRIORITY_MY_DATA
      My data priority.
      See Also:
    • PRIORITY_MY_NETDB_LOOKUP

      public static final int PRIORITY_MY_NETDB_LOOKUP
      My netdb lookup priority.
      See Also:
    • PRIORITY_MY_NETDB_STORE_LOW

      public static final int PRIORITY_MY_NETDB_STORE_LOW
      My netdb store low priority.
      See Also:
    • PRIORITY_MY_NETDB_STORE

      public static final int PRIORITY_MY_NETDB_STORE
      My netdb store priority.
      See Also:
    • PRIORITY_NETDB_EXPLORE

      public static final int PRIORITY_NETDB_EXPLORE
      Netdb explore priority.
      See Also:
    • PRIORITY_NETDB_FLOOD

      public static final int PRIORITY_NETDB_FLOOD
      Netdb flood priority.
      See Also:
    • PRIORITY_NETDB_HARVEST

      public static final int PRIORITY_NETDB_HARVEST
      Netdb harvest priority.
      See Also:
    • PRIORITY_NETDB_REPLY

      public static final int PRIORITY_NETDB_REPLY
      Netdb reply priority.
      See Also:
    • PRIORITY_HIS_BUILD_REQUEST

      public static final int PRIORITY_HIS_BUILD_REQUEST
      His build request priority.
      See Also:
    • PRIORITY_HIS_NETDB_STORE

      public static final int PRIORITY_HIS_NETDB_STORE
      His netdb store priority.
      See Also:
  • Constructor Details

    • OutNetMessage

      public OutNetMessage(RouterContext context)
      Null msg and target, zero expiration (used in OutboundMessageRegistry only).
      Parameters:
      context - the router context
    • OutNetMessage

      public OutNetMessage(RouterContext context, I2NPMessage msg, long expiration, int priority, RouterInfo target)
      Standard constructor.
      Parameters:
      context - the router context
      msg - generally non-null
      expiration - the expiration time
      priority - the send priority; higher is sent sooner, 100 (PRIORITY_LOWEST) through 1000 (PRIORITY_HIGHEST)
      target - generally non-null
  • Method Details

    • timestamp

      public void timestamp(String eventName)
      Stamp the message's progress. Only useful if log level is INFO or DEBUG.
      Parameters:
      eventName - the label this stamp is filed under; reusing a name overwrites its earlier time and appends a duplicate to the order list
    • locked_initTimestamps

      private void locked_initTimestamps()
      Stamps the message's timing fields.
    • getTarget

      public RouterInfo getTarget()
      Specifies the router to which the message should be delivered. Generally non-null but may be null in special cases.
      Returns:
      the target router
    • getMessage

      public I2NPMessage getMessage()
      Specifies the message to be sent. Generally non-null but may be null in special cases.
      Returns:
      the I2NP message to be sent, or null for the registry-only placeholder, in which case the message type, ID and size are all zero
    • getMessageType

      public String getMessageType()
      For debugging only.
      Returns:
      the simple class name
    • getMessageTypeId

      public int getMessageTypeId()
      Message type ID.
      Returns:
      the type id, 0 to 31
    • getMessageId

      public long getMessageId()
      Message ID.
      Returns:
      the id to match the reply with
    • getMessageSize

      public int getMessageSize()
      How large the message is, including the full 16 byte header. Transports with different header sizes should adjust.
      Returns:
      the message size
    • getMessageData

      public int getMessageData(byte[] outBuffer)
      Copies the message data to outbuffer. Used only by VM Comm System.
      Parameters:
      outBuffer - the buffer to copy to
      Returns:
      the length, or -1 if message is null
    • getPriority

      public int getPriority()
      Specify the priority of the message, where higher numbers are higher priority. Higher priority messages should be delivered before lower priority ones, though some algorithm may be used to avoid starvation.
      Specified by:
      getPriority in interface PQEntry
      Returns:
      the delivery priority, one of the PRIORITY_ constants, where higher numbers are delivered first
    • getExpiration

      public long getExpiration()
      Specify the # ms since the epoch after which if the message has not been sent the OnFailedSend job should be fired and the message should be removed from the pool. If the message has already been sent, this expiration is ignored and the expiration from the ReplySelector is used.
      Returns:
      the expiration time
    • getOnSendJob

      public Job getOnSendJob()
      After the message is successfully passed to the router specified, the given job is enqueued.
      Returns:
      the onSend job
    • setOnSendJob

      public void setOnSendJob(Job job)
      The job enqueued when the message is sent.
      Parameters:
      job - the onSend job
    • getOnFailedSendJob

      public Job getOnFailedSendJob()
      If the router could not be reached or the expiration passed, this job is enqueued.
      Returns:
      the onFailedSend job
    • setOnFailedSendJob

      public void setOnFailedSendJob(Job job)
      The job enqueued when the message cannot be sent.
      Parameters:
      job - the onFailedSend job
    • getOnReplyJob

      public ReplyJob getOnReplyJob()
      If the MessageSelector detects a reply, this job is enqueued.
      Returns:
      the onReply job
    • setOnReplyJob

      public void setOnReplyJob(ReplyJob job)
      The job enqueued when a reply is detected.
      Parameters:
      job - the onReply job
    • getOnFailedReplyJob

      public Job getOnFailedReplyJob()
      If the Message selector is specified but it doesn't find a reply before its expiration passes, this job is enqueued.
      Returns:
      the onFailedReply job
    • setOnFailedReplyJob

      public void setOnFailedReplyJob(Job job)
      The job enqueued when no reply arrives before expiration.
      Parameters:
      job - the onFailedReply job
    • getReplySelector

      public MessageSelector getReplySelector()
      Defines a MessageSelector to find a reply to this message.
      Returns:
      the reply selector
    • setReplySelector

      public void setReplySelector(MessageSelector selector)
      The selector used to find a reply to this message.
      Parameters:
      selector - the reply selector
    • transportFailed

      public int transportFailed(String transportStyle)
      Record a transport that failed to deliver this message, and return how many transports had already failed.
      Parameters:
      transportStyle - the transport that failed
      Returns:
      the number of previously failed transports
    • getFailedTransportCount

      public int getFailedTransportCount()
      Number of transports that have failed to deliver this message.
      Returns:
      the number of failed transports
    • getFailedTransports

      public List<String> getFailedTransports()
      The transports that have failed to deliver this message.

      As of 0.9.55, changed from a Set to a List. The list is safe to iterate, format or query while another thread records another failure; what an iteration sees is a snapshot of the failures recorded so far.

      Returns:
      the list of failed transports
    • getSendBegin

      public long getSendBegin()
      When the sending process began.
      Returns:
      the time, in epoch ms
    • beginSend

      public void beginSend()
      Record the time the send process began.
    • getCreated

      public long getCreated()
      Creation time.
      Returns:
      the time, in epoch ms
    • resetCreatedTime

      public void resetCreatedTime()
      Reset creation time for dispatch age tracking on requeue.
    • getLifetime

      public long getLifetime()
      How long the message has existed.
      Returns:
      the age, in ms
    • getSendTime

      public long getSendTime()
      How long the send has been under way.
      Returns:
      the elapsed time, in ms
    • setEnqueueTime

      public void setEnqueueTime(long now)
      The enqueue time, used by the CDQ.
      Specified by:
      setEnqueueTime in interface CDQEntry
      Parameters:
      now - the enqueue time
    • getEnqueueTime

      public long getEnqueueTime()
      The enqueue time, used by the CDQ.
      Specified by:
      getEnqueueTime in interface CDQEntry
      Returns:
      the enqueue time
    • setTransportQueued

      public void setTransportQueued(long now)
      When the message entered the transport queue (set by transport send()).
      Parameters:
      now - the queue time
    • getTransportQueued

      public long getTransportQueued()
      When the transport took the message.
      Returns:
      the time, in epoch ms
    • drop

      public void drop()
      For CDQ.
      Specified by:
      drop in interface CDQEntry
    • setSeqNum

      public void setSeqNum(long num)
      The sequence number, used by the CDPQ.
      Specified by:
      setSeqNum in interface PQEntry
      Parameters:
      num - the sequence number
    • getSeqNum

      public long getSeqNum()
      The sequence number, used by the CDPQ.
      Specified by:
      getSeqNum in interface PQEntry
      Returns:
      the seq num
    • discardData

      public void discardData()
      We've done what we need to do with the data from this message, though we may keep the object around for a while to use its ID, jobs, etc.
    • toString

      public String toString()
      String representation of this message for debugging.
      Overrides:
      toString in class Object
    • renderTimestamps

      private void renderTimestamps(StringBuilder buf)
      Only useful if log level is INFO or DEBUG; locked_initTimestamps() must have been called previously.
      Parameters:
      buf - the builder the timestamp lines are appended to