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_FILE |
static String |
BLOCKLIST_FILE_DEFAULT |
static String |
ID_FEED
For Update Manager
|
static String |
ID_SYBIL |
Constructor and Description |
---|
Blocklist(RouterContext context)
Router MUST call startup()
|
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(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 |
addCountryFile()
The blocklist-country.txt file was created or updated.
|
void |
disable() |
int |
getBlocklistSize()
Size of permanent blocklist
Public for console only, not a public API
|
static int |
getFrom(long entry)
Public for console only, not a public API
|
long[] |
getPermanentBlocks(int max)
IP ranges blocked until restart.
|
static int |
getTo(long entry)
Public for console only, not a public API
|
List<Integer> |
getTransientIPv4Blocks()
Single IPs blocked until restart.
|
List<BigInteger> |
getTransientIPv6Blocks()
Single IPs blocked until restart.
|
boolean |
isBlocklisted(byte[] ip)
calling this externally won't banlist the peer, this is just an IP check
|
boolean |
isBlocklisted(Hash peer)
Does the peer's IP address appear in the blocklist?
If so, and it isn't banlisted, banlist it forever...
|
boolean |
isBlocklisted(RouterInfo pinfo)
Does the peer's IP address appear in the blocklist?
If so, and it isn't banlisted, banlist it forever...
|
boolean |
isBlocklisted(String ip)
calling this externally won't banlist the peer, this is just an IP check
|
boolean |
isPermanentlyBlocklisted(int ip)
Do a binary search through the in-memory range list which
is a sorted array of longs.
|
void |
remove(byte[] ip)
Remove from the in-memory single-IP blocklist.
|
void |
renderStatusHTML(Writer out)
Deprecated.
|
void |
startup()
Loads the following files in-order:
$I2P/blocklist.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)
Public for console only, not a public API
|
public static final String BLOCKLIST_FILE_DEFAULT
public static final String BLOCKLIST_COUNTRY_FILE
public static final String ID_FEED
public static final String ID_SYBIL
public Blocklist(RouterContext context)
public void startup()
public void addCountryFile()
public void disable()
public void add(String ip)
ip
- IPv4 or IPv6public void add(byte[] ip)
ip
- IPv4 or IPv6public void remove(byte[] ip)
ip
- IPv4 or IPv6public boolean isBlocklisted(Hash peer)
public boolean isBlocklisted(RouterInfo pinfo)
public boolean isBlocklisted(String ip)
ip
- IPv4 or IPv6public boolean isBlocklisted(byte[] ip)
ip
- IPv4 or IPv6public boolean isPermanentlyBlocklisted(int ip)
public static int getFrom(long entry)
public static int getTo(long entry)
public static String toStr(int ip)
public List<Integer> getTransientIPv4Blocks()
public List<BigInteger> getTransientIPv6Blocks()
public long[] getPermanentBlocks(int max)
max
- maximum entries to returnpublic int getBlocklistSize()
@Deprecated public void renderStatusHTML(Writer out) throws IOException
IOException