diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index f729ed0..d5cf9a3 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -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 CandidateHarvesters which will be used to + * harvest candidates synchronously, and previously to harvesting by + * {@link #harvesters}. + */ + private final List hostHarvesters + = new LinkedList(); + /** * 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 Agent 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 true 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 Components 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; + } + } diff --git a/src/org/ice4j/ice/harvest/CandidateHarvester.java b/src/org/ice4j/ice/harvest/CandidateHarvester.java index 3d03b43..75d5cd4 100644 --- a/src/org/ice4j/ice/harvest/CandidateHarvester.java +++ b/src/org/ice4j/ice/harvest/CandidateHarvester.java @@ -55,4 +55,20 @@ public abstract class CandidateHarvester { return harvestStatistics; } + + /** + * Returns true if this CandidateHarvester is to be + * considered a harvester for host candidates. Such a harvester should + * 1. Create local candidates of type HOST_CANDIDATE. + * 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 true if this CandidateHarvester is a harvester + * for host candidates. + */ + public boolean isHostHarvester() + { + return false; + } } diff --git a/src/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java b/src/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java index 55c8ee6..7ed72af 100644 --- a/src/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java +++ b/src/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java @@ -58,7 +58,7 @@ public class MultiplexingTcpHostHarvester /** * Returns a list of all addresses on the interfaces in interfaces * 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 Thread which will accept new SocketChannels from all * ServerSocketChannels 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); diff --git a/src/org/ice4j/socket/IceUdpSocketWrapper.java b/src/org/ice4j/socket/IceUdpSocketWrapper.java index 6b40452..d9b2066 100644 --- a/src/org/ice4j/socket/IceUdpSocketWrapper.java +++ b/src/org/ice4j/socket/IceUdpSocketWrapper.java @@ -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); }