public void timeReached() { LookupThrottler.this.counter.clear(); } }
/** * Checks if individual count is over the limit by this much. Does not increment. * @since 0.9.34 */ boolean isOverBy(Hash h, int over) { if (_max > 0) return this.counter.count(h) > _max + over; return false; }
public void lookupFailed(Hash h) { this.counter.increment(h); }
/** * @return null if not found */ private String query(String host, boolean isv6, List<String> toQuery) { for (String url : toQuery) { if (fails.count(url) > MAX_FAILS) continue; int tcode = isv6 ? V6_CODE : V4_CODE; String furl = url + "name=" + host + "&type=" + tcode; log("Fetching " + furl); baos.reset(); SSLEepGet eepget = new SSLEepGet(ctx, baos, furl, state); if (ctx.isRouterContext()) eepget.addStatusListener(this); else fetchStart = System.currentTimeMillis(); // debug String rv = fetch(eepget, host, isv6); if (rv != null) { fails.clear(url); return rv; } if (state == null) state = eepget.getSSLState(); // we treat all fails the same, whether server responded or not fails.increment(url); log("No result from " + furl); } return null; }
/** * For reliability reasons, don't allow a peer in more than x% of * client and exploratory tunnels. * * This also will prevent a single huge-capacity (or malicious) peer from * taking all the tunnels in the network (although it would be nice to limit * the % of total network tunnels to 10% or so, but that appears to be * too low to set as a default here... much lower than 33% will push client * tunnels out of the fast tier into high cap or beyond...) * * Possible improvement - restrict based on count per IP, or IP block, * to slightly increase costs of collusion * * @return Set of peers that should not be allowed in another tunnel */ public Set<Hash> selectPeersInTooManyTunnels() { ObjectCounter<Hash> lc = new ObjectCounter<Hash>(); int tunnelCount = countTunnelsPerPeer(lc); Set<Hash> rv = new HashSet<Hash>(); if (tunnelCount >= 4 && _context.router().getUptime() > 10*60*1000) { int max = _context.getProperty("router.maxTunnelPercentage", DEFAULT_MAX_PCT_TUNNELS); for (Hash h : lc.objects()) { if (lc.count(h) > 0 && (lc.count(h) + 1) * 100 / (tunnelCount + 1) > max) rv.add(h); } } return rv; }
ParticipatingThrottler(RouterContext ctx) { this.context = ctx; this.counter = new ObjectCounter<Hash>(); ctx.simpleTimer2().addPeriodicEvent(new Cleaner(), CLEAN_TIME); }
ConnThrottler(int max, int totalMax, long period, SimpleTimer2 timer) { _max = max; _totalMax = totalMax; this.counter = new ObjectCounter<Hash>(); _currentTotal = new AtomicInteger(); // shorten the initial period by a random amount // to prevent correlation across destinations // and identification of router startup time timer.addPeriodicEvent(new Cleaner(), (period / 2) + RandomSource.getInstance().nextLong(period / 2), period); }
public void timeReached() { FloodThrottler.this.counter.clear(); } }
/** increments before checking */ boolean shouldThrottle(Hash h) { return this.counter.increment(h) > MAX_FLOODS; }
/** * Checks individual count only. Does not increment. * @since 0.9.3 */ boolean isThrottled(Hash h) { if (_max > 0) return this.counter.count(h) > _max; return false; }
public IPThrottler(int max, long time) { _max = max; _counter = new ObjectCounter<Integer>(); SimpleTimer2.getInstance().addPeriodicEvent(new Cleaner(), time); }
public void timeReached() { NegativeLookupCache.this.counter.clear(); } }
/** * Checks both individual and total. Increments before checking. */ boolean shouldThrottle(Hash h) { // do this first, so we don't increment total if individual throttled if (_max > 0 && this.counter.increment(h) > _max) return true; if (_totalMax > 0 && _currentTotal.incrementAndGet() > _totalMax) return true; return false; }
public boolean isCached(Hash h) { if (counter.count(h) >= _maxFails) return true; synchronized(badDests) { return badDests.get(h) != null; } }
RequestThrottler(RouterContext ctx) { this.context = ctx; this.counter = new ObjectCounter<Hash>(); ctx.simpleTimer2().addPeriodicEvent(new Cleaner(), CLEAN_TIME); }
public void timeReached() { _counter.clear(); } }
/** * increments before checking * @param key non-null * @param id null if for direct lookups */ boolean shouldThrottle(Hash key, TunnelId id) { return this.counter.increment(new ReplyTunnel(key, id)) > MAX_LOOKUPS; }
/** * Checks individual count only. Does not increment. * @since 0.9.3 */ boolean isThrottled(Hash h) { if (_max > 0) return this.counter.count(h) > _max; return false; }