net.i2p.router

## Class Banlist

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

-     public class Banlist
      extends 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.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Banlist.Entry` Entry representing a banned peer with expiration and reason information

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static long` | `BANLIST_DURATION_FOREVER` Permanent ban duration (will be rounded down to 180 days on console).
    `static long` | `BANLIST_DURATION_MAX` Maximum ban duration for transient bans.
    `static long` | `BANLIST_DURATION_MS` Default ban duration for transient bans.
    `static long` | `BANLIST_DURATION_NO_NETWORK` Buggy i2pd fork
    `static long` | `BANLIST_DURATION_PARTIAL` Default ban duration for transport-specific bans.
    `static long` | `BANLIST_DURATION_PRIVATE` Ban duration for private IP addresses.
    `static Hash` | `HASH_ZERORI` hash of 387 zeros

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Banlist(RouterContext context)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `banlistRouter(Hash peer)` Ban a router with default duration.
    `boolean` | `banlistRouter(Hash peer, String reason)` Ban a router with default duration.
    `boolean` | `banlistRouter(Hash peer, String reason, String transport)` Ban a router on a specific transport.
    `boolean` | `banlistRouter(Hash peer, String reason, String transport, boolean forever)` Ban a router with configurable duration and transport.
    `boolean` | `banlistRouter(Hash peer, String reason, String reasonCode, String transport, long expireOn)` Ban a router with a specified expiration time.
    `boolean` | `banlistRouter(String reasonCode, Hash peer, String reason)` Ban a router with default duration.
    `boolean` | `banlistRouterForever(Hash peer, String reason)` Permanently ban a router.
    `boolean` | `banlistRouterForever(Hash peer, String reason, String reasonCode)` Permanently ban a router.
    `Map<Hash,Banlist.Entry>` | `getEntries()` Get the banlist entries.
    `int` | `getRouterCount()` Get the number of currently banlisted routers.
    `boolean` | `isBanlisted(Hash peer)` Check if a router is banlisted.
    `boolean` | `isBanlisted(Hash peer, String transport)` Check if a router is banlisted on a specific transport.
    `boolean` | `isBanlistedForever(Hash peer)` Check if a router is permanently banlisted.
    `boolean` | `isBanlistedHostile(Hash peer)` Check if a router is banlisted with a hostile duration (at least 1 hour).
    `void` | `unbanlistRouter(Hash peer)` Remove a router from the banlist.
    `void` | `unbanlistRouter(Hash peer, String transport)` Remove a router from the banlist for a specific transport.

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

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

- - ### Field Detail

    - #### BANLIST_DURATION_FOREVER

          public static final long BANLIST_DURATION_FOREVER

      Permanent ban duration (will be rounded down to 180 days on console).
      See Also:
        Constant Field Values

    - #### BANLIST_DURATION_MAX

          public static final long BANLIST_DURATION_MAX

      Maximum ban duration for transient bans.
      See Also:
        Constant Field Values

    - #### BANLIST_DURATION_MS

          public static final long BANLIST_DURATION_MS

      Default ban duration for transient bans.
      See Also:
        Constant Field Values

    - #### BANLIST_DURATION_NO_NETWORK

          public static final long BANLIST_DURATION_NO_NETWORK

      Buggy i2pd fork
      See Also:
        Constant Field Values

    - #### BANLIST_DURATION_PARTIAL

          public static final long BANLIST_DURATION_PARTIAL

      Default ban duration for transport-specific bans.
      See Also:
        Constant Field Values

    - #### BANLIST_DURATION_PRIVATE

          public static final long BANLIST_DURATION_PRIVATE

      Ban duration for private IP addresses.
      See Also:
        Constant Field Values

    - #### HASH_ZERORI

          public static final Hash HASH_ZERORI

      hash of 387 zeros

  - ### Constructor Detail

    - #### Banlist

          public Banlist(RouterContext context)

      Constructor.
      Parameters:
        `context` - the router context

  - ### Method Detail

    - #### 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 reason for the ban (may be null)
      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 reason for the ban (may be null)
        `transport` - the transport to ban (may be null for all transports)
      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 reason for the ban (may be null)
        `transport` - the transport to ban (may be null for all transports)
        `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 reason for the ban (may be null)
        `reasonCode` - separate code so cause can contain {0} for translation (may be null)
        `transport` - the transport to ban (may be null for all transports)
        `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

    - #### 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 reason for the ban (may be null)
      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 reason for the ban (may be null)
      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 reason for the ban (may be null)
        `reasonCode` - separate code so cause can contain {0} for translation
      Returns:
        true if it WAS previously on the list

    - #### 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

    - #### getRouterCount

          public int getRouterCount()

      Get the number of currently banlisted routers.
      Returns:
        the number of currently banlisted routers

    - #### 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 to check (may be null)
      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

    - #### unbanlistRouter

          public void unbanlistRouter(Hash peer)

      Remove a router from the banlist.
      Parameters:
        `peer` - the router hash to remove from banlist

    - #### 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 to unban (may be null for all transports)