refactor: Moves the getAllowedInetAddresses method to HostCandidateHarvester.
This commit is contained in:
parent
256176dde6
commit
c919de1b3a
@ -19,10 +19,7 @@ package org.ice4j.ice.harvest;
|
|||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.attribute.*;
|
import org.ice4j.attribute.*;
|
||||||
import org.ice4j.ice.*;
|
|
||||||
import org.ice4j.message.*;
|
import org.ice4j.message.*;
|
||||||
import org.ice4j.socket.*;
|
|
||||||
import org.ice4j.stack.*;
|
|
||||||
import org.ice4j.util.*;
|
import org.ice4j.util.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -85,7 +82,8 @@ public abstract class AbstractUdpListener
|
|||||||
public static List<TransportAddress> getAllowedAddresses(int port)
|
public static List<TransportAddress> getAllowedAddresses(int port)
|
||||||
{
|
{
|
||||||
List<TransportAddress> addresses = new LinkedList<>();
|
List<TransportAddress> addresses = new LinkedList<>();
|
||||||
for (InetAddress address : getAllowedInetAddresses())
|
for (InetAddress address
|
||||||
|
: HostCandidateHarvester.getAllAllowedAddresses())
|
||||||
{
|
{
|
||||||
addresses.add(new TransportAddress(address, port, Transport.UDP));
|
addresses.add(new TransportAddress(address, port, Transport.UDP));
|
||||||
}
|
}
|
||||||
@ -93,60 +91,6 @@ public abstract class AbstractUdpListener
|
|||||||
return addresses;
|
return addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the list of all local IP addresses from all allowed network
|
|
||||||
* interfaces, which are allowed addresses.
|
|
||||||
*/
|
|
||||||
public static List<InetAddress> getAllowedInetAddresses()
|
|
||||||
{
|
|
||||||
List<InetAddress> 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<InetAddress> 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 <tt>buf</tt> at offset <tt>off</tt> (and
|
* Tries to parse the bytes in <tt>buf</tt> at offset <tt>off</tt> (and
|
||||||
* length <tt>len</tt>) as a STUN Binding Request message. If successful,
|
* length <tt>len</tt>) as a STUN Binding Request message. If successful,
|
||||||
|
|||||||
@ -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.
|
* @return the list of explicitly allowed addresses.
|
||||||
*/
|
*/
|
||||||
public static synchronized List<InetAddress> getAllowedAddresses()
|
public static synchronized List<InetAddress> 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<InetAddress> getAllAllowedAddresses()
|
||||||
|
{
|
||||||
|
List<InetAddress> 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<InetAddress> 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
|
* Gathers all candidate addresses on the local machine, binds sockets on
|
||||||
* them and creates {@link HostCandidate}s. The harvester would always
|
* them and creates {@link HostCandidate}s. The harvester would always
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user