Supports multiple "host" harvesters. Allows the default dynamic harvester to be disabled.

This commit is contained in:
boris 2015-02-27 16:42:37 +00:00
parent 5ebfe11c55
commit a55f6c6be6
4 changed files with 83 additions and 8 deletions

View File

@ -39,6 +39,7 @@ import org.ice4j.stack.*;
* @author Lyubomir Marinov * @author Lyubomir Marinov
* @author Sebastien Vincent * @author Sebastien Vincent
* @author Aakash Garg * @author Aakash Garg
* @author Boris Grozev
*/ */
public class Agent public class Agent
{ {
@ -106,6 +107,14 @@ public class Agent
private final HostCandidateHarvester hostCandidateHarvester private final HostCandidateHarvester hostCandidateHarvester
= new HostCandidateHarvester(); = new HostCandidateHarvester();
/**
* A list of additional <tt>CandidateHarvester</tt>s which will be used to
* harvest candidates synchronously, and previously to harvesting by
* {@link #harvesters}.
*/
private final List<CandidateHarvester> hostHarvesters
= new LinkedList<CandidateHarvester>();
/** /**
* The set of harvesters (i.e. STUN, TURN, and others) that the agent should * The set of harvesters (i.e. STUN, TURN, and others) that the agent should
* use when gathering candidates for components. * use when gathering candidates for components.
@ -254,6 +263,12 @@ public class Agent
*/ */
private boolean performConsentFreshness = false; private boolean performConsentFreshness = false;
/**
* The flag which specifies whether {@link #hostCandidateHarvester} should
* be used or not.
*/
private boolean useHostHarvester = true;
/** /**
* Creates an empty <tt>Agent</tt> with no streams, and no address. * Creates an empty <tt>Agent</tt> with no streams, and no address.
*/ */
@ -412,9 +427,17 @@ public class Agent
logger.info("Gather candidates for component " + logger.info("Gather candidates for component " +
component.toShortString()); component.toShortString());
if (useHostHarvester)
{
hostCandidateHarvester.harvest( hostCandidateHarvester.harvest(
component, component,
preferredPort, minPort, maxPort, Transport.UDP); preferredPort, minPort, maxPort, Transport.UDP);
}
for (CandidateHarvester harvester : hostHarvesters)
{
harvester.harvest(component);
}
logger.fine("host candidate count: " + logger.fine("host candidate count: " +
component.getLocalCandidateCount()); component.getLocalCandidateCount());
@ -749,6 +772,9 @@ public class Agent
*/ */
public void addCandidateHarvester(CandidateHarvester harvester) public void addCandidateHarvester(CandidateHarvester harvester)
{ {
if (harvester.isHostHarvester())
hostHarvesters.add(harvester);
else
harvesters.add(harvester); harvesters.add(harvester);
} }
@ -2432,4 +2458,27 @@ public class Agent
{ {
this.performConsentFreshness = performConsentFreshness; this.performConsentFreshness = performConsentFreshness;
} }
/**
* Checks whether using the dynamic UDP host harvester is enabled or not.
*
* @return <tt>true</tt> if using the dynamic UDP host harvester is enabled.
*/
public boolean dynamicHostHarvesterEnabled()
{
return useHostHarvester;
}
/**
* Sets the flag to enable or disable the dynamic UDP host harvester.
* Note: to have the desired effect this needs to be called before any
* any <tt>Component</tt>s are created using
* {@link #createComponent(IceMediaStream, org.ice4j.Transport, int, int, int)}
* @param enable the value to set.
*/
public void enableDynamicHostHarvester(boolean enable)
{
this.useHostHarvester = enable;
}
} }

View File

@ -55,4 +55,20 @@ public abstract class CandidateHarvester
{ {
return harvestStatistics; return harvestStatistics;
} }
/**
* Returns <tt>true</tt> if this <tt>CandidateHarvester</tt> is to be
* considered a harvester for host candidates. Such a harvester should
* 1. Create local candidates of type <tt>HOST_CANDIDATE</tt>.
* 2. Not depend on other local candidates, already harvested for the
* component for which it is called.
* 3. Not perform blocking operations while harvesting.
*
* @return <tt>true</tt> if this <tt>CandidateHarvester</tt> is a harvester
* for host candidates.
*/
public boolean isHostHarvester()
{
return false;
}
} }

View File

@ -58,7 +58,7 @@ public class MultiplexingTcpHostHarvester
/** /**
* Returns a list of all addresses on the interfaces in <tt>interfaces</tt> * Returns a list of all addresses on the interfaces in <tt>interfaces</tt>
* which are found suitable for candidate allocations (are not loopback, are * which are found suitable for candidate allocations (are not loopback, are
* up, and are allowed by the configuration. * up, and are allowed by the configuration).
* *
* @param port the port to use. * @param port the port to use.
* @param interfaces the list of interfaces to use. * @param interfaces the list of interfaces to use.
@ -637,6 +637,15 @@ public class MultiplexingTcpHostHarvester
} }
} }
/**
* {@inheritDoc}
*/
@Override
public boolean isHostHarvester()
{
return true;
}
/** /**
* A <tt>Thread</tt> which will accept new <tt>SocketChannel</tt>s from all * A <tt>Thread</tt> which will accept new <tt>SocketChannel</tt>s from all
* <tt>ServerSocketChannel</tt>s in {@link #serverSocketChannels}. * <tt>ServerSocketChannel</tt>s in {@link #serverSocketChannels}.
@ -1253,13 +1262,13 @@ public class MultiplexingTcpHostHarvester
// The rest of the stack will read from the socket's // The rest of the stack will read from the socket's
// InputStream. We cannot change the blocking mode // InputStream. We cannot change the blocking mode
// bore the channel is removed from the selector (by // before the channel is removed from the selector (by
// cancelling the key) // cancelling the key)
key.cancel(); key.cancel();
channel.channel.configureBlocking(true); channel.channel.configureBlocking(true);
// Construct a DatagramPacket from the just-read packet // Construct a DatagramPacket from the just-read packet
// which is to be pushed pack // which is to be pushed back
DatagramPacket p DatagramPacket p
= new DatagramPacket(bytesRead, = new DatagramPacket(bytesRead,
bytesRead.length); bytesRead.length);

View File

@ -36,7 +36,8 @@ public class IceUdpSocketWrapper
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void send(DatagramPacket p) throws IOException public void send(DatagramPacket p)
throws IOException
{ {
socket.send(p); socket.send(p);
} }