Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libnice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
libnice
Commits
4ee70c86
Commit
4ee70c86
authored
Jul 20, 2010
by
Youness Alaoui
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote branch 'tester/misc-fixes' into nice-kakaroto
Conflicts: agent/agent.c
parents
358a999f
3b16d8b0
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
530 additions
and
739 deletions
+530
-739
agent/agent.c
agent/agent.c
+179
-255
agent/agent.h
agent/agent.h
+3
-1
agent/component.c
agent/component.c
+3
-13
agent/conncheck.c
agent/conncheck.c
+108
-155
agent/discovery.c
agent/discovery.c
+233
-294
agent/stream.c
agent/stream.c
+1
-16
socket/tcp-bsd.c
socket/tcp-bsd.c
+3
-1
socket/udp-bsd.c
socket/udp-bsd.c
+0
-4
No files found.
agent/agent.c
View file @
4ee70c86
...
...
@@ -1294,22 +1294,18 @@ agent_candidate_pair_priority (NiceAgent *agent, NiceCandidate *local, NiceCandi
return
nice_candidate_pair_priority
(
remote
->
priority
,
local
->
priority
);
}
static
gboolean
static
void
priv_add_new_candidate_discovery_stun
(
NiceAgent
*
agent
,
NiceSocket
*
socket
,
NiceAddress
server
,
Stream
*
stream
,
guint
component_id
)
{
CandidateDiscovery
*
cdisco
;
GSList
*
modified_list
;
/* note: no need to check for redundant candidates, as this is
* done later on in the process */
cdisco
=
g_slice_new0
(
CandidateDiscovery
);
if
(
cdisco
)
{
modified_list
=
g_slist_append
(
agent
->
discovery_list
,
cdisco
);
if
(
modified_list
)
{
cdisco
->
type
=
NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE
;
cdisco
->
nicesock
=
socket
;
cdisco
->
server
=
server
;
...
...
@@ -1321,35 +1317,23 @@ priv_add_new_candidate_discovery_stun (NiceAgent *agent,
nice_debug
(
"Agent %p : Adding new srv-rflx candidate discovery %p
\n
"
,
agent
,
cdisco
);
agent
->
discovery_list
=
modified_list
;
++
agent
->
discovery_unsched_items
;
}
return
TRUE
;
}
return
FALSE
;
agent
->
discovery_list
=
g_slist_append
(
agent
->
discovery_list
,
cdisco
);
++
agent
->
discovery_unsched_items
;
}
static
gboolean
static
void
priv_add_new_candidate_discovery_turn
(
NiceAgent
*
agent
,
NiceSocket
*
socket
,
TurnServer
*
turn
,
Stream
*
stream
,
guint
component_id
)
{
CandidateDiscovery
*
cdisco
;
GSList
*
modified_list
;
GSList
*
socket_modified_list
;
Component
*
component
=
stream_find_component_by_id
(
stream
,
component_id
);
/* note: no need to check for redundant candidates, as this is
* done later on in the process */
cdisco
=
g_slice_new0
(
CandidateDiscovery
);
if
(
cdisco
)
{
modified_list
=
g_slist_append
(
agent
->
discovery_list
,
cdisco
);
if
(
modified_list
)
{
Component
*
component
=
stream_find_component_by_id
(
stream
,
component_id
);
cdisco
->
type
=
NICE_CANDIDATE_TYPE_RELAYED
;
if
(
turn
->
type
==
NICE_RELAY_TYPE_TURN_UDP
)
{
...
...
@@ -1363,14 +1347,8 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
_priv_set_socket_tos
(
agent
,
new_socket
,
stream
->
tos
);
agent_attach_stream_component_socket
(
agent
,
stream
,
component
,
new_socket
);
socket_modified_list
=
g_slist_append
(
component
->
sockets
,
new_socket
);
if
(
socket_modified_list
)
{
/* success: store a pointer to the sockaddr */
component
->
sockets
=
socket_modified_list
;
component
->
sockets
=
g_slist_append
(
component
->
sockets
,
new_socket
);
socket
=
new_socket
;
}
else
{
nice_socket_free
(
new_socket
);
}
}
}
cdisco
->
nicesock
=
socket
;
...
...
@@ -1410,20 +1388,11 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
cdisco
->
nicesock
=
nice_tcp_turn_socket_new
(
agent
,
socket
,
agent_to_turn_socket_compatibility
(
agent
));
if
(
!
cdisco
->
nicesock
)
{
agent
->
discovery_list
=
g_slist_remove
(
modified_list
,
cdisco
);
g_slice_free
(
CandidateDiscovery
,
cdisco
);
return
FALSE
;
}
agent_attach_stream_component_socket
(
agent
,
stream
,
component
,
cdisco
->
nicesock
);
socket_modified_list
=
g_slist_append
(
component
->
sockets
,
cdisco
->
nicesock
);
if
(
socket_modified_list
)
{
/* success: store a pointer to the sockaddr */
component
->
sockets
=
socket_modified_list
;
}
component
->
sockets
=
g_slist_append
(
component
->
sockets
,
cdisco
->
nicesock
);
}
cdisco
->
turn
=
turn
;
cdisco
->
server
=
turn
->
server
;
...
...
@@ -1451,14 +1420,8 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
nice_debug
(
"Agent %p : Adding new relay-rflx candidate discovery %p
\n
"
,
agent
,
cdisco
);
agent
->
discovery_list
=
modified_list
;
agent
->
discovery_list
=
g_slist_append
(
agent
->
discovery_list
,
cdisco
)
;
++
agent
->
discovery_unsched_items
;
}
return
TRUE
;
}
return
FALSE
;
}
NICEAPI_EXPORT
guint
...
...
@@ -1467,15 +1430,13 @@ nice_agent_add_stream (
guint
n_components
)
{
Stream
*
stream
;
GSList
*
modified_list
=
NULL
;
guint
ret
=
0
;
guint
i
;
agent_lock
();
stream
=
stream_new
(
n_components
);
if
(
stream
)
{
modified_list
=
g_slist_append
(
agent
->
streams
,
stream
);
if
(
modified_list
)
{
agent
->
streams
=
g_slist_append
(
agent
->
streams
,
stream
);
stream
->
id
=
agent
->
next_stream_id
++
;
nice_debug
(
"Agent %p : allocating stream id %u (%p)"
,
agent
,
stream
->
id
,
stream
);
if
(
agent
->
reliable
)
{
...
...
@@ -1506,12 +1467,6 @@ nice_agent_add_stream (
stream_initialize_credentials
(
stream
,
agent
->
rng
);
agent
->
streams
=
modified_list
;
}
else
stream_free
(
stream
);
}
ret
=
stream
->
id
;
agent_unlock
();
...
...
@@ -1703,7 +1658,7 @@ static void _upnp_error_mapping_port (GUPnPSimpleIgd *self, GError *error,
#endif
NICEAPI_EXPORT
void
NICEAPI_EXPORT
gboolean
nice_agent_gather_candidates
(
NiceAgent
*
agent
,
guint
stream_id
)
...
...
@@ -1788,8 +1743,8 @@ nice_agent_gather_candidates (
n
+
1
,
addr
);
if
(
!
host_candidate
)
{
g_
error
(
"No host candidate??"
);
break
;
g_
warning
(
"No host candidate??"
);
return
FALSE
;
}
#ifdef HAVE_GUPNP
...
...
@@ -1808,20 +1763,13 @@ nice_agent_gather_candidates (
agent
->
stun_server_ip
)
{
NiceAddress
stun_server
;
if
(
nice_address_set_from_string
(
&
stun_server
,
agent
->
stun_server_ip
))
{
gboolean
res
;
nice_address_set_port
(
&
stun_server
,
agent
->
stun_server_port
);
res
=
priv_add_new_candidate_discovery_stun
(
agent
,
host_candidate
->
sockptr
,
stun_server
,
stream
,
n
+
1
);
if
(
res
!=
TRUE
)
{
/* note: memory allocation failure, return error */
g_error
(
"Memory allocation failure?"
);
}
}
}
...
...
@@ -1831,17 +1779,11 @@ nice_agent_gather_candidates (
for
(
item
=
component
->
turn_servers
;
item
;
item
=
item
->
next
)
{
TurnServer
*
turn
=
item
->
data
;
gboolean
res
=
priv_add_new_candidate_discovery_turn
(
agent
,
host_candidate
->
sockptr
,
turn
,
stream
,
n
+
1
);
if
(
res
!=
TRUE
)
{
/* note: memory allocation failure, return error */
g_error
(
"Memory allocation failure?"
);
}
}
}
}
...
...
@@ -1863,6 +1805,8 @@ nice_agent_gather_candidates (
done:
agent_unlock
();
return
TRUE
;
}
static
void
priv_free_upnp
(
NiceAgent
*
agent
)
...
...
@@ -1935,24 +1879,15 @@ NICEAPI_EXPORT gboolean
nice_agent_add_local_address
(
NiceAgent
*
agent
,
NiceAddress
*
addr
)
{
NiceAddress
*
dup
;
GSList
*
modified_list
;
gboolean
ret
=
FALSE
;
agent_lock
();
dup
=
nice_address_dup
(
addr
);
nice_address_set_port
(
dup
,
0
);
modified_list
=
g_slist_append
(
agent
->
local_addresses
,
dup
);
if
(
modified_list
)
{
agent
->
local_addresses
=
modified_list
;
ret
=
TRUE
;
goto
done
;
}
agent
->
local_addresses
=
g_slist_append
(
agent
->
local_addresses
,
dup
);
done:
agent_unlock
();
return
ret
;
return
TRUE
;
}
static
gboolean
priv_add_remote_candidate
(
...
...
@@ -1970,7 +1905,6 @@ static gboolean priv_add_remote_candidate (
{
Component
*
component
;
NiceCandidate
*
candidate
;
gboolean
error_flag
=
FALSE
;
if
(
!
agent_find_component
(
agent
,
stream_id
,
component_id
,
NULL
,
&
component
))
return
FALSE
;
...
...
@@ -2013,16 +1947,14 @@ static gboolean priv_add_remote_candidate (
candidate
->
password
=
g_strdup
(
password
);
}
if
(
conn_check_add_for_candidate
(
agent
,
stream_id
,
component
,
candidate
)
<
0
)
error_flag
=
TRUE
;
goto
errors
;
}
else
{
/* case 2: add a new candidate */
candidate
=
nice_candidate_new
(
type
);
if
(
candidate
)
{
GSList
*
modified_list
=
g_slist_append
(
component
->
remote_candidates
,
candidate
);
if
(
modified_list
)
{
component
->
remote_candidates
=
modified_list
;
component
->
remote_candidates
=
g_slist_append
(
component
->
remote_candidates
,
candidate
);
candidate
->
stream_id
=
stream_id
;
candidate
->
component_id
=
component_id
;
...
...
@@ -2030,6 +1962,7 @@ static gboolean priv_add_remote_candidate (
candidate
->
type
=
type
;
if
(
addr
)
candidate
->
addr
=
*
addr
;
{
gchar
tmpbuf
[
INET6_ADDRSTRLEN
]
=
{
0
};
if
(
addr
)
...
...
@@ -2053,22 +1986,14 @@ static gboolean priv_add_remote_candidate (
NICE_CANDIDATE_MAX_FOUNDATION
);
if
(
conn_check_add_for_candidate
(
agent
,
stream_id
,
component
,
candidate
)
<
0
)
error_flag
=
TRUE
;
}
else
/* memory alloc error: list insert */
error_flag
=
TRUE
;
}
else
/* memory alloc error: candidate creation */
error_flag
=
TRUE
;
goto
errors
;
}
if
(
error_flag
)
{
if
(
candidate
)
return
TRUE
;
errors:
nice_candidate_free
(
candidate
);
return
FALSE
;
}
return
TRUE
;
}
NICEAPI_EXPORT
gboolean
...
...
@@ -2490,14 +2415,13 @@ io_ctx_new (
IOCtx
*
ctx
;
ctx
=
g_slice_new0
(
IOCtx
);
if
(
ctx
)
{
ctx
->
agent
=
agent
;
ctx
->
stream
=
stream
;
ctx
->
component
=
component
;
ctx
->
socket
=
socket
;
ctx
->
channel
=
channel
;
ctx
->
source
=
source
;
}
return
ctx
;
}
...
...
agent/agent.h
View file @
4ee70c86
...
...
@@ -385,6 +385,8 @@ gboolean nice_agent_set_relay_info(
* Start the candidate gathering process.
* Once done, #NiceAgent::candidate-gathering-done is called for the stream
*
* Returns: %FALSE if there were no local addresses and they couldn't be discovered. In this case, call nice_agent_add_local_address() first.
*
* See also: nice_agent_add_local_address()
<note>
<para>
...
...
@@ -397,7 +399,7 @@ gboolean nice_agent_set_relay_info(
</para>
</note>
*/
void
gboolean
nice_agent_gather_candidates
(
NiceAgent
*
agent
,
guint
stream_id
);
...
...
agent/component.c
View file @
4ee70c86
...
...
@@ -310,21 +310,11 @@ component_set_selected_remote_candidate (NiceAgent *agent, Component *component,
candidate
->
transport
);
if
(
!
remote
)
{
GSList
*
modified_list
=
NULL
;
remote
=
nice_candidate_copy
(
candidate
);
modified_list
=
g_slist_append
(
component
->
remote_candidates
,
component
->
remote_candidates
=
g_slist_append
(
component
->
remote_candidates
,
remote
);
if
(
modified_list
)
{
component
->
remote_candidates
=
modified_list
;
agent_signal_new_remote_candidate
(
agent
,
remote
);
}
else
{
/* error: memory alloc / list */
nice_candidate_free
(
remote
),
remote
=
NULL
;
return
NULL
;
}
}
if
(
component
->
selected_pair
.
keepalive
.
tick_source
!=
NULL
)
{
g_source_destroy
(
component
->
selected_pair
.
keepalive
.
tick_source
);
...
...
agent/conncheck.c
View file @
4ee70c86
...
...
@@ -1249,16 +1249,13 @@ static void priv_mark_pair_nominated (NiceAgent *agent, Stream *stream, Componen
* Creates a new connectivity check pair and adds it to
* the agent's list of checks.
*/
static
gboolean
priv_add_new_check_pair
(
NiceAgent
*
agent
,
guint
stream_id
,
Component
*
component
,
NiceCandidate
*
local
,
NiceCandidate
*
remote
,
NiceCheckState
initial_state
,
gboolean
use_candidate
)
static
void
priv_add_new_check_pair
(
NiceAgent
*
agent
,
guint
stream_id
,
Component
*
component
,
NiceCandidate
*
local
,
NiceCandidate
*
remote
,
NiceCheckState
initial_state
,
gboolean
use_candidate
)
{
gboolean
result
=
FALSE
;
Stream
*
stream
=
agent_find_stream
(
agent
,
stream_id
);
CandidateCheckPair
*
pair
=
g_slice_new0
(
CandidateCheckPair
);
if
(
pair
)
{
GSList
*
modified_list
=
g_slist_insert_sorted
(
stream
->
conncheck_list
,
pair
,
(
GCompareFunc
)
conn_check_compare
);
if
(
modified_list
)
{
/* step: allocation and addition succesful, do rest of the work */
stream
->
conncheck_list
=
g_slist_insert_sorted
(
stream
->
conncheck_list
,
pair
,
(
GCompareFunc
)
conn_check_compare
);
pair
->
agent
=
agent
;
pair
->
stream_id
=
stream_id
;
...
...
@@ -1276,9 +1273,7 @@ static gboolean priv_add_new_check_pair (NiceAgent *agent, guint stream_id, Comp
/* note: for the first added check */
if
(
!
stream
->
conncheck_list
)
stream
->
conncheck_state
=
NICE_CHECKLIST_RUNNING
;
stream
->
conncheck_list
=
modified_list
;
result
=
TRUE
;
nice_debug
(
"Agent %p : added a new conncheck %p with foundation of '%s' to list %u."
,
agent
,
pair
,
pair
->
foundation
,
stream_id
);
/* implement the hard upper limit for number of
...
...
@@ -1287,22 +1282,6 @@ static gboolean priv_add_new_check_pair (NiceAgent *agent, guint stream_id, Comp
stream
->
conncheck_list
=
priv_limit_conn_check_list_size
(
stream
->
conncheck_list
,
agent
->
max_conn_checks
);
}
if
(
!
stream
->
conncheck_list
)
{
stream
->
conncheck_state
=
NICE_CHECKLIST_FAILED
;
result
=
FALSE
;
}
}
else
{
/* memory alloc failed: list insert */
conn_check_free_item
(
pair
,
NULL
);
stream
->
conncheck_state
=
NICE_CHECKLIST_FAILED
;
}
}
else
{
/* memory alloc failed: new pair */
stream
->
conncheck_state
=
NICE_CHECKLIST_FAILED
;
}
return
result
;
}
/*
...
...
@@ -1330,8 +1309,6 @@ int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component *
if
(
local
->
transport
==
remote
->
transport
&&
local
->
addr
.
s
.
addr
.
sa_family
==
remote
->
addr
.
s
.
addr
.
sa_family
)
{
gboolean
result
;
/* note: do not create pairs where local candidate is
* a srv-reflexive (ICE 5.7.3. "Pruning the Pairs" ID-19) */
if
((
agent
->
compatibility
==
NICE_COMPATIBILITY_RFC5245
||
...
...
@@ -1339,8 +1316,7 @@ int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component *
local
->
type
==
NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE
)
continue
;
result
=
priv_add_new_check_pair
(
agent
,
stream_id
,
component
,
local
,
remote
,
NICE_CHECK_FROZEN
,
FALSE
);
if
(
result
)
{
priv_add_new_check_pair
(
agent
,
stream_id
,
component
,
local
,
remote
,
NICE_CHECK_FROZEN
,
FALSE
);
++
added
;
if
(
component
->
state
<
NICE_COMPONENT_STATE_CONNECTED
)
{
agent_signal_component_state_change
(
agent
,
...
...
@@ -1354,11 +1330,6 @@ int conn_check_add_for_candidate (NiceAgent *agent, guint stream_id, Component *
NICE_COMPONENT_STATE_CONNECTED
);
}
}
else
{
added
=
-
1
;
break
;
}
}
}
return
added
;
...
...
@@ -1766,7 +1737,7 @@ static guint priv_prune_pending_checks (Stream *stream, guint component_id)
static
gboolean
priv_schedule_triggered_check
(
NiceAgent
*
agent
,
Stream
*
stream
,
Component
*
component
,
NiceSocket
*
local_socket
,
NiceCandidate
*
remote_cand
,
gboolean
use_candidate
)
{
GSList
*
i
;
gboolean
result
=
FALSE
;
NiceCandidate
*
local
=
NULL
;
for
(
i
=
stream
->
conncheck_list
;
i
;
i
=
i
->
next
)
{
CandidateCheckPair
*
p
=
i
->
data
;
...
...
@@ -1807,23 +1778,21 @@ static gboolean priv_schedule_triggered_check (NiceAgent *agent, Stream *stream,
}
}
{
NiceCandidate
*
local
=
NULL
;
for
(
i
=
component
->
local_candidates
;
i
;
i
=
i
->
next
)
{
local
=
i
->
data
;
if
(
local
->
sockptr
==
local_socket
)
break
;
}
if
(
i
)
{
nice_debug
(
"Agent %p : Adding a triggered check to conn.check list (local=%p)."
,
agent
,
local
);
result
=
priv_add_new_check_pair
(
agent
,
stream
->
id
,
component
,
local
,
remote_cand
,
NICE_CHECK_WAITING
,
use_candidate
);
priv_add_new_check_pair
(
agent
,
stream
->
id
,
component
,
local
,
remote_cand
,
NICE_CHECK_WAITING
,
use_candidate
);
return
TRUE
;
}
else
else
{
nice_debug
(
"Agent %p : Didn't find a matching pair for triggered check (remote-cand=%p)."
,
agent
,
remote_cand
);
return
FALSE
;
}
return
result
;
}
...
...
@@ -1895,10 +1864,7 @@ static int priv_store_pending_check (NiceAgent *agent, Component *component,
}
icheck
=
g_slice_new0
(
IncomingCheck
);
if
(
icheck
)
{
GSList
*
pending
=
g_slist_append
(
component
->
incoming_checks
,
icheck
);
if
(
pending
)
{
component
->
incoming_checks
=
pending
;
component
->
incoming_checks
=
g_slist_append
(
component
->
incoming_checks
,
icheck
);
icheck
->
from
=
*
from
;
icheck
->
local_socket
=
socket
;
icheck
->
priority
=
priority
;
...
...
@@ -1907,11 +1873,8 @@ static int priv_store_pending_check (NiceAgent *agent, Component *component,
icheck
->
username
=
NULL
;
if
(
username_len
>
0
)
icheck
->
username
=
g_memdup
(
username
,
username_len
);
return
0
;
}
}
return
-
1
;
return
0
;
}
/*
...
...
@@ -1923,11 +1886,9 @@ static int priv_store_pending_check (NiceAgent *agent, Component *component,
static
CandidateCheckPair
*
priv_add_peer_reflexive_pair
(
NiceAgent
*
agent
,
guint
stream_id
,
guint
component_id
,
NiceCandidate
*
local_cand
,
CandidateCheckPair
*
parent_pair
)
{
CandidateCheckPair
*
pair
=
g_slice_new0
(
CandidateCheckPair
);
if
(
pair
)
{
Stream
*
stream
=
agent_find_stream
(
agent
,
stream_id
);
GSList
*
modified_list
=
g_slist_append
(
stream
->
conncheck_list
,
pair
);
if
(
modified_list
)
{
stream
->
conncheck_list
=
modified_list
;
stream
->
conncheck_list
=
g_slist_append
(
stream
->
conncheck_list
,
pair
);
pair
->
agent
=
agent
;
pair
->
stream_id
=
stream_id
;
pair
->
component_id
=
component_id
;;
...
...
@@ -1935,19 +1896,19 @@ static CandidateCheckPair *priv_add_peer_reflexive_pair (NiceAgent *agent, guint
pair
->
remote
=
parent_pair
->
remote
;
pair
->
state
=
NICE_CHECK_DISCOVERED
;
nice_debug
(
"Agent %p : pair %p state DISCOVERED"
,
agent
,
pair
);
g_snprintf
(
pair
->
foundation
,
NICE_CANDIDATE_PAIR_MAX_FOUNDATION
,
"%s:%s"
,
local_cand
->
foundation
,
parent_pair
->
remote
->
foundation
);
g_snprintf
(
pair
->
foundation
,
NICE_CANDIDATE_PAIR_MAX_FOUNDATION
,
"%s:%s"
,
local_cand
->
foundation
,
parent_pair
->
remote
->
foundation
);
if
(
agent
->
controlling_mode
==
TRUE
)
pair
->
priority
=
nice_candidate_pair_priority
(
local_cand
->
priority
,
parent_pair
->
priority
);
pair
->
priority
=
nice_candidate_pair_priority
(
local_cand
->
priority
,
parent_pair
->
priority
);
else
pair
->
priority
=
nice_candidate_pair_priority
(
parent_pair
->
priority
,
local_cand
->
priority
);
pair
->
priority
=
nice_candidate_pair_priority
(
parent_pair
->
priority
,
local_cand
->
priority
);
pair
->
nominated
=
FALSE
;
pair
->
controlling
=
agent
->
controlling_mode
;
nice_debug
(
"Agent %p : added a new peer-discovered pair with foundation of '%s'."
,
agent
,
pair
->
foundation
);
return
pair
;
}
}
return
NULL
;
return
pair
;
}
/*
...
...
@@ -2254,13 +2215,10 @@ priv_add_new_turn_refresh (CandidateDiscovery *cdisco, NiceCandidate *relay_cand
{
CandidateRefresh
*
cand
;
NiceAgent
*
agent
=
cdisco
->
agent
;
GSList
*
modified_list
;
cand
=
g_slice_new0
(
CandidateRefresh
);
if
(
cand
)
{
modified_list
=
g_slist_append
(
agent
->
refresh_list
,
cand
);
agent
->
refresh_list
=
g_slist_append
(
agent
->
refresh_list
,
cand
);
if
(
modified_list
)
{
cand
->
nicesock
=
cdisco
->
nicesock
;
cand
->
relay_socket
=
relay_cand
->
sockptr
;
cand
->
server
=
cdisco
->
server
;
...
...
@@ -2271,7 +2229,6 @@ priv_add_new_turn_refresh (CandidateDiscovery *cdisco, NiceCandidate *relay_cand
memcpy
(
&
cand
->
stun_agent
,
&
cdisco
->
stun_agent
,
sizeof
(
StunAgent
));
nice_debug
(
"Agent %p : Adding new refresh candidate %p with timeout %d"
,
agent
,
cand
,
(
lifetime
-
60
)
*
1000
);
agent
->
refresh_list
=
modified_list
;
/* step: also start the refresh timer */
/* refresh should be sent 1 minute before it expires */
...
...
@@ -2280,8 +2237,6 @@ priv_add_new_turn_refresh (CandidateDiscovery *cdisco, NiceCandidate *relay_cand
priv_turn_allocate_refresh_tick
,
cand
);
nice_debug
(
"timer source is : %d"
,
cand
->
timer_source
);
}
}
return
cand
;
}
...
...
@@ -2700,8 +2655,6 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
}
}
if
(
validater_data
.
password
)
g_free
(
validater_data
.
password
);
if
(
valid
==
STUN_VALIDATION_NOT_STUN
||
...
...
agent/discovery.c
View file @
4ee70c86
...
...
@@ -87,15 +87,12 @@ void discovery_free_item (gpointer data, gpointer user_data)
*/
void
discovery_free
(
NiceAgent
*
agent
)
{
if
(
agent
->
discovery_list
)
{
GSList
*
tmp
=
agent
->
discovery_list
;
agent
->
discovery_list
=
NULL
;
g_slist_foreach
(
tmp
,
discovery_free_item
,
NULL
);
g_slist_free
(
tmp
);
g_slist_foreach
(
agent
->
discovery_list
,
discovery_free_item
,
NULL
);
g_slist_free
(
agent
->
discovery_list
);
agent
->
discovery_list
=
NULL
;
agent
->
discovery_unsched_items
=
0
;
}
if
(
agent
->
discovery_timer_source
!=
NULL
)
{
g_source_destroy
(
agent
->
discovery_timer_source
);
g_source_unref
(
agent
->
discovery_timer_source
);
...
...
@@ -204,14 +201,9 @@ void refresh_free_item (gpointer data, gpointer user_data)
*/
void
refresh_free
(
NiceAgent
*
agent
)
{
if
(
agent
->
refresh_list
)
{
GSList
*
tmp
=
agent
->
refresh_list
;
g_slist_foreach
(
agent
->
refresh_list
,
refresh_free_item
,
NULL
);
g_slist_free
(
agent
->
refresh_list
)
;
agent
->
refresh_list
=
NULL
;
g_slist_foreach
(
tmp
,
refresh_free_item
,
NULL
);
g_slist_free
(
tmp
);
}
}
/*
...
...
@@ -252,7 +244,7 @@ void refresh_cancel (CandidateRefresh *refresh)
*/
static
gboolean
priv_add_local_candidate_pruned
(
Component
*
component
,
NiceCandidate
*
candidate
)
{
GSList
*
modified_list
,
*
i
;
GSList
*
i
;
for
(
i
=
component
->
local_candidates
;
i
;
i
=
i
->
next
)
{
NiceCandidate
*
c
=
i
->
data
;
...
...
@@ -264,11 +256,8 @@ static gboolean priv_add_local_candidate_pruned (Component *component, NiceCandi
}
}
modified_list
=
g_slist_append
(
component
->
local_candidates
,
component
->
local_candidates
=
g_slist_append
(
component
->
local_candidates
,
candidate
);
if
(
modified_list
)
{
component
->
local_candidates
=
modified_list
;
}
return
TRUE
;
}
...
...
@@ -418,9 +407,7 @@ void priv_generate_candidate_credentials (NiceAgent *agent,
guchar
username
[
32
];
guchar
password
[
16
];
if
(
candidate
->
username
)
g_free
(
candidate
->
username
);
if
(
candidate
->
password
)
g_free
(
candidate
->
password
);
nice_rng_generate_bytes
(
agent
->
rng
,
32
,
(
gchar
*
)
username
);
...
...
@@ -432,9 +419,7 @@ void priv_generate_candidate_credentials (NiceAgent *agent,
}
else
if
(
agent
->
compatibility
==
NICE_COMPATIBILITY_GOOGLE
)
{
gchar
username
[
16
];
if
(
candidate
->
username
)
g_free
(
candidate
->
username
);
if
(
candidate
->
password
)
g_free
(
candidate
->
password
);
candidate
->
password
=
NULL
;
...
...
@@ -462,13 +447,11 @@ NiceCandidate *discovery_add_local_host_candidate (
Component
*
component
;
Stream
*
stream
;
NiceSocket
*
udp_socket
=
NULL
;
gboolean
errors
=
FALSE
;
if
(
!
agent_find_component
(
agent
,
stream_id
,
component_id
,
&
stream
,
&
component
))
return
NULL
;
candidate
=
nice_candidate_new
(
NICE_CANDIDATE_TYPE_HOST
);
if
(
candidate
)
{
candidate
->
stream_id
=
stream_id
;
candidate
->
component_id
=
component_id
;
candidate
->
addr
=
*
address
;
...
...
@@ -487,8 +470,9 @@ NiceCandidate *discovery_add_local_host_candidate (
/* note: candidate username and password are left NULL as stream
level ufrag/password are used */
udp_socket
=
nice_udp_bsd_socket_new
(
address
);
if
(
udp_socket
)
{
gboolean
result
;
if
(
!
udp_socket
)
goto
errors
;
_priv_set_socket_tos
(
agent
,
udp_socket
,
stream
->
tos
);
agent_attach_stream_component_socket
(
agent
,
stream
,
...
...
@@ -498,36 +482,19 @@ NiceCandidate *discovery_add_local_host_candidate (
candidate
->
addr
=
udp_socket
->
addr
;
candidate
->
base_addr
=
udp_socket
->
addr
;
result
=
priv_add_local_candidate_pruned
(
component
,
candidate
);
if
(
!
priv_add_local_candidate_pruned
(
component
,
candidate
))
goto
errors
;
if
(
result
==
TRUE
)
{
GSList
*
modified_list
=
g_slist_append
(
component
->
sockets
,
udp_socket
);
if
(
modified_list
)
{
/* success: store a pointer to the sockaddr */
component
->
sockets
=
modified_list
;
component
->
sockets
=
g_slist_append
(
component
->
sockets
,
udp_socket
);
agent_signal_new_candidate
(
agent
,
candidate
);
}
else
{
/* error: list memory allocation */
candidate
=
NULL
;
/* note: candidate already owned by component */
}
}
else
{
/* error: memory allocation, or duplicate candidates */
errors
=
TRUE
;
}
}
else
{
/* error: socket new */
errors
=
TRUE
;
}
}
/* clean up after errors */
if
(
errors
)
{
if
(
candidate
)
nice_candidate_free
(
candidate
),
candidate
=
NULL
;
return
candidate
;
errors:
nice_candidate_free
(
candidate
)
;
if
(
udp_socket
)
nice_socket_free
(
udp_socket
);
}
return
candidate
;
return
NULL
;
}
/*
...
...
@@ -553,7 +520,7 @@ discovery_add_server_reflexive_candidate (
return
NULL
;
candidate
=
nice_candidate_new
(
NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE
);
if
(
candidate
)
{
if
(
agent
->
compatibility
==
NICE_COMPATIBILITY_GOOGLE
)
{
candidate
->
priority
=
nice_candidate_jingle_priority
(
candidate
);
}
else
if
(
agent
->
compatibility
==
NICE_COMPATIBILITY_MSN
)
{
...
...
@@ -578,10 +545,9 @@ discovery_add_server_reflexive_candidate (
agent_signal_new_candidate
(
agent
,
candidate
);
}
else
{
/* error: memory allocation, or duplicate candidatet
*/
/* error: duplicate candidate
*/
nice_candidate_free
(
candidate
),
candidate
=
NULL
;
}
}
return
candidate
;
}
...
...
@@ -605,15 +571,13 @@ discovery_add_relay_candidate (
NiceCandidate
*
candidate
;
Component
*
component
;
Stream
*
stream
;
gboolean
result
=
FALSE
;
gboolean
errors
=
FALSE
;
NiceSocket
*
relay_socket
=
NULL
;
if
(
!
agent_find_component
(
agent
,
stream_id
,
component_id
,
&
stream
,
&
component
))
return
NULL
;
candidate
=
nice_candidate_new
(
NICE_CANDIDATE_TYPE_RELAYED
);
if
(
candidate
)
{
if
(
agent
->
compatibility
==
NICE_COMPATIBILITY_GOOGLE
)
{
candidate
->
priority
=
nice_candidate_jingle_priority
(
candidate
);
}
else
if
(
agent
->
compatibility
==
NICE_COMPATIBILITY_MSN
)
{
...
...
@@ -632,7 +596,9 @@ discovery_add_relay_candidate (
base_socket
,
&
turn
->
server
,
turn
->
username
,
turn
->
password
,
agent_to_turn_socket_compatibility
(
agent
));
if
(
relay_socket
)
{
if
(
!
relay_socket
)
goto
errors
;
candidate
->
sockptr
=
relay_socket
;
candidate
->
base_addr
=
base_socket
->
addr
;
...
...
@@ -646,35 +612,19 @@ discovery_add_relay_candidate (
priv_assign_foundation
(
agent
,
candidate
);
result
=
priv_add_local_candidate_pruned
(
component
,
candidate
);
if
(
result
)
{
GSList
*
modified_list
=
g_slist_append
(
component
->
sockets
,
relay_socket
);
if
(
modified_list
)
{
/* success: store a pointer to the sockaddr */
component
->
sockets
=
modified_list
;
}
if
(
!
priv_add_local_candidate_pruned
(
component
,
candidate
))
goto
errors
;
component
->
sockets
=
g_slist_append
(
component
->
sockets
,
relay_socket
);
agent_signal_new_candidate
(
agent
,
candidate
);
}
else
{
/* error: memory allocation, or duplicate candidate */
errors
=
TRUE
;
}
}
else
{
/* error: socket factory make */
errors
=
TRUE
;
}
}
else
{
/* error: udp socket memory allocation */
errors
=
TRUE
;
}
/* clean up after errors */
if
(
errors
)
{
if
(
candidate
)
nice_candidate_free
(
candidate
),
candidate
=
NULL
;
return
candidate
;
errors:
nice_candidate_free
(
candidate
)
;
if
(
relay_socket
)
nice_socket_free
(
relay_socket
);
}
return
candidate
;
return
NULL
;
}
/*
...
...
@@ -696,13 +646,12 @@ discovery_add_peer_reflexive_candidate (
NiceCandidate
*
candidate
;
Component
*
component
;
Stream
*
stream
;
gboolean
result
;
if
(
!
agent_find_component
(
agent
,
stream_id
,
component_id
,
&
stream
,
&
component
))
return
NULL
;
candidate
=
nice_candidate_new
(
NICE_CANDIDATE_TYPE_PEER_REFLEXIVE
);
if
(
candidate
)
{
gboolean
result
;
candidate
->
transport
=
NICE_CANDIDATE_TRANSPORT_UDP
;
if
(
agent
->
compatibility
==
NICE_COMPATIBILITY_GOOGLE
)
{
...
...
@@ -761,7 +710,6 @@ discovery_add_peer_reflexive_candidate (
/* error: memory allocation, or duplicate candidatet */
nice_candidate_free
(
candidate
),
candidate
=
NULL
;
}
}
return
candidate
;
}
...
...
@@ -792,8 +740,6 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
(
void
)
udp_socket
;
candidate
=
nice_candidate_new
(
NICE_CANDIDATE_TYPE_PEER_REFLEXIVE
);
if
(
candidate
)
{
GSList
*
modified_list
;
candidate
->
transport
=
NICE_CANDIDATE_TRANSPORT_UDP
;
candidate
->
addr
=
*
remote_address
;
...
...
@@ -847,21 +793,14 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
candidate
->
password
=
g_strdup
(
remote
->
password
);
}
candidate
->
sockptr
=
NULL
;
/* not stored for remote candidates */
/* note: candidate username and password are left NULL as stream
level ufrag/password are used */
modified_list
=
g_slist_append
(
component
->
remote_candidates
,
component
->
remote_candidates
=
g_slist_append
(
component
->
remote_candidates
,
candidate
);
if
(
modified_list
)
{
component
->
remote_candidates
=
modified_list
;
agent_signal_new_remote_candidate
(
agent
,
candidate
);
}
else
{
/* error: memory alloc / list */
nice_candidate_free
(
candidate
),
candidate
=
NULL
;
}
}
return
candidate
;
}
...
...
agent/stream.c
View file @
4ee70c86
...
...
@@ -52,27 +52,12 @@ stream_new (guint n_components)
{
Stream
*
stream
;
guint
n
;
gboolean
errors
=
FALSE
;
GSList
*
modified_list
;
Component
*
component
;
stream
=
g_slice_new0
(
Stream
);
for
(
n
=
0
;
n
<
n_components
;
n
++
)
{
component
=
component_new
(
n
+
1
);
if
(
component
)
{
modified_list
=
g_slist_append
(
stream
->
components
,
component
);
if
(
modified_list
)
stream
->
components
=
modified_list
;
else
errors
=
TRUE
;
}
else
errors
=
TRUE
;
}
if
(
errors
)
{
stream_free
(
stream
);
return
NULL
;
stream
->
components
=
g_slist_append
(
stream
->
components
,
component
);
}
stream
->
n_components
=
n_components
;
...
...
socket/tcp-bsd.c
View file @
4ee70c86
...
...
@@ -91,7 +91,7 @@ nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr)
int
ret
;
struct
sockaddr_storage
name
;
guint
name_len
=
sizeof
(
name
);
NiceSocket
*
sock
=
g_slice_new0
(
NiceSocket
)
;
NiceSocket
*
sock
;
TcpPriv
*
priv
;
if
(
addr
==
NULL
)
{
...
...
@@ -99,6 +99,8 @@ nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr)
return
NULL
;
}
sock
=
g_slice_new0
(
NiceSocket
);
nice_address_copy_to_sockaddr
(
addr
,
(
struct
sockaddr
*
)
&
name
);
if
(
sockfd
==
-
1
)
{
...
...
socket/udp-bsd.c
View file @
4ee70c86
...
...
@@ -73,10 +73,6 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
socklen_t
name_len
=
sizeof
(
name
);
NiceSocket
*
sock
=
g_slice_new0
(
NiceSocket
);
if
(
!
sock
)
{
return
NULL
;
}
if
(
addr
!=
NULL
)
{
nice_address_copy_to_sockaddr
(
addr
,
(
struct
sockaddr
*
)
&
name
);
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment