/** increments before checking */ boolean shouldThrottle(Hash h) { return this.counter.increment(h) > MAX_FLOODS; }
public void lookupFailed(Hash h) { this.counter.increment(h); }
/** * 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; }
/** * 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; }
/** increments before checking */ boolean shouldThrottle(Hash h) { int numTunnels = this.context.tunnelManager().getParticipatingCount(); int limit = Math.max(MIN_LIMIT, Math.min(MAX_LIMIT, numTunnels * PERCENT_LIMIT / 100)); return this.counter.increment(h) > limit; }
/** increments before checking */ boolean shouldThrottle(Hash h) { int numTunnels = this.context.tunnelManager().getParticipatingCount(); int limit = Math.max(MIN_LIMIT, Math.min(MAX_LIMIT, numTunnels * PERCENT_LIMIT / 100)); return this.counter.increment(h) > limit; }
/** * Increments before checking */ public boolean shouldThrottle(byte[] ip) { // for IPv4 we simply use the IP; // for IPv6 we use a secure hash as an attacker could select the lower bytes Integer key; if (ip.length == 4) key = toInt(ip); else key = Integer.valueOf(SipHash.hashCode(ip)); return _counter.increment(key) > _max; }
int count = _blockedIPs.count(ba); if (count > 0) { count = _blockedIPs.increment(ba); if (_log.shouldLog(Log.WARN)) _log.warn("Blocking accept of IP with count " + count + ": " + Addresses.toString(ip));
/** @return total number of non-fallback expl. + client tunnels */ private int countTunnelsPerPeer(ObjectCounter<Hash> lc) { List<TunnelPool> pools = new ArrayList<TunnelPool>(); listPools(pools); int tunnelCount = 0; for (TunnelPool tp : pools) { for (TunnelInfo info : tp.listTunnels()) { if (info.getLength() > 1) { tunnelCount++; for (int j = 0; j < info.getLength(); j++) { Hash peer = info.getPeer(j); if (!_context.routerHash().equals(peer)) lc.increment(peer); } } } } return tunnelCount; }
/** * @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; }
/** * 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 void run() { try { InputStream in = _socket.getInputStream(); OutputStream out = _socket.getOutputStream(); // this is for the readahead in PeerAcceptor.connection() in = new BufferedInputStream(in); if (_log.shouldLog(Log.DEBUG)) _log.debug("Handling socket from " + _socket.getPeerDestination().calculateHash()); peeracceptor.connection(_socket, in, out); } catch (PeerAcceptor.ProtocolException ihe) { _badCounter.increment(_socket.getPeerDestination().calculateHash()); if (_log.shouldLog(Log.INFO)) _log.info("Protocol error from " + _socket.getPeerDestination().calculateHash(), ihe); try { _socket.close(); } catch (IOException ignored) { } } catch (IOException ioe) { if (_log.shouldLog(Log.DEBUG)) _log.debug("Error handling connection from " + _socket.getPeerDestination().calculateHash(), ioe); try { _socket.close(); } catch (IOException ignored) { } } } }
byte[] ip = addr.getAddress(); ByteArray ba = new ByteArray(ip); count = _blockedIPs.increment(ba); if (_log.shouldLog(Log.WARN)) _log.warn("EOF on inbound before receiving any, blocking IP " + Addresses.toString(ip) + " with count " + count + ": " + con); byte[] ip = addr.getAddress(); ByteArray ba = new ByteArray(ip); count = _blockedIPs.increment(ba); if (_log.shouldLog(Log.WARN)) _log.warn("Blocking IP " + Addresses.toString(ip) + " with count " + count + ": " + con, ioe);
_badCounter.increment(h); if (_log.shouldLog(Log.WARN)) _log.error("Dropping incoming HTTP from " + h);