diff --git a/src/main/java/org/ice4j/StackProperties.java b/src/main/java/org/ice4j/StackProperties.java index dc35a6f..81b7009 100644 --- a/src/main/java/org/ice4j/StackProperties.java +++ b/src/main/java/org/ice4j/StackProperties.java @@ -86,12 +86,6 @@ public class StackProperties public static final String MAX_CTRAN_RETRANSMISSIONS = "org.ice4j.MAX_RETRANSMISSIONS"; - /** - * The value of the SOFTWARE attribute that ice4j should include in all - * outgoing messages. - */ - public static final String SOFTWARE = "org.ice4j.SOFTWARE"; - /** * The name of the property that tells the stack whether or not it should * let the application see retransmissions of incoming requests. @@ -172,18 +166,6 @@ public class StackProperties public static final String BLOCKED_ADDRESSES = "org.ice4j.ice.harvest.BLOCKED_ADDRESSES"; - /** - * The name of the property which specifies whether the per-component - * merging socket should be enabled by default (the default value can be - * overridden with {@link Agent#createComponent(IceMediaStream, Transport, - * int, int, int, KeepAliveStrategy, boolean)}. - * If enabled, the user of the library must use the socket instance provided - * by {@link Component#getSocket()}. Otherwise, the socket instance from the - * desired {@link CandidatePair} must be used. - */ - public static final String USE_COMPONENT_SOCKET - = "org.ice4j.ice.USE_COMPONENT_SOCKET"; - /** * Returns the String value of the specified property (minus all * encompassing whitespaces)and null in case no property value was mapped diff --git a/src/main/java/org/ice4j/ice/Agent.java b/src/main/java/org/ice4j/ice/Agent.java index 0a2273f..44ced99 100644 --- a/src/main/java/org/ice4j/ice/Agent.java +++ b/src/main/java/org/ice4j/ice/Agent.java @@ -349,11 +349,6 @@ public class Agent //add the FINGERPRINT attribute to all messages. System.setProperty(StackProperties.ALWAYS_SIGN, "true"); - //add the software attribute to all messages - if (StackProperties.getString(StackProperties.SOFTWARE) == null) - System.setProperty(StackProperties.SOFTWARE, "ice4j.org"); - - password = ensureIceAttributeLength( new BigInteger(128, random).toString(32), @@ -447,7 +442,7 @@ public class Agent stream, preferredPort, minPort, maxPort, KeepAliveStrategy.SELECTED_ONLY, - StackProperties.getBoolean(StackProperties.USE_COMPONENT_SOCKET, true)); + config.getUseComponentSocket()); } /** diff --git a/src/main/java/org/ice4j/ice/Component.java b/src/main/java/org/ice4j/ice/Component.java index 67ac85c..42c1eca 100644 --- a/src/main/java/org/ice4j/ice/Component.java +++ b/src/main/java/org/ice4j/ice/Component.java @@ -1063,8 +1063,7 @@ public class Component componentID, mediaStream, KeepAliveStrategy.SELECTED_ONLY, - StackProperties.getBoolean( - StackProperties.USE_COMPONENT_SOCKET, true), + AgentConfig.config.getUseComponentSocket(), parentLogger ); } diff --git a/src/main/java/org/ice4j/ice/IceMediaStream.java b/src/main/java/org/ice4j/ice/IceMediaStream.java index 43e2a52..10e0500 100644 --- a/src/main/java/org/ice4j/ice/IceMediaStream.java +++ b/src/main/java/org/ice4j/ice/IceMediaStream.java @@ -170,7 +170,7 @@ public class IceMediaStream * @param keepAliveStrategy the keep-alive strategy, which dictates which * candidates pairs are going to be kept alive. * @param useComponentSocket whether the "component socket" should be used - * or not. See {@link StackProperties#USE_COMPONENT_SOCKET}. + * or not. See {@link AgentConfig#getUseComponentSocket()}. * * @return the newly created stream Component after adding it to * the stream first. diff --git a/src/main/java/org/ice4j/message/Message.java b/src/main/java/org/ice4j/message/Message.java index 2f16a91..c858776 100644 --- a/src/main/java/org/ice4j/message/Message.java +++ b/src/main/java/org/ice4j/message/Message.java @@ -22,6 +22,7 @@ import java.util.logging.*; import org.ice4j.*; import org.ice4j.attribute.*; +import org.ice4j.ice.*; import org.ice4j.stack.*; /** @@ -1020,7 +1021,7 @@ public abstract class Message //add a SOFTWARE attribute if the user said so, and unless they did it //themselves. - String software = System.getProperty(StackProperties.SOFTWARE); + String software = AgentConfig.config.getSoftware(); if (getAttribute(Attribute.SOFTWARE) == null && software != null && software.length() > 0) diff --git a/src/main/kotlin/org/ice4j/ice/AgentConfig.kt b/src/main/kotlin/org/ice4j/ice/AgentConfig.kt index 762fbe1..d436fe3 100644 --- a/src/main/kotlin/org/ice4j/ice/AgentConfig.kt +++ b/src/main/kotlin/org/ice4j/ice/AgentConfig.kt @@ -55,6 +55,23 @@ class AgentConfig { "ice4j.ice.max-check-list-size".from(configSource) } + /** The value of the SOFTWARE attribute that ice4j should include in all outgoing messages. */ + val software: String? by config { + "org.ice4j.SOFTWARE".from(configSource) + "ice4j.software".from(configSource) + } + + /** + * Whether the per-component merging socket should be enabled by default (the default value can be + * overridden with the [Agent] API). + * If enabled, the user of the library must use the socket instance provided by [Component.getSocket]. Otherwise, + * the socket instance from the desired [CandidatePair] must be used. + */ + val useComponentSocket: Boolean by config { + "org.ice4j.ice.USE_COMPONENT_SOCKET".from(configSource) + "ice4j.use-component-socket".from(configSource) + } + companion object { @JvmField val config = AgentConfig() diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index ff752e1..c572849 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -6,6 +6,16 @@ ice4j { termination-delay = 3 seconds } + // The value of the SOFTWARE attribute that ice4j should include in all outgoing messages. Set to the empty string to + // not include a SOFTWARE attribute. + software = "ice4j.org" + + // Whether the per-component merging socket should be enabled by default (the default value can be + // overridden with the [Agent] API). + // If enabled, the user of the library must use the socket instance provided by [Component.getSocket]. Otherwise, + // the socket instance from the desired [CandidatePair] must be used. + use-component-socket = true + consent-freshness { // How often a STUN Binding request used for consent freshness check will be sent. interval = 15 seconds diff --git a/src/test/java/org/ice4j/TestExecutionListener.java b/src/test/java/org/ice4j/TestExecutionListener.java new file mode 100644 index 0000000..35f60e4 --- /dev/null +++ b/src/test/java/org/ice4j/TestExecutionListener.java @@ -0,0 +1,47 @@ +/* + * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. + * + * Copyright @ 2015 Atlassian Pty Ltd + * + * 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 org.jitsi.metaconfig.*; +import org.junit.platform.launcher.*; + +public class TestExecutionListener implements org.junit.platform.launcher.TestExecutionListener { + private static boolean initialized = false; + + private static void beforeAll() + { + // Disable config caching. + MetaconfigSettings.Companion.setCacheEnabled(false); + } + + public TestExecutionListener() + {} + + @Override + public void executionStarted(TestIdentifier testIdentifier) + { + synchronized (TestExecutionListener.class) + { + if (!initialized) + { + beforeAll(); + initialized = true; + } + } + } +} diff --git a/src/test/java/org/ice4j/message/MessageTest.java b/src/test/java/org/ice4j/message/MessageTest.java index db05972..4cf7c41 100644 --- a/src/test/java/org/ice4j/message/MessageTest.java +++ b/src/test/java/org/ice4j/message/MessageTest.java @@ -22,10 +22,27 @@ import static org.junit.jupiter.api.Assertions.*; import org.ice4j.*; import org.ice4j.attribute.*; import org.ice4j.stack.*; +import org.jitsi.config.*; import org.junit.jupiter.api.*; public class MessageTest { + + @BeforeAll + public static void setupConfig() + { + System.clearProperty(StackProperties.ALWAYS_SIGN); + System.setProperty("ice4j.software", ""); + JitsiConfig.Companion.reloadNewConfig(); + } + + @AfterAll + public static void resetConfig() + { + System.clearProperty("ice4j.software"); + JitsiConfig.Companion.reloadNewConfig(); + } + private Message bindingRequest = null; private Message bindingResponse = null; @@ -45,8 +62,6 @@ public class MessageTest @BeforeEach public void setUp() throws Exception { - System.clearProperty(StackProperties.ALWAYS_SIGN); - System.clearProperty(StackProperties.SOFTWARE); msgFixture = new MsgFixture(); stunStack = new StunStack(); diff --git a/src/test/java/org/ice4j/stack/ShallowStackTest.java b/src/test/java/org/ice4j/stack/ShallowStackTest.java index ebdef1d..25431ee 100644 --- a/src/test/java/org/ice4j/stack/ShallowStackTest.java +++ b/src/test/java/org/ice4j/stack/ShallowStackTest.java @@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.*; import org.ice4j.*; import org.ice4j.message.*; import org.ice4j.socket.*; +import org.jitsi.config.*; import org.junit.jupiter.api.*; /** @@ -35,6 +36,21 @@ import org.junit.jupiter.api.*; */ public class ShallowStackTest { + @BeforeAll + public static void setupConfig() + { + System.clearProperty(StackProperties.ALWAYS_SIGN); + System.setProperty("ice4j.software", ""); + JitsiConfig.Companion.reloadNewConfig(); + } + + @AfterAll + public static void resetConfig() + { + System.clearProperty("ice4j.software"); + JitsiConfig.Companion.reloadNewConfig(); + } + /** * The Logger used by the ShallowStackTest class and its * instances for logging output. @@ -66,9 +82,6 @@ public class ShallowStackTest public void setUp() throws Exception { - System.clearProperty(StackProperties.ALWAYS_SIGN); - System.clearProperty(StackProperties.SOFTWARE); - msgFixture = new MsgFixture(); //init the stack diff --git a/src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener b/src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener new file mode 100644 index 0000000..4368430 --- /dev/null +++ b/src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener @@ -0,0 +1 @@ +org.ice4j.TestExecutionListener