@Override public void setData(byte[] data) { super.setData(data); _cachedHashCode = SipHash.hashCode(data); }
@Override public void readBytes(InputStream in) throws DataFormatException, IOException { super.readBytes(in); _cachedHashCode = SipHash.hashCode(_data); }
/** * 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; }
/** * @param create if true, instantiate the data array and fill it with random data. */ public SessionTag(boolean create) { super(); if (create) { _data = SimpleByteCache.acquire(BYTE_LENGTH); RandomSource.getInstance().nextBytes(_data); _cachedHashCode = SipHash.hashCode(_data); } }