Skip to content

Commit d8415f2

Browse files
committed
Merge branch 'i2p.i2p.2.4.0-revert-blocklist-changes' into 'master'
Revert Blocklist/Banlist Changes See merge request i2p-hackers/i2p.i2p!149
2 parents 8ce79f3 + 878f7b0 commit d8415f2

17 files changed

+77
-129
lines changed

apps/routerconsole/java/src/net/i2p/router/update/NewsFetcher.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ private void processBlocklistEntries(BlocklistEntries ble) {
657657
continue;
658658
}
659659
Hash h = Hash.create(b);
660-
if (!ban.isBanlistedHard(h)) {
660+
if (!ban.isBanlistedForever(h)) {
661661
ban.banlistRouterForever(h, reason);
662662
_context.commSystem().forceDisconnect(h);
663663
}
@@ -681,7 +681,7 @@ private void processBlocklistEntries(BlocklistEntries ble) {
681681
if (b == null || b.length != Hash.HASH_LENGTH)
682682
continue;
683683
Hash h = Hash.create(b);
684-
if (ban.isBanlistedHard(h))
684+
if (ban.isBanlistedForever(h))
685685
ban.unbanlistRouter(h);
686686
} else {
687687
byte[] ip = Addresses.getIP(s);

apps/routerconsole/java/src/net/i2p/router/web/helpers/BanlistRenderer.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,12 @@ else if (expires < 5l*24*60*60*1000)
7878
buf.append(" on the following transport: ").append(transports);
7979
if (entry.cause != null) {
8080
buf.append("<br>\n");
81-
if (entry.causeComment != null)
82-
buf.append(_t(entry.cause, entry.causeComment));
81+
if (entry.causeCode != null)
82+
buf.append(_t(entry.cause, entry.causeCode));
8383
else
8484
buf.append(_t(entry.cause));
8585
}
8686
if (!key.equals(Hash.FAKE_HASH)) {
87-
if (entry.causeCode == 1)
88-
buf.append(" (H)");
8987
// note: CSS hides anchor text
9088
buf.append(" <a href=\"configpeer?peer=").append(key.toBase64())
9189
.append("#unsh\" title=\"").append(unban).append("\">[").append(unban).append("]</a>");

router/java/src/net/i2p/router/Banlist.java

+37-77
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ public static class Entry {
3939
public long expireOn;
4040
/** why they were banlisted */
4141
public String cause;
42-
/** separate comment so cause can contain {0} for translation */
43-
public String causeComment;
44-
/** Code used for classifying the handling of the ban */
45-
public Integer causeCode;
42+
/** separate code so cause can contain {0} for translation */
43+
public String causeCode;
4644
/** what transports they were banlisted for (String), or null for all transports */
4745
public Set<String> transports;
4846
}
@@ -54,18 +52,15 @@ public static class Entry {
5452
public final static long BANLIST_DURATION_MS = 7*60*1000;
5553
public final static long BANLIST_DURATION_MAX = 30*60*1000;
5654
public final static long BANLIST_DURATION_PARTIAL = 10*60*1000;
57-
public final static long BANLIST_DURATION_HARD = 181l*24*60*60*1000; // will get rounded down to 180d on console
55+
public final static long BANLIST_DURATION_FOREVER = 181l*24*60*60*1000; // will get rounded down to 180d on console
5856
/**
5957
* Buggy i2pd fork
6058
* @since 0.9.52
6159
*/
6260
public final static long BANLIST_DURATION_NO_NETWORK = 30*24*60*60*1000L;
6361
public final static long BANLIST_DURATION_LOCALHOST = 2*60*60*1000;
6462
private final static long BANLIST_CLEANER_START_DELAY = BANLIST_DURATION_PARTIAL;
65-
66-
public final static Integer BANLIST_CODE_SOFT = 0;
67-
public final static Integer BANLIST_CODE_HARD = 1;
68-
63+
6964
public Banlist(RouterContext context) {
7065
_context = context;
7166
_log = context.logManager().getLog(Banlist.class);
@@ -135,8 +130,8 @@ public boolean banlistRouter(Hash peer) {
135130
/**
136131
* @return true if it WAS previously on the list
137132
*/
138-
public boolean banlistRouter(String reasonComment, Hash peer, String reason) {
139-
return banlistRouter(peer, reason, reasonComment, null, false);
133+
public boolean banlistRouter(String reasonCode, Hash peer, String reason) {
134+
return banlistRouter(peer, reason, reasonCode, null, false);
140135
}
141136

142137
/**
@@ -156,65 +151,46 @@ public boolean banlistRouterForever(Hash peer, String reason) {
156151
/**
157152
* @return true if it WAS previously on the list
158153
*/
159-
public boolean banlistRouterForever(Hash peer, String reason, String reasonComment) {
160-
return banlistRouter(peer, reason, reasonComment, null, true);
154+
public boolean banlistRouterForever(Hash peer, String reason, String reasonCode) {
155+
return banlistRouter(peer, reason, reasonCode, null, true);
161156
}
162157

163158
/**
164159
* @return true if it WAS previously on the list
165160
*/
166-
public boolean banlistRouter(Hash peer, String reason, String transport, boolean hard) {
167-
return banlistRouter(peer, reason, null, transport, hard);
161+
public boolean banlistRouter(Hash peer, String reason, String transport, boolean forever) {
162+
return banlistRouter(peer, reason, null, transport, forever);
168163
}
169164

170165
/**
171166
* @return true if it WAS previously on the list
172167
*/
173-
private boolean banlistRouter(Hash peer, String reason, String reasonComment, String transport, boolean hard) {
168+
private boolean banlistRouter(Hash peer, String reason, String reasonCode, String transport, boolean forever) {
174169
long expireOn;
175-
Integer reasonCode;
176-
if (hard) {
177-
expireOn = _context.clock().now() + BANLIST_DURATION_HARD;
178-
reasonCode = BANLIST_CODE_HARD;
170+
if (forever) {
171+
expireOn = _context.clock().now() + BANLIST_DURATION_FOREVER;
179172
} else if (transport != null) {
180173
expireOn = _context.clock().now() + BANLIST_DURATION_PARTIAL;
181-
reasonCode = BANLIST_CODE_SOFT;
182174
} else {
183175
long period = BANLIST_DURATION_MS + _context.random().nextLong(BANLIST_DURATION_MS / 4);
184176
if (period > BANLIST_DURATION_MAX)
185177
period = BANLIST_DURATION_MAX;
186178
expireOn = _context.clock().now() + period;
187-
reasonCode = BANLIST_CODE_SOFT;
188179
}
189-
return banlistRouter(peer, reason, reasonComment, reasonCode, transport, expireOn);
190-
}
191-
192-
/**
193-
* @return true if it WAS previously on the list
194-
*/
195-
public boolean banlistRouter(Hash peer, String reason, String reasonComment, String transport, long expireOn) {
196-
Integer reasonCode = BANLIST_CODE_SOFT; // Default
197-
// To maintain legacy behavior, set reasonCode to BANLIST_CODE_HARD
198-
// if expireOn is longer than 2 days.
199-
if (expireOn > _context.clock().now() + 2*24*60*60*1000L)
200-
reasonCode = BANLIST_CODE_HARD;
201-
return banlistRouter(peer, reason, reasonComment, reasonCode, transport, expireOn);
180+
return banlistRouter(peer, reason, reasonCode, transport, expireOn);
202181
}
203182

204183
/**
205184
* So that we may specify an expiration
206185
*
207186
* @param reason may be null
208-
* @param reasonComment may be null
209-
* @param reasonCode Integer handling code.
210-
* BANLIST_CODE_SOFT - 0 - SOFT ban handling
211-
* BANLIST_CODE_HARD - 1 - HARD ban handling (corresponds to legacy 'forever' ban handling)
187+
* @param reasonCode may be null
212188
* @param expireOn absolute time, not a duration
213189
* @param transport may be null
214190
* @return true if it WAS previously on the list
215191
* @since 0.9.18
216192
*/
217-
public boolean banlistRouter(Hash peer, String reason, String reasonComment, Integer reasonCode, String transport, long expireOn) {
193+
public boolean banlistRouter(Hash peer, String reason, String reasonCode, String transport, long expireOn) {
218194
if (peer == null) {
219195
_log.error("ban null?", new Exception());
220196
return false;
@@ -232,40 +208,33 @@ public boolean banlistRouter(Hash peer, String reason, String reasonComment, Int
232208
Entry e = new Entry();
233209
e.expireOn = expireOn;
234210
e.cause = reason;
235-
e.causeComment = reasonComment;
236211
e.causeCode = reasonCode;
237212
e.transports = null;
238213
if (transport != null) {
239214
e.transports = new ConcurrentHashSet<String>(2);
240215
e.transports.add(transport);
241216
}
242217

243-
Entry old = _entries.get(peer);
244-
if (old != null) {
245-
wasAlready = true;
246-
// take the oldest expiration and cause, combine transports
247-
if (old.expireOn > e.expireOn) {
248-
e.expireOn = old.expireOn;
249-
e.cause = old.cause;
250-
e.causeComment = old.causeComment;
251-
}
252-
// Preserve BANLIST_CODE_HARD over BANLIST_CODE_SOFT
253-
// Otherwise, take the highest banlist handling code.
254-
if ((e.causeCode == 1) || (old.causeCode == 1))
255-
e.causeCode = 1;
256-
else
257-
e.causeCode = Math.max(e.causeCode, old.causeCode);
258-
if (e.transports != null) {
259-
if (old.transports != null)
260-
e.transports.addAll(old.transports);
261-
else {
262-
e.transports = null;
263-
e.cause = reason;
264-
e.causeComment = reasonComment;
218+
Entry old = _entries.get(peer);
219+
if (old != null) {
220+
wasAlready = true;
221+
// take the oldest expiration and cause, combine transports
222+
if (old.expireOn > e.expireOn) {
223+
e.expireOn = old.expireOn;
224+
e.cause = old.cause;
225+
e.causeCode = old.causeCode;
226+
}
227+
if (e.transports != null) {
228+
if (old.transports != null)
229+
e.transports.addAll(old.transports);
230+
else {
231+
e.transports = null;
232+
e.cause = reason;
233+
e.causeCode = reasonCode;
234+
}
265235
}
266236
}
267-
}
268-
_entries.put(peer, e);
237+
_entries.put(peer, e);
269238

270239
if (transport == null) {
271240
// we hate the peer on *any* transport
@@ -349,19 +318,10 @@ public boolean isBanlisted(Hash peer, String transport) {
349318

350319
return rv;
351320
}
352-
353-
public boolean isBanlistedHard(Hash peer) {
354-
boolean rv = false;
355-
321+
322+
public boolean isBanlistedForever(Hash peer) {
356323
Entry entry = _entries.get(peer);
357-
if (entry == null)
358-
rv = false;
359-
else if (entry.causeCode == BANLIST_CODE_HARD)
360-
rv = true;
361-
else
362-
rv = (entry.expireOn > _context.clock().now() + 2*24*60*60*1000L);
363-
364-
return rv;
324+
return entry != null && entry.expireOn > _context.clock().now() + 2*24*60*60*1000L;
365325
}
366326

367327
/** @deprecated moved to router console */

router/java/src/net/i2p/router/Blocklist.java

+14-25
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ public synchronized void startup() {
227227
// but it's important to have this initialized before we read in the netdb.
228228
//job.getTiming().setStartAfter(_context.clock().now() + 30*1000);
229229
_context.jobQueue().addJob(job);
230-
Job cleanupJob = new CleanupJob();
231-
cleanupJob.getTiming().setStartAfter(_context.clock().now() + expireInterval());
232-
_context.jobQueue().addJob(cleanupJob);
230+
if (expireInterval() > 0) {
231+
Job cleanupJob = new CleanupJob();
232+
cleanupJob.getTiming().setStartAfter(_context.clock().now() + expireInterval());
233+
_context.jobQueue().addJob(cleanupJob);
234+
}
233235
}
234236

235237
/**
@@ -278,21 +280,12 @@ public String getName(){
278280
return "Expire blocklist at user-defined interval of " + expireInterval();
279281
}
280282
public void runJob() {
281-
int jobInterval;
282-
283-
if (expireInterval() > 0) {
284-
clear();
285-
_lastExpired = System.currentTimeMillis();
286-
jobInterval = expireInterval();
287-
if (_log.shouldLog(Log.DEBUG))
288-
_log.debug("Expiring blocklist entrys at" + _lastExpired);
289-
} else {
290-
// Set the next job interval to 15 minutes when expireInterval disabled
291-
jobInterval = 15 * 60 * 1000;
292-
}
293-
283+
clear();
284+
_lastExpired = System.currentTimeMillis();
285+
if (_log.shouldLog(Log.DEBUG))
286+
_log.debug("Expiring blocklist entrys at" + _lastExpired);
294287
// schedule the next one
295-
super.requeue(jobInterval);
288+
super.requeue(expireInterval());
296289
}
297290
}
298291

@@ -368,9 +361,7 @@ private int process() {
368361

369362
private void banlistRouter(Hash peer, String reason, String comment) {
370363
if (expireInterval() > 0)
371-
_context.banlist().banlistRouter(peer, reason, comment,
372-
_context.banlist().BANLIST_CODE_HARD, null,
373-
_context.clock().now() + expireInterval());
364+
_context.banlist().banlistRouter(peer, reason, comment, null, expireInterval());
374365
else
375366
_context.banlist().banlistRouterForever(peer, reason, comment);
376367
}
@@ -1281,13 +1272,11 @@ public void runJob() {
12811272
* So we also stagger these jobs.
12821273
*
12831274
*/
1284-
private void banlistRouter( Hash peer, String reason, String reasonComment, long duration) {
1275+
private void banlistRouter( Hash peer, String reason, String reasonCode, long duration) {
12851276
if (duration > 0)
1286-
_context.banlist().banlistRouter(peer, reason, reasonComment,
1287-
_context.banlist().BANLIST_CODE_HARD, null,
1288-
System.currentTimeMillis()+expireInterval());
1277+
_context.banlist().banlistRouter(peer, reason, reasonCode, null, System.currentTimeMillis()+expireInterval());
12891278
else
1290-
_context.banlist().banlistRouterForever(peer, reason, reasonComment);
1279+
_context.banlist().banlistRouterForever(peer, reason, reasonCode);
12911280
}
12921281
private synchronized void banlistRouter(Hash peer, List<byte[]> ips, long duration) {
12931282
// This only checks one file for now, pick the best one

router/java/src/net/i2p/router/networkdb/kademlia/FloodfillDatabaseLookupMessageHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Job createJob(I2NPMessage receivedMessage, RouterIdentity from, Hash from
6666

6767
DatabaseLookupMessage dlm = (DatabaseLookupMessage)receivedMessage;
6868
boolean isBanned = dlm.getFrom() != null
69-
&& (_context.banlist().isBanlistedHard(dlm.getFrom())
69+
&& (_context.banlist().isBanlistedForever(dlm.getFrom())
7070
|| _context.banlist().isBanlisted(dlm.getFrom()));
7171
if (isBanned) {
7272
_context.statManager().addRateData("netDb.lookupsDroppedDueToPriorBan", 1);

router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public boolean floodConditional(DatabaseEntry ds) {
247247
if (!floodfillEnabled())
248248
return false;
249249
Hash h = ds.getHash();
250-
if (_context.banlist().isBanlistedHard(h))
250+
if (_context.banlist().isBanlistedForever(h))
251251
return false;
252252
if (shouldThrottleFlood(h)) {
253253
_context.statManager().addRateData("netDb.floodThrottled", 1);
@@ -668,7 +668,7 @@ protected void lookupBeforeDropping(Hash peer, RouterInfo info) {
668668
knownRouters > MAX_DB_BEFORE_SKIPPING_SEARCH ||
669669
_context.jobQueue().getMaxLag() > 500 ||
670670
_context.router().gracefulShutdownInProgress() ||
671-
_context.banlist().isBanlistedHard(peer)) {
671+
_context.banlist().isBanlistedForever(peer)) {
672672
// don't try to overload ourselves (e.g. failing 3000 router refs at
673673
// once, and then firing off 3000 netDb lookup tasks)
674674
// Also don't queue a search if we have plenty of routerinfos

router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private List<Hash> selectFloodfillParticipants(Set<Hash> toIgnore, KBucketSet<Ha
140140
List<Hash> rv = new ArrayList<Hash>(set.size());
141141
for (Hash h : set) {
142142
if ((toIgnore != null && toIgnore.contains(h)) ||
143-
_context.banlist().isBanlistedHard(h))
143+
_context.banlist().isBanlistedForever(h))
144144
continue;
145145
rv.add(h);
146146
}
@@ -371,7 +371,7 @@ public void add(Hash entry) {
371371
//if (_context.banlist().isBanlisted(entry))
372372
// return;
373373
// ... unless they are really bad
374-
if (_context.banlist().isBanlistedHard(entry))
374+
if (_context.banlist().isBanlistedForever(entry))
375375
return;
376376
RouterInfo info = (RouterInfo) _context.netDb().lookupLocallyWithoutValidation(entry);
377377
//if (info == null)

router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseStoreMessageJob.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ else if (_fromHash.equals(key))
412412
// Check new routerinfo address against blocklist
413413
if (wasNew) {
414414
// TODO should we not flood temporarily banned routers either?
415-
boolean forever = getContext().banlist().isBanlistedHard(key);
415+
boolean forever = getContext().banlist().isBanlistedForever(key);
416416
if (forever) {
417417
wasNew = false; // don't flood
418418
shouldStore = false; // don't call heardAbout()

router/java/src/net/i2p/router/networkdb/kademlia/IterativeLookupJob.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void runJob() {
6262
invalidPeers++;
6363
continue;
6464
}
65-
if (getContext().banlist().isBanlistedHard(peer)) {
65+
if (getContext().banlist().isBanlistedForever(peer)) {
6666
oldPeers++;
6767
continue;
6868
}

router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ void newPeerToTry(Hash peer) {
594594
if (peer.equals(getContext().routerHash()) ||
595595
peer.equals(_key))
596596
return;
597-
if (getContext().banlist().isBanlistedHard(peer)) {
597+
if (getContext().banlist().isBanlistedForever(peer)) {
598598
if (_log.shouldLog(Log.INFO))
599599
_log.info(getJobId() + ": banlisted peer from DSRM " + peer);
600600
return;

router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ public void lookupRouterInfo(Hash key, Job onFindJob, Job onFailedLookupJob, lon
824824
if (ri != null) {
825825
if (onFindJob != null)
826826
_context.jobQueue().addJob(onFindJob);
827-
} else if (_context.banlist().isBanlistedHard(key)) {
827+
} else if (_context.banlist().isBanlistedForever(key)) {
828828
if (onFailedLookupJob != null)
829829
_context.jobQueue().addJob(onFailedLookupJob);
830830
} else if (isNegativeCached(key)) {

0 commit comments

Comments
 (0)