diff --git a/pom.xml b/pom.xml
index b8bc54a..8815bcd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,6 +17,9 @@
UTF-8
+ 1.1-53-gdc63c67
+ 1.3.72
+ 4.1.3
@@ -33,7 +36,12 @@
${project.groupId}jitsi-utils
- 1.0-12-gcdf6537
+ 1.0-59-g5dc2b5f
+
+
+ ${project.groupId}
+ jicoco-config
+ ${jicoco.version}
@@ -43,14 +51,103 @@
4.11test
+
+ io.kotest
+ kotest-runner-junit5-jvm
+ ${kotest.version}
+ test
+
+
+ io.kotest
+ kotest-assertions-core-jvm
+ ${kotest.version}
+ test
+
+
+ io.kotest
+ kotest-runner-console-jvm
+ ${kotest.version}
+ test
+
+
+ org.jitsi
+ jicoco-test-kotlin
+ ${jicoco.version}
+ test
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ ${project.basedir}/src/main/kotlin
+ ${project.basedir}/src/main/java
+
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+ ${project.basedir}/src/test/kotlin
+ ${project.basedir}/src/test/java
+
+
+
+
+
+ 1.8
+
+ -Xallow-result-return-type
+
+
+ org.apache.maven.pluginsmaven-compiler-plugin3.8.0
+
+
+
+ default-compile
+ none
+
+
+
+ default-testCompile
+ none
+
+
+ java-compile
+ compile
+
+ compile
+
+
+
+ java-test-compile
+ test-compile
+
+ testCompile
+
+
+ 1.81.8
@@ -264,5 +361,9 @@
https://github.com/jitsi/jitsi-maven-repository/raw/master/releases/
+
+ jitpack.io
+ https://jitpack.io
+
diff --git a/src/main/java/org/ice4j/StackProperties.java b/src/main/java/org/ice4j/StackProperties.java
index b743fe6..db1789e 100644
--- a/src/main/java/org/ice4j/StackProperties.java
+++ b/src/main/java/org/ice4j/StackProperties.java
@@ -59,43 +59,6 @@ public class StackProperties
*/
public static final String BIND_WILDCARD = "org.ice4j.BIND_WILDCARD";
- /**
- * How often a STUN Binding request used for consent freshness check will be
- * sent(value in milliseconds).
- */
- public static final String CONSENT_FRESHNESS_INTERVAL
- = "org.ice4j.ice.CONSENT_FRESHNESS_INTERVAL";
-
- /**
- * The maximum number of retransmissions of a STUN Binding request without
- * a valid STUN Binding response after which consent freshness is to be
- * considered unconfirmed according to "STUN Usage for Consent
- * Freshness".
- */
- public static final String CONSENT_FRESHNESS_MAX_RETRANSMISSIONS
- = "org.ice4j.ice.CONSENT_FRESHNESS_MAX_RETRANSMISSIONS";
-
- /**
- * The number of milliseconds without a valid STUN Binding response after
- * which a STUN Binding request is to be retransmitted according to
- * "STUN Usage for Consent Freshness". This is the final value
- * for the back-off strategy.
- * {@link #CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL} defines the initial
- * interval for the first request sent. Value in milliseconds.
- */
- public static final String CONSENT_FRESHNESS_MAX_WAIT_INTERVAL
- = "org.ice4j.ice.CONSENT_FRESHNESS_MAX_WAIT_INTERVAL";
-
- /**
- * The number of milliseconds without a valid STUN Binding response after
- * which a STUN Binding request is to be retransmitted according to
- * "STUN Usage for Consent Freshness". This is the original value
- * for back-off strategy. {@link #CONSENT_FRESHNESS_MAX_WAIT_INTERVAL} sets
- * the upper limit. Value in milliseconds.
- */
- public static final String CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL
- = "org.ice4j.ice.CONSENT_FRESHNESS_WAIT_INTERVAL";
-
/**
* The number of milliseconds a client transaction should wait before
* retransmitting, after it has sent a request for the first time.
@@ -123,13 +86,6 @@ public class StackProperties
public static final String MAX_CTRAN_RETRANSMISSIONS
= "org.ice4j.MAX_RETRANSMISSIONS";
- /**
- * The name of the System property that allows us to set a custom maximum
- * for check list sizes.
- */
- public static final String MAX_CHECK_LIST_SIZE
- = "org.ice4j.MAX_CHECK_LIST_SIZE";
-
/**
* The value of the SOFTWARE attribute that ice4j should include in all
* outgoing messages.
@@ -164,14 +120,6 @@ public class StackProperties
public static final String REQUIRE_MESSAGE_INTEGRITY
= "org.ice4j.REQUIRE_MESSAGE_INTEGRITY";
- /**
- * The name of the property that can be used to specify the number of
- * milliseconds that we must wait after ICE processing enters a COMPLTED
- * state and before we free candidates and move into the TERMINATED state.
- */
- public static final String TERMINATION_DELAY
- = "org.ice4j.TERMINATION_DELAY";
-
/**
* The name of the property that can be used to disable STUN keep alives.
* Set to true to disable.
diff --git a/src/main/java/org/ice4j/ice/Agent.java b/src/main/java/org/ice4j/ice/Agent.java
index f021ad2..8cc5107 100644
--- a/src/main/java/org/ice4j/ice/Agent.java
+++ b/src/main/java/org/ice4j/ice/Agent.java
@@ -36,6 +36,8 @@ import java.util.*;
import java.util.concurrent.*;
import java.util.logging.*;
+import static org.ice4j.ice.AgentConfig.config;
+
/**
* An Agent could be described as the main class (i.e. the chef
* d'orchestre) of an ICE implementation.
@@ -59,42 +61,6 @@ import java.util.logging.*;
*/
public class Agent
{
- /**
- * Default value for {@link StackProperties#CONSENT_FRESHNESS_INTERVAL}.
- */
- private static final int DEFAULT_CONSENT_FRESHNESS_INTERVAL = 15000;
-
- /**
- * Default value for
- * {@link StackProperties#CONSENT_FRESHNESS_MAX_RETRANSMISSIONS}.
- */
- private static final int DEFAULT_CONSENT_FRESHNESS_MAX_RETRANSMISSIONS = 30;
-
- /**
- * Default value for
- * {@link StackProperties#CONSENT_FRESHNESS_MAX_WAIT_INTERVAL}.
- */
- private static final int DEFAULT_CONSENT_FRESHNESS_MAX_WAIT_INTERVAL = 500;
-
- /**
- * Default value for
- * {@link StackProperties#CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL}.
- */
- private static final int DEFAULT_CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL
- = 500;
-
- /**
- * The default maximum size for check lists.
- */
- public static final int DEFAULT_MAX_CHECK_LIST_SIZE = 100;
-
- /**
- * The default number of milliseconds we should wait before moving from
- * {@link IceProcessingState#COMPLETED} into {@link
- * IceProcessingState#TERMINATED}.
- */
- public static final int DEFAULT_TERMINATION_DELAY = 3000;
-
/**
* The constant which defines an empty array with element type
* PropertyChangeListener and represents the fact that there are no
@@ -976,31 +942,24 @@ public class Agent
*/
protected void initCheckLists()
{
- //first init the check list.
- List streams
- = getStreamsWithPendingConnectivityEstablishment();
+ // First init the check list.
+ List streams = getStreamsWithPendingConnectivityEstablishment();
int streamCount = streams.size();
- //init the maximum number of check list entries per stream.
- int maxCheckListSize = Integer.getInteger(
- StackProperties.MAX_CHECK_LIST_SIZE,
- DEFAULT_MAX_CHECK_LIST_SIZE);
-
- int maxPerStreamSize =
- streamCount == 0
- ? 0
- : maxCheckListSize / streamCount;
-
- for (IceMediaStream stream : streams)
- {
- logger.info("Init checklist for stream " + stream.getName());
- stream.setMaxCheckListSize(maxPerStreamSize);
- stream.initCheckList();
- }
-
- //init the states of the first media stream as per 5245
if (streamCount > 0)
+ {
+ int maxCheckListSizePerStream = config.getMaxCheckListSize() / streamCount;
+
+ for (IceMediaStream stream : streams)
+ {
+ logger.info("Init checklist for stream " + stream.getName());
+ stream.setMaxCheckListSize(maxCheckListSizePerStream);
+ stream.initCheckList();
+ }
+
+ // Init the states of the first media stream as per 5245
streams.get(0).getCheckList().computeInitialCheckListPairStates();
+ }
}
/**
@@ -2190,10 +2149,7 @@ public class Agent
{
if (terminationFuture == null)
{
- long terminationDelay
- = Integer.getInteger(
- StackProperties.TERMINATION_DELAY,
- DEFAULT_TERMINATION_DELAY);
+ long terminationDelay = config.getTerminationDelay().toMillis();
if (terminationDelay > 0)
{
@@ -2690,21 +2646,14 @@ public class Agent
*/
private final class StunKeepAliveRunner extends PeriodicRunnable
{
- private final long consentFreshnessInterval = Long.getLong(
- StackProperties.CONSENT_FRESHNESS_INTERVAL,
- DEFAULT_CONSENT_FRESHNESS_INTERVAL);
+ private final long consentFreshnessInterval = config.getConsentFreshnessInterval().toMillis();
+ private final int originalConsentFreshnessWaitInterval
+ = (int) config.getConsentFreshnessOriginalWaitInterval().toMillis();
- private final int originalConsentFreshnessWaitInterval = Integer.getInteger(
- StackProperties.CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL,
- DEFAULT_CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL);
+ private final int maxConsentFreshnessWaitInterval
+ = (int) config.getConsentFreshnessMaxWaitInterval().toMillis();
- private final int maxConsentFreshnessWaitInterval = Integer.getInteger(
- StackProperties.CONSENT_FRESHNESS_MAX_WAIT_INTERVAL,
- DEFAULT_CONSENT_FRESHNESS_MAX_WAIT_INTERVAL);
-
- private final int consentFreshnessMaxRetransmissions = Integer.getInteger(
- StackProperties.CONSENT_FRESHNESS_MAX_RETRANSMISSIONS,
- DEFAULT_CONSENT_FRESHNESS_MAX_RETRANSMISSIONS);
+ private final int consentFreshnessMaxRetransmissions = config.getMaxConsentFreshnessRetransmissions();
private int keepAliveSent = 0;
diff --git a/src/main/java/org/ice4j/ice/IceMediaStream.java b/src/main/java/org/ice4j/ice/IceMediaStream.java
index 6a4d22c..2ffd941 100644
--- a/src/main/java/org/ice4j/ice/IceMediaStream.java
+++ b/src/main/java/org/ice4j/ice/IceMediaStream.java
@@ -24,6 +24,8 @@ import org.ice4j.*;
import org.jitsi.utils.collections.*;
import org.jitsi.utils.logging2.*;
+import static org.ice4j.ice.AgentConfig.config;
+
/**
* The class represents a media stream from the ICE perspective, i.e. a
* collection of components.
@@ -127,7 +129,7 @@ public class IceMediaStream
* across all check lists to a specific value, adn this value MUST be
* configurable. A default of 100 is RECOMMENDED.
*/
- private int maxCheckListSize = Agent.DEFAULT_MAX_CHECK_LIST_SIZE;
+ private int maxCheckListSize = config.getMaxCheckListSize();
/**
* The user fragment that we received from the remote party.
diff --git a/src/main/kotlin/org/ice4j/ice/AgentConfig.kt b/src/main/kotlin/org/ice4j/ice/AgentConfig.kt
new file mode 100644
index 0000000..0745cb7
--- /dev/null
+++ b/src/main/kotlin/org/ice4j/ice/AgentConfig.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright @ 2020 - Present, 8x8 Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.ice4j.ice
+
+import org.jitsi.metaconfig.config
+import java.time.Duration
+
+import org.jitsi.config.JitsiConfig.Companion.newConfig as configSource
+
+class AgentConfig {
+ val consentFreshnessInterval: Duration by config {
+ "org.ice4j.ice.CONSENT_FRESHNESS_INTERVAL".from(configSource)
+ .convertFrom { Duration.ofMillis(it) }
+ "ice4j.consent-freshness.interval".from(configSource)
+ }
+
+ val consentFreshnessOriginalWaitInterval: Duration by config {
+ "org.ice4j.ice.CONSENT_FRESHNESS_WAIT_INTERVAL".from(configSource)
+ .convertFrom { Duration.ofMillis(it) }
+ "ice4j.consent-freshness.original-wait-interval".from(configSource)
+ }
+
+ val consentFreshnessMaxWaitInterval: Duration by config {
+ "org.ice4j.ice.CONSENT_FRESHNESS_MAX_WAIT_INTERVAL".from(configSource)
+ .convertFrom { Duration.ofMillis(it) }
+ "ice4j.consent-freshness.max-wait-interval".from(configSource)
+ }
+
+ val maxConsentFreshnessRetransmissions: Int by config {
+ "org.ice4j.ice.CONSENT_FRESHNESS_MAX_RETRANSMISSIONS".from(configSource)
+ "ice4j.consent-freshness.max-retransmissions".from(configSource)
+ }
+
+ val terminationDelay: Duration by config {
+ "org.ice4j.TERMINATION_DELAY".from(configSource)
+ .convertFrom { Duration.ofMillis(it) }
+ "ice4j.ice.termination-delay".from(configSource)
+ }
+
+ val maxCheckListSize: Int by config {
+ "org.ice4j.MAX_CHECK_LIST_SIZE".from(configSource)
+ "ice4j.ice.max-check-list-size".from(configSource)
+ }
+
+ companion object {
+ @JvmField
+ val config = AgentConfig()
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf
new file mode 100644
index 0000000..2179a49
--- /dev/null
+++ b/src/main/resources/reference.conf
@@ -0,0 +1,25 @@
+ice4j {
+ ice {
+ max-check-list-size = 100
+ # The amount of time that we must wait after ICE processing enters a COMPLETED state before we free candidates
+ # and move into the TERMINATED state.
+ termination-delay = 3 seconds
+ }
+
+ consent-freshness {
+ # How often a STUN Binding request used for consent freshness check will be sent.
+ interval = 15 seconds
+ # The amount of time without a valid STUN Binding response after which a STUN Binding request is to be
+ # retransmitted according to `STUN Usage for Consent Freshness` (RFC7675).
+ # This is the original value for back-off strategy, while `max-wait-interval` sets the upper limit.
+ original-wait-interval = 500 milliseconds
+ # The amount of time without a valid STUN Binding response after which a STUN Binding request is to be
+ # retransmitted according to `STUN Usage for Consent Freshness` (RFC7675).
+ # This is the final value for the back-off strategy, while `original-wait-interval` defines the initial interval for
+ # the first request sent.
+ max-wait-interval = 500 milliseconds
+ # The maximum number of retransmissions of a STUN Binding request without a valid STUN Binding response after which
+ # consent freshness is to be considered unconfirmed according to `STUN Usage for Consent Freshness` (RFC7675).
+ max-retransmissions = 30
+ }
+}
diff --git a/src/test/kotlin/org/ice4j/ConfigTest.kt b/src/test/kotlin/org/ice4j/ConfigTest.kt
new file mode 100644
index 0000000..bc0e361
--- /dev/null
+++ b/src/test/kotlin/org/ice4j/ConfigTest.kt
@@ -0,0 +1,42 @@
+/*
+ * Copyright @ 2020 - present 8x8, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.ice4j
+
+import io.kotest.core.spec.IsolationMode
+import io.kotest.core.spec.Spec
+import io.kotest.core.spec.style.ShouldSpec
+import io.kotest.extensions.system.withSystemProperties
+import org.jitsi.config.useNewConfig
+import org.jitsi.metaconfig.MetaconfigSettings
+
+/**
+ * A helper class for testing configuration properties
+ */
+abstract class ConfigTest : ShouldSpec() {
+ override fun isolationMode(): IsolationMode? = IsolationMode.InstancePerLeaf
+
+ override fun beforeSpec(spec: Spec) {
+ super.beforeSpec(spec)
+ MetaconfigSettings.cacheEnabled = false
+ }
+
+ inline fun withNewConfig(config: String, block: () -> Unit) {
+ useNewConfig("new-${this::class.simpleName}", config, true, block)
+ }
+
+ fun withLegacyConfig(config: Map, block: () -> Unit) = withSystemProperties(config) { block }
+}
diff --git a/src/test/kotlin/org/ice4j/ice/AgentConfigTest.kt b/src/test/kotlin/org/ice4j/ice/AgentConfigTest.kt
new file mode 100644
index 0000000..6a10e5b
--- /dev/null
+++ b/src/test/kotlin/org/ice4j/ice/AgentConfigTest.kt
@@ -0,0 +1,86 @@
+/*
+ * Copyright @ 2020 - present 8x8, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.ice4j.ice
+
+import io.kotest.matchers.shouldBe
+import org.ice4j.ConfigTest
+import org.ice4j.ice.AgentConfig.Companion.config
+import org.jitsi.utils.ms
+import org.jitsi.utils.secs
+
+class AgentConfigTest : ConfigTest() {
+ init {
+ context("Default values") {
+ config.consentFreshnessInterval shouldBe 15.secs
+ config.consentFreshnessMaxWaitInterval shouldBe 500.ms
+ config.consentFreshnessOriginalWaitInterval shouldBe 500.ms
+ config.maxConsentFreshnessRetransmissions shouldBe 30
+ config.maxCheckListSize shouldBe 100
+ config.terminationDelay shouldBe 3.secs
+ }
+ context("Setting via legacy config (system properties)") {
+ withLegacyConfig(legacyConfig) {
+ config.consentFreshnessInterval shouldBe 5.secs
+ config.consentFreshnessMaxWaitInterval shouldBe 5.secs
+ config.consentFreshnessOriginalWaitInterval shouldBe 5.secs
+ config.maxConsentFreshnessRetransmissions shouldBe 5000
+ config.terminationDelay shouldBe 5.secs
+ config.maxCheckListSize shouldBe 5000
+ }
+ }
+ context("Setting via new config") {
+ withNewConfig(newConfig) {
+ config.consentFreshnessInterval shouldBe 6.secs
+ config.consentFreshnessMaxWaitInterval shouldBe 6.secs
+ config.consentFreshnessOriginalWaitInterval shouldBe 6.secs
+ config.maxConsentFreshnessRetransmissions shouldBe 6000
+ config.terminationDelay shouldBe 6.secs
+ config.maxCheckListSize shouldBe 6000
+ }
+ }
+ context("Legacy config must take precedence") {
+ withLegacyConfig(legacyConfig) {
+ withNewConfig(newConfig) {
+ config.consentFreshnessInterval shouldBe 5.secs
+ config.consentFreshnessMaxWaitInterval shouldBe 5.secs
+ config.consentFreshnessOriginalWaitInterval shouldBe 5.secs
+ config.maxConsentFreshnessRetransmissions shouldBe 5000
+ config.terminationDelay shouldBe 5.secs
+ config.maxCheckListSize shouldBe 5000
+ }
+ }
+ }
+ }
+}
+
+private val legacyConfig = mapOf(
+ "org.ice4j.ice.CONSENT_FRESHNESS_INTERVAL" to "5000",
+ "org.ice4j.ice.CONSENT_FRESHNESS_MAX_WAIT_INTERVAL" to "5000",
+ "org.ice4j.ice.CONSENT_FRESHNESS_WAIT_INTERVAL" to "5000",
+ "org.ice4j.ice.CONSENT_FRESHNESS_MAX_RETRANSMISSIONS" to "5000",
+ "org.ice4j.TERMINATION_DELAY" to "5000",
+ "org.ice4j.MAX_CHECK_LIST_SIZE" to "5000")
+
+private val newConfig = """
+ ice4j.consent-freshness.interval = 6 seconds
+ ice4j.consent-freshness.original-wait-interval = 6 seconds
+ ice4j.consent-freshness.max-wait-interval = 6 seconds
+ ice4j.consent-freshness.max-retransmissions = 6000
+ ice4j.ice.max-check-list-size = 6000
+ ice4j.ice.termination-delay = 6 seconds
+
+""".trimIndent()