Commit 5d3c509b authored by Youness Alaoui's avatar Youness Alaoui

Add a nice_agent_set_port_range API to allow forcing the listening port on local host candidates

parent 99595a96
......@@ -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)
{
......
......@@ -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
......
......@@ -123,6 +123,8 @@ struct _Component
GSource* tcp_clock;
TcpUserData *tcp_data;
gboolean tcp_readable;
guint min_port;
guint max_port;
};
Component *
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment