summaryrefslogtreecommitdiff
path: root/agent
diff options
context:
space:
mode:
authorLivio Madaro <livio.madaro@telecomitalia.it>2013-03-07 17:46:34 +0100
committerYouness Alaoui <youness.alaoui@collabora.co.uk>2013-03-20 15:50:33 -0400
commite176b4143ce907e71c5a1e5e38698e027e887114 (patch)
treec7fa985c2b657d4662cf89be6125c9b23e0215e6 /agent
parent4dd302735f5cca6908fda009b06994b253b41168 (diff)
downloadlibnice-e176b4143ce907e71c5a1e5e38698e027e887114.tar.gz
Open socket with random port. Use random port to avoid TURN error 437 Allocation Mismatch
Diffstat (limited to 'agent')
-rw-r--r--agent/agent.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/agent/agent.c b/agent/agent.c
index e8b550f..0b4fdff 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -1827,11 +1827,16 @@ nice_agent_gather_candidates (
for (n = 0; n < stream->n_components; n++) {
Component *component = stream_find_component_by_id (stream, n + 1);
guint current_port;
+ guint start_port;
if (component == NULL)
continue;
- current_port = component->min_port;
+ start_port = component->min_port;
+ if(component->min_port != 0) {
+ start_port = nice_rng_generate_int(agent->rng, component->min_port, component->max_port+1);
+ }
+ current_port = start_port;
if (agent->reliable && component->tcp == NULL) {
nice_debug ("Agent %p: not gathering candidates for s%d:%d because "
@@ -1848,7 +1853,8 @@ nice_agent_gather_candidates (
n + 1, addr);
if (current_port > 0)
current_port++;
- if (current_port == 0 || current_port > component->max_port)
+ if (current_port > component->max_port) current_port = component->min_port;
+ if (current_port == 0 || current_port == start_port)
break;
}
nice_address_set_port (addr, 0);