blocklist feed tweaks

This commit is contained in:
zzz
2016-11-24 13:54:54 +00:00
parent 1d280156a2
commit 64f5fed05a
3 changed files with 23 additions and 7 deletions

View File

@ -40,6 +40,7 @@ public class BlocklistEntries {
private boolean verified;
public static final int MAX_ENTRIES = 2000;
private static final String CONTENT_ROUTER = "router";
public static final long MAX_FUTURE = 2*24*60*60*1000L;
public BlocklistEntries(int capacity) {
entries = new ArrayList<String>(capacity);
@ -55,6 +56,8 @@ public class BlocklistEntries {
return true;
if (signer == null || sig == null || supdated == null)
return false;
if (updated > ctx.clock().now() + MAX_FUTURE)
return false;
Log log = ctx.logManager().getLog(BlocklistEntries.class);
String[] ss = DataHelper.split(sig, ":", 2);
if (ss.length != 2) {
@ -267,7 +270,8 @@ public class BlocklistEntries {
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) {
System.out.println(" <i2p:block>" + e + "</i2p:block>");
}

View File

@ -424,15 +424,18 @@ public class NewsXMLParser {
return null;
List<Node> entries = getNodes(bl, "i2p:block");
BlocklistEntries rv = new BlocklistEntries(entries.size());
String a = bl.getAttributeValue("signed-by");
String a = bl.getAttributeValue("signer");
if (a.length() > 0)
rv.signer = a;
a = bl.getAttributeValue("sig");
if (a.length() > 0) {
rv.sig = a;
}
a = bl.getAttributeValue("updated");
if (a.length() > 0) {
Node n = bl.getNode("updated");
if (n == null)
return null;
a = n.getValue();
if (a != null) {
rv.supdated = a;
long time = RFC3339Date.parse3339Date(a.trim());
if (time > 0)

View File

@ -639,6 +639,9 @@ class NewsFetcher extends UpdateRunner {
}
Blocklist bl = _context.blocklist();
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;
for (Iterator<String> iter = ble.entries.iterator(); iter.hasNext(); ) {
String s = iter.next();
@ -650,7 +653,7 @@ class NewsFetcher extends UpdateRunner {
}
Hash h = Hash.create(b);
if (!ban.isBanlistedForever(h))
ban.banlistRouterForever(h, "News feed");
ban.banlistRouterForever(h, reason);
} else {
byte[] ip = Addresses.getIP(s);
if (ip == null) {
@ -692,11 +695,15 @@ class NewsFetcher extends UpdateRunner {
out.write("# ");
out.write(ble.supdated);
out.newLine();
banned = 0;
for (String s : ble.entries) {
s = s.replace(':', ';'); // IPv6
out.write("Blocklist Feed:");
out.write(reason);
out.write(':');
out.write(s);
out.newLine();
if (++banned >= BlocklistEntries.MAX_ENTRIES)
break;
}
} catch (IOException ioe) {
_log.error("Error writing blocklist", ioe);
@ -706,8 +713,10 @@ class NewsFetcher extends UpdateRunner {
out.close();
} catch (IOException ioe) {}
}
if (!fail)
if (!fail) {
f.setLastModified(ble.updated);
_context.router().saveConfig(PROP_BLOCKLIST_TIME, Long.toString(ble.updated));
}
if (_log.shouldWarn())
_log.warn("Processed " + ble.entries.size() + " blocks and " + ble.removes.size() + " unblocks from news feed");
}