public class BlocklistManager extends Object
This class handles two types of blocklists:
The blocklist files are located in the I2P config directory and are monitored for changes. The URL blocklist is compiled into a regex pattern for efficient matching.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CLIENT_LIMIT
Default maximum number of entries in the client blocklist
|
static String |
HTTP_BLOCKLIST
Default filename for the URL blocklist
|
static String |
HTTP_BLOCKLIST_CLIENTS
Default filename for the client blocklist
|
| Constructor and Description |
|---|
BlocklistManager(Log log,
int clientLimit)
Creates a new BlocklistManager.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
existsInClientBlocklist(String destination)
Checks if a destination exists in the client blocklist.
|
int |
getClientBlocklistSize()
Gets the current size of the client blocklist.
|
String |
getMatchedBlocklistString(StringBuilder command)
Gets the matched string from the blocklist for a request.
|
void |
logBlockedDestination(String destination)
Logs a blocked destination to the client blocklist.
|
boolean |
shouldBlockRequest(StringBuilder command)
Checks if a request should be blocked based on the URL blocklist.
|
public static final int DEFAULT_CLIENT_LIMIT
public static final String HTTP_BLOCKLIST
public static final String HTTP_BLOCKLIST_CLIENTS
public BlocklistManager(Log log, int clientLimit)
log - the Log instance for logging blocklist eventsclientLimit - the maximum number of entries to keep in the client blocklist;
if 0 or negative, uses DEFAULT_CLIENT_LIMITpublic boolean existsInClientBlocklist(String destination) throws IOException
This method checks if the given destination has been previously blocked. The blocklist file is monitored for changes and will be reloaded if modified.
destination - the Base32-encoded destination to checkIOException - if an I/O error occurspublic int getClientBlocklistSize()
public String getMatchedBlocklistString(StringBuilder command)
If shouldBlockRequest() returns true, this method can be called to retrieve the specific pattern that matched.
command - the HTTP request command containing the URLpublic void logBlockedDestination(String destination) throws IOException
This method adds the destination to the http_blocklist_clients.txt file if not already present. The client blocklist is used to track destinations that have been blocked, to prevent repeated abuse attempts.
The client blocklist has a maximum size limit. When the limit is reached, the oldest entry is removed before adding a new one.
destination - the Base32-encoded destination to logIOException - if an I/O error occurspublic boolean shouldBlockRequest(StringBuilder command)
This method checks if the request URL matches any pattern in the http_blocklist.txt file. The blocklist file is monitored for changes and will be reloaded if modified.
Each line in the blocklist file is treated as a literal string (not regex), case-insensitive matching is applied.
command - the HTTP request command containing the URL