@Override public InetAddress getDefaultPublicAddressV6( boolean peek ) { if(!supportsIPv6) return null; // check bindings first for(InetAddress addr : currentBindIPs) { // found a specific bind address, use that one if(AddressUtils.isGlobalAddressV6(addr)){ return addr; } } for(InetAddress addr : currentBindIPs){ // found v6 any-local address, check interfaces for a best match if(addr instanceof Inet6Address && addr.isAnyLocalAddress()) { ArrayList<InetAddress> addrs = new ArrayList<>(); for(NetworkInterface iface : old_network_interfaces) addrs.addAll(Collections.list(iface.getInetAddresses())); return AddressUtils.pickBestGlobalV6Address(addrs); } } return null; }
/** * picks 1 global-scoped address out of a list based on the heuristic * "true" ipv6/tunnel broker > 6to4 > teredo * * @return null if no proper v6 address is found, best one otherwise */ public static InetAddress pickBestGlobalV6Address(List<InetAddress> addrs) { InetAddress bestPick = null; int currentRanking = 0; for(InetAddress addr : addrs) { if(!isGlobalAddressV6(addr)) continue; int ranking = 3; if(isTeredo(addr)) ranking = 1; else if(is6to4(addr)) ranking = 2; if(ranking > currentRanking) { bestPick = addr; currentRanking = ranking; } } return bestPick; }
if(AddressUtils.isGlobalAddressV6(handshake.getIPv6())) alternativeAddress = handshake.getIPv6();
if(AddressUtils.isGlobalAddressV6(handshake.getIPv6())) alternativeAddress = handshake.getIPv6();