diff --git a/src/main/java/org/ice4j/ice/harvest/AbstractUdpListener.java b/src/main/java/org/ice4j/ice/harvest/AbstractUdpListener.java index 78acca5..3ef9840 100644 --- a/src/main/java/org/ice4j/ice/harvest/AbstractUdpListener.java +++ b/src/main/java/org/ice4j/ice/harvest/AbstractUdpListener.java @@ -19,10 +19,7 @@ package org.ice4j.ice.harvest; import org.ice4j.*; import org.ice4j.attribute.*; -import org.ice4j.ice.*; import org.ice4j.message.*; -import org.ice4j.socket.*; -import org.ice4j.stack.*; import org.ice4j.util.*; import java.io.*; @@ -85,7 +82,8 @@ public abstract class AbstractUdpListener public static List getAllowedAddresses(int port) { List addresses = new LinkedList<>(); - for (InetAddress address : getAllowedInetAddresses()) + for (InetAddress address + : HostCandidateHarvester.getAllAllowedAddresses()) { addresses.add(new TransportAddress(address, port, Transport.UDP)); } @@ -93,60 +91,6 @@ public abstract class AbstractUdpListener return addresses; } - /** - * @return the list of all local IP addresses from all allowed network - * interfaces, which are allowed addresses. - */ - public static List getAllowedInetAddresses() - { - List addresses = new LinkedList<>(); - boolean isIPv6Disabled = StackProperties.getBoolean( - StackProperties.DISABLE_IPv6, - false); - boolean isIPv6LinkLocalDisabled = StackProperties.getBoolean( - StackProperties.DISABLE_LINK_LOCAL_ADDRESSES, - false); - - try - { - for (NetworkInterface iface - : Collections.list(NetworkInterface.getNetworkInterfaces())) - { - if (NetworkUtils.isInterfaceLoopback(iface) - || !NetworkUtils.isInterfaceUp(iface) - || !HostCandidateHarvester.isInterfaceAllowed(iface)) - { - continue; - } - - Enumeration ifaceAddresses - = iface.getInetAddresses(); - while (ifaceAddresses.hasMoreElements()) - { - InetAddress address = ifaceAddresses.nextElement(); - - if (!HostCandidateHarvester.isAddressAllowed(address)) - continue; - - if (isIPv6Disabled && address instanceof Inet6Address) - continue; - if (isIPv6LinkLocalDisabled - && address instanceof Inet6Address - && address.isLinkLocalAddress()) - continue; - - addresses.add(address); - } - } - } - catch (SocketException se) - { - logger.info("Failed to get network interfaces: " + se); - } - - return addresses; - } - /** * Tries to parse the bytes in buf at offset off (and * length len) as a STUN Binding Request message. If successful, diff --git a/src/main/java/org/ice4j/ice/harvest/HostCandidateHarvester.java b/src/main/java/org/ice4j/ice/harvest/HostCandidateHarvester.java index 04efdec..66e42d4 100644 --- a/src/main/java/org/ice4j/ice/harvest/HostCandidateHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/HostCandidateHarvester.java @@ -129,7 +129,9 @@ public class HostCandidateHarvester } /** - * Gets the list of explicitly allowed addresses. + * Gets the list of addresses which have been explicitly allowed via + * configuration properties. To get the list of all allowed addresses, + * use {@link #getAllAllowedAddresses()}. * @return the list of explicitly allowed addresses. */ public static synchronized List getAllowedAddresses() @@ -220,6 +222,60 @@ public class HostCandidateHarvester } } + /** + * @return the list of all local IP addresses from all allowed network + * interfaces, which are allowed addresses. + */ + public static List getAllAllowedAddresses() + { + List addresses = new LinkedList<>(); + boolean isIPv6Disabled = StackProperties.getBoolean( + StackProperties.DISABLE_IPv6, + false); + boolean isIPv6LinkLocalDisabled = StackProperties.getBoolean( + StackProperties.DISABLE_LINK_LOCAL_ADDRESSES, + false); + + try + { + for (NetworkInterface iface + : Collections.list(NetworkInterface.getNetworkInterfaces())) + { + if (NetworkUtils.isInterfaceLoopback(iface) + || !NetworkUtils.isInterfaceUp(iface) + || !isInterfaceAllowed(iface)) + { + continue; + } + + Enumeration ifaceAddresses + = iface.getInetAddresses(); + while (ifaceAddresses.hasMoreElements()) + { + InetAddress address = ifaceAddresses.nextElement(); + + if (!isAddressAllowed(address)) + continue; + + if (isIPv6Disabled && address instanceof Inet6Address) + continue; + if (isIPv6LinkLocalDisabled + && address instanceof Inet6Address + && address.isLinkLocalAddress()) + continue; + + addresses.add(address); + } + } + } + catch (SocketException se) + { + logger.info("Failed to get network interfaces: " + se); + } + + return addresses; + } + /** * Gathers all candidate addresses on the local machine, binds sockets on * them and creates {@link HostCandidate}s. The harvester would always