public class Blocklist extends Object
1) The list of IP ranges, read in from a file at startup 2) The list of hashes, read in from the same file 3) A list of single IPs, initially empty, added to as neededRead in the IP blocklist from a file, store it in-memory as efficiently as we can, and perform tests against it as requested. When queried for a peer that is blocklisted but isn't banlisted, banlist it forever, then go back to the file to get the original entry so we can add the reason to the banlist text. On-disk blocklist supports IPv4 only. In-memory supports both IPv4 and IPv6.
| Modifier and Type | Field and Description |
|---|---|
static String | BLOCKLIST_COUNTRY_FILECountry-based blocklist filename. |
static String | BLOCKLIST_FILE_DEFAULTDefault blocklist filename in the installation directory. |
static String | BLOCKLIST_FILE_TOR_EXITSTor exit nodes blocklist filename. |
static String | ID_FEEDFor Update Manager |
static String | ID_SYBILSybil attack blocklist ID |
static String | ID_TORTor exit nodes blocklist ID |
| Constructor and Description |
|---|
Blocklist(RouterContext context)Constructor. |
| Modifier and Type | Method and Description |
|---|---|
void | add(byte[] ip)Maintain a simple in-memory single-IP blocklist
This is used for new additions, NOT for the main list
of IP ranges read in from the file. |
void | add(byte[] ip,
String source)Maintain a simple in-memory single-IP blocklist
This is used for new additions, NOT for the main list
of IP ranges read in from the file. |
void | add(String ip)Maintain a simple in-memory single-IP blocklist
This is used for new additions, NOT for the main list
of IP ranges read in from the file. |
void | add(String ip,
String source)Maintain a simple in-memory single-IP blocklist
This is used for new additions, NOT for the main list
of IP ranges read in from the file. |
void | addCountryFile()The blocklist-country.txt file was created or updated. |
void | clearAll()Clear all blocked IPs and peers. |
void | disable()Disable the blocklist and clear all entries. |
int | getBlocklistSize()Get the size of the permanent blocklist. |
static int | getFrom(long entry)Extract the starting IP from a compressed blocklist entry. |
long[] | getPermanentBlocks(int max)IP ranges blocked until restart. |
static int | getTo(long entry)Extract the ending IP from a compressed blocklist entry. |
List<Integer> | getTransientIPv4Blocks()Single IPs blocked until restart. |
List<BigInteger> | getTransientIPv6Blocks()Single IPs blocked until restart. |
boolean | isBlocklisted(byte[] ip)Check if an IP address is blocklisted. |
boolean | isBlocklisted(Hash peer)Check if a peer is blocklisted by IP address. |
boolean | isBlocklisted(RouterInfo pinfo)Check if a peer is blocklisted by IP address. |
boolean | isBlocklisted(String ip)Check if an IP address is blocklisted. |
boolean | isBlocklistEnabled()Check if blocklist is enabled. |
boolean | isCountryBlocklistEnabled()Check if country blocklist is enabled. |
boolean | isPermanentlyBlocklisted(int ip)Check if an IP is permanently blocklisted using binary search. |
boolean | isTorBlocklistEnabled()Check if Tor blocklist is enabled. |
void | reloadConfig()Reload configuration from properties. |
void | remove(byte[] ip)Remove from the in-memory single-IP blocklist. |
void | startup()Loads the following files in-order:
$I2P/blocklist.txt
$I2P/blocklist_tor.txt
~/.i2p/blocklist.txt
~/.i2p/docs/feed/blocklist/blocklist.txt
~/.i2p/blocklist-countries.txt
File if specified with router.blocklist.file |
static String | toStr(int ip)Convert an IPv4 address to a string representation. |
public static final String BLOCKLIST_COUNTRY_FILE
public static final String BLOCKLIST_FILE_DEFAULT
public static final String BLOCKLIST_FILE_TOR_EXITS
public static final String ID_FEED
public static final String ID_SYBIL
public static final String ID_TOR
public Blocklist(RouterContext context)
context - the router contextpublic void add(byte[] ip)
ip - IPv4 or IPv6public void add(byte[] ip,
String source)ip - IPv4 or IPv6source - for logging only, may be nullpublic void add(String ip)
ip - IPv4 or IPv6public void add(String ip, String source)
ip - IPv4 or IPv6source - for logging only, may be nullpublic void addCountryFile()
public void clearAll()
public void disable()
public int getBlocklistSize()
public static int getFrom(long entry)
entry - the compressed blocklist entrypublic long[] getPermanentBlocks(int max)
max - maximum entries to returnpublic static int getTo(long entry)
entry - the compressed blocklist entrypublic List<Integer> getTransientIPv4Blocks()
public List<BigInteger> getTransientIPv6Blocks()
public boolean isBlocklisted(byte[] ip)
ip - the IP address as a byte array (IPv4 or IPv6)public boolean isBlocklisted(Hash peer)
peer - the router hash to checkpublic boolean isBlocklisted(RouterInfo pinfo)
pinfo - the router info to checkpublic boolean isBlocklisted(String ip)
ip - the IP address as a string (IPv4 or IPv6)public boolean isBlocklistEnabled()
public boolean isCountryBlocklistEnabled()
public boolean isPermanentlyBlocklisted(int ip)
ip - the IPv4 address as an integerpublic boolean isTorBlocklistEnabled()
public void reloadConfig()
public void remove(byte[] ip)
ip - IPv4 or IPv6public void startup()
public static String toStr(int ip)
ip - the IPv4 address as an integer