@Test public void testAnonymizedAddressDiffers() throws UnknownHostException { int differsCounter = 0; String hash1 = AnonymizedOriginTracer.getAnonymizedOrigin(address1); for (int tries = 0; tries < 100; ++tries) { ++rawAddress[0]; InetAddress differentAddress = InetAddress.getByAddress(rawAddress); String hash2 = AnonymizedOriginTracer.getAnonymizedOrigin(differentAddress); if (!hash1.equals(hash2)) { ++differsCounter; } } assertThat(differsCounter, is(greaterThan(95))); }
public static String getAnonymizedOrigin(InetAddress address) { synchronized (CLIENT_CACHE) { String id = CLIENT_CACHE.get(address); if (id == null) { byte[] raw = address.getAddress().clone(); try { if (HMAC == null) { byte[] mask = KEY.getEncoded(); for (int index = 0; index < raw.length; ++index) { raw[index] ^= mask[index]; } } else { HMAC.init(KEY); raw = HMAC.doFinal(raw); } } catch (InvalidKeyException e) { } id = StringUtil.byteArray2HexString(raw, StringUtil.NO_SEPARATOR, ID_LENGTH); CLIENT_CACHE.put(address, id); } return id; } }
AnonymizedOriginTracer extends MessageInterceptorAdapter { public static String getAnonymizedOrigin(InetAddress address) { synchronized (CLIENT_CACHE) { String id = CLIENT_CACHE.get(address); if (id == null) { byte[] raw = address.getAddress().clone(); try { if (HMAC == null) { byte[] mask = KEY.getEncoded(); for (int index = 0; index < raw.length; ++index) { raw[index] ^= mask[index]; } } else { HMAC.init(KEY); raw = HMAC.doFinal(raw); } } catch (InvalidKeyException e) { } id = StringUtil.byteArray2HexString(raw, StringUtil.NO_SEPARATOR, ID_LENGTH); CLIENT_CACHE.put(address, id); } return id; } } }
AnonymizedOriginTracer extends MessageInterceptorAdapter { public static String getAnonymizedOrigin(InetAddress address) { synchronized (CLIENT_CACHE) { String id = CLIENT_CACHE.get(address); if (id == null) { byte[] raw = address.getAddress().clone(); try { if (HMAC == null) { byte[] mask = KEY.getEncoded(); for (int index = 0; index < raw.length; ++index) { raw[index] ^= mask[index]; } } else { HMAC.init(KEY); raw = HMAC.doFinal(raw); } } catch (InvalidKeyException e) { } id = StringUtil.byteArray2HexString(raw, StringUtil.NO_SEPARATOR, ID_LENGTH); CLIENT_CACHE.put(address, id); } return id; } } AnonymizedOriginTracer(String scheme);  AnonymizedOriginTracer(String scheme, long filterTimeout); }
AnonymizedOriginTracer extends MessageInterceptorAdapter { public static String getAnonymizedOrigin(InetAddress address) { synchronized (CLIENT_CACHE) { String id = CLIENT_CACHE.get(address); if (id == null) { byte[] raw = address.getAddress().clone(); try { if (HMAC == null) { byte[] mask = KEY.getEncoded(); for (int index = 0; index < raw.length; ++index) { raw[index] ^= mask[index]; } } else { HMAC.init(KEY); raw = HMAC.doFinal(raw); } } catch (InvalidKeyException e) { } id = StringUtil.byteArray2HexString(raw, StringUtil.NO_SEPARATOR, ID_LENGTH); CLIENT_CACHE.put(address, id); } return id; } } AnonymizedOriginTracer(String scheme);  AnonymizedOriginTracer(String scheme, long filterTimeout); @Override void receiveRequest(Request request); @Override void receiveEmptyMessage(EmptyMessage message); boolean log(Message message); static String getAnonymizedOrigin(InetAddress address); }
AnonymizedOriginTracer extends MessageInterceptorAdapter { public static String getAnonymizedOrigin(InetAddress address) { synchronized (CLIENT_CACHE) { String id = CLIENT_CACHE.get(address); if (id == null) { byte[] raw = address.getAddress().clone(); try { if (HMAC == null) { byte[] mask = KEY.getEncoded(); for (int index = 0; index < raw.length; ++index) { raw[index] ^= mask[index]; } } else { HMAC.init(KEY); raw = HMAC.doFinal(raw); } } catch (InvalidKeyException e) { } id = StringUtil.byteArray2HexString(raw, StringUtil.NO_SEPARATOR, ID_LENGTH); CLIENT_CACHE.put(address, id); } return id; } } AnonymizedOriginTracer(String scheme);  AnonymizedOriginTracer(String scheme, long filterTimeout); @Override void receiveRequest(Request request); @Override void receiveEmptyMessage(EmptyMessage message); boolean log(Message message); static String getAnonymizedOrigin(InetAddress address);  }