platform/upstream/libnice.git
5 years agomeson: check for gtkdoc-scan
Tim-Philipp Müller [Sat, 3 Nov 2018 00:10:19 +0000 (00:10 +0000)]
meson: check for gtkdoc-scan

5 years agomeson: add new unit test
Tim-Philipp Müller [Fri, 2 Nov 2018 19:26:25 +0000 (19:26 +0000)]
meson: add new unit test

5 years agomeson: allow selecting crypto library manually via an option
Tim-Philipp Müller [Fri, 2 Nov 2018 19:16:36 +0000 (19:16 +0000)]
meson: allow selecting crypto library manually via an option

5 years agoAdd support for Meson build system
Tim-Philipp Müller [Sun, 30 Jul 2017 15:42:52 +0000 (16:42 +0100)]
Add support for Meson build system

5 years agoagent: Don't require stream names to parse remote SDP
Jakub Adam [Fri, 14 Dec 2018 09:45:37 +0000 (10:45 +0100)]
agent: Don't require stream names to parse remote SDP

The streams are matched by the order in which they appear in the SDP,
not by name, so insisting on local streams to have one makes no sense.

This likely should have been removed in 5972db0.

5 years agotcp-passive: Clear connection on child closing
Olivier Crête [Sun, 21 Oct 2018 10:01:55 +0000 (12:01 +0200)]
tcp-passive: Clear connection on child closing

If this isn't done, then there may be invalid points left inside the
passive socket which could be used and cause a crash.

Fixes #33

5 years agotcp-bsd: Restore global locks
Jakub Adam [Tue, 20 Nov 2018 18:35:04 +0000 (19:35 +0100)]
tcp-bsd: Restore global locks

Avoids race between socket_send_more() and socket_close() leading either
to crash on use of freed NiceSocket, or abort upon attempting to
g_mutex_clear() a locked mutex.

Akin to what d1611c0c0ba6c5bce500b96a8f61de4fe5f144e9 did to udp-turn.

5 years agoudp-turn: Create locked version of realm&nonce cache function
Olivier Crête [Fri, 16 Nov 2018 22:34:16 +0000 (17:34 -0500)]
udp-turn: Create locked version of realm&nonce cache function

To be able to call it from a context that is already locked.

5 years agoudp-bsd: Protect the GSocketAddress cache with a mutex
Olivier Crête [Fri, 16 Nov 2018 22:03:39 +0000 (17:03 -0500)]
udp-bsd: Protect the GSocketAddress cache with a mutex

5 years agoagent: check message length before extracting RFC4571 frame size
Jakub Adam [Wed, 31 Oct 2018 00:56:39 +0000 (01:56 +0100)]
agent: check message length before extracting RFC4571 frame size

nice_socket_recv_messages() may return a NiceInputMessage of length = 0,
so before attempting to read the RFC4571 header check the message really
has at least sizeof (guint16) bytes of data.

The bug's always been there, the previous commit only made it more
apparent.

5 years agoudp-turn: handle multiple RFC4571 frames received in a TCP-TURN message
Jakub Adam [Fri, 26 Oct 2018 22:31:53 +0000 (00:31 +0200)]
udp-turn: handle multiple RFC4571 frames received in a TCP-TURN message

There might be multiple RFC4571-framed messages (or fragments thereof)
within a single TCP-TURN message. Make sure each NiceInputMessage
passed by the user into socket_recv_messages() gets exactly one RFC4571
frame, or remains empty if there aren't any messages to receive.

We should keep any data that doesn't fit into the user buffers for
the next time socket_recv_messages() gets called with the socket.

5 years agoudp-turn: don't re-iterate incoming TURN control messages
Jakub Adam [Fri, 26 Oct 2018 23:10:22 +0000 (01:10 +0200)]
udp-turn: don't re-iterate incoming TURN control messages

After being parsed, a TURN control message turns into a NiceInputMessage
with zero length. Such message doesn't increment the iteration counter i
and so is re-processed in the next iteration, which detects right away
that message->length == 0 and continues to the next element in
recv_messages.

Thus, n_valid_messages variable serves no real purpose and to achieve
the same result we can simply increment the iteration counter after each
message.

5 years agoudp-turn: Start function with lock instead of unlock
Olivier Crête [Wed, 31 Oct 2018 11:44:16 +0000 (11:44 +0000)]
udp-turn: Start function with lock instead of unlock

5 years agoudp-turn: Restore global locks
Olivier Crête [Sun, 28 Oct 2018 16:32:27 +0000 (16:32 +0000)]
udp-turn: Restore global locks

The socket abstraction not being reference counted, we need a global
lock for them in the short term.

5 years agoudp-turn: Rename misleading function, it's a timeout
Olivier Crête [Sun, 28 Oct 2018 16:11:54 +0000 (16:11 +0000)]
udp-turn: Rename misleading function, it's a timeout

It's not locked in any way.

5 years agoudp-turn: Factor our SendRequest destruction
Olivier Crête [Sun, 28 Oct 2018 16:09:55 +0000 (16:09 +0000)]
udp-turn: Factor our SendRequest destruction

5 years agocomponent: Replace agent pointer with weak reference
Olivier Crête [Sun, 28 Oct 2018 14:46:11 +0000 (14:46 +0000)]
component: Replace agent pointer with weak reference

This should make it safer.

5 years agoudp-turn: Restore synchronized seconds timeout
Olivier Crête [Sun, 28 Oct 2018 14:43:42 +0000 (14:43 +0000)]
udp-turn: Restore synchronized seconds timeout

5 years agoagent: Remove explicit parent pointers
Olivier Crête [Sun, 28 Oct 2018 13:54:45 +0000 (13:54 +0000)]
agent: Remove explicit parent pointers

Remove all pointers that don't include have a reference except to agents

5 years agoUse per-agent locks and GWeakRefs in callbacks from timeout sources
Juan Navarro [Mon, 20 Aug 2018 16:01:02 +0000 (18:01 +0200)]
Use per-agent locks and GWeakRefs in callbacks from timeout sources

Work on libnice's bug #1 in Gitlab. This work is composed of multiple
merged parts:

- "Global lock contention removed"
Phabricator D1900: https://phabricator.freedesktop.org/D1900
By @nifigase
Opened in GitLab as Merge Request !12

- "agent: properly handle NiceAgent ref in callbacks from timeout
sources"
Phabricator D1898: https://phabricator.freedesktop.org/D1898
By @mparis
This patch was itself based upon a previous version of the work done in
D1900. After the switch of hosting, it got lost.

On top of these, additions to follow some review comments from @ocrete:
- https://phabricator.freedesktop.org/D1900#40412
- https://phabricator.freedesktop.org/D1898#39332

5 years agocomponent: Also accept TCP from udp-turn socket
Olivier Crête [Sun, 21 Oct 2018 09:18:00 +0000 (11:18 +0200)]
component: Also accept TCP from udp-turn socket

5 years agoFix build with android NDK r16
Matthew Waters [Wed, 14 Feb 2018 12:22:16 +0000 (23:22 +1100)]
Fix build with android NDK r16

getifaddrs() may only be available if the target API is >= 24

5 years agoconncheck: don't disable keepalive on TCP if it's explicitly enabled
Michael Olbrich [Mon, 9 Jul 2018 13:22:01 +0000 (15:22 +0200)]
conncheck: don't disable keepalive on TCP if it's explicitly enabled

This makes it possible to enable keepalive for TCP candidates. It is useful
to detect disappearing peers or network failures faster.

5 years agostun: check identifier before using it
Michael Olbrich [Mon, 9 Jul 2018 13:08:15 +0000 (15:08 +0200)]
stun: check identifier before using it

By default, 'candidate_identifier == NULL' only happens for 'compatibility
== NICE_COMPATIBILITY_GOOGLE'. However, keepalive=true will also trigger
the same code path so candidate_identifier must be checked to avoid a
segfault.

5 years agoagent: fix crash with debugging enabled
Michael Olbrich [Mon, 9 Jul 2018 12:52:08 +0000 (14:52 +0200)]
agent: fix crash with debugging enabled

For some connection types nicesock->fileno is never set.
Make sure it is not NULL before using it.

5 years agoconfigure: Allow selecting crypto library manually
Olivier Crête [Sun, 21 Oct 2018 08:02:43 +0000 (04:02 -0400)]
configure: Allow selecting crypto library manually

5 years agostun: Add support to detect OpenSSL
Brendan Shanks [Thu, 10 May 2018 00:50:13 +0000 (17:50 -0700)]
stun: Add support to detect OpenSSL

5 years agostun: Add implementation using OpenSSL for rand/SHA1/MD5
Brendan Shanks [Thu, 10 May 2018 00:18:44 +0000 (17:18 -0700)]
stun: Add implementation using OpenSSL for rand/SHA1/MD5

5 years agoopenssl: Add ax_check_openssl.m4
Brendan Shanks [Wed, 9 May 2018 19:45:22 +0000 (12:45 -0700)]
openssl: Add ax_check_openssl.m4

5 years agotests: Remove non-existing mainloop test from Makefile.am
Olivier Crête [Sun, 21 Oct 2018 07:31:48 +0000 (03:31 -0400)]
tests: Remove non-existing mainloop test from Makefile.am

6 years agoAdd GitLab CI configuration
Olivier Crête [Tue, 19 Jun 2018 17:59:31 +0000 (13:59 -0400)]
Add GitLab CI configuration

6 years agodocs: Add missing symbols to various sections
Olivier Crête [Tue, 19 Jun 2018 17:58:30 +0000 (13:58 -0400)]
docs: Add missing symbols to various sections

6 years agoMakefile.am: Replace valgrind.sh with valgrind-test-driver
Olivier Crête [Tue, 19 Jun 2018 17:58:05 +0000 (13:58 -0400)]
Makefile.am: Replace valgrind.sh with valgrind-test-driver

6 years agoRemove Phabricator .arcconfig
Olivier Crête [Mon, 18 Jun 2018 15:47:04 +0000 (11:47 -0400)]
Remove Phabricator .arcconfig

Now, we use GitLab at https://gitlab.freedesktop.org/libnice/libnice

6 years agotest-bind: define MSG_NOSIGNAL if undefined
Justin Kim [Wed, 13 Jun 2018 04:59:09 +0000 (13:59 +0900)]
test-bind: define MSG_NOSIGNAL if undefined

MacOS X and Windows don't have MSG_NOSIGNAL.

Signed-off-by: Justin Kim <justin.kim@collabora.com>
6 years agoFix queue_clear replaced by queue_free error
Nicolas Dufresne [Mon, 18 Jun 2018 12:43:17 +0000 (08:43 -0400)]
Fix queue_clear replaced by queue_free error

There was two cases where instead of freeing the queue, we actually
clear the queue so it's ready for reused. Notably in
nice_socket_free_send_queue(), a missed name function and nicesrc
element state change.

This regression was introduced by: fa783b1dd727a6ee2b99a111ca24790ae850c2f7

6 years agoFix cast-function-type warning introduced in GCC 8
Nicolas Dufresne [Sat, 26 May 2018 15:58:21 +0000 (15:58 +0000)]
Fix cast-function-type warning introduced in GCC 8

This is new warning introduced with GCC 8. This is being fixed by using appropriate function, like g_queue_free_full/g_list_free_full or by casting to GCallback before casting to the target function signature.

Closes: #46

6 years agodiscovery: fix candidate foundation using valid characters
Miguel París Díaz [Tue, 5 Jul 2016 12:42:44 +0000 (14:42 +0200)]
discovery: fix candidate foundation using valid characters

Following [1] and [2], "-" character is not allowed for foundation

Refs
[1] https://tools.ietf.org/html/rfc5245#page-73
[2] https://tools.ietf.org/html/rfc5234#appendix-B.1

6 years agotest-pseudotcp(-fuzzy): Fix format string warnings causing build errors on 32-bit
Brendan Shanks [Wed, 9 May 2018 22:05:18 +0000 (15:05 -0700)]
test-pseudotcp(-fuzzy): Fix format string warnings causing build errors on 32-bit

Closes: ttps://gitlab.freedesktop.org/libnice/libnice/issues/45

6 years agostun: Also rename windows-specific function
Edward Hervey [Wed, 21 Feb 2018 07:49:15 +0000 (08:49 +0100)]
stun: Also rename windows-specific function

Like all other instances of nice_RAND_bytes that were renamed
to nice_RAND_nonce.

Fixes the windows build

6 years agoagent: Redefine socket error messages for windows
Edward Hervey [Wed, 21 Feb 2018 08:05:45 +0000 (09:05 +0100)]
agent: Redefine socket error messages for windows

In the same way we do it for the other error messages

6 years agostund: Pass sockaddr_storage size for both families
Olivier Crête [Fri, 4 May 2018 14:50:45 +0000 (16:50 +0200)]
stund: Pass sockaddr_storage size for both families

6 years agostund: Pass the right length for ipv6
Olivier Crête [Fri, 4 May 2018 14:44:45 +0000 (16:44 +0200)]
stund: Pass the right length for ipv6

6 years agoIgnore function case warnings
Olivier Crête [Fri, 4 May 2018 13:44:05 +0000 (15:44 +0200)]
Ignore function case warnings

This makes GLib usage annoying as it makes GSourceFunc casts invalid.

6 years agoagent: don't require "reliable" be TRUE in order to use "ice-tcp"
Jakub Adam [Wed, 19 Apr 2017 12:17:04 +0000 (14:17 +0200)]
agent: don't require "reliable" be TRUE in order to use "ice-tcp"

Setting writable socket callbacks doesn't have to be limited to reliable
agents. TCP sockets need the callback in any case for correct operation
and calling nice_socket_set_writable_callback() on a NiceSocket that has
UDP as its base has no effect.

Differential Revision: https://phabricator.freedesktop.org/D1726

6 years agodiscovery: ignore bogus Skype for Business srflx addresses
Jakub Adam [Sat, 3 Feb 2018 22:59:20 +0000 (23:59 +0100)]
discovery: ignore bogus Skype for Business srflx addresses

If main SfB TURN server sends our allocation request to an alternate
server, the response will have XOR_MAPPED_ADDRESS containing the IP
address of the turn server that proxied the message instead of our own
actual external IP.

Before we create server reflexive candidates upon receiving an allocate
response, check that the TURN port got assigned on the same server we
sent out allocate request to. Otherwise, the request was proxied and
XOR_MAPPED_ADDRESS contains a bogus value we should ignore.

Issue introduced by 59fcf95d505c3995f858b826d10cd48321ed383e.
Differential Revision: https://phabricator.freedesktop.org/D1949

6 years agoagent: make candidate username and password immutable
Fabrice Bellet [Mon, 11 Dec 2017 07:50:33 +0000 (08:50 +0100)]
agent: make candidate username and password immutable

With this patch we prevent the username and the password of a candidate
to be modified during a session, as required by the RFC, sect 9.1.2.
This is also needed from a memory management point of view, because the
password string pointer may be recorded in the components stun agent
sent_ids[] struct key member, and freeing these values there may cause
an use-after-free condition, when an inbound stun is received from this
candidate. This behavior has been observed with pidgin, xmpp, and
farstream when a same remote candidates are "updated" several times,
even if the credentials don't change in this case.

Reviewed-by: Olivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1917

6 years agodiscovery: ignore all non-relay local candidates when relay is forced
Fabrice Bellet [Thu, 30 Nov 2017 19:11:22 +0000 (20:11 +0100)]
discovery: ignore all non-relay local candidates when relay is forced

The tcp server reflexive discovered local candidates must be ignored
when force_relay is set.

Reviewed-by: Olivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1899

6 years agoconncheck: dont fail a stream with a empty conncheck list
Fabrice Bellet [Wed, 29 Nov 2017 10:04:04 +0000 (11:04 +0100)]
conncheck: dont fail a stream with a empty conncheck list

Since commit 17f30e4, we may have a stream with an empty conncheck list,
and such a stream obviously should not be tested for failed components.

Reviewed-by: Olivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1895

6 years agosocket: ping the stun server address on the right socket
Fabrice Bellet [Mon, 27 Nov 2017 22:56:17 +0000 (23:56 +0100)]
socket: ping the stun server address on the right socket

Verify the compatibility of the socket domain with the stun server
IP address, before sending a request.

Reviewed-by: Olivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1894

6 years agoconncheck: make debug more homonegeous
Fabrice Bellet [Sun, 26 Nov 2017 18:31:39 +0000 (19:31 +0100)]
conncheck: make debug more homonegeous

Reviewed-by: Olivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1893

6 years agoconncheck: factorize pair state debug
Fabrice Bellet [Sun, 26 Nov 2017 17:10:12 +0000 (18:10 +0100)]
conncheck: factorize pair state debug

Reviewed-by: Olivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1892

6 years agoconncheck: the conncheck send function may fail
Fabrice Bellet [Sun, 26 Nov 2017 16:49:25 +0000 (17:49 +0100)]
conncheck: the conncheck send function may fail

With this patch, we put the pair in state failed if we cannot send
the connection check, for example due to missing local credentials.

Reviewed-by: Olivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1891

6 years agotest-new-dribble: make credentials swap asymmetric
Fabrice Bellet [Sun, 26 Nov 2017 16:36:27 +0000 (17:36 +0100)]
test-new-dribble: make credentials swap asymmetric

the first case of test-new-dribble (standard-test) is updated, by making
the credentials swap between the left and right agent asymmetric.
Previously, ragent started to receive stun requests without initially
knowing lagent candidates. Now, ragent also ignores lagent credentials.
This modification allows to test changes introduced by the previous
commit.

Reviewed-by: Olivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1890

6 years agoconncheck: rework early stun requests handling
Fabrice Bellet [Sun, 26 Nov 2017 16:13:19 +0000 (17:13 +0100)]
conncheck: rework early stun requests handling

With this patch we simplify the code used to handle the incoming stun
request when remote candidates or remote credentials have not been
received yet.

When the remote credentials is unknown, the stun request is stored
in a list of incoming_checks for later processing, and no further
processing is done, except responding to the request.

When the remote credentials are received, the triggered checks for these
incoming checks can now be queued, and the related pairs are created.

If the remote candidates have not been received when the stun request
on a valid local port arrives, a peer-reflexive remote candidate will be
created. This candidate may need to be updated later when remote
candidates are finally received, including candidate priority and
foundation, and also related pairs.

Reviewed-by: Olivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1889

6 years agoagent: Fixes incompatible pointer type warning on OSX.
Jozsef Vass [Mon, 8 Jan 2018 18:53:23 +0000 (10:53 -0800)]
agent: Fixes incompatible pointer type warning on OSX.

The variable tie is actually never read.

6 years agoconncheck: handle alternate-server for turn relays differently
Youness Alaoui [Tue, 28 Nov 2017 21:05:18 +0000 (16:05 -0500)]
conncheck: handle alternate-server for turn relays differently

If a relay gives us an alternate-server, we need to cancel and reset
every candidate discovery attempt that uses the same server, to avoid
ending up with one component on one server and the other component on
another server (causing relay candidates with mismatched foundations).

6 years agodiscovery: Increase discovery_unsched_items whenever we restart a check
Youness Alaoui [Tue, 28 Nov 2017 20:14:11 +0000 (15:14 -0500)]
discovery: Increase discovery_unsched_items whenever we restart a check

The discovery_unsched_items is decremented every time a DiscoveryCandidate
goes from non-pending to pending. So if we restart a check by setting
pending to FALSE, we should re-increase the discovery_unsched_items.

6 years agoturn: Add support for ALTERNATE_SERVER in OC2007 Compatibility
Youness Alaoui [Mon, 27 Nov 2017 22:07:02 +0000 (17:07 -0500)]
turn: Add support for ALTERNATE_SERVER in OC2007 Compatibility

The MS Office TURN servers will always return the MS_ALTERNATE_SERVER in
allocation responses, and if they are not handled, we end up using the
main turn server to send allocation requests that then get sent to the
alternate server which will return the XOR_MAPPED_ADDRESS containing
the IP address of the turn server that proxied the message instead of
our own actual external IP.

6 years agoconncheck: do not require that all streams have a connection check list
Miguel París [Wed, 8 Nov 2017 16:26:47 +0000 (16:26 +0000)]
conncheck: do not require that all streams have a connection check list

One or more streams might not have any connection check list if the
number of streams differs from the peer agent.
Differential Revision: https://phabricator.freedesktop.org/D1880

6 years agoMakefile: really enable debug for tests
Fabrice Bellet [Thu, 23 Nov 2017 17:31:31 +0000 (18:31 +0100)]
Makefile: really enable debug for tests

Differential Revision: https://phabricator.freedesktop.org/D1888

6 years agoagent: prevent external role change while conncheck is running
Fabrice Bellet [Tue, 21 Nov 2017 14:12:45 +0000 (15:12 +0100)]
agent: prevent external role change while conncheck is running

With this patch, we stash the controlling mode property change, and
apply it safely, when it won't interfere with an ongoing conncheck
running. According to RFC5245, sect 5.2. "Determining Role", the role
is determined for a session, and persists unless an ICE is restarted.

Differential Revision: https://phabricator.freedesktop.org/D1887

6 years agostun: Fix FD leak in test/utility code
Philip Withnall [Thu, 3 Aug 2017 11:20:32 +0000 (12:20 +0100)]
stun: Fix FD leak in test/utility code

https://phabricator.freedesktop.org/T7798

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: Olivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1819

6 years agotests: Fix agent.h header inclusion in test-gstreamer.c
Philip Withnall [Tue, 12 Sep 2017 12:23:53 +0000 (13:23 +0100)]
tests: Fix agent.h header inclusion in test-gstreamer.c

Spotted by Lukas Gradl on the mailing list.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
6 years agotests: Fix copyright dates in test-gstreamer.c
Philip Withnall [Tue, 12 Sep 2017 12:23:31 +0000 (13:23 +0100)]
tests: Fix copyright dates in test-gstreamer.c

This code is not 1000 years old.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
6 years agoconncheck: change state before updating nominated pairs
Fabrice Bellet [Sun, 2 Jul 2017 14:02:09 +0000 (16:02 +0200)]
conncheck: change state before updating nominated pairs

When a pair is nominated while in state failed, we first move
back to state connecting, then we update the selected pair, and
finally we move to state connected.

6 years agoconncheck: forgot to put a pair in triggered check list
Fabrice Bellet [Wed, 28 Jun 2017 10:06:48 +0000 (12:06 +0200)]
conncheck: forgot to put a pair in triggered check list

When a new pair is created from an unknown remote candidate, it
should be enqueue for a triggered check, to allow it to be marked
as nominated on response arrival in priv_mark_pair_nominated().
Creating it in waiting state is not sufficient since the update
in priv_mark_pair_nominated() from previous commits.

Differential Revision: https://phabricator.freedesktop.org/D1763

6 years agoconncheck: update the state of triggered checks pairs
Fabrice Bellet [Tue, 27 Jun 2017 09:01:14 +0000 (11:01 +0200)]
conncheck: update the state of triggered checks pairs

With this patch, we fix an ambiguity of some parts of the spec, when
the document refers to in-progress pairs, that also concern pairs in
the triggered checks list.

The first cast is in section 7.1.2.5, "Updating the Nominated Flag",
when the in-progress pair will be nominated on response arrival. This is
handled in function priv_mark_pair_nominated(), when a pair is put to
the triggered check list in reaction to a matching inbound stun request.
Such a pair in priv_mark_pair_nominated() will _always_ be in the
triggered check list, from the previously called function
priv_schedule_triggered_check().

The second case is in section 8.1.2, "Updating State" when an in-progress
pair stops its retransmission when another pair of higher priority is
already nominated. This is handled by function priv_prune_pending_checks().

Until now, pairs enqueued in the triggered check list move transiently
to state waiting, according to 7.2.1.4. But this state causes wrong
decisions in the two previous cases, because such pairs should in fact
rather be considered "like in-progress", to avoid discarding them
inadvertantly.

This patch update the state of the triggered check list
pairs to in-progress. It allows to remove exception handling cited
above: the code is a bit more simple, and allows some refactoring
in priv_mark_pair_nominated() between RFC and compatibility modes.

Differential Revision: https://phabricator.freedesktop.org/D1762

6 years agoconncheck: support several stun requests per pair
Fabrice Bellet [Mon, 26 Jun 2017 19:41:44 +0000 (21:41 +0200)]
conncheck: support several stun requests per pair

This patch should improve the reliabily of the connection check by
keeping the record of several simultaneous ongoing stun requests per
pair. A new stun request on an in-progress pair typically is caused by
in inbound stun request from the peer on this same pair. This is named
"Triggered Checks" in the spec. When this situation arises, it is fair
to handle these two stun requests simultaneously, the triggered check,
and the initial ordinary check, since both can potentially succeed.

Differential Revision: https://phabricator.freedesktop.org/D1761

6 years agoconncheck: use stun_timer_remainder less frequently
Fabrice Bellet [Mon, 26 Jun 2017 19:06:36 +0000 (21:06 +0200)]
conncheck: use stun_timer_remainder less frequently

We try to use stun_timer_remainder() less frequently, particularily
in the debug messages, and favour of the next_tick value associated
to the pair.

Differential Revision: https://phabricator.freedesktop.org/D1760

6 years agoconncheck: make debug sentences more accurate
Fabrice Bellet [Mon, 26 Jun 2017 18:41:49 +0000 (20:41 +0200)]
conncheck: make debug sentences more accurate

We add a helper function to print the pair state in-extenso.

Differential Revision: https://phabricator.freedesktop.org/D1759

6 years agoconncheck: reorder some chunks of code
Fabrice Bellet [Mon, 26 Jun 2017 18:36:35 +0000 (20:36 +0200)]
conncheck: reorder some chunks of code

With this patch we simplify the levels of code indentation.

Differential Revision: https://phabricator.freedesktop.org/D1758

6 years agoagent: Set error if it isn't set
Olivier Crête [Tue, 5 Sep 2017 18:50:29 +0000 (14:50 -0400)]
agent: Set error if it isn't set

7 years agoconncheck: improve role conflict debug
Fabrice Bellet [Tue, 12 Apr 2016 11:22:21 +0000 (13:22 +0200)]
conncheck: improve role conflict debug

This patch displays explicitely the controlling or controlled
role of the agent.

Differential Revision: https://phabricator.freedesktop.org/D874

7 years agoconfigure: Remove -Wswitch-enum
Olivier Crête [Thu, 22 Jun 2017 00:42:57 +0000 (20:42 -0400)]
configure: Remove -Wswitch-enum

Creates useless warnings when other libraries change.

https://phabricator.freedesktop.org/T7770

7 years agocomponent: Use non-GClosure dummy callbacks
Olivier Crête [Fri, 12 Feb 2016 03:16:48 +0000 (22:16 -0500)]
component: Use non-GClosure dummy callbacks

GClosures are not that cheap to setup

7 years agoagent: Don't crash if recv cancelled without a GError
Olivier Crête [Thu, 11 Feb 2016 04:20:39 +0000 (23:20 -0500)]
agent: Don't crash if recv cancelled without a GError

7 years agoRepleace UNRELEASED with 0.1.15
Olivier Crête [Wed, 21 Jun 2017 21:07:17 +0000 (17:07 -0400)]
Repleace UNRELEASED with 0.1.15

7 years agoagent: Adjust the nice_agent_new_full() to use flags
Olivier Crête [Wed, 21 Jun 2017 20:55:32 +0000 (16:55 -0400)]
agent: Adjust the nice_agent_new_full() to use flags

This makes it easier to read and more extensible.

7 years agoagent: remove spurious newlines
Fabrice Bellet [Sun, 18 Jun 2017 08:12:58 +0000 (10:12 +0200)]
agent: remove spurious newlines

Differential Revision: https://phabricator.freedesktop.org/D1756

7 years agostun: fix gcc7 implicit fallthrough warning
Fabrice Bellet [Sun, 28 May 2017 20:20:36 +0000 (22:20 +0200)]
stun: fix gcc7 implicit fallthrough warning

Differential Revision: https://phabricator.freedesktop.org/D1754

7 years agoagent: add new pairs only for gathering streams
Fabrice Bellet [Fri, 15 Jul 2016 21:31:42 +0000 (23:31 +0200)]
agent: add new pairs only for gathering streams

At the end of the local candidate gathering process, we only create new
pairs for streams that are in gathering state.

Other stream that may be in ready state for example, due to a
previously succeeded conncheck process, may have accumulated some
couples (local,remote) candidates that have not resulted in the creation
a new pair during this previous conncheck process, and we don't want
these new pairs to be added now, because it would generate unneeded
transition changes for a stream unconcerned by this gathering.

Differential Revision: https://phabricator.freedesktop.org/D1755

7 years agoconncheck: fix the component failed transition
Fabrice Bellet [Tue, 21 Jun 2016 19:47:42 +0000 (21:47 +0200)]
conncheck: fix the component failed transition

This patch fixes the transition of a component from connecting to
failed, that previously occured due to the propagation of the
keep_timer_going variable, and to the final call to function
priv_update_check_list_failed_components(), after the global agent
timer was stopped.

Previously, the code almost never entered to failed state, because the
timer was going one, as long as the number of nominated pair was not
enough, and as long as there were valid pairs not yet nominated. Even
if all pair timers were over.

The definition of the Failed state of a conncheck list is somewhat
contradictory in the spec, depending on weather you read :

 * sect 5.7.4. "Computing States",
 "Failed:  In this state, the ICE checks have not completed successfully
 for this media stream."

 or

 * sect 7.1.3.3. "Check List and Timer State Updates",
 "If all of the pairs in the check list are now either in the Failed or
 Succeeded state: If there is not a pair in the valid list for each
 component of the media stream, the state of the check list is set to
 Failed."

Our understanding of the ICE spec is that, the proper way to enter failed
state instead in when all connchecks have no longer in-progress pairs.
All pairs are either in state succeeded, discovered, or failed. No timer
is still running, and we have no hope that the conncheck list changes
again, except if an unexpected STUN packet arrives later. All pairs in
frozen state is a special case, that is handled separately (sect
7.1.3.3).

A special grace delay is added before declaring a component in state
Failed. This delay is not part of the RFC, and it is aimed to limit the
cases when a conncheck list is reactivated just after it's been declared
failed, causing a user visible transition from connecting to failed, and
back from failed to connecting again. This is also required by the test
suite, that counts exactly the number of time each state is entered, and
doesn't expect these transcient failed states to happen (frequent due to
the nature of the testsuite, less frequent in real life).

Differential Revision: https://phabricator.freedesktop.org/D1111

7 years agoconncheck: remove cancelled pair state
Fabrice Bellet [Thu, 16 Jun 2016 15:32:39 +0000 (17:32 +0200)]
conncheck: remove cancelled pair state

Pairs with the state NICE_CHECK_CANCELLED are the pairs targeted for
removal after the nomination of a pair with an higher priority,
described in Section 8.1.2 "Updating States", item 2 of RFC 5245. They
include also pairs that overflow the conncheck list size, but this is a
somewhat more marginal situation. So we are mainly interested in the
first use case of this state.

This state mixes two different situations, that deserve a distinct
handling : on one side, there are waiting or frozen pairs that must be
removed, this is an immediate action that doesn't need a dedicated state
for that. And on the other side, there are in-progress pairs that
should no longer be retransmitted, because another pair with a higher
priority has already been nominated.

This patch removes the cancelled state, and adds a flag
retransmit_on_timeout to deal with this last situation. Note that this
case should not generate a triggered check, as per described in section
7.2.1.4, when the state of the pair is In-Progress or Failed, since this
pair of lower priority has no hope to replace the nominated one.

Differential Revision: https://phabricator.freedesktop.org/D1114

7 years agoconncheck: adjust recheck on timeout strategy
Fabrice Bellet [Tue, 14 Jun 2016 19:32:26 +0000 (21:32 +0200)]
conncheck: adjust recheck on timeout strategy

The pair recheck on timeout can easily cause repetitive rechecks in
a ping-pong effect, if both peers with the same behaviour try to
check the same pair almost simultaneously, and if the network rtt
is greater than the initial timer rto. The reply to the initial
stun request may arrive after the in-progress conncheck
cancellation (described in RFC 5245, sect 7.2.1.4). Cancellation
creates a new stun request, and forgets the initial one.
The conncheck timer is restarted with the same initial value,
so the same situation happens again later.

We choose to avoid resetting the timer in such situation. After enough
retransmissions, the timeout delay, that doubles after each timeout,
becomes longer than the rtt, and the stun reply can be handled.

Differential Revision: https://phabricator.freedesktop.org/D1115

7 years agoconncheck: do not recheck a just succeeded pair
Fabrice Bellet [Tue, 14 Jun 2016 19:20:49 +0000 (21:20 +0200)]
conncheck: do not recheck a just succeeded pair

We cancel the potential in-progress transaction cancellation, caused by
sect 7.2.1.4 "Triggered Checks", when we receive a valid reply before
transmission timeout, or just after timeout, when the pair is
temporarily put on the triggered check list on the way to be
rechecked. This situation is not covered by the RFC 5245.

Differential Revision: https://phabricator.freedesktop.org/D1119

7 years agoconncheck: fix a state transition case
Fabrice Bellet [Tue, 14 Jun 2016 19:12:16 +0000 (21:12 +0200)]
conncheck: fix a state transition case

When a new stun request hits a valid pair, of a failed component, we may
have a transition from state failed to connected. In this situation, we
do a logical progression failed -> connecting -> connected, like we do
in function priv_update_check_list_state_for_ready()

Similarily, when a new stun request hits a failed pair, of a failed
component, triggering a new conncheck for this pair may also cause the
component state to move back from failed to connecting state.

Differential Revision: https://phabricator.freedesktop.org/D1118

7 years agoconncheck: try to change earlier to state ready
Fabrice Bellet [Tue, 14 Jun 2016 19:04:49 +0000 (21:04 +0200)]
conncheck: try to change earlier to state ready

We check if we can move from state connected to ready just
after a pair expired its retransmission count. This pair
will be marked failed, and will no longer be in-progress.
The number of in-progress dropping down to zero is one
of the conditions needed to make the transition to ready,
per component (and not globally as it's the case in other
locations where this check function is called).

Differential Revision: https://phabricator.freedesktop.org/D1117

7 years agoconncheck: dont cancel a pair for triggered check
Fabrice Bellet [Mon, 11 Apr 2016 11:13:51 +0000 (13:13 +0200)]
conncheck: dont cancel a pair for triggered check

This patch adds another supplementary "corner" case, not covered by the
ICE spec, sect 8.1.2, "Updating States". A pair in waiting state and in
the triggered check list should be considered like an in-progress pair,
and cancelled only if its priority is lower than the priority of the
nominated pair. This is required in some aggressive nomination
situations for both peers to select the same pair, having the highest
priority.

Differential Revision: https://phabricator.freedesktop.org/D933

7 years agoconncheck: remove a useless pair recheck
Fabrice Bellet [Fri, 1 Apr 2016 15:31:44 +0000 (17:31 +0200)]
conncheck: remove a useless pair recheck

This exception to the ICE spec is no longer needed: when a pair is in
the succeeded state, there is no needed to recheck it again upon
reception of an incoming stun request on it.

Differential Revision: https://phabricator.freedesktop.org/D884

7 years agoconncheck: update the pair state in triggered check list
Fabrice Bellet [Tue, 12 Apr 2016 10:56:28 +0000 (12:56 +0200)]
conncheck: update the pair state in triggered check list

With this patch, we update the state of the pair to waiting when
it is put in the triggered check queue. We also take care to call
priv_schedule_triggered_check() before priv_mark_pair_nominated()
so a pair to be rechecked and put on the triggered check queue
will have a unique state to be tested in the following call to
priv_mark_pair_nominated() when evaluating its nomination attributes.

Differential Revision: https://phabricator.freedesktop.org/D883

7 years agoconncheck: new pairs never have the nominated flag preset
Fabrice Bellet [Tue, 12 Apr 2016 11:32:49 +0000 (13:32 +0200)]
conncheck: new pairs never have the nominated flag preset

This patch disables the possibility to set the nominated flag of a
candidate pair at creation time. This possibility was used when a new
pair is created from a new peer reflexive remote candidate, when the
agent is in controlled mode, and an stun request with USE-CANDIDATE is
received. In this case, since previous commit "conncheck: fix a
nomination corner case", we set the nominated flag when the stun
response of this new pair will arrive, and not before.  Consequently,
this flag is no longer required when the pair is created.

Differential Revision: https://phabricator.freedesktop.org/D881

7 years agoconncheck: fix a nomination corner case
Fabrice Bellet [Tue, 12 Apr 2016 11:30:04 +0000 (13:30 +0200)]
conncheck: fix a nomination corner case

This patch add two supplementary cases, not covered by the ICE spec,
sect 7.2.1.5 "Updating the Nominated Flag" when a controlled agent
receives a STUN request with the USE-CANDIDATE flag, for a pair that is
in the waiting state. We consider that this case is similar to the
in-progress state, and should be handled in the same way. We also accept
when the pair is in frozen state. This latter case happens in the
new-dribble test, when an agent replays incoming early connchecks.

Differential Revision: https://phabricator.freedesktop.org/D880

7 years agoconncheck: use the right pair when retriggering a check
Fabrice Bellet [Tue, 19 Apr 2016 16:16:26 +0000 (18:16 +0200)]
conncheck: use the right pair when retriggering a check

This patch completes the previous patch by adding a link back from the
discovered pair, to the parent pair that generated this check. This link
is needed by the ICE spec, to comply with section 8.1.1.1, "Regular
nomination", where the check to be retriggered is the initial check that
caused the discovery of the valid pair. When the valid pair is a
peer-reflexive pair, the retriggered check must target the succeeded
pair, and not the valid discovered pair.

Differential Revision: https://phabricator.freedesktop.org/D879

7 years agoconncheck: link succeeded and discovered pairs
Fabrice Bellet [Tue, 12 Apr 2016 11:25:16 +0000 (13:25 +0200)]
conncheck: link succeeded and discovered pairs

When the agent has the role of the stun server, is in controlled mode,
and receives a pair with the "use-candidate" attribute set, it must find
a matching succeded or discovered pair in its conncheck list. This is
described in ICE spec 7.2.1.5, "Updating the Nominated Flag", item #1.
When a matching pair is in succeeded state, the agent must nominate the
valid pair (a discovered pair) constructed from section 7.1.3.2.2,
that's been created from this succeeded one. To make this lookup, we
introduce a new "discovered_pair" member of the CandidateCheckPair
struct, that links the succeeded pair, and its discovered pair
if any.

Differential Revision: https://phabricator.freedesktop.org/D878

7 years agoconncheck: improve triggered check of in-progress pairs
Fabrice Bellet [Tue, 19 Apr 2016 15:59:27 +0000 (17:59 +0200)]
conncheck: improve triggered check of in-progress pairs

This patch update the way triggered checks of in-progress pairs are
handled, according to ICE spec, section 7.2.1.4. Previously the same
connection check was retransmitted with an updated timeout. This causes
problems when a controlling role switch occurs in this time frame.
This is the reason why a new connection check must be generated
reflecting the updated role. We introduce a new flag "recheck_on_timeout"
in the pair indicating that the pair must be rechecked at the next timer
expiration.

Differential Revision: https://phabricator.freedesktop.org/D875

7 years agoconncheck: invoke the debug dump in more places
Fabrice Bellet [Tue, 12 Apr 2016 11:20:38 +0000 (13:20 +0200)]
conncheck: invoke the debug dump in more places

Differential Revision: https://phabricator.freedesktop.org/D1123

7 years agoconncheck: improve the selection of the pairs to be checked
Fabrice Bellet [Tue, 19 Apr 2016 15:06:32 +0000 (17:06 +0200)]
conncheck: improve the selection of the pairs to be checked

This patch aims to implement more closely the algorithm described
in RFC 5245 indicating how pairs are transitionned from state Frozen
to Waiting. This is described in 7.1.3.2 when a check succeeded, and
correspond to modifications in function priv_conn_check_unfreeze_related().
This is also described in 5.7.4 when defining the initial state of the
pairs in a conncheck, and correspond to modifications in function
priv_conn_check_unfreeze_next().

This patch introduces the notion of active and frozen check list. It
allows us to define the timer restranmission delay as described in 16.1.

Another modification in priv_conn_check_tick_unlocked() is that every
stream in handled consecutively, and in an independant way. The pacing
was previously of a single STUN request emitted per callback, it is now
of a triggered check per callback OR a single STUN per callback AND per
stream per callback.

The description of ordinary checks per stream in 5.8 is detailled in
function priv_conn_check_tick_stream(), and a remaining of the code
used to nominate a pair by the controlling agent is put in a dedicated
function priv_conn_check_tick_stream_nominate()

Differential Revision: https://phabricator.freedesktop.org/D813

7 years agoconncheck: update pair valid property selectively
Fabrice Bellet [Mon, 7 Mar 2016 15:35:09 +0000 (16:35 +0100)]
conncheck: update pair valid property selectively

With this patch, we fix a corner case when the succeeded pair is a
peer-reflexive candidate pair, that already has been discovered
previously, In this case, the current pair -p- should not be marked
valid, because the valid flag is already set on the discovered pair.

Differential Revision: https://phabricator.freedesktop.org/D1124

7 years agotest-nomination: added a new test for the nomination mode
Fabrice Bellet [Wed, 22 Jun 2016 13:44:39 +0000 (15:44 +0200)]
test-nomination: added a new test for the nomination mode

Differential Revision: https://phabricator.freedesktop.org/D1107