forked from I2P_Developers/i2p.i2p
* DecayingBloomFilter:
- Replace with new DecayingHashSet for 3 of 4 uses, and also in the 4th if the router is low-bandwidth. Saves 8 MB heap.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package net.i2p.router;
|
||||
|
||||
import net.i2p.util.DecayingBloomFilter;
|
||||
import net.i2p.util.DecayingHashSet;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
@ -95,7 +96,7 @@ public class MessageValidator {
|
||||
}
|
||||
|
||||
public void startup() {
|
||||
_filter = new DecayingBloomFilter(_context, (int)Router.CLOCK_FUDGE_FACTOR * 2, 8);
|
||||
_filter = new DecayingHashSet(_context, (int)Router.CLOCK_FUDGE_FACTOR * 2, 8, "RouterMV");
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
|
@ -5,6 +5,7 @@ import java.util.Map;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.DecayingBloomFilter;
|
||||
import net.i2p.util.DecayingHashSet;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
@ -52,7 +53,7 @@ public class InboundMessageFragments /*implements UDPTransport.PartialACKSource
|
||||
// may want to extend the DecayingBloomFilter so we can use a smaller
|
||||
// array size (currently its tuned for 10 minute rates for the
|
||||
// messageValidator)
|
||||
_recentlyCompletedMessages = new DecayingBloomFilter(_context, DECAY_PERIOD, 4);
|
||||
_recentlyCompletedMessages = new DecayingHashSet(_context, DECAY_PERIOD, 4, "UDPIMF");
|
||||
_ackSender.startup();
|
||||
_messageReceiver.startup();
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package net.i2p.router.tunnel;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.ByteArray;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.ByteCache;
|
||||
import net.i2p.util.DecayingBloomFilter;
|
||||
import net.i2p.util.DecayingHashSet;
|
||||
|
||||
/**
|
||||
* Manage the IV validation for all of the router's tunnels by way of a big
|
||||
@ -12,7 +13,7 @@ import net.i2p.util.DecayingBloomFilter;
|
||||
*
|
||||
*/
|
||||
public class BloomFilterIVValidator implements IVValidator {
|
||||
private I2PAppContext _context;
|
||||
private RouterContext _context;
|
||||
private DecayingBloomFilter _filter;
|
||||
private ByteCache _ivXorCache = ByteCache.getInstance(32, HopProcessor.IV_LENGTH);
|
||||
|
||||
@ -23,9 +24,17 @@ public class BloomFilterIVValidator implements IVValidator {
|
||||
*
|
||||
*/
|
||||
private static final int HALFLIFE_MS = 10*60*1000;
|
||||
public BloomFilterIVValidator(I2PAppContext ctx, int KBps) {
|
||||
private static final int MIN_SHARE_KBPS_TO_USE_BLOOM = 64;
|
||||
|
||||
public BloomFilterIVValidator(RouterContext ctx, int KBps) {
|
||||
_context = ctx;
|
||||
_filter = new DecayingBloomFilter(ctx, HALFLIFE_MS, 16);
|
||||
// Select the filter based on share bandwidth.
|
||||
// Note that at rates approaching 1MB, we need to do something else,
|
||||
// as the Bloom filter false positive rates approach 0.1%. FIXME
|
||||
if (getShareBandwidth(ctx) < MIN_SHARE_KBPS_TO_USE_BLOOM)
|
||||
_filter = new DecayingHashSet(ctx, HALFLIFE_MS, 16, "TunnelIVV"); // appx. 4MB max
|
||||
else
|
||||
_filter = new DecayingBloomFilter(ctx, HALFLIFE_MS, 16, "TunnelIVV"); // 2MB fixed
|
||||
ctx.statManager().createRateStat("tunnel.duplicateIV", "Note that a duplicate IV was received", "Tunnels",
|
||||
new long[] { 10*60*1000l, 60*60*1000l, 3*60*60*1000l, 24*60*60*1000l });
|
||||
}
|
||||
@ -39,4 +48,11 @@ public class BloomFilterIVValidator implements IVValidator {
|
||||
return !dup; // return true if it is OK, false if it isn't
|
||||
}
|
||||
public void destroy() { _filter.stopDecaying(); }
|
||||
|
||||
private static int getShareBandwidth(RouterContext ctx) {
|
||||
int irateKBps = ctx.bandwidthLimiter().getInboundKBytesPerSecond();
|
||||
int orateKBps = ctx.bandwidthLimiter().getOutboundKBytesPerSecond();
|
||||
double pct = ctx.router().getSharePercentage();
|
||||
return (int) (pct * Math.min(irateKBps, orateKBps));
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import net.i2p.data.SessionKey;
|
||||
import net.i2p.data.i2np.BuildRequestRecord;
|
||||
import net.i2p.data.i2np.TunnelBuildMessage;
|
||||
import net.i2p.util.DecayingBloomFilter;
|
||||
import net.i2p.util.DecayingHashSet;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
@ -22,7 +23,7 @@ public class BuildMessageProcessor {
|
||||
private DecayingBloomFilter _filter;
|
||||
|
||||
public BuildMessageProcessor(I2PAppContext ctx) {
|
||||
_filter = new DecayingBloomFilter(ctx, 60*1000, 32);
|
||||
_filter = new DecayingHashSet(ctx, 60*1000, 32, "TunnelBMP");
|
||||
ctx.statManager().createRateStat("tunnel.buildRequestDup", "How frequently we get dup build request messages", "Tunnels", new long[] { 60*1000, 10*60*1000 });
|
||||
}
|
||||
/**
|
||||
|
Reference in New Issue
Block a user