public class HostCandidateHarvester extends Object
Component
. Most CandidateHarvesters
would rely on the output of the host harvester, that is all host addresses,
to be already present and bound in a Component before being able to
harvest the type of addresses that they are responsible for.Modifier and Type | Field and Description |
---|---|
private static boolean |
addressFiltersInitialized
A boolean value that indicates whether the host candidate address
filters have been initialized or not.
|
private static List<InetAddress> |
allowedAddresses
The list of allowed addresses.
|
private static String[] |
allowedInterfaces
Holds the list of allowed interfaces.
|
private static List<InetAddress> |
blockedAddresses
The list of blocked addresses.
|
private static String[] |
blockedInterfaces
Holds the list of blocked interfaces.
|
private HarvestStatistics |
harvestStatistics
Manages statistics about harvesting time.
|
private static boolean |
interfaceFiltersInitialized
A boolean value that indicates whether the host candidate interface
filters have been initialized or not.
|
private static Logger |
logger
Our class logger.
|
Constructor and Description |
---|
HostCandidateHarvester() |
Modifier and Type | Method and Description |
---|---|
private void |
checkPorts(int preferredPort,
int minPort,
int maxPort)
Checks if the different ports are correctly set.
|
private void |
createAndRegisterStunSocket(HostCandidate candidate)
Since we are most certainly going to use all local host candidates for
sending and receiving STUN connectivity checks, and possibly for STUN
harvesting too, we might as well create their STUN sockets here and
register them with the StunStack.
|
private IceSocketWrapper |
createDatagramSocket(InetAddress laddr,
int preferredPort,
int minPort,
int maxPort)
Creates a DatagramSocket and binds it to the specified
localAddress and a port in the range specified by the
minPort and maxPort parameters.
|
private IceSocketWrapper |
createServerSocket(InetAddress laddr,
int preferredPort,
int minPort,
int maxPort,
Component component)
Creates a ServerSocket and binds it to the specified
localAddress and a port in the range specified by the
minPort and maxPort parameters.
|
static List<InetAddress> |
getAllAllowedAddresses() |
static List<InetAddress> |
getAllowedAddresses()
Gets the list of addresses which have been explicitly allowed via
configuration properties.
|
static String[] |
getAllowedInterfaces()
Gets the array of allowed interfaces.
|
static List<InetAddress> |
getBlockedAddresses()
Gets the list of blocked addresses.
|
static String[] |
getBlockedInterfaces()
Gets the array of blocked interfaces.
|
HarvestStatistics |
getHarvestStatistics()
Returns the statistics describing how well the various harvests of this
harvester went.
|
void |
harvest(Component component,
int preferredPort,
int minPort,
int maxPort,
Transport transport)
Gathers all candidate addresses on the local machine, binds sockets on
them and creates
HostCandidate s. |
private static void |
initializeAddressFilters()
Initializes the lists of allowed and blocked addresses according to the
configuration properties.
|
static void |
initializeInterfaceFilters()
Initializes the host candidate interface filters stored in the
org.ice4j.ice.harvest.ALLOWED_INTERFACES and
org.ice4j.ice.harvest.BLOCKED_INTERFACES properties.
|
(package private) static boolean |
isAddressAllowed(InetAddress address)
Returns true if address is allowed to be used by this
HostCandidateHarvester for the purposes of candidate allocation,
and false otherwise.
|
(package private) static boolean |
isInterfaceAllowed(NetworkInterface iface)
Returns a boolean value indicating whether ice4j should allocate a host
candidate for the specified interface.
|
private static final Logger logger
private HarvestStatistics harvestStatistics
private static String[] allowedInterfaces
private static String[] blockedInterfaces
private static List<InetAddress> allowedAddresses
private static List<InetAddress> blockedAddresses
private static boolean interfaceFiltersInitialized
private static boolean addressFiltersInitialized
public static String[] getAllowedInterfaces()
public static String[] getBlockedInterfaces()
public static List<InetAddress> getAllowedAddresses()
getAllAllowedAddresses()
.public static List<InetAddress> getBlockedAddresses()
private static void initializeAddressFilters()
public static List<InetAddress> getAllAllowedAddresses()
public void harvest(Component component, int preferredPort, int minPort, int maxPort, Transport transport) throws IllegalArgumentException, IOException
HostCandidate
s. The harvester would always
try to bind the sockets on the specified preferredPort first.
If that fails we will move through all ports between minPort and
maxPort and give up if still can't find a free port.component
- the Component
that we'd like to gather candidate
addresses for.preferredPort
- the port number that should be tried first when
binding local Candidate sockets for this Component.minPort
- the port number where we should first try to bind before
moving to the next one (i.e. minPort + 1)maxPort
- the maximum port number where we should try binding
before giving up and throwing an exception.transport
- transport protocol usedIllegalArgumentException
- if either minPort or
maxPort is not a valid port number, minPort >
maxPort or if transport is not supported.IOException
- if an error occurs while the underlying resolver lib
is using sockets.static boolean isInterfaceAllowed(NetworkInterface iface)
iface
- The NetworkInterface
.NetworkInterface
is listed in the
org.ice4j.ice.harvest.ALLOWED_INTERFACES list. If that list
isn't defined, returns true if it's not listed in the
org.ice4j.ice.harvest.BLOCKED_INTERFACES list. It returns
false otherwise.static boolean isAddressAllowed(InetAddress address)
address
- the address to checkprivate IceSocketWrapper createServerSocket(InetAddress laddr, int preferredPort, int minPort, int maxPort, Component component) throws IllegalArgumentException, IOException, BindException
laddr
- the address that we'd like to bind the socket on.preferredPort
- the port number that we should try to bind to first.minPort
- the port number where we should first try to bind before
moving to the next one (i.e. minPort + 1)maxPort
- the maximum port number where we should try binding
before giving up and throwing an exception.IllegalArgumentException
- if either minPort or
maxPort is not a valid port number or if minPort >
maxPort.IOException
- if an error occurs while the underlying resolver lib
is using sockets.BindException
- if we couldn't find a free port between
minPort and maxPort before reaching the maximum allowed
number of retries.private IceSocketWrapper createDatagramSocket(InetAddress laddr, int preferredPort, int minPort, int maxPort) throws IllegalArgumentException, IOException, BindException
laddr
- the address that we'd like to bind the socket on.preferredPort
- the port number that we should try to bind to first.minPort
- the port number where we should first try to bind before
moving to the next one (i.e. minPort + 1)maxPort
- the maximum port number where we should try binding
before giving up and throwing an exception.IllegalArgumentException
- if either minPort or
maxPort is not a valid port number or if minPort >
maxPort.IOException
- if an error occurs while the underlying resolver lib
is using sockets.BindException
- if we couldn't find a free port between
minPort and maxPort before reaching the maximum allowed
number of retries.private void createAndRegisterStunSocket(HostCandidate candidate)
candidate
- the candidate whose stun socket we'd like to initialize
and register with the StunStack.private void checkPorts(int preferredPort, int minPort, int maxPort) throws IllegalArgumentException
preferredPort
- the port number that we should try to bind to first.minPort
- the port number where we should first try to bind before
moving to the next one (i.e. minPort + 1)maxPort
- the maximum port number where we should try binding
before giving up and throwing an exception.IllegalArgumentException
- if either minPort or
maxPort is not a valid port number or if minPort is
greater than maxPort.public HarvestStatistics getHarvestStatistics()
HarvestStatistics
describing this harvester's
harvests.public static void initializeInterfaceFilters()
IllegalStateException
- if there were errors during host
candidate interface filters initialization.Copyright © 2018. All rights reserved.