From fc1498ef7e902dd8267a6cc1d3bfb85d2a2c6125 Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Wed, 29 Dec 2021 15:29:03 -0600 Subject: [PATCH] feat: Allow useDynamicPorts to be set per-Agent. --- src/main/java/org/ice4j/ice/Agent.java | 15 ++++++++++++++- src/main/resources/reference.conf | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) 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 }