diff --git a/src/main/java/org/ice4j/ice/Agent.java b/src/main/java/org/ice4j/ice/Agent.java
index 87256fe..cb5fa10 100644
--- a/src/main/java/org/ice4j/ice/Agent.java
+++ b/src/main/java/org/ice4j/ice/Agent.java
@@ -301,6 +301,11 @@ public class Agent
*/
private final Logger logger;
+ /**
+ * Whether this {@link Agent} should use dynamic ports. Can be overridden via {@link #setUseDynamicPorts(boolean)}.
+ */
+ private boolean useDynamicPorts = HarvestConfig.config.useDynamicPorts();
+
/**
* Creates an empty Agent with no streams, and no address.
*/
@@ -574,6 +579,14 @@ public class Agent
return new CandidatePair(local, remote);
}
+ /**
+ * Sets the flag for whether this {@link Agent} instance should use dynamic ports.
+ */
+ public void setUseDynamicPorts(boolean value)
+ {
+ useDynamicPorts = value;
+ }
+
/**
* Uses all CandidateHarvesters currently registered with this
* Agent to obtain whatever addresses they can discover.
@@ -607,7 +620,7 @@ public class Agent
logger.info("Gathering candidates for component " +
component.toShortString() +".");
- if (HarvestConfig.config.useDynamicPorts())
+ if (useDynamicPorts)
{
hostCandidateHarvester.harvest(
component,
diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf
index 58892d6..ff752e1 100644
--- a/src/main/resources/reference.conf
+++ b/src/main/resources/reference.conf
@@ -38,7 +38,8 @@ ice4j {
// The size in bytes to set on the UDP socket (SO_RCVBUF). If not specified, the default from the OS will be used.
#receive-buffer-size = 10485760
- // Whether to allocate ephemeral ports for local candidates.
+ // Whether to allocate ephemeral ports for local candidates. This is the default value, and can be overridden
+ // for Agent instances.
use-dynamic-ports = true
}