net.i2p.router.tunnel.pool

## Class GhostPeerManager

- java.lang.Object
- - net.i2p.router.tunnel.pool.GhostPeerManager

-     public class GhostPeerManager
      extends Object

  Tracks routers that consistently fail to respond to tunnel build requests and temporarily excludes them from tunnel selection during network stress. This helps mitigate ghost peer attacks where malicious routers accept tunnel build requests but never respond, causing resource exhaustion.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `GhostPeerManager(RouterContext context)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `cleanup()` Cleanup old entries to prevent memory growth.
    `void` | `clearGhost(Hash peer)` Clear ghost status for a peer (manual intervention).
    `int` | `getGhostCount()` Get count of currently tracked ghost peers.
    `int` | `getThreshold()` Get the current timeout threshold.
    `int` | `getTimeoutCount(Hash peer)` Get consecutive timeout count for a peer.
    `boolean` | `isGhost(Hash peer)` Check if a peer should be excluded from tunnel selection.
    `boolean` | `isInCooldown(Hash peer)` Check if a peer is in ghost cooldown period.
    `void` | `recordSuccess(Hash peer)` Record successful tunnel participation by a peer.
    `void` | `recordTimeout(Hash peer)` Record that a peer timed out during tunnel build.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### GhostPeerManager

          public GhostPeerManager(RouterContext context)

  - ### Method Detail

    - #### cleanup

          public void cleanup()

      Cleanup old entries to prevent memory growth. Called periodically or when threshold is reached.

    - #### clearGhost

          public void clearGhost(Hash peer)

      Clear ghost status for a peer (manual intervention).
      Parameters:
        `peer` - the peer hash to clear

    - #### getGhostCount

          public int getGhostCount()

      Get count of currently tracked ghost peers.
      Returns:
        number of ghost peers

    - #### getThreshold

          public int getThreshold()

      Get the current timeout threshold. Lower threshold during attacks (build success < 40%).
      Returns:
        threshold number of timeouts before exclusion

    - #### getTimeoutCount

          public int getTimeoutCount(Hash peer)

      Get consecutive timeout count for a peer.
      Parameters:
        `peer` - the peer hash
      Returns:
        timeout count, or 0 if not tracked

    - #### isGhost

          public boolean isGhost(Hash peer)

      Check if a peer should be excluded from tunnel selection.
      Parameters:
        `peer` - the peer hash to check
      Returns:
        true if the peer is a ghost and should be skipped

    - #### isInCooldown

          public boolean isInCooldown(Hash peer)

      Check if a peer is in ghost cooldown period. Peers in cooldown were previously ghosts but may be retried.
      Parameters:
        `peer` - the peer hash to check
      Returns:
        true if peer is in cooldown period

    - #### recordSuccess

          public void recordSuccess(Hash peer)

      Record successful tunnel participation by a peer. Clears ghost status when a peer successfully participates in a tunnel.
      Parameters:
        `peer` - the peer hash that participated successfully

    - #### recordTimeout

          public void recordTimeout(Hash peer)

      Record that a peer timed out during tunnel build. Called from BuildExecutor when a tunnel build expires.
      Parameters:
        `peer` - the peer hash that timed out