forked from I2P_Developers/i2p.i2p
* Blocklist:
- Fix delayed lookup of reason from file - Tag strings for translation - Sort IPs on configpeer.jsp correctly - Cleanups
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
2011-07-13 zzz
|
||||||
|
* Blocklist:
|
||||||
|
- Fix delayed lookup of reason from file
|
||||||
|
- Tag strings for translation
|
||||||
|
- Sort IPs on configpeer.jsp correctly
|
||||||
|
* SummaryHelper: Fix NPE at startup (ticket #493)
|
||||||
|
|
||||||
2011-07-10 zzz
|
2011-07-10 zzz
|
||||||
* DH, YK:
|
* DH, YK:
|
||||||
- Improve YK speed test
|
- Improve YK speed test
|
||||||
|
@@ -30,6 +30,7 @@ import net.i2p.data.RouterInfo;
|
|||||||
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
|
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
|
||||||
import net.i2p.util.ConcurrentHashSet;
|
import net.i2p.util.ConcurrentHashSet;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
import net.i2p.util.Translate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage blocking by IP address, in a manner similar to the Shitlist,
|
* Manage blocking by IP address, in a manner similar to the Shitlist,
|
||||||
@@ -60,7 +61,7 @@ import net.i2p.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class Blocklist {
|
public class Blocklist {
|
||||||
private final Log _log;
|
private final Log _log;
|
||||||
private RouterContext _context;
|
private final RouterContext _context;
|
||||||
private long _blocklist[];
|
private long _blocklist[];
|
||||||
private int _blocklistSize;
|
private int _blocklistSize;
|
||||||
private final Object _lock = new Object();
|
private final Object _lock = new Object();
|
||||||
@@ -75,7 +76,8 @@ public class Blocklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** only for testing with main() */
|
/** only for testing with main() */
|
||||||
public Blocklist() {
|
private Blocklist() {
|
||||||
|
_context = null;
|
||||||
_log = new Log(Blocklist.class);
|
_log = new Log(Blocklist.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +100,7 @@ public class Blocklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class ReadinJob extends JobImpl {
|
private class ReadinJob extends JobImpl {
|
||||||
private String _file;
|
private final String _file;
|
||||||
public ReadinJob (String f) {
|
public ReadinJob (String f) {
|
||||||
super(_context);
|
super(_context);
|
||||||
_file = f;
|
_file = f;
|
||||||
@@ -261,10 +263,10 @@ public class Blocklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class Entry {
|
private static class Entry {
|
||||||
String comment;
|
final String comment;
|
||||||
byte ip1[];
|
final byte ip1[];
|
||||||
byte ip2[];
|
final byte ip2[];
|
||||||
Hash peer;
|
final Hash peer;
|
||||||
|
|
||||||
public Entry(String c, Hash h, byte[] i1, byte[] i2) {
|
public Entry(String c, Hash h, byte[] i1, byte[] i2) {
|
||||||
comment = c;
|
comment = c;
|
||||||
@@ -428,9 +430,11 @@ public class Blocklist {
|
|||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maintain a simple in-memory single-IP blocklist
|
/**
|
||||||
// This is used for new additions, NOT for the main list
|
* Maintain a simple in-memory single-IP blocklist
|
||||||
// of IP ranges read in from the file.
|
* This is used for new additions, NOT for the main list
|
||||||
|
* of IP ranges read in from the file.
|
||||||
|
*/
|
||||||
public void add(String ip) {
|
public void add(String ip) {
|
||||||
InetAddress pi;
|
InetAddress pi;
|
||||||
try {
|
try {
|
||||||
@@ -443,6 +447,11 @@ public class Blocklist {
|
|||||||
add(pib);
|
add(pib);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
public void add(byte ip[]) {
|
public void add(byte ip[]) {
|
||||||
if (ip.length != 4)
|
if (ip.length != 4)
|
||||||
return;
|
return;
|
||||||
@@ -513,7 +522,9 @@ public class Blocklist {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calling this externally won't shitlist the peer, this is just an IP check
|
/**
|
||||||
|
* calling this externally won't shitlist the peer, this is just an IP check
|
||||||
|
*/
|
||||||
public boolean isBlocklisted(String ip) {
|
public boolean isBlocklisted(String ip) {
|
||||||
InetAddress pi;
|
InetAddress pi;
|
||||||
try {
|
try {
|
||||||
@@ -526,7 +537,9 @@ public class Blocklist {
|
|||||||
return isBlocklisted(pib);
|
return isBlocklisted(pib);
|
||||||
}
|
}
|
||||||
|
|
||||||
// calling this externally won't shitlist the peer, this is just an IP check
|
/**
|
||||||
|
* calling this externally won't shitlist the peer, this is just an IP check
|
||||||
|
*/
|
||||||
public boolean isBlocklisted(byte ip[]) {
|
public boolean isBlocklisted(byte ip[]) {
|
||||||
if (ip.length != 4)
|
if (ip.length != 4)
|
||||||
return false;
|
return false;
|
||||||
@@ -630,6 +643,7 @@ public class Blocklist {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** IP to string */
|
||||||
public static String toStr(byte[] ip) {
|
public static String toStr(byte[] ip) {
|
||||||
return toStr(toInt(ip));
|
return toStr(toInt(ip));
|
||||||
}
|
}
|
||||||
@@ -667,7 +681,7 @@ public class Blocklist {
|
|||||||
public void shitlist(Hash peer) {
|
public void shitlist(Hash peer) {
|
||||||
// Temporary reason, until the job finishes
|
// Temporary reason, until the job finishes
|
||||||
_context.shitlist().shitlistRouterForever(peer, _x("IP banned"));
|
_context.shitlist().shitlistRouterForever(peer, _x("IP banned"));
|
||||||
if (! "true".equals( _context.getProperty(PROP_BLOCKLIST_DETAIL, "true")))
|
if (! _context.getBooleanPropertyDefaultTrue(PROP_BLOCKLIST_DETAIL))
|
||||||
return;
|
return;
|
||||||
boolean shouldRunJob;
|
boolean shouldRunJob;
|
||||||
int number;
|
int number;
|
||||||
@@ -677,21 +691,24 @@ public class Blocklist {
|
|||||||
}
|
}
|
||||||
if (!shouldRunJob)
|
if (!shouldRunJob)
|
||||||
return;
|
return;
|
||||||
Job job = new ShitlistJob(peer);
|
// get the IPs now because it won't be in the netdb by the time the job runs
|
||||||
|
Job job = new ShitlistJob(peer, getAddresses(peer));
|
||||||
if (number > 0)
|
if (number > 0)
|
||||||
job.getTiming().setStartAfter(_context.clock().now() + (30*1000l * number));
|
job.getTiming().setStartAfter(_context.clock().now() + (30*1000l * number));
|
||||||
_context.jobQueue().addJob(job);
|
_context.jobQueue().addJob(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ShitlistJob extends JobImpl {
|
private class ShitlistJob extends JobImpl {
|
||||||
private Hash _peer;
|
private final Hash _peer;
|
||||||
public ShitlistJob (Hash p) {
|
private final List<byte[]> _ips;
|
||||||
|
public ShitlistJob (Hash p, List<byte[]> ips) {
|
||||||
super(_context);
|
super(_context);
|
||||||
_peer = p;
|
_peer = p;
|
||||||
|
_ips = ips;
|
||||||
}
|
}
|
||||||
public String getName() { return "Ban Peer by IP"; }
|
public String getName() { return "Ban Peer by IP"; }
|
||||||
public void runJob() {
|
public void runJob() {
|
||||||
shitlistForever(_peer);
|
shitlistForever(_peer, _ips);
|
||||||
synchronized (_inProcess) {
|
synchronized (_inProcess) {
|
||||||
_inProcess.remove(_peer);
|
_inProcess.remove(_peer);
|
||||||
}
|
}
|
||||||
@@ -707,7 +724,7 @@ public class Blocklist {
|
|||||||
* So we also stagger these jobs.
|
* So we also stagger these jobs.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private synchronized void shitlistForever(Hash peer) {
|
private synchronized void shitlistForever(Hash peer, List<byte[]> ips) {
|
||||||
String file = _context.getProperty(PROP_BLOCKLIST_FILE, BLOCKLIST_FILE_DEFAULT);
|
String file = _context.getProperty(PROP_BLOCKLIST_FILE, BLOCKLIST_FILE_DEFAULT);
|
||||||
File BLFile = new File(file);
|
File BLFile = new File(file);
|
||||||
if (!BLFile.isAbsolute())
|
if (!BLFile.isAbsolute())
|
||||||
@@ -719,7 +736,6 @@ public class Blocklist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// look through the file for each address to find which one was the cause
|
// look through the file for each address to find which one was the cause
|
||||||
List ips = getAddresses(peer);
|
|
||||||
for (Iterator<byte[]> iter = ips.iterator(); iter.hasNext(); ) {
|
for (Iterator<byte[]> iter = ips.iterator(); iter.hasNext(); ) {
|
||||||
byte ip[] = iter.next();
|
byte ip[] = iter.next();
|
||||||
int ipint = toInt(ip);
|
int ipint = toInt(ip);
|
||||||
@@ -763,25 +779,67 @@ public class Blocklist {
|
|||||||
|
|
||||||
private static final int MAX_DISPLAY = 1000;
|
private static final int MAX_DISPLAY = 1000;
|
||||||
|
|
||||||
/** write directly to the stream so we don't OOM on a huge list */
|
/**
|
||||||
|
* Write directly to the stream so we don't OOM on a huge list.
|
||||||
|
* Go through each list twice since we store out-of-order.
|
||||||
|
*/
|
||||||
public void renderStatusHTML(Writer out) throws IOException {
|
public void renderStatusHTML(Writer out) throws IOException {
|
||||||
// move to the jsp
|
// move to the jsp
|
||||||
//out.write("<h2>Banned IPs</h2>");
|
//out.write("<h2>Banned IPs</h2>");
|
||||||
Set<Integer> singles = new TreeSet();
|
Set<Integer> singles = new TreeSet();
|
||||||
singles.addAll(_singleIPBlocklist);
|
singles.addAll(_singleIPBlocklist);
|
||||||
if (!singles.isEmpty()) {
|
if (!singles.isEmpty()) {
|
||||||
out.write("<table><tr><td><b>Transient IPs</b></td></tr>");
|
out.write("<table><tr><th align=center colspan=2><b>");
|
||||||
for (Iterator<Integer> iter = singles.iterator(); iter.hasNext(); ) {
|
out.write(_("IPs Banned Until Restart"));
|
||||||
int ip = iter.next().intValue();
|
out.write("</b></td></tr>");
|
||||||
out.write("<tr><td align=right>"); out.write(toStr(ip)); out.write("</td></tr>\n");
|
// first 0 - 127
|
||||||
|
for (Integer ii : singles) {
|
||||||
|
int ip = ii.intValue();
|
||||||
|
if (ip < 0)
|
||||||
|
continue;
|
||||||
|
out.write("<tr><td align=center width=50%>");
|
||||||
|
out.write(toStr(ip));
|
||||||
|
out.write("</td><td width=50%> </td></tr>\n");
|
||||||
|
}
|
||||||
|
// then 128 - 255
|
||||||
|
for (Integer ii : singles) {
|
||||||
|
int ip = ii.intValue();
|
||||||
|
if (ip >= 0)
|
||||||
|
break;
|
||||||
|
out.write("<tr><td align=center width=50%>");
|
||||||
|
out.write(toStr(ip));
|
||||||
|
out.write("</td><td width=50%> </td></tr>\n");
|
||||||
}
|
}
|
||||||
out.write("</table>");
|
out.write("</table>");
|
||||||
}
|
}
|
||||||
if (_blocklistSize > 0) {
|
if (_blocklistSize > 0) {
|
||||||
out.write("<table><tr><th align=center colspan=2><b>IPs from Blocklist File</b></th></tr><tr><td align=center width=50%><b>From:</b></td><td align=center width=50%><b>To:</b></td></tr>");
|
out.write("<table><tr><th align=center colspan=2><b>");
|
||||||
|
out.write(_("IPs Permanently Banned"));
|
||||||
|
out.write("</b></th></tr><tr><td align=center width=50%><b>");
|
||||||
|
out.write(_("From"));
|
||||||
|
out.write("</b></td><td align=center width=50%><b>");
|
||||||
|
out.write(_("To"));
|
||||||
|
out.write("</b></td></tr>");
|
||||||
int max = Math.min(_blocklistSize, MAX_DISPLAY);
|
int max = Math.min(_blocklistSize, MAX_DISPLAY);
|
||||||
|
int displayed = 0;
|
||||||
|
// first 0 - 127
|
||||||
for (int i = 0; i < max; i++) {
|
for (int i = 0; i < max; i++) {
|
||||||
int from = getFrom(_blocklist[i]);
|
int from = getFrom(_blocklist[i]);
|
||||||
|
if (from < 0)
|
||||||
|
continue;
|
||||||
|
out.write("<tr><td align=center width=50%>"); out.write(toStr(from)); out.write("</td><td align=center width=50%>");
|
||||||
|
int to = getTo(_blocklist[i]);
|
||||||
|
if (to != from) {
|
||||||
|
out.write(toStr(to)); out.write("</td></tr>\n");
|
||||||
|
} else
|
||||||
|
out.write(" </td></tr>\n");
|
||||||
|
displayed++;
|
||||||
|
}
|
||||||
|
// then 128 - 255
|
||||||
|
for (int i = 0; i < max && displayed++ < max; i++) {
|
||||||
|
int from = getFrom(_blocklist[i]);
|
||||||
|
if (from >= 0)
|
||||||
|
break;
|
||||||
out.write("<tr><td align=center width=50%>"); out.write(toStr(from)); out.write("</td><td align=center width=50%>");
|
out.write("<tr><td align=center width=50%>"); out.write(toStr(from)); out.write("</td><td align=center width=50%>");
|
||||||
int to = getTo(_blocklist[i]);
|
int to = getTo(_blocklist[i]);
|
||||||
if (to != from) {
|
if (to != from) {
|
||||||
@@ -790,11 +848,14 @@ public class Blocklist {
|
|||||||
out.write(" </td></tr>\n");
|
out.write(" </td></tr>\n");
|
||||||
}
|
}
|
||||||
if (_blocklistSize > MAX_DISPLAY)
|
if (_blocklistSize > MAX_DISPLAY)
|
||||||
|
// very rare, don't bother translating
|
||||||
out.write("<tr><th colspan=2>First " + MAX_DISPLAY + " displayed, see the " +
|
out.write("<tr><th colspan=2>First " + MAX_DISPLAY + " displayed, see the " +
|
||||||
BLOCKLIST_FILE_DEFAULT + " file for the full list</th></tr>");
|
BLOCKLIST_FILE_DEFAULT + " file for the full list</th></tr>");
|
||||||
out.write("</table>");
|
out.write("</table>");
|
||||||
} else {
|
} else {
|
||||||
out.write("<br><i>No blocklist file entries.</i>");
|
out.write("<br><i>");
|
||||||
|
out.write(_("none"));
|
||||||
|
out.write("</i>");
|
||||||
}
|
}
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
@@ -809,6 +870,13 @@ public class Blocklist {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String BUNDLE_NAME = "net.i2p.router.web.messages";
|
||||||
|
|
||||||
|
/** translate */
|
||||||
|
private String _(String key) {
|
||||||
|
return Translate.getString(key, _context, BUNDLE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
Blocklist b = new Blocklist();
|
Blocklist b = new Blocklist();
|
||||||
if ( (args != null) && (args.length == 1) )
|
if ( (args != null) && (args.length == 1) )
|
||||||
|
@@ -18,7 +18,7 @@ public class RouterVersion {
|
|||||||
/** deprecated */
|
/** deprecated */
|
||||||
public final static String ID = "Monotone";
|
public final static String ID = "Monotone";
|
||||||
public final static String VERSION = CoreVersion.VERSION;
|
public final static String VERSION = CoreVersion.VERSION;
|
||||||
public final static long BUILD = 9;
|
public final static long BUILD = 10;
|
||||||
|
|
||||||
/** for example "-test" */
|
/** for example "-test" */
|
||||||
public final static String EXTRA = "";
|
public final static String EXTRA = "";
|
||||||
|
Reference in New Issue
Block a user