use of java.net.InetAddress in project platformlayer by platformlayer.
the class OpenstackComputeMachine method getNetworkPoint.
@Override
public NetworkPoint getNetworkPoint() throws OpsException {
if (networkPoint == null) {
// TODO: Check private networks
OpenstackCloudHelpers helpers = new OpenstackCloudHelpers();
List<InetAddress> addresses = Lists.newArrayList();
// We assume that private networks can still reach the public internet, so these work for everyone
List<Ip> publicIps = helpers.findPublicIps(cloud, server);
for (Ip ip : publicIps) {
// if (Objects.equal("6", ip.getVersion())) {
// continue;
// }
String addr = ip.getAddr();
if (!Strings.isNullOrEmpty(addr)) {
addresses.add(InetAddresses.forString(addr));
}
}
if (addresses.size() != 1) {
throw new OpsException("Found multiple addresses: " + Joiner.on(",").join(addresses));
}
networkPoint = NetworkPoint.forAddress(addresses.get(0));
}
return networkPoint;
}
use of java.net.InetAddress in project platformlayer by platformlayer.
the class DiskImageController method waitForAddress.
private Machine waitForAddress(final Machine machine) throws OpsException {
try {
final NetworkPoint myNetworkPoint = NetworkPoint.forMe();
List<InetAddress> addresses = machine.getNetworkPoint().findAddresses(myNetworkPoint);
if (!addresses.isEmpty()) {
return machine;
}
return TimeoutPoll.poll(TimeSpan.FIVE_MINUTES, TimeSpan.TEN_SECONDS, new PollFunction<Machine>() {
@Override
public Machine call() throws Exception {
Machine refreshed = cloud.refreshMachine(machine);
List<InetAddress> addresses = refreshed.getNetworkPoint().findAddresses(myNetworkPoint);
if (!addresses.isEmpty()) {
return refreshed;
}
return null;
}
});
} catch (ExecutionException e) {
throw new OpsException("Error while waiting for address", e);
} catch (TimeoutException e) {
throw new OpsException("Timeout while waiting for address", e);
}
}
use of java.net.InetAddress in project platformlayer by platformlayer.
the class DnsResolverServiceController method findAddresses.
@Override
public List<InetAddress> findAddresses(NetworkPoint from) throws OpsException {
Machine machine = instances.getMachine(model);
if (machine == null) {
return Collections.emptyList();
}
List<InetAddress> addresses = machine.getNetworkPoint().findAddresses(from);
return addresses;
}
use of java.net.InetAddress in project platform_frameworks_base by android.
the class Vpn method makeLinkProperties.
private LinkProperties makeLinkProperties() {
boolean allowIPv4 = mConfig.allowIPv4;
boolean allowIPv6 = mConfig.allowIPv6;
LinkProperties lp = new LinkProperties();
lp.setInterfaceName(mInterface);
if (mConfig.addresses != null) {
for (LinkAddress address : mConfig.addresses) {
lp.addLinkAddress(address);
allowIPv4 |= address.getAddress() instanceof Inet4Address;
allowIPv6 |= address.getAddress() instanceof Inet6Address;
}
}
if (mConfig.routes != null) {
for (RouteInfo route : mConfig.routes) {
lp.addRoute(route);
InetAddress address = route.getDestination().getAddress();
allowIPv4 |= address instanceof Inet4Address;
allowIPv6 |= address instanceof Inet6Address;
}
}
if (mConfig.dnsServers != null) {
for (String dnsServer : mConfig.dnsServers) {
InetAddress address = InetAddress.parseNumericAddress(dnsServer);
lp.addDnsServer(address);
allowIPv4 |= address instanceof Inet4Address;
allowIPv6 |= address instanceof Inet6Address;
}
}
if (!allowIPv4) {
lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), RTN_UNREACHABLE));
}
if (!allowIPv6) {
lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_UNREACHABLE));
}
// Concatenate search domains into a string.
StringBuilder buffer = new StringBuilder();
if (mConfig.searchDomains != null) {
for (String domain : mConfig.searchDomains) {
buffer.append(domain).append(' ');
}
}
lp.setDomains(buffer.toString().trim());
return lp;
}
use of java.net.InetAddress in project platform_frameworks_base by android.
the class NetworkDiagnostics method prepareExplicitSourceIcmpMeasurements.
private void prepareExplicitSourceIcmpMeasurements(InetAddress target) {
for (LinkAddress l : mLinkProperties.getLinkAddresses()) {
InetAddress source = l.getAddress();
if (source instanceof Inet6Address && l.isGlobalPreferred()) {
Pair<InetAddress, InetAddress> srcTarget = new Pair<>(source, target);
if (!mExplicitSourceIcmpChecks.containsKey(srcTarget)) {
Measurement measurement = new Measurement();
measurement.thread = new Thread(new IcmpCheck(source, target, measurement));
mExplicitSourceIcmpChecks.put(srcTarget, measurement);
}
}
}
}
Aggregations