@@ -39,10 +39,8 @@ public static class Entry {
39
39
public long expireOn ;
40
40
/** why they were banlisted */
41
41
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 ;
46
44
/** what transports they were banlisted for (String), or null for all transports */
47
45
public Set <String > transports ;
48
46
}
@@ -54,18 +52,15 @@ public static class Entry {
54
52
public final static long BANLIST_DURATION_MS = 7 *60 *1000 ;
55
53
public final static long BANLIST_DURATION_MAX = 30 *60 *1000 ;
56
54
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
58
56
/**
59
57
* Buggy i2pd fork
60
58
* @since 0.9.52
61
59
*/
62
60
public final static long BANLIST_DURATION_NO_NETWORK = 30 *24 *60 *60 *1000L ;
63
61
public final static long BANLIST_DURATION_LOCALHOST = 2 *60 *60 *1000 ;
64
62
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
+
69
64
public Banlist (RouterContext context ) {
70
65
_context = context ;
71
66
_log = context .logManager ().getLog (Banlist .class );
@@ -135,8 +130,8 @@ public boolean banlistRouter(Hash peer) {
135
130
/**
136
131
* @return true if it WAS previously on the list
137
132
*/
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 );
140
135
}
141
136
142
137
/**
@@ -156,65 +151,46 @@ public boolean banlistRouterForever(Hash peer, String reason) {
156
151
/**
157
152
* @return true if it WAS previously on the list
158
153
*/
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 );
161
156
}
162
157
163
158
/**
164
159
* @return true if it WAS previously on the list
165
160
*/
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 );
168
163
}
169
164
170
165
/**
171
166
* @return true if it WAS previously on the list
172
167
*/
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 ) {
174
169
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 ;
179
172
} else if (transport != null ) {
180
173
expireOn = _context .clock ().now () + BANLIST_DURATION_PARTIAL ;
181
- reasonCode = BANLIST_CODE_SOFT ;
182
174
} else {
183
175
long period = BANLIST_DURATION_MS + _context .random ().nextLong (BANLIST_DURATION_MS / 4 );
184
176
if (period > BANLIST_DURATION_MAX )
185
177
period = BANLIST_DURATION_MAX ;
186
178
expireOn = _context .clock ().now () + period ;
187
- reasonCode = BANLIST_CODE_SOFT ;
188
179
}
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 );
202
181
}
203
182
204
183
/**
205
184
* So that we may specify an expiration
206
185
*
207
186
* @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
212
188
* @param expireOn absolute time, not a duration
213
189
* @param transport may be null
214
190
* @return true if it WAS previously on the list
215
191
* @since 0.9.18
216
192
*/
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 ) {
218
194
if (peer == null ) {
219
195
_log .error ("ban null?" , new Exception ());
220
196
return false ;
@@ -232,40 +208,33 @@ public boolean banlistRouter(Hash peer, String reason, String reasonComment, Int
232
208
Entry e = new Entry ();
233
209
e .expireOn = expireOn ;
234
210
e .cause = reason ;
235
- e .causeComment = reasonComment ;
236
211
e .causeCode = reasonCode ;
237
212
e .transports = null ;
238
213
if (transport != null ) {
239
214
e .transports = new ConcurrentHashSet <String >(2 );
240
215
e .transports .add (transport );
241
216
}
242
217
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
+ }
265
235
}
266
236
}
267
- }
268
- _entries .put (peer , e );
237
+ _entries .put (peer , e );
269
238
270
239
if (transport == null ) {
271
240
// we hate the peer on *any* transport
@@ -349,19 +318,10 @@ public boolean isBanlisted(Hash peer, String transport) {
349
318
350
319
return rv ;
351
320
}
352
-
353
- public boolean isBanlistedHard (Hash peer ) {
354
- boolean rv = false ;
355
-
321
+
322
+ public boolean isBanlistedForever (Hash peer ) {
356
323
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 ;
365
325
}
366
326
367
327
/** @deprecated moved to router console */
0 commit comments