From 63a2a6da081ff2762b29afdbd0fd96b100757ad6 Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 22 Dec 2016 14:08:44 +0000 Subject: [PATCH] Router: Check blocklist when loading RIs Ensure blocklist is initialized before netdb --- router/java/src/net/i2p/router/Blocklist.java | 18 ++++++++++++++++-- .../kademlia/PersistentDataStore.java | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/router/java/src/net/i2p/router/Blocklist.java b/router/java/src/net/i2p/router/Blocklist.java index 1ae393ff7..1e239e9be 100644 --- a/router/java/src/net/i2p/router/Blocklist.java +++ b/router/java/src/net/i2p/router/Blocklist.java @@ -77,6 +77,7 @@ public class Blocklist { private Entry _wrapSave; private final Set _inProcess = new HashSet(4); private final File _blocklistFeedFile; + private boolean _started; // temp private Map _peerBlocklist = new HashMap(4); @@ -99,6 +100,9 @@ public class Blocklist { private static final Object DUMMY = Integer.valueOf(0); + /** + * Router MUST call startup() + */ public Blocklist(RouterContext context) { _context = context; _log = context.logManager().getLog(Blocklist.class); @@ -119,7 +123,10 @@ public class Blocklist { * ~/.i2p/docs/feed/blocklist/blocklist.txt * File if specified with router.blocklist.file */ - public void startup() { + public synchronized void startup() { + if (_started) + return; + _started = true; if (! _context.getBooleanPropertyDefaultTrue(PROP_BLOCKLIST_ENABLED)) return; List files = new ArrayList(4); @@ -142,7 +149,12 @@ public class Blocklist { files.add(blFile); } Job job = new ReadinJob(files); - job.getTiming().setStartAfter(_context.clock().now() + 30*1000); + // Run immediately, so it's initialized before netdb. + // As this is called by Router.runRouter() before job queue parallel operation, + // this will block StartupJob, and will complete before netdb initialization. + // If there is a huge blocklist, it will delay router startup, + // but it's important to have this initialized before we read in the netdb. + //job.getTiming().setStartAfter(_context.clock().now() + 30*1000); _context.jobQueue().addJob(job); } @@ -171,6 +183,7 @@ public class Blocklist { return; } merge(ccount); + /**** debug, and now run before netdb is initialized anyway if (_log.shouldLog(Log.WARN)) { if (_blocklistSize <= 0) return; @@ -184,6 +197,7 @@ public class Blocklist { if (count > 0) _log.warn("Blocklisted " + count + " routers in the netDb"); } + ****/ _peerBlocklist = null; } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java b/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java index 9601ed4f9..515ba8b18 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java @@ -523,6 +523,10 @@ public class PersistentDataStore extends TransientDataStore { // Don't store but don't delete if (_log.shouldLog(Log.WARN)) _log.warn("Skipping since netdb newer than " + _routerFile); + } else if (getContext().blocklist().isBlocklisted(ri)) { + corrupt = true; + if (_log.shouldLog(Log.WARN)) + _log.warn(ri.getHash() + " is blocklisted"); } else { try { // persist = false so we don't write what we just read