summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYouness Alaoui <youness.alaoui@collabora.co.uk>2011-01-19 23:32:29 (GMT)
committerYouness Alaoui <youness.alaoui@collabora.co.uk>2011-01-19 23:39:46 (GMT)
commit5d3c509bf300e40d38527c08fd7332773e758743 (patch)
tree59e8b56592f9bb2e9c9dabf65a16bbc66b12287e
parent99595a967976c1cba1835888458f4aaf6e613019 (diff)
downloadlibnice-5d3c509bf300e40d38527c08fd7332773e758743.tar.gz
libnice-5d3c509bf300e40d38527c08fd7332773e758743.tar.xz
Add a nice_agent_set_port_range API to allow forcing the listening port on local host candidates
-rw-r--r--agent/agent.c32
-rw-r--r--agent/agent.h27
-rw-r--r--agent/component.h2
-rw-r--r--docs/reference/libnice/libnice-sections.txt1
4 files changed, 60 insertions, 2 deletions
diff --git a/agent/agent.c b/agent/agent.c
index 4c9feb4..6313d2e 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -1780,6 +1780,7 @@ 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 = component->min_port;
if (agent->reliable && component->tcp == NULL) {
nice_debug ("Agent %p: not gathering candidates for s%d:%d because "
@@ -1788,14 +1789,25 @@ nice_agent_gather_candidates (
continue;
}
- host_candidate = discovery_add_local_host_candidate (agent, stream->id,
- n + 1, addr);
+ host_candidate = NULL;
+ while (host_candidate == NULL) {
+ nice_debug ("Agent %p: Trying to create host candidate on port %d", agent, current_port);
+ nice_address_set_port (addr, current_port);
+ host_candidate = discovery_add_local_host_candidate (agent, stream->id,
+ n + 1, addr);
+ if (current_port > 0)
+ current_port++;
+ if (current_port == 0 || current_port > component->max_port)
+ break;
+ }
+ nice_address_set_port (addr, 0);
if (!host_candidate) {
gchar ip[NICE_ADDRESS_STRING_LEN];
nice_address_to_string (addr, ip);
nice_debug ("Agent %p: Unable to add local host candidate %s for s%d:%d"
". Invalid interface?", agent, ip, stream->id, component->id);
+ ret = FALSE;
goto error;
}
@@ -1930,6 +1942,22 @@ nice_agent_remove_stream (
agent_unlock();
}
+NICEAPI_EXPORT void
+nice_agent_set_port_range (NiceAgent *agent, guint stream_id, guint component_id,
+ guint min_port, guint max_port)
+{
+ Component *component;
+
+ agent_lock();
+
+ if (agent_find_component (agent, stream_id, component_id, NULL, &component)) {
+ component->min_port = min_port;
+ component->max_port = max_port;
+ }
+
+ agent_unlock();
+}
+
NICEAPI_EXPORT gboolean
nice_agent_add_local_address (NiceAgent *agent, NiceAddress *addr)
{
diff --git a/agent/agent.h b/agent/agent.h
index 0632075..f4a14d7 100644
--- a/agent/agent.h
+++ b/agent/agent.h
@@ -355,6 +355,33 @@ nice_agent_remove_stream (
NiceAgent *agent,
guint stream_id);
+
+/**
+ * nice_agent_set_port_range:
+ * @agent: The #NiceAgent Object
+ * @stream_id: The ID of the stream
+ * @component_id: The ID of the component
+ * @min_port: The minimum port to use
+ * @max_port: The maximum port to use
+ *
+ * Sets a preferred port range for allocating host candidates.
+ * <para>
+ * If a local host candidate cannot be created on that port
+ * range, then the nice_agent_gather_candidates() call will fail.
+ * </para>
+ * <para>
+ * This MUST be called before nice_agent_gather_candidates()
+ * </para>
+ *
+ */
+void
+nice_agent_set_port_range (
+ NiceAgent *agent,
+ guint stream_id,
+ guint component_id,
+ guint min_port,
+ guint max_port);
+
/**
* nice_agent_set_relay_info:
* @agent: The #NiceAgent Object
diff --git a/agent/component.h b/agent/component.h
index e55c32a..577dbfe 100644
--- a/agent/component.h
+++ b/agent/component.h
@@ -123,6 +123,8 @@ struct _Component
GSource* tcp_clock;
TcpUserData *tcp_data;
gboolean tcp_readable;
+ guint min_port;
+ guint max_port;
};
Component *
diff --git a/docs/reference/libnice/libnice-sections.txt b/docs/reference/libnice/libnice-sections.txt
index f5d213f..03241ff 100644
--- a/docs/reference/libnice/libnice-sections.txt
+++ b/docs/reference/libnice/libnice-sections.txt
@@ -11,6 +11,7 @@ NICE_AGENT_MAX_REMOTE_CANDIDATES
nice_agent_new
nice_agent_new_reliable
nice_agent_add_local_address
+nice_agent_set_port_range
nice_agent_add_stream
nice_agent_remove_stream
nice_agent_set_relay_info