ref: Port StunMappingHarvester config. (#215)
This commit is contained in:
parent
29ae8061ad
commit
3a55627ba0
@ -16,6 +16,7 @@
|
|||||||
package org.ice4j.ice.harvest;
|
package org.ice4j.ice.harvest;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
|
import org.jetbrains.annotations.*;
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -66,16 +67,6 @@ public class MappingCandidateHarvesters
|
|||||||
public static final String FORCE_AWS_HARVESTER_PNAME
|
public static final String FORCE_AWS_HARVESTER_PNAME
|
||||||
= "org.ice4j.ice.harvest.FORCE_AWS_HARVESTER";
|
= "org.ice4j.ice.harvest.FORCE_AWS_HARVESTER";
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the property which contains the addresses of the STUN servers
|
|
||||||
* to use for the STUN mapping harvester. The property should contain a
|
|
||||||
* comma-separated list of addresses (pairs of IP address and port,
|
|
||||||
* separated by a colon). Example:
|
|
||||||
* {@code stun1.example.com:12345,stun2.example.com:23456}
|
|
||||||
*/
|
|
||||||
public static final String STUN_MAPPING_HARVESTER_ADDRESSES_PNAME
|
|
||||||
= "org.ice4j.ice.harvest.STUN_MAPPING_HARVESTER_ADDRESSES";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether {@link #harvesters} has been initialized.
|
* Whether {@link #harvesters} has been initialized.
|
||||||
*/
|
*/
|
||||||
@ -162,26 +153,20 @@ public class MappingCandidateHarvesters
|
|||||||
}
|
}
|
||||||
|
|
||||||
// STUN harvesters
|
// STUN harvesters
|
||||||
String stunServers
|
List<String> stunServers = HarvestConfig.config.stunMappingCandidateHarvesterAddresses();
|
||||||
= StackProperties.getString(STUN_MAPPING_HARVESTER_ADDRESSES_PNAME);
|
if (!stunServers.isEmpty())
|
||||||
if (stunServers != null && !stunServers.isEmpty())
|
|
||||||
{
|
{
|
||||||
// Create STUN harvesters (and wait for all of their discovery to
|
// Create STUN harvesters (and wait for all of their discovery to finish).
|
||||||
// finish).
|
List<StunMappingCandidateHarvester> stunHarvesters = createStunHarvesters(stunServers);
|
||||||
List<StunMappingCandidateHarvester> stunHarvesters
|
|
||||||
= createStunHarvesters(stunServers.split(","));
|
|
||||||
|
|
||||||
// We have STUN servers configured, so flag the failure if none of
|
// We have STUN servers configured, so flag failure if none of them were able to discover an address.
|
||||||
// them were able to discover an address.
|
|
||||||
stunDiscoveryFailed = stunHarvesters.isEmpty();
|
stunDiscoveryFailed = stunHarvesters.isEmpty();
|
||||||
|
|
||||||
harvesterList.addAll(stunHarvesters);
|
harvesterList.addAll(stunHarvesters);
|
||||||
}
|
}
|
||||||
|
|
||||||
harvesterList = prune(harvesterList);
|
harvesterList = prune(harvesterList);
|
||||||
harvesters
|
harvesters = harvesterList.toArray(new MappingCandidateHarvester[harvesterList.size()]);
|
||||||
= harvesterList.toArray(
|
|
||||||
new MappingCandidateHarvester[harvesterList.size()]);
|
|
||||||
|
|
||||||
for (MappingCandidateHarvester harvester : harvesters)
|
for (MappingCandidateHarvester harvester : harvesters)
|
||||||
{
|
{
|
||||||
@ -248,17 +233,10 @@ public class MappingCandidateHarvesters
|
|||||||
* pairs).
|
* pairs).
|
||||||
* @return the list of those who were successful in discovering an address.
|
* @return the list of those who were successful in discovering an address.
|
||||||
*/
|
*/
|
||||||
private static List<StunMappingCandidateHarvester> createStunHarvesters(
|
private static List<StunMappingCandidateHarvester> createStunHarvesters(@NotNull List<String> stunServers)
|
||||||
String[] stunServers)
|
|
||||||
{
|
{
|
||||||
List<StunMappingCandidateHarvester> stunHarvesters = new LinkedList<>();
|
List<StunMappingCandidateHarvester> stunHarvesters = new LinkedList<>();
|
||||||
|
|
||||||
if (stunServers == null || stunServers.length == 0)
|
|
||||||
{
|
|
||||||
logger.severe("No STUN servers configured.");
|
|
||||||
return stunHarvesters;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Callable<StunMappingCandidateHarvester>> tasks = new LinkedList<>();
|
List<Callable<StunMappingCandidateHarvester>> tasks = new LinkedList<>();
|
||||||
|
|
||||||
// Create a StunMappingCandidateHarvester for each local:remote address
|
// Create a StunMappingCandidateHarvester for each local:remote address
|
||||||
|
|||||||
@ -56,6 +56,13 @@ class HarvestConfig {
|
|||||||
}
|
}
|
||||||
fun timeout() = timeout
|
fun timeout() = timeout
|
||||||
|
|
||||||
|
val stunMappingCandidateHarvesterAddresses: List<String> by config {
|
||||||
|
"org.ice4j.ice.harvest.STUN_MAPPING_HARVESTER_ADDRESSES".from(configSource)
|
||||||
|
.convertFrom<String> { it.split(",") }
|
||||||
|
"ice4j.harvest.mapping.stun.addresses".from(configSource)
|
||||||
|
}
|
||||||
|
fun stunMappingCandidateHarvesterAddresses() = stunMappingCandidateHarvesterAddresses
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField
|
||||||
val config = HarvestConfig()
|
val config = HarvestConfig()
|
||||||
|
|||||||
@ -41,5 +41,13 @@ ice4j {
|
|||||||
// Whether to allocate ephemeral ports for local candidates.
|
// Whether to allocate ephemeral ports for local candidates.
|
||||||
use-dynamic-ports = true
|
use-dynamic-ports = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configuration for the set of "mapping" harvesters.
|
||||||
|
mapping {
|
||||||
|
stun {
|
||||||
|
addresses = [ ]
|
||||||
|
# addresses = [ "stun1.example.com:5379", "stun2.example.com:443" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ class HarvestConfigTest : ConfigTest() {
|
|||||||
config.useIpv6 shouldBe true
|
config.useIpv6 shouldBe true
|
||||||
config.useLinkLocalAddresses shouldBe true
|
config.useLinkLocalAddresses shouldBe true
|
||||||
config.udpReceiveBufferSize shouldBe null
|
config.udpReceiveBufferSize shouldBe null
|
||||||
|
config.stunMappingCandidateHarvesterAddresses shouldBe emptyList()
|
||||||
}
|
}
|
||||||
context("Setting via legacy config (system properties)") {
|
context("Setting via legacy config (system properties)") {
|
||||||
withLegacyConfig(legacyConfig) {
|
withLegacyConfig(legacyConfig) {
|
||||||
@ -37,6 +38,7 @@ class HarvestConfigTest : ConfigTest() {
|
|||||||
config.useIpv6 shouldBe false
|
config.useIpv6 shouldBe false
|
||||||
config.useLinkLocalAddresses shouldBe false
|
config.useLinkLocalAddresses shouldBe false
|
||||||
config.udpReceiveBufferSize shouldBe 555
|
config.udpReceiveBufferSize shouldBe 555
|
||||||
|
config.stunMappingCandidateHarvesterAddresses shouldBe listOf("stun1.legacy:555", "stun2.legacy")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context("Setting via new config") {
|
context("Setting via new config") {
|
||||||
@ -46,6 +48,7 @@ class HarvestConfigTest : ConfigTest() {
|
|||||||
config.useIpv6 shouldBe false
|
config.useIpv6 shouldBe false
|
||||||
config.useLinkLocalAddresses shouldBe false
|
config.useLinkLocalAddresses shouldBe false
|
||||||
config.udpReceiveBufferSize shouldBe 666
|
config.udpReceiveBufferSize shouldBe 666
|
||||||
|
config.stunMappingCandidateHarvesterAddresses shouldBe listOf("stun1.new:666", "stun2.new")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
context("Legacy config must take precedence") {
|
context("Legacy config must take precedence") {
|
||||||
@ -56,6 +59,7 @@ class HarvestConfigTest : ConfigTest() {
|
|||||||
config.useIpv6 shouldBe false
|
config.useIpv6 shouldBe false
|
||||||
config.useLinkLocalAddresses shouldBe false
|
config.useLinkLocalAddresses shouldBe false
|
||||||
config.udpReceiveBufferSize shouldBe 555
|
config.udpReceiveBufferSize shouldBe 555
|
||||||
|
config.stunMappingCandidateHarvesterAddresses shouldBe listOf("stun1.legacy:555", "stun2.legacy")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,7 +71,8 @@ private val legacyConfig = mapOf(
|
|||||||
"org.ice4j.ice.harvest.USE_DYNAMIC_HOST_HARVESTER" to "false",
|
"org.ice4j.ice.harvest.USE_DYNAMIC_HOST_HARVESTER" to "false",
|
||||||
"org.ice4j.ipv6.DISABLED" to "true",
|
"org.ice4j.ipv6.DISABLED" to "true",
|
||||||
"org.ice4j.ice.harvest.DISABLE_LINK_LOCAL_ADDRESSES" to "true",
|
"org.ice4j.ice.harvest.DISABLE_LINK_LOCAL_ADDRESSES" to "true",
|
||||||
"org.ice4j.ice.harvest.AbstractUdpListener.SO_RCVBUF" to "555"
|
"org.ice4j.ice.harvest.AbstractUdpListener.SO_RCVBUF" to "555",
|
||||||
|
"org.ice4j.ice.harvest.STUN_MAPPING_HARVESTER_ADDRESSES" to "stun1.legacy:555,stun2.legacy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// New config which overrides the default
|
// New config which overrides the default
|
||||||
@ -81,6 +86,11 @@ private val newConfigNonDefault = """
|
|||||||
receive-buffer-size = 666
|
receive-buffer-size = 666
|
||||||
use-dynamic-ports = false
|
use-dynamic-ports = false
|
||||||
}
|
}
|
||||||
|
mapping {
|
||||||
|
stun {
|
||||||
|
addresses = [ "stun1.new:666", "stun2.new" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
@ -96,6 +106,11 @@ private val newConfigDefault = """
|
|||||||
receive-buffer-size = 666
|
receive-buffer-size = 666
|
||||||
use-dynamic-ports = true
|
use-dynamic-ports = true
|
||||||
}
|
}
|
||||||
|
mapping {
|
||||||
|
stun {
|
||||||
|
addresses = [ "stun1.new:666", "stun2.new" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user