Supports multiple "host" harvesters. Allows the default dynamic harvester to be disabled.
This commit is contained in:
parent
5ebfe11c55
commit
a55f6c6be6
@ -39,6 +39,7 @@ import org.ice4j.stack.*;
|
||||
* @author Lyubomir Marinov
|
||||
* @author Sebastien Vincent
|
||||
* @author Aakash Garg
|
||||
* @author Boris Grozev
|
||||
*/
|
||||
public class Agent
|
||||
{
|
||||
@ -106,6 +107,14 @@ public class Agent
|
||||
private final HostCandidateHarvester 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
|
||||
* use when gathering candidates for components.
|
||||
@ -254,6 +263,12 @@ public class Agent
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -412,9 +427,17 @@ public class Agent
|
||||
logger.info("Gather candidates for component " +
|
||||
component.toShortString());
|
||||
|
||||
hostCandidateHarvester.harvest(
|
||||
component,
|
||||
preferredPort, minPort, maxPort, Transport.UDP);
|
||||
if (useHostHarvester)
|
||||
{
|
||||
hostCandidateHarvester.harvest(
|
||||
component,
|
||||
preferredPort, minPort, maxPort, Transport.UDP);
|
||||
}
|
||||
|
||||
for (CandidateHarvester harvester : hostHarvesters)
|
||||
{
|
||||
harvester.harvest(component);
|
||||
}
|
||||
|
||||
logger.fine("host candidate count: " +
|
||||
component.getLocalCandidateCount());
|
||||
@ -749,7 +772,10 @@ public class Agent
|
||||
*/
|
||||
public void addCandidateHarvester(CandidateHarvester harvester)
|
||||
{
|
||||
harvesters.add(harvester);
|
||||
if (harvester.isHostHarvester())
|
||||
hostHarvesters.add(harvester);
|
||||
else
|
||||
harvesters.add(harvester);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2432,4 +2458,27 @@ public class Agent
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -55,4 +55,20 @@ public abstract class CandidateHarvester
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ public class MultiplexingTcpHostHarvester
|
||||
/**
|
||||
* Returns a list of all addresses on the interfaces in <tt>interfaces</tt>
|
||||
* 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 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
|
||||
* <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
|
||||
// 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)
|
||||
key.cancel();
|
||||
channel.channel.configureBlocking(true);
|
||||
|
||||
// Construct a DatagramPacket from the just-read packet
|
||||
// which is to be pushed pack
|
||||
// which is to be pushed back
|
||||
DatagramPacket p
|
||||
= new DatagramPacket(bytesRead,
|
||||
bytesRead.length);
|
||||
|
||||
@ -36,7 +36,8 @@ public class IceUdpSocketWrapper
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void send(DatagramPacket p) throws IOException
|
||||
public void send(DatagramPacket p)
|
||||
throws IOException
|
||||
{
|
||||
socket.send(p);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user