java.lang.Object
net.i2p.router.Banlist

public class Banlistextends Object
Manages router banlist entries with configurable expiration times and transport-specific bans. Provides methods to add, remove, and query ban status for routers based on various criteria including permanent bans, temporary bans, and transport-specific restrictions.
  • Field Details

    • _log

      private final Log _log
      Logger for ban decisions.
    • _context

      private final RouterContext _context
      The router context.
    • _entries

      private final Map<Hash, Banlist.Entry> _entries
      Active bans by router hash.
    • _badPacketIPs

      private final ConcurrentHashMap<String,long[]> _badPacketIPs
      Bad packet offenses by IP address, with times.
    • _corruptConnectionIPs

      private final ConcurrentHashMap<String,long[]> _corruptConnectionIPs
      Corrupt connection offenses by IP address, with times.
    • _portHoppingIPs

      private final ConcurrentHashMap<String,long[]> _portHoppingIPs
      Port hopping offenses by IP address, with times.
    • PROP_MAX_OFFENSES

      private static final String PROP_MAX_OFFENSES
      Config key for the offenses needed to ban.
      See Also:
    • MAX_OFFENSES_DEFAULT

      private static final int MAX_OFFENSES_DEFAULT
      Default offenses needed to ban.
      See Also:
    • _maxOffenses

      private int _maxOffenses
      Offenses needed to ban, in effect right now.
    • PROP_OFFENSE_WINDOW

      private static final String PROP_OFFENSE_WINDOW
      Config key for the window offenses count in, 15 minutes by default.
      See Also:
    • OFFENSE_WINDOW_DEFAULT

      private static final long OFFENSE_WINDOW_DEFAULT
      The default offense window is 15 minutes.
      See Also:
    • _offenseWindow

      private long _offenseWindow
      Offense window in effect right now.
    • PROP_STARTUP_GRACE

      private static final String PROP_STARTUP_GRACE
      Config key for the startup grace period, during which offenses are not tracked, 3 minutes by default.
      See Also:
    • STARTUP_GRACE_DEFAULT

      private static final long STARTUP_GRACE_DEFAULT
      The default startup grace before offenses count is 3 minutes.
      See Also:
    • _startupGrace

      private long _startupGrace
      Startup grace period in effect right now.
    • PROP_BAD_PACKET_DURATION

      private static final String PROP_BAD_PACKET_DURATION
      Config key for the bad packet ban length.
      See Also:
    • BANLIST_DURATION_BAD_PACKETS_DEFAULT

      private static final long BANLIST_DURATION_BAD_PACKETS_DEFAULT
      The default bad packet ban lasts 1 hour.
      See Also:
    • _badPacketDuration

      private long _badPacketDuration
      Bad packet ban length in effect right now.
    • PROP_ENABLE_BAD_PACKET_BAN

      private static final String PROP_ENABLE_BAD_PACKET_BAN
      Config key turning the bad packet ban on or off.
      See Also:
    • ENABLE_BAD_PACKET_BAN_DEFAULT

      private static final boolean ENABLE_BAD_PACKET_BAN_DEFAULT
      Bad packet banning is off by default.
      See Also:
    • _enableBadPacketBan

      private boolean _enableBadPacketBan
      Whether bad packet banning is enabled.
    • PROP_ENABLE_CORRUPT_CONNECTION_BAN

      private static final String PROP_ENABLE_CORRUPT_CONNECTION_BAN
      Config key turning the corrupt connection ban on or off.
      See Also:
    • ENABLE_CORRUPT_CONNECTION_BAN_DEFAULT

      private static final boolean ENABLE_CORRUPT_CONNECTION_BAN_DEFAULT
      Corrupt connection banning is off by default.
      See Also:
    • _enableCorruptConnectionBan

      private boolean _enableCorruptConnectionBan
      Whether corrupt connection banning is enabled.
    • PROP_ENABLE_PORT_HOPPING_BAN

      private static final String PROP_ENABLE_PORT_HOPPING_BAN
      Config key turning the port hopping ban on or off.
      See Also:
    • ENABLE_PORT_HOPPING_BAN_DEFAULT

      private static final boolean ENABLE_PORT_HOPPING_BAN_DEFAULT
      Port hopping banning is off by default.
      See Also:
    • _enablePortHoppingBan

      private boolean _enablePortHoppingBan
      Whether port hopping banning is enabled.
    • PROP_ENABLE_BLOCKLIST

      private static final String PROP_ENABLE_BLOCKLIST
      Config key turning the blocklist on or off.
      See Also:
    • ENABLE_BLOCKLIST_DEFAULT

      private static final boolean ENABLE_BLOCKLIST_DEFAULT
      The blocklist is on by default.
      See Also:
    • _enableBlocklist

      private boolean _enableBlocklist
      Whether the blocklist is enabled.
    • PROP_ENABLE_TOR_BLOCKLIST

      private static final String PROP_ENABLE_TOR_BLOCKLIST
      Config key turning the Tor blocklist on or off.
      See Also:
    • ENABLE_TOR_BLOCKLIST_DEFAULT

      private static final boolean ENABLE_TOR_BLOCKLIST_DEFAULT
      The Tor blocklist is on by default.
      See Also:
    • _enableTorBlocklist

      private boolean _enableTorBlocklist
      Whether the Tor blocklist is enabled.
    • PROP_ENABLE_COUNTRY_BAN

      private static final String PROP_ENABLE_COUNTRY_BAN
      Config key turning the country blocklist on or off.
      See Also:
    • ENABLE_COUNTRY_BAN_DEFAULT

      private static final boolean ENABLE_COUNTRY_BAN_DEFAULT
      Country banning is off by default.
      See Also:
    • _enableCountryBan

      private boolean _enableCountryBan
      Whether country banning is enabled.
    • PROP_ENABLE_XG_BAN

      private static final String PROP_ENABLE_XG_BAN
      Config key turning the XG router ban on or off.
      See Also:
    • ENABLE_XG_BAN_DEFAULT

      private static final boolean ENABLE_XG_BAN_DEFAULT
      Banning XG capacity routers is off by default.
      See Also:
    • _enableXgBan

      private boolean _enableXgBan
      Whether the XG router ban is enabled.
    • PROP_ENABLE_LU_BAN

      private static final String PROP_ENABLE_LU_BAN
      Config key turning the LU router ban on or off.
      See Also:
    • ENABLE_LU_BAN_DEFAULT

      private static final boolean ENABLE_LU_BAN_DEFAULT
      Banning LU capacity routers is off by default.
      See Also:
    • _enableLuBan

      private boolean _enableLuBan
      Whether the LU router ban is enabled.
    • PROP_ENABLE_INTRODUCER_BAN

      private static final String PROP_ENABLE_INTRODUCER_BAN
      Config key turning the introducer-cap ban on or off, for an SSU2 address advertising more introducers than the spec allows.
      See Also:
    • ENABLE_INTRODUCER_BAN_DEFAULT

      private static final boolean ENABLE_INTRODUCER_BAN_DEFAULT
      Banning introducer-capped routers is on by default.
      See Also:
    • _enableIntroducerBan

      private boolean _enableIntroducerBan
      Whether the introducer-cap ban is enabled.
    • PROP_ENABLE_INVALID_VERSION_BAN

      private static final String PROP_ENABLE_INVALID_VERSION_BAN
      Config key turning the invalid version ban on or off.
      See Also:
    • ENABLE_INVALID_VERSION_BAN_DEFAULT

      private static final boolean ENABLE_INVALID_VERSION_BAN_DEFAULT
      Banning invalid router versions is on by default.
      See Also:
    • _enableInvalidVersionBan

      private boolean _enableInvalidVersionBan
      Whether the invalid version ban is enabled.
    • PROP_ENABLE_PUB_DATE_BAN

      private static final String PROP_ENABLE_PUB_DATE_BAN
      Config key turning the bad publication date ban on or off, for a router info published in the past epoch.
      See Also:
    • ENABLE_PUB_DATE_BAN_DEFAULT

      private static final boolean ENABLE_PUB_DATE_BAN_DEFAULT
      Banning bad publication dates is on by default.
      See Also:
    • _enablePubDateBan

      private boolean _enablePubDateBan
      Whether the bad publication date ban is enabled.
    • PROP_ENABLE_RU_CAPS_BAN

      private static final String PROP_ENABLE_RU_CAPS_BAN
      Config key turning the contradictory caps ban on or off.
      See Also:
    • ENABLE_RU_CAPS_BAN_DEFAULT

      private static final boolean ENABLE_RU_CAPS_BAN_DEFAULT
      Banning contradictory reachability caps is on by default.
      See Also:
    • _enableRUCapsBan

      private boolean _enableRUCapsBan
      Whether the contradictory caps ban is enabled.
    • PROP_CUSTOM_CAPABILITY_BANS

      private static final String PROP_CUSTOM_CAPABILITY_BANS
      Config key listing capability letters to ban.
      See Also:
    • COMMA_SPLIT

      private static final Pattern COMMA_SPLIT
      Splits the capability ban list on commas and spaces.
    • _customCapabilityBans

      private String _customCapabilityBans
      Capability letters to ban, from the config.
    • HASH_ZERORI

      public static final Hash HASH_ZERORI
      Hash of 387 zeros.
    • BANLIST_DURATION_MS

      public static final long BANLIST_DURATION_MS
      Default ban duration for transient bans.
      See Also:
    • BANLIST_DURATION_MAX

      public static final long BANLIST_DURATION_MAX
      Maximum ban duration for transient bans.
      See Also:
    • BANLIST_DURATION_PARTIAL

      public static final long BANLIST_DURATION_PARTIAL
      Default ban duration for transport-specific bans.
      See Also:
    • BANLIST_DURATION_FOREVER

      public static final long BANLIST_DURATION_FOREVER
      Permanent ban duration (will be rounded down to 180 days on console).
      See Also:
    • BANLIST_DURATION_NO_NETWORK

      public static final long BANLIST_DURATION_NO_NETWORK
      Buggy i2pd fork.
      See Also:
    • BANLIST_DURATION_PRIVATE

      public static final long BANLIST_DURATION_PRIVATE
      Ban duration for private IP addresses.
      See Also:
    • BANLIST_DURATION_BAD_PACKETS

      public static final long BANLIST_DURATION_BAD_PACKETS
      Ban duration for repeat bad packet offenders.
      See Also:
    • BANLIST_CLEANER_START_DELAY

      private static final long BANLIST_CLEANER_START_DELAY
      Wait before the cleanup job first runs.
      See Also:
    • BAN_COUNT_BASELINE

      private static final int BAN_COUNT_BASELINE
      Ban count baseline for proportional duration reduction. At this count or below, no reduction is applied. Above this, remaining durations are scaled by baseline / count, minimum scale floor MIN_BAN_SCALE.
      See Also:
    • MIN_BAN_SCALE

      private static final double MIN_BAN_SCALE
      Smallest factor a ban duration may be scaled by.
      See Also:
    • BAN_REDUCTION_MIN

      private static final long BAN_REDUCTION_MIN
      Eligible ban durations for reduction: > 4 hours.
      See Also:
    • BAN_REDUCTION_MAX

      private static final long BAN_REDUCTION_MAX
      Eligible ban durations for reduction: < 1 week.
      See Also:
    • BAN_COUNT_HIGH

      private static final int BAN_COUNT_HIGH
      Above this count, ALL bans over 1h are halved regardless of existing scaling.
      See Also:
    • BANLIST_FOREVER_THRESHOLD

      private static final long BANLIST_FOREVER_THRESHOLD
      A ban that expires after this will return true in isBanlistedForever(Hash). In the transports, "forever" is treated as a hard ban, and both inbound and outbound connections will be rejected. Not-forever is treated as a soft ban, with outbound rejected but inbound will be allowed and will automatically unban.
      See Also:
    • MAX_VALID_VERSION

      static final String MAX_VALID_VERSION
      Highest I2P version recognised as real. No released version reaches it, so a RouterInfo publishing a version at or above this ceiling has built the RouterInfo by hand - usually a scanner probing for netdb storage. Kept here so the NTCP2 handshake, the floodfill store path and the data store all agree on one ceiling.
      See Also:
  • Constructor Details

    • Banlist

      public Banlist(RouterContext context)
      Seeds the entry maps, bans the known invalid hashes, and reads the config.
      Parameters:
      context - the router context
  • Method Details

    • initConfig

      private void initConfig()
      Initialize configurable properties. Reads from router config, falls back to defaults.
    • reloadConfig

      public void reloadConfig()
      Reload configuration from properties. Called when settings are changed in the console.
    • clearSessionBans

      public void clearSessionBans()
      Clear all session-based bans.
    • getMaxOffenses

      public int getMaxOffenses()
      Get the current max offenses setting.
      Returns:
      the maximum offenses before auto-ban
    • getOffenseWindow

      public long getOffenseWindow()
      Get the current offense window setting in ms.
      Returns:
      the offense window in milliseconds
    • getStartupGrace

      public long getStartupGrace()
      Get the current startup grace period in ms.
      Returns:
      the startup grace period in milliseconds
    • getBadPacketDuration

      public long getBadPacketDuration()
      Get the current bad packet ban duration in ms.
      Returns:
      the bad packet ban duration in milliseconds
    • isBadPacketBanEnabled

      public boolean isBadPacketBanEnabled()
      Check if bad packet auto-ban is enabled.
      Returns:
      true if bad packet auto-ban is enabled
    • isCorruptConnectionBanEnabled

      public boolean isCorruptConnectionBanEnabled()
      Check if corrupt connection auto-ban is enabled.
      Returns:
      true if corrupt connection auto-ban is enabled
    • isPortHoppingBanEnabled

      public boolean isPortHoppingBanEnabled()
      Check if port hopping auto-ban is enabled.
      Returns:
      true if port hopping auto-ban is enabled
    • isBlocklistEnabled

      public boolean isBlocklistEnabled()
      Check if IP blocklist is enabled.
      Returns:
      true if IP blocklist is enabled
    • isTorBlocklistEnabled

      public boolean isTorBlocklistEnabled()
      Check if Tor exit node blocklist is enabled.
      Returns:
      true if Tor exit node blocklist is enabled
    • isCountryBanEnabled

      public boolean isCountryBanEnabled()
      Check if country-based bans are enabled.
      Returns:
      true if country-based bans are enabled
    • isXgBanEnabled

      public boolean isXgBanEnabled()
      Check if XG router bans are enabled. XG = unlimited bandwidth (X), no transit tunnels (G) - often botnet indicators.
      Returns:
      true if XG router bans are enabled
    • isLuBanEnabled

      public boolean isLuBanEnabled()
      Check if LU router bans are enabled. LU = low bandwidth tier (L) + unreachable/firewalled (U).
      Returns:
      true if LU router bans are enabled
    • isIntroducerBanEnabled

      public boolean isIntroducerBanEnabled()
      Check if introducer-cap router bans are enabled. An SSU2 address advertising more than the spec's five introducers is out of spec - usually a scanner or a modified client - so it can be banned when we learn of it, not only when we handshake.
      Returns:
      true if over-cap introducer bans are enabled
    • isInvalidVersionBanEnabled

      public boolean isInvalidVersionBanEnabled()
      Check the invalid-RouterInfo-version ban is enabled. A RouterInfo publishing a version above every released version is fabricated, so it can be banned where it is seen rather than only at the handshake.
      Returns:
      true if fabricated-version bans are enabled
    • isPubDateBanEnabled

      public boolean isPubDateBanEnabled()
      Check the invalid-publication-date ban is enabled.
      Returns:
      true if bad-publication-date bans are enabled
    • isRUCapsBanEnabled

      public boolean isRUCapsBanEnabled()
      Check the contradictory-reachability-caps ban is enabled.
      Returns:
      true if routers publishing both R and U are banned
    • isInvalidVersion

      public static boolean isInvalidVersion(String version)
      Whether a RouterInfo version is above every version that has been released, which makes the RouterInfo fabricated rather than merely old.
      Parameters:
      version - the version string from the RouterInfo, may be null
      Returns:
      true if the version is not a plausible released version
    • publishesContradictoryCaps

      public static boolean publishesContradictoryCaps(String caps)
      Whether a capability string claims to be reachable and unreachable at once. The two flags are mutually exclusive by definition, so a router publishing both has assembled its own RouterInfo rather than run a router that measured its reachability.
      Parameters:
      caps - the capability string, may be null
      Returns:
      true if both the R and U flags are present
    • shouldPurgeExistingRouters

      public boolean shouldPurgeExistingRouters()
      Check if a retroactive NetDb purge sweep is needed. True if LU/XG/introducer bans, the RouterInfo validation bans (version, publication date, reachability flags), or custom capability bans are enabled.
      Returns:
      true if existing routers should be purged
    • getCustomCapabilityBans

      public String getCustomCapabilityBans()
      Get custom capability ban pattern. Format: string of capability letters (e.g., "DG", "UX").
      Returns:
      the custom capability ban pattern, or empty string if none
    • shouldBanlistByCapability

      public String shouldBanlistByCapability(String capabilities)
      Check if router capabilities match any of the custom ban patterns.

      A pattern may carry an exclusion group after '!': "G!f" matches routers with G in their caps unless they are also floodfills. Exclusions require at least one required character.

      Comparison is case-sensitive throughout: capability letters are case-significant (lowercase 'f' is floodfill, uppercase letters are separate meanings), so neither the stored patterns nor the router's caps may be case-folded before matching.

      Parameters:
      capabilities - router capabilities string (e.g., "XfP")
      Returns:
      the matched pattern exactly as configured (e.g., "G!f") or null if no match
    • matchCapabilityPattern

      static String matchCapabilityPattern(String capabilities, String patternsStr)
      Pure decision helper: match a capabilities string against a comma/space-separated list of capability ban patterns.

      Each pattern is a set of required characters, optionally followed by '!'. A router matches when it carries every required character and none of the excluded ones. A pattern with an empty required part can never match, so a bare exclusion cannot ban the entire network. Case-sensitive: see shouldBanlistByCapability(String).

      Parameters:
      capabilities - router capabilities string, may be null
      patternsStr - configured patterns, may be null or empty
      Returns:
      the first matching pattern as configured, or null if none match
    • reduceDurations

      private void reduceDurations(long now)
      When the ban count exceeds BAN_COUNT_BASELINE, proportionally reduce remaining durations of eligible entries (between BAN_REDUCTION_MIN and BAN_REDUCTION_MAX) to keep the list manageable under memory pressure. Scaling: remaining *= max(MIN_BAN_SCALE, (double) BAN_COUNT_BASELINE / count).
      Parameters:
      now - the current time in ms, the reference for each entry's remaining duration
    • badPacket

      public void badPacket(String ip, String version)
      Record a bad packet from an IP. If threshold exceeded, ban the IP.
      Parameters:
      ip - IP address (format: "1.2.3.4" or "1.2.3.4:port")
      version - router version info (may be null)
    • badPacket

      public void badPacket(Hash hash, String version)
      Record a bad packet from a peer identified by its Router hash. Looks up the RouterInfo from the local netdb to extract the peer's IP address, caps, and version for threshold tracking and full-context BanLogger output. Silently returns if the RouterInfo is not in the netdb or has no reachable address.

      Prefer this overload when a Router hash is available at the call site; otherwise use badPacket(String, String) for IP-only tracking.

      Parameters:
      hash - Router hash (non-null, must exist in local netdb)
      version - router version info (may be null, falls back to RouterInfo version)
    • corruptConnection

      public void corruptConnection(String ip, String version)
      Record a corrupt connection (EOF/no data during establishment) from an IP. If threshold exceeded, ban the IP.
      Parameters:
      ip - IP address (format: "1.2.3.4" or "1.2.3.4:port")
      version - router version info (may be null)
    • corruptConnection

      public void corruptConnection(Hash hash, String version)
      Record a corrupt connection from a peer identified by its Router hash. Looks up the RouterInfo from the local netdb to extract the peer's IP address, caps, and version for threshold tracking and full-context BanLogger output. Silently returns if the RouterInfo is not in the netdb or has no reachable address.

      Prefer this overload when a Router hash is available at the call site; otherwise use corruptConnection(String, String) for IP-only tracking.

      Parameters:
      hash - Router hash (non-null, must exist in local netdb)
      version - router version info (may be null, falls back to RouterInfo version)
    • portHopping

      public void portHopping(String ip)
      Record a port hopping attempt from an IP. If threshold exceeded, ban the IP.
      Parameters:
      ip - IP address (format: "1.2.3.4")
    • portHopping

      public void portHopping(Hash hash)
      Record a port hopping attempt from a peer identified by its Router hash. Looks up the RouterInfo from the local netdb to extract the peer's IP address, caps, and version for threshold tracking and full-context BanLogger output. Silently returns if the RouterInfo is not in the netdb or has no reachable address.

      Prefer this overload when a Router hash is available at the call site; otherwise use portHopping(String) for IP-only tracking.

      Parameters:
      hash - Router hash (non-null, must exist in local netdb)
    • getRouterIP

      private static String getRouterIP(RouterInfo ri)
      Extract the first reachable IP from a RouterInfo's address list. Iterates over all published addresses and returns the host portion of the first one that has a non-null host string. This is used by the Hash-based overloads to obtain an IP for threshold tracking when the caller only has a Router hash.
      Parameters:
      ri - RouterInfo to extract from (null-safe)
      Returns:
      the IP address string, or null if no address has a host
    • getRouterCount

      public int getRouterCount()
      Number of currently banlisted routers.
      Returns:
      the size of the ban map
    • getEntries

      public Map<Hash, Banlist.Entry> getEntries()
      Get the banlist entries. For BanlistRenderer in router console. Note - may contain expired entries.
      Returns:
      an unmodifiable map of router hashes to banlist entries
    • banlistRouter

      public boolean banlistRouter(Hash peer)
      Ban a router with default duration.
      Parameters:
      peer - the router hash to ban
      Returns:
      true if it WAS previously on the list
    • banlistRouter

      public boolean banlistRouter(Hash peer, String reason)
      Ban a router with default duration.
      Parameters:
      peer - the router hash to ban
      reason - the human-readable cause of the ban, stored in the entry and shown in the console
      Returns:
      true if it WAS previously on the list
    • banlistRouter

      public boolean banlistRouter(String reasonCode, Hash peer, String reason)
      Ban a router with default duration.
      Parameters:
      reasonCode - separate code so cause can contain {0} for translation
      peer - the router hash to ban
      reason - the human-readable cause of the ban, stored in the entry and shown in the console
      Returns:
      true if it WAS previously on the list
    • banlistRouter

      public boolean banlistRouter(Hash peer, String reason, String transport)
      Ban a router on a specific transport.
      Parameters:
      peer - the router hash to ban
      reason - the human-readable cause of the ban, stored in the entry and shown in the console
      transport - the transport name to restrict the ban to; null bans on every transport
      Returns:
      true if it WAS previously on the list
    • banlistRouterForever

      public boolean banlistRouterForever(Hash peer, String reason)
      Permanently ban a router.
      Parameters:
      peer - the router hash to ban
      reason - the human-readable cause of the ban, stored in the entry and shown in the console
      Returns:
      true if it WAS previously on the list
    • banlistRouterForever

      public boolean banlistRouterForever(Hash peer, String reason, String reasonCode)
      Permanently ban a router.
      Parameters:
      peer - the router hash to ban
      reason - the human-readable cause of the ban, stored in the entry and shown in the console
      reasonCode - separate code so cause can contain {0} for translation
      Returns:
      true if it WAS previously on the list
    • banlistRouter

      public boolean banlistRouter(Hash peer, String reason, String transport, boolean forever)
      Ban a router with configurable duration and transport.
      Parameters:
      peer - the router hash to ban
      reason - the human-readable cause of the ban, stored in the entry and shown in the console
      transport - the transport name to restrict the ban to; null bans on every transport
      forever - if true, ban permanently
      Returns:
      true if it WAS previously on the list
    • banlistRouter

      private boolean banlistRouter(Hash peer, String reason, String reasonCode, String transport, boolean forever)
      Ban a router with automatic duration calculation.
      Parameters:
      peer - the router hash to ban
      reason - the human-readable cause of the ban, stored in the entry and shown in the console
      reasonCode - separate code so cause can contain {0} for translation (may be null)
      transport - the transport name to restrict the ban to; null bans on every transport
      forever - if true, ban permanently
      Returns:
      true if it WAS previously on the list
    • banlistRouter

      public boolean banlistRouter(Hash peer, String reason, String reasonCode, String transport, long expireOn)
      Ban a router with a specified expiration time.
      Parameters:
      peer - the router hash to ban
      reason - the human-readable cause of the ban, stored in the entry and shown in the console
      reasonCode - separate code so cause can contain {0} for translation (may be null)
      transport - the transport name to restrict the ban to; null bans on every transport
      expireOn - absolute time when the ban expires, not a duration
      Returns:
      true if it WAS previously on the list
      Throws:
      IllegalArgumentException - if expireOn is before the earliest valid time
    • unbanlistRouter

      public void unbanlistRouter(Hash peer)
      Remove a router from the banlist.
      Parameters:
      peer - the router hash to remove from banlist
    • unbanlistRouter

      private void unbanlistRouter(Hash peer, boolean realUnbanlist)
      Remove a peer from the banlist, optionally updating message history.
      Parameters:
      peer - the router hash to remove from banlist
      realUnbanlist - if true, update message history
    • unbanlistRouter

      public void unbanlistRouter(Hash peer, String transport)
      Remove a router from the banlist for a specific transport.
      Parameters:
      peer - the router hash to remove from banlist
      transport - the transport name whose ban to lift; null lifts the ban on every transport
    • unbanlistRouter

      private void unbanlistRouter(Hash peer, boolean realUnbanlist, String transport)
      Remove a router from the banlist.
      Parameters:
      peer - the router hash to remove from banlist
      realUnbanlist - if true, update message history
      transport - the transport name whose ban to lift; null lifts the ban on every transport
    • isBanlisted

      public boolean isBanlisted(Hash peer)
      Check if a router is banlisted.
      Parameters:
      peer - the router hash to check
      Returns:
      true if the router is banlisted on any transport
    • isBanlisted

      public boolean isBanlisted(Hash peer, String transport)
      Check if a router is banlisted on a specific transport.
      Parameters:
      peer - the router hash to check
      transport - the transport name to check; null matches a ban on any transport
      Returns:
      true if the router is banlisted on the specified transport
    • isBanlistedForever

      public boolean isBanlistedForever(Hash peer)
      Check if a router is permanently banlisted.
      Parameters:
      peer - the router hash to check
      Returns:
      true if the router is permanently banlisted
    • isBanlistedHostile

      public boolean isBanlistedHostile(Hash peer)
      Check if a router is banlisted with a hostile duration (at least 1 hour).
      Parameters:
      peer - the router hash to check
      Returns:
      true if the router is banlisted with hostile duration
    • getBanAge

      public long getBanAge(Hash peer)
      How long the banlist has been holding a peer, in milliseconds.

      This is the discriminator between the two reasons a build request arrives naming a banlisted peer, which need different fixes:

      • old age — the ban predates the build, so peer selection handed out a peer the banlist already held, which is a selection bug;
      • young age — the ban landed while the build was in flight, so the selection was correct and only a selection-time cooldown would stop the next request repeating it.
      The ban duration class cannot substitute: a peer permanently banned mid-flight and one banned last week both report as permanent.
      Parameters:
      peer - the router hash to check
      Returns:
      age of the standing ban in ms, or -1 if the peer is not currently banlisted or the entry predates this field
    • getBanCause

      public String getBanCause(Hash peer)
      Reason recorded when the peer was banlisted.

      Diagnostic only. A rejected tunnel build says a peer was banned but not why, so a burst of rejections cannot be attributed to a cause. Without it the only way to find out which subsystem is banning peers is to add temporary logging to each caller.

      Parameters:
      peer - the router hash to check
      Returns:
      the recorded cause code or reason, or null when the peer is not currently banlisted or no cause was recorded