java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
org.klomp.snark.dht.KRPC.ReplyWaiter
All Implemented Interfaces:
Runnable
Enclosing class:
KRPC

protected class KRPC.ReplyWaiterextends SimpleTimer2.TimedEvent
Callback for replies.
  • Field Details

    • mid

      private final MsgID mid
      The message id being tracked.
    • sentTo

      private final NodeInfo sentTo
      The node the request was sent to.
    • onReply

      private final Runnable onReply
      Runnable run when the reply arrives.
    • onTimeout

      private final Runnable onTimeout
      Runnable run when the reply times out.
    • replyCode

      private volatile int replyCode
      Reply code received, zero until it arrives.
    • sentObject

      private Object sentObject
      Object sent with the request.
    • replyObject

      private Object replyObject
      Object returned by the reply.
  • Constructor Details

    • ReplyWaiter

      public ReplyWaiter(MsgID mID, NodeInfo nInfo, Runnable onReply, Runnable onTimeout)
      Either wait on this object with a timeout, or use non-null Runnables. Any sent data to be remembered may be stored by setSentObject(Object). Reply object may be in getReplyObject().
      Parameters:
      mID - the message ID of the query being awaited
      nInfo - the node the query was sent to, and whose reply is credited
      onReply - must be fast, otherwise set to null and wait on this UNUSED
      onTimeout - must be fast, otherwise set to null and wait on this UNUSED
  • Method Details

    • getSentTo

      public NodeInfo getSentTo()
      The destination the packet was sent to.
      Returns:
      the sent to
    • setSentObject

      public void setSentObject(Object o)
      Only used for get_peers, to save the Info Hash.
      Parameters:
      o - the payload remembered alongside the query, read back by getSentObject()
    • getSentObject

      public Object getSentObject()
      The object stored with setSentObject().
      Returns:
      that stored with setSentObject()
    • getReplyObject

      public Object getReplyObject()
      Should contain null if getReplyCode is REPLY_PONG. Should contain List<Hash> if getReplyCode is REPLY_PEERS. Should contain List<NodeInfo> if getReplyCode is REPLY_NODES. Should contain String if getReplyCode is > 200.
      Returns:
      may be null depending on what happened. Cast to expected type.
    • getReplyCode

      public int getReplyCode()
      If nonzero, we got a reply, and getReplyObject() may contain something.
      Returns:
      code or 0 if no error
    • gotReply

      public void gotReply(int code, Object o)
      Will notify this and run onReply. Also removes from _sentQueries and calls KRPC.heardFrom(NodeInfo).
      Parameters:
      code - the reply status code, as returned by getReplyCode()
      o - the parsed reply payload, stored in getReplyObject()
    • timeReached

      public void timeReached()
      Timer callback on timeout.
      Specified by:
      timeReached in class SimpleTimer2.TimedEvent
    • networkFail

      public void networkFail()
      Will notify this but not run onReply or onTimeout, or remove from _sentQueries, or call heardFrom().