public class BanLogger extends Object
This allows analysis of ban patterns without parsing router.log.
| Constructor and Description |
|---|
BanLogger(RouterContext context) |
| 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.
|
public BanLogger(RouterContext context)
public void archiveIfNeeded()
public boolean checkPatternAndPredict(Hash hash, RouterContext context)
hash - Router hash to checkcontext - RouterContext for banlist operationspublic void close()
public void flush()
public File getLogFile()
public void initialize(RouterContext context)
public static boolean isInitialized()
public void logBan(Hash hash, RouterContext context, String reason, long durationMs)
hash - Router hash (may be null)context - Router context for IP lookupreason - Reason for the bandurationMs - Ban duration in milliseconds, or 0 for permanentpublic void logBan(Hash hash, String ip, String reason, long durationMs)
hash - Router hash (may be null)ip - IP address with port (format: "1.2.3.4:5678" or "ipv6:port")reason - Reason for the bandurationMs - Ban duration in milliseconds, or 0 for permanentpublic void logBan(String ip, String reason, long durationMs)
ip - IP address with port (format: "1.2.3.4:5678" or "ipv6:port")reason - Reason for the bandurationMs - Ban duration in milliseconds, or 0 for permanentpublic void logBanForever(Hash hash, RouterContext context, String reason)
hash - Router hash (may be null)context - Router context for IP lookupreason - Reason for the banpublic void logBanForever(Hash hash, String ip, String reason)
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