net.i2p.router

## Class BanLogger

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

-     public class BanLogger
      extends Object

  Dedicated logger for all ban events. Writes to sessionbans.txt in the router's data directory.

  This allows analysis of ban patterns without parsing router.log.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BanLogger(RouterContext context)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `archiveIfNeeded()` Archive the current log when closing.
    `boolean` | `checkPatternAndPredict(Hash hash, RouterContext context)` Check if a router hash matches known attack patterns and should be predictively banned.
    `void` | `close()` Close the log writer and archive if there are entries.
    `void` | `flush()` Flush the log writer.
    `File` | `getLogFile()` Get the log file path.
    `void` | `initialize(RouterContext context)` Initialize the logger.
    `static boolean` | `isInitialized()` Check if the logger is initialized.
    `void` | `logBan(Hash hash, RouterContext context, String reason, long durationMs)` Log a ban by hash with RouterContext (IP will be looked up from banlist).
    `void` | `logBan(Hash hash, String ip, String reason, long durationMs)` Log a ban by hash with IP address.
    `void` | `logBan(String ip, String reason, long durationMs)` Log a ban by IP only (no router hash available).
    `void` | `logBanForever(Hash hash, RouterContext context, String reason)` Log a permanent ban with RouterContext.
    `void` | `logBanForever(Hash hash, String ip, String reason)` Log a permanent ban (forever).
    `void` | `logBanForever(String ip, String reason)` Log a permanent ban by IP only.

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

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

- - ### Constructor Detail

    - #### BanLogger

          public BanLogger(RouterContext context)

  - ### Method Detail

    - #### archiveIfNeeded

          public void archiveIfNeeded()

      Archive the current log when closing. Uses the router start time to timestamp the archive.

    - #### checkPatternAndPredict

          public boolean checkPatternAndPredict(Hash hash,
                                                RouterContext context)

      Check if a router hash matches known attack patterns and should be predictively banned. Call this BEFORE processing messages from a peer to proactively ban algorithmic identities.
      Parameters:
        `hash` - Router hash to check
        `context` - RouterContext for banlist operations
      Returns:
        true if predictively banned, false otherwise

    - #### close

          public void close()

      Close the log writer and archive if there are entries.

    - #### flush

          public void flush()

      Flush the log writer.

    - #### getLogFile

          public File getLogFile()

      Get the log file path.

    - #### initialize

          public void initialize(RouterContext context)

      Initialize the logger. Safe to call multiple times.

    - #### isInitialized

          public static boolean isInitialized()

      Check if the logger is initialized.

    - #### logBan

          public void logBan(Hash hash,
                             RouterContext context,
                             String reason,
                             long durationMs)

      Log a ban by hash with RouterContext (IP will be looked up from banlist).
      Parameters:
        `hash` - Router hash (may be null)
        `context` - Router context for IP lookup
        `reason` - Reason for the ban
        `durationMs` - Ban duration in milliseconds, or 0 for permanent

    - #### logBan

          public void logBan(Hash hash,
                             String ip,
                             String reason,
                             long durationMs)

      Log a ban by hash with IP address.
      Parameters:
        `hash` - Router hash (may be null)
        `ip` - IP address with port (format: "1.2.3.4:5678" or "ipv6:port")
        `reason` - Reason for the ban
        `durationMs` - Ban duration in milliseconds, or 0 for permanent

    - #### logBan

          public void logBan(String ip,
                             String reason,
                             long durationMs)

      Log a ban by IP only (no router hash available).
      Parameters:
        `ip` - IP address with port (format: "1.2.3.4:5678" or "ipv6:port")
        `reason` - Reason for the ban
        `durationMs` - Ban duration in milliseconds, or 0 for permanent

    - #### logBanForever

          public void logBanForever(Hash hash,
                                    RouterContext context,
                                    String reason)

      Log a permanent ban with RouterContext.
      Parameters:
        `hash` - Router hash (may be null)
        `context` - Router context for IP lookup
        `reason` - Reason for the ban

    - #### logBanForever

          public void logBanForever(Hash hash,
                                    String ip,
                                    String reason)

      Log a permanent ban (forever).
      Parameters:
        `hash` - Router hash (may be null)
        `ip` - IP address with port (format: "1.2.3.4:5678" or "ipv6:port")
        `reason` - Reason for the ban

    - #### logBanForever

          public void logBanForever(String ip,
                                    String reason)

      Log a permanent ban by IP only.