List of usage examples for java.net InetAddress equals
public boolean equals(Object obj)
From source file:org.silverpeas.components.silvercrawler.util.IpAddressMatcher.java
public boolean matches(String address) { InetAddress remoteAddress = parseAddress(address); if (!requiredAddress.getClass().equals(remoteAddress.getClass())) { return false; }/*from ww w . ja va 2s.c o m*/ if (nMaskBits < 0) { return remoteAddress.equals(requiredAddress); } byte[] remAddr = remoteAddress.getAddress(); byte[] reqAddr = requiredAddress.getAddress(); int oddBits = nMaskBits % 8; int nMaskBytes = nMaskBits / 8 + (oddBits == 0 ? 0 : 1); byte[] mask = new byte[nMaskBytes]; Arrays.fill(mask, 0, oddBits == 0 ? mask.length : mask.length - 1, (byte) 0xFF); if (oddBits != 0) { int finalByte = (1 << oddBits) - 1; finalByte <<= 8 - oddBits; mask[mask.length - 1] = (byte) finalByte; } for (int i = 0; i < mask.length; i++) { if ((remAddr[i] & mask[i]) != (reqAddr[i] & mask[i])) { return false; } } return true; }
From source file:org.tamacat.httpd.util.IpAddressMatcher.java
public boolean matches(String address) { InetAddress remoteAddress = parseAddress(address); if (!requiredAddress.getClass().equals(remoteAddress.getClass())) { return false; }//from w w w . j a va 2s.c om if (nMaskBits < 0) { return remoteAddress.equals(requiredAddress); } byte[] remAddr = remoteAddress.getAddress(); byte[] reqAddr = requiredAddress.getAddress(); int oddBits = nMaskBits % 8; int nMaskBytes = nMaskBits / 8 + (oddBits == 0 ? 0 : 1); byte[] mask = new byte[nMaskBytes]; Arrays.fill(mask, 0, oddBits == 0 ? mask.length : mask.length - 1, (byte) 0xFF); if (oddBits != 0) { int finalByte = (1 << oddBits) - 1; finalByte <<= 8 - oddBits; mask[mask.length - 1] = (byte) finalByte; } for (int i = 0; i < mask.length; i++) { if ((remAddr[i] & mask[i]) != (reqAddr[i] & mask[i])) { return false; } } return true; }
From source file:org.lealone.cluster.gms.FailureDetector.java
@Override public boolean isAlive(InetAddress ep) { if (ep.equals(Utils.getBroadcastAddress())) return true; EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(ep); // we could assert not-null, but having isAlive fail screws a node over so badly that // it's worth being defensive here so minor bugs don't cause disproportionate // badness. (See lealone-1463 for an example). if (epState == null) logger.error("unknown endpoint {}", ep); return epState != null && epState.isAlive(); }
From source file:org.apache.cassandra.CassandraServiceController.java
public InetAddress getPublicHost(InetAddress privateHost) { for (Instance instance : cluster.getInstances()) if (privateHost.equals(instance.getPrivateAddress())) return instance.getPublicAddress(); throw new RuntimeException("No public host for private host " + privateHost); }
From source file:it.anyplace.sync.client.protocol.rp.RelayClient.java
public SessionInvitation getSessionInvitation(InetSocketAddress relaySocketAddress, String deviceId) throws Exception { logger.debug("connecting to relay = {} (temporary protocol mode)", relaySocketAddress); try (Socket socket = keystoreHandler.createSocket(relaySocketAddress, RELAY); RelayDataInputStream in = new RelayDataInputStream(socket.getInputStream()); RelayDataOutputStream out = new RelayDataOutputStream(socket.getOutputStream());) { {/*from w w w. jav a 2 s. co m*/ logger.debug("sending connect request for device = {}", deviceId); byte[] deviceIdData = deviceIdStringToHashData(deviceId); int lengthOfId = deviceIdData.length; out.writeHeader(CONNECT_REQUEST, 4 + lengthOfId); out.writeInt(lengthOfId); out.write(deviceIdData); out.flush(); } { logger.debug("receiving session invitation"); MessageReader messageReader = in.readMessage(); logger.debug("received message = {}", messageReader.dumpMessageForDebug()); checkArgument(messageReader.getType() == SESSION_INVITATION, "message type mismatch, expected %s, got %s", SESSION_INVITATION, messageReader.getType()); SessionInvitation.Builder builder = SessionInvitation.newBuilder(); builder.setFrom(hashDataToDeviceIdString(messageReader.readLengthAndData())); builder.setKey(BaseEncoding.base16().encode(messageReader.readLengthAndData())); byte[] address = messageReader.readLengthAndData(); if (address.length == 0) { builder.setAddress(socket.getInetAddress()); } else { InetAddress inetAddress = InetAddress.getByAddress(address); if (inetAddress.equals(InetAddress.getByName("0.0.0.0"))) { builder.setAddress(socket.getInetAddress()); } else { builder.setAddress(inetAddress); } } int zero = messageReader.getBuffer().getShort(); checkArgument(zero == 0, "expected 0, found %s", zero); int port = messageReader.getBuffer().getShort(); checkArgument(port > 0, "got invalid port value = %s", port); builder.setPort(port); int serverSocket = messageReader.getBuffer().getInt() & 1; builder.setServerSocket(serverSocket == 1); logger.debug("closing connection (temporary protocol mode)"); return builder.build(); } } }
From source file:org.apache.cassandra.dht.BootStrapperTest.java
@Test public void testMulitipleAutomaticBootstraps() throws IOException { StorageService ss = StorageService.instance; generateFakeEndpoints(5);/* w w w . j a va 2 s . c o m*/ InetAddress[] addrs = new InetAddress[] { InetAddress.getByName("127.0.0.2"), InetAddress.getByName("127.0.0.3"), InetAddress.getByName("127.0.0.4"), InetAddress.getByName("127.0.0.5"), }; InetAddress[] bootstrapAddrs = new InetAddress[] { InetAddress.getByName("127.0.0.12"), InetAddress.getByName("127.0.0.13"), InetAddress.getByName("127.0.0.14"), InetAddress.getByName("127.0.0.15"), }; Map<InetAddress, Double> load = new HashMap<InetAddress, Double>(); for (int i = 0; i < addrs.length; i++) load.put(addrs[i], (double) i + 2); // give every node a bootstrap source. for (int i = 3; i >= 0; i--) { InetAddress bootstrapSource = BootStrapper.getBootstrapSource(ss.getTokenMetadata(), load); assert bootstrapSource != null; assert bootstrapSource.equals(addrs[i]) : String.format("expected %s but got %s for %d", addrs[i], bootstrapSource, i); assert !ss.getTokenMetadata().getBootstrapTokens().containsValue(bootstrapSource); Range range = ss.getPrimaryRangeForEndpoint(bootstrapSource); Token token = StorageService.getPartitioner().midpoint(range.left, range.right); assert range.contains(token); ss.onChange(bootstrapAddrs[i], ApplicationState.STATUS, StorageService.instance.valueFactory.bootstrapping(token)); } // any further attempt to bootsrtap should fail since every node in the cluster is splitting. try { BootStrapper.getBootstrapSource(ss.getTokenMetadata(), load); throw new AssertionError("This bootstrap should have failed."); } catch (RuntimeException ex) { // success! } // indicate that one of the nodes is done. see if the node it was bootstrapping from is still available. Range range = ss.getPrimaryRangeForEndpoint(addrs[2]); Token token = StorageService.getPartitioner().midpoint(range.left, range.right); ss.onChange(bootstrapAddrs[2], ApplicationState.STATUS, StorageService.instance.valueFactory.normal(token)); load.put(bootstrapAddrs[2], 0d); InetAddress addr = BootStrapper.getBootstrapSource(ss.getTokenMetadata(), load); assert addr != null && addr.equals(addrs[2]); }
From source file:com.master.metehan.filtereagle.AdapterLog.java
public boolean isKnownAddress(String addr) { try {//w w w .ja v a 2 s . com InetAddress a = InetAddress.getByName(addr); if (a.equals(dns) || a.equals(vpn4) || a.equals(vpn6)) return true; } catch (UnknownHostException ignored) { } return false; }
From source file:android_network.hetnet.vpn_service.AdapterLog.java
public boolean isKnownAddress(String addr) { try {/*from w w w . j a va 2 s . c om*/ InetAddress a = InetAddress.getByName(addr); if (a.equals(dns1) || a.equals(dns2) || a.equals(vpn4) || a.equals(vpn6)) return true; } catch (UnknownHostException ignored) { } return false; }
From source file:com.master.metehan.filtereagle.AdapterLog.java
private String getKnownAddress(String addr) { try {//w ww . ja va2 s . c o m InetAddress a = InetAddress.getByName(addr); if (a.equals(dns)) return "dns"; if (a.equals(vpn4) || a.equals(vpn6)) return "vpn"; } catch (UnknownHostException ignored) { } return addr; }
From source file:android_network.hetnet.vpn_service.AdapterLog.java
private String getKnownAddress(String addr) { try {/*from w w w . j a va2s . c o m*/ InetAddress a = InetAddress.getByName(addr); if (a.equals(dns1) || a.equals(dns2)) return "dns"; if (a.equals(vpn4) || a.equals(vpn6)) return "vpn"; } catch (UnknownHostException ignored) { } return addr; }