forked from I2P_Developers/i2p.i2p
blocklist feed tweaks
This commit is contained in:
@ -40,6 +40,7 @@ public class BlocklistEntries {
|
|||||||
private boolean verified;
|
private boolean verified;
|
||||||
public static final int MAX_ENTRIES = 2000;
|
public static final int MAX_ENTRIES = 2000;
|
||||||
private static final String CONTENT_ROUTER = "router";
|
private static final String CONTENT_ROUTER = "router";
|
||||||
|
public static final long MAX_FUTURE = 2*24*60*60*1000L;
|
||||||
|
|
||||||
public BlocklistEntries(int capacity) {
|
public BlocklistEntries(int capacity) {
|
||||||
entries = new ArrayList<String>(capacity);
|
entries = new ArrayList<String>(capacity);
|
||||||
@ -55,6 +56,8 @@ public class BlocklistEntries {
|
|||||||
return true;
|
return true;
|
||||||
if (signer == null || sig == null || supdated == null)
|
if (signer == null || sig == null || supdated == null)
|
||||||
return false;
|
return false;
|
||||||
|
if (updated > ctx.clock().now() + MAX_FUTURE)
|
||||||
|
return false;
|
||||||
Log log = ctx.logManager().getLog(BlocklistEntries.class);
|
Log log = ctx.logManager().getLog(BlocklistEntries.class);
|
||||||
String[] ss = DataHelper.split(sig, ":", 2);
|
String[] ss = DataHelper.split(sig, ":", 2);
|
||||||
if (ss.length != 2) {
|
if (ss.length != 2) {
|
||||||
@ -267,7 +270,8 @@ public class BlocklistEntries {
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(" <i2p:blocklist updated=\"" + date + "\" signed-by=\"" + signerName + "\" sig=\"" + type.getCode() + ':' + bsig + "\">");
|
System.out.println(" <i2p:blocklist signer=\"" + signerName + "\" sig=\"" + type.getCode() + ':' + bsig + "\">");
|
||||||
|
System.out.println(" <updated>" + date + "</updated>");
|
||||||
for (String e : elist) {
|
for (String e : elist) {
|
||||||
System.out.println(" <i2p:block>" + e + "</i2p:block>");
|
System.out.println(" <i2p:block>" + e + "</i2p:block>");
|
||||||
}
|
}
|
||||||
|
@ -424,15 +424,18 @@ public class NewsXMLParser {
|
|||||||
return null;
|
return null;
|
||||||
List<Node> entries = getNodes(bl, "i2p:block");
|
List<Node> entries = getNodes(bl, "i2p:block");
|
||||||
BlocklistEntries rv = new BlocklistEntries(entries.size());
|
BlocklistEntries rv = new BlocklistEntries(entries.size());
|
||||||
String a = bl.getAttributeValue("signed-by");
|
String a = bl.getAttributeValue("signer");
|
||||||
if (a.length() > 0)
|
if (a.length() > 0)
|
||||||
rv.signer = a;
|
rv.signer = a;
|
||||||
a = bl.getAttributeValue("sig");
|
a = bl.getAttributeValue("sig");
|
||||||
if (a.length() > 0) {
|
if (a.length() > 0) {
|
||||||
rv.sig = a;
|
rv.sig = a;
|
||||||
}
|
}
|
||||||
a = bl.getAttributeValue("updated");
|
Node n = bl.getNode("updated");
|
||||||
if (a.length() > 0) {
|
if (n == null)
|
||||||
|
return null;
|
||||||
|
a = n.getValue();
|
||||||
|
if (a != null) {
|
||||||
rv.supdated = a;
|
rv.supdated = a;
|
||||||
long time = RFC3339Date.parse3339Date(a.trim());
|
long time = RFC3339Date.parse3339Date(a.trim());
|
||||||
if (time > 0)
|
if (time > 0)
|
||||||
|
@ -639,6 +639,9 @@ class NewsFetcher extends UpdateRunner {
|
|||||||
}
|
}
|
||||||
Blocklist bl = _context.blocklist();
|
Blocklist bl = _context.blocklist();
|
||||||
Banlist ban = _context.banlist();
|
Banlist ban = _context.banlist();
|
||||||
|
DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
|
fmt.setTimeZone(SystemVersion.getSystemTimeZone(_context));
|
||||||
|
String reason = "Blocklist feed " + new Date(ble.updated);
|
||||||
int banned = 0;
|
int banned = 0;
|
||||||
for (Iterator<String> iter = ble.entries.iterator(); iter.hasNext(); ) {
|
for (Iterator<String> iter = ble.entries.iterator(); iter.hasNext(); ) {
|
||||||
String s = iter.next();
|
String s = iter.next();
|
||||||
@ -650,7 +653,7 @@ class NewsFetcher extends UpdateRunner {
|
|||||||
}
|
}
|
||||||
Hash h = Hash.create(b);
|
Hash h = Hash.create(b);
|
||||||
if (!ban.isBanlistedForever(h))
|
if (!ban.isBanlistedForever(h))
|
||||||
ban.banlistRouterForever(h, "News feed");
|
ban.banlistRouterForever(h, reason);
|
||||||
} else {
|
} else {
|
||||||
byte[] ip = Addresses.getIP(s);
|
byte[] ip = Addresses.getIP(s);
|
||||||
if (ip == null) {
|
if (ip == null) {
|
||||||
@ -692,11 +695,15 @@ class NewsFetcher extends UpdateRunner {
|
|||||||
out.write("# ");
|
out.write("# ");
|
||||||
out.write(ble.supdated);
|
out.write(ble.supdated);
|
||||||
out.newLine();
|
out.newLine();
|
||||||
|
banned = 0;
|
||||||
for (String s : ble.entries) {
|
for (String s : ble.entries) {
|
||||||
s = s.replace(':', ';'); // IPv6
|
s = s.replace(':', ';'); // IPv6
|
||||||
out.write("Blocklist Feed:");
|
out.write(reason);
|
||||||
|
out.write(':');
|
||||||
out.write(s);
|
out.write(s);
|
||||||
out.newLine();
|
out.newLine();
|
||||||
|
if (++banned >= BlocklistEntries.MAX_ENTRIES)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
_log.error("Error writing blocklist", ioe);
|
_log.error("Error writing blocklist", ioe);
|
||||||
@ -706,8 +713,10 @@ class NewsFetcher extends UpdateRunner {
|
|||||||
out.close();
|
out.close();
|
||||||
} catch (IOException ioe) {}
|
} catch (IOException ioe) {}
|
||||||
}
|
}
|
||||||
if (!fail)
|
if (!fail) {
|
||||||
|
f.setLastModified(ble.updated);
|
||||||
_context.router().saveConfig(PROP_BLOCKLIST_TIME, Long.toString(ble.updated));
|
_context.router().saveConfig(PROP_BLOCKLIST_TIME, Long.toString(ble.updated));
|
||||||
|
}
|
||||||
if (_log.shouldWarn())
|
if (_log.shouldWarn())
|
||||||
_log.warn("Processed " + ble.entries.size() + " blocks and " + ble.removes.size() + " unblocks from news feed");
|
_log.warn("Processed " + ble.entries.size() + " blocks and " + ble.removes.size() + " unblocks from news feed");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user