Adds two configuration properties that give the possibility to define lists of allowed or lists of blocked interfaces for host candidate allocation.

This commit is contained in:
gp 2014-05-28 10:27:59 +00:00
parent ed918505b8
commit e14e8b6a9f
2 changed files with 95 additions and 1 deletions

View File

@ -7,6 +7,8 @@
*/
package org.ice4j;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.*;
/**
@ -167,6 +169,36 @@ public class StackProperties
return str;
}
/**
* Returns the String array of the specified property, or null in case
* the returned property string array had zero length.
*
* @param propertyName the name of the property that is being queried.
* @param regex the delimiting regular expression
*
* @return the array of strings computed by splitting the specified
* property value around matches of the given regular expression
*/
public static String[] getStringArray(String propertyName, String regex)
{
String str = getString(propertyName);
if (str == null)
return null;
String[] parts = str.split(regex);
// Remove mal-formatted entries.
List<String> res = new ArrayList<String>();
for (String s : parts)
if (s != null && s.trim().length() != 0)
res.add(s);
if (res.size() == 0)
return null;
return res.toArray(new String[res.size()]);
}
/**
* Returns the value of a specific property as a signed decimal integer. If
* a property with the specified property name exists, its string

View File

@ -27,6 +27,20 @@ import org.ice4j.socket.*;
*/
public class HostCandidateHarvester
{
/**
* The name of the allowed interfaces property which specifies the allowed
* interfaces for host candidate allocations.
*/
public static final String ALLOWED_INTERFACES
= "org.ice4j.ice.harvest.ALLOWED_INTERFACES";
/**
* The name of the allowed interfaces property which specifies the blocked
* interfaces for host candidate allocations.
*/
public static final String BLOCKED_INTERFACES
= "org.ice4j.ice.harvest.BLOCKED_INTERFACES";
/**
* Our class logger.
*/
@ -90,7 +104,8 @@ public class HostCandidateHarvester
NetworkInterface iface = interfaces.nextElement();
if (NetworkUtils.isInterfaceLoopback(iface)
|| !NetworkUtils.isInterfaceUp(iface))
|| !NetworkUtils.isInterfaceUp(iface)
|| !isInterfaceAllowed(iface))
{
//this one is obviously not going to do
continue;
@ -187,6 +202,53 @@ public class HostCandidateHarvester
.stopHarvestTiming(component.getLocalCandidateCount());
}
/**
* Returns a boolean value indicating whether ice4j should allocate a host
* candidate for the specified interface.
*
* @param iface The {@link NetworkInterface}.
*
* @return <tt>true</tt> if the {@link NetworkInterface} is listed in the
* <tt>org.ice4j.ice.harvest.ALLOWED_INTERFACES</tt> list. If that list
* isn't defined, returns <tt>true</tt> if it's not listed in the
* <tt>org.ice4j.ice.harvest.BLOCKED_INTERFACES</tt> list. It returns
* <tt>false</tt> otherwise.
*/
private boolean isInterfaceAllowed(NetworkInterface iface) {
if (iface == null)
throw new IllegalArgumentException("iface cannot be null");
// gp: use getDisplayName() on Windows and getName() on Linux. Also
// see NetworkAddressManagementServiceImpl in Jitsi.
String ifName = (System.getProperty("os.name") == null
|| System.getProperty("os.name").startsWith("Windows"))
? iface.getDisplayName()
: iface.getName();
String[] allowedInterfaces = StackProperties
.getStringArray(ALLOWED_INTERFACES, ";");
if (allowedInterfaces != null)
{
// A list of allowed interfaces exists.
return Arrays.asList(allowedInterfaces).contains(ifName);
}
else
{
// A list of allowed interfaces does not exist.
String[] blockedInterfaces = StackProperties
.getStringArray(BLOCKED_INTERFACES, ";");
if (blockedInterfaces != null)
{
// but a list of blocked interfaces exists.
return !Arrays.asList(blockedInterfaces).contains(ifName);
}
}
return true;
}
/**
* Creates a <tt>ServerSocket</tt> and binds it to the specified
* <tt>localAddress</tt> and a port in the range specified by the