java.lang.Object
org.klomp.snark.DontHaveMemo

class DontHaveMemoextends Object
Tracks the pieces a peer said it no longer has (BEP 54 dont_have), so the piece is not re-requested from that peer even if it re-announces HAVE, until the remembered state expires.

The peer's HAVE bitfield is already cleared on dont_have; this additionally suppresses requests once the peer re-sets the bit, avoiding a request/dont_have ping-pong with peers that flap or purge pieces transiently.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Map<Integer,Long>
    Blocks the peer refused, by block number, with the time of each
    private final long
    When the memo was made, for expiring it.
    private static final long
    How long a dont_have keeps a piece unrequestable from that peer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a memo using the default five minute suppression window.
    DontHaveMemo(long memoTime)
    Create a memo with a caller-chosen suppression window, for tests and for tuning the expiry.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    (package private) void
    add(int piece)
    Remember that the peer no longer has the piece.
    (package private) boolean
    contains(int piece)
    Whether the peer recently said it does not have the piece.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_MEMO_TIME

      private static final long DEFAULT_MEMO_TIME
      How long a dont_have keeps a piece unrequestable from that peer.
      See Also:
    • _memoTime

      private final long _memoTime
      When the memo was made, for expiring it.
    • _dontHave

      private final Map<Integer,Long> _dontHave
      Blocks the peer refused, by block number, with the time of each
  • Constructor Details

    • DontHaveMemo

      DontHaveMemo()
      Create a memo using the default five minute suppression window.
    • DontHaveMemo

      DontHaveMemo(long memoTime)
      Create a memo with a caller-chosen suppression window, for tests and for tuning the expiry.
      Parameters:
      memoTime - how long a dont_have suppresses requests, milliseconds
  • Method Details

    • add

      void add(int piece)
      Remember that the peer no longer has the piece.
      Parameters:
      piece - the piece index
    • contains

      boolean contains(int piece)
      Whether the peer recently said it does not have the piece. Expired entries are dropped.
      Parameters:
      piece - the piece index
      Returns:
      true if within the retention window