platform/upstream/libnice.git
8 years agotimer: Maximum retransmission should include the original one
Olivier Crête [Mon, 6 Jun 2016 20:21:54 +0000 (16:21 -0400)]
timer: Maximum retransmission should include the original one

We really care about the maximum transmissions, the first one counts.

8 years agopseudotcp: it's still a GObject
Olivier Crête [Fri, 3 Jun 2016 22:42:59 +0000 (18:42 -0400)]
pseudotcp: it's still a GObject

8 years agopseudotcp: Make sure duplicate ack representing losses have no data
Olivier Crête [Thu, 14 Apr 2016 11:32:51 +0000 (13:32 +0200)]
pseudotcp: Make sure duplicate ack representing losses have no data

If they have data in them, they won't be recognized as duplicate acks by
the sender.

8 years agopseudotcp: Implement NewReno timestamp heuristic
Olivier Crête [Thu, 14 Apr 2016 07:50:09 +0000 (09:50 +0200)]
pseudotcp: Implement NewReno timestamp heuristic

This allows the sender to enter fast retransmit after a timeout because
it can now detect that three duplicate acks are caused by a packet loss.

As specific in RFC 6582 section 4.2.

8 years agopseudotcp: Set min RTO to 1 second
Olivier Crête [Wed, 6 Apr 2016 07:46:46 +0000 (10:46 +0300)]
pseudotcp: Set min RTO to 1 second

This is recommended by RFC 6298

8 years agopseudotcp: Implement full NewReno
Olivier Crête [Tue, 5 Apr 2016 22:59:36 +0000 (01:59 +0300)]
pseudotcp: Implement full NewReno

8 years agopseudotcp: Make debug more useful
Olivier Crête [Tue, 2 Feb 2016 21:59:18 +0000 (16:59 -0500)]
pseudotcp: Make debug more useful

8 years agopseudotcp: Separate default and maximum MTU
Olivier Crête [Wed, 13 Jan 2016 01:14:48 +0000 (20:14 -0500)]
pseudotcp: Separate default and maximum MTU

Accept packets much beyond the default MTU, but
set a reasonable default MTU for sending of 1400

8 years agopseudotcp: close local socket on initial transmission error
Olivier Crête [Thu, 24 Dec 2015 06:15:59 +0000 (01:15 -0500)]
pseudotcp: close local socket on initial transmission error

This is required as no retransmissions will happen

8 years agopseudotcp: Export more symbols for PseudoTCP
Olivier Crête [Fri, 18 Sep 2015 01:26:36 +0000 (21:26 -0400)]
pseudotcp: Export more symbols for PseudoTCP

8 years agopseudotcp: Make structs definitions private
Olivier Crête [Thu, 17 Sep 2015 19:00:27 +0000 (15:00 -0400)]
pseudotcp: Make structs definitions private

8 years agopseudotcp: Correct behaviour of buffer size methods when part-closed
Philip Withnall [Tue, 23 Jun 2015 14:42:33 +0000 (15:42 +0100)]
pseudotcp: Correct behaviour of buffer size methods when part-closed

Correct the behaviour of pseudo_tcp_socket_get_available_bytes() and
pseudo_tcp_get_available_send_space() when the socket is not in
TCP_ESTABLISHED state. It’s still permissible to send and receive up
until the local side calls pseudo_tcp_socket_close(), which means we
may be in state TCP_ESTABLISHED *or TCP_CLOSE_WAIT*.

8 years agopseudotcp: Fix EOS checks in high packet loss situations
Philip Withnall [Fri, 31 Jul 2015 13:28:51 +0000 (14:28 +0100)]
pseudotcp: Fix EOS checks in high packet loss situations

The state tracking previously assumed that if a FIN packet was sent, the
other side received it and the preceding packets, and hence it was
correct to sent an RST if an unexpected packet (such as a delayed
SYN-ACK) was received.

In cases where there is high packet loss, this won’t work. For example,
peer A sends a SYN, it is received and peer B replies with a SYN-ACK
which is also received; then peer A sends its data and a FIN, which are
both dropped. Since it hasn’t received anything since the original SYN,
peer B resends its SYN-ACK. If that is received, peer A was incorrectly
treating it as an erroneous packet, and would then send a RST. In actual
fact, it should take this as a signal that the data and FIN packets were
dropped, and should resend them.

TODO: Add unit tests

8 years agopseudotcp: Propagate error codes from transmit() to callers
Philip Withnall [Fri, 31 Jul 2015 13:19:30 +0000 (14:19 +0100)]
pseudotcp: Propagate error codes from transmit() to callers

Otherwise we can’t easily differentiate between different transmission
failures; for example: underlying socket failures, versus retransmission
timeouts.

8 years agopseudotcp: Add more debug info on closing down a pseudo-TCP socket
Philip Withnall [Tue, 23 Jun 2015 14:40:13 +0000 (15:40 +0100)]
pseudotcp: Add more debug info on closing down a pseudo-TCP socket

8 years agopseudotcp: Fix pseudo_tcp_socket_recv() in state TCP_CLOSE_WAIT
Philip Withnall [Wed, 24 Jun 2015 13:06:05 +0000 (14:06 +0100)]
pseudotcp: Fix pseudo_tcp_socket_recv() in state TCP_CLOSE_WAIT

Previously, pseudo_tcp_socket_recv() would start returning 0 (EOS) as
soon as a FIN segment was received from the peer, even if there was
unread data already in the receive buffer.

Instead, the unread data should all be accessible before
pseudo_tcp_socket_recv() starts returning 0.

8 years agopseudotcp: Fix retransmission of segments before handling a FIN
Philip Withnall [Wed, 24 Jun 2015 12:52:16 +0000 (13:52 +0100)]
pseudotcp: Fix retransmission of segments before handling a FIN

Previously, if peer A transmitted one or more data segments (1),
followed by a FIN segment (2) to peer B, and segments 1 were
dropped, peer B would not request retransmission of them and would
instead continue with the FIN handshake. This effectively meant
segments 1 were lost without peer B realising.

Fix this by only handling the FIN segment once its sequence number is
acknowledged in the receive window.

8 years agosocket: Assert trying to use free'd socket
Olivier Crête [Thu, 2 Jun 2016 23:22:50 +0000 (19:22 -0400)]
socket: Assert trying to use free'd socket

Cleanly returnign makes no sense and may hide
worse problems.

8 years agocomponent: Fix set TCP selected remote candidate
Misha Uliutin [Mon, 25 Apr 2016 06:59:48 +0000 (09:59 +0300)]
component: Fix set TCP selected remote candidate

https://phabricator.freedesktop.org/T7407

8 years agoagent: Parse TURN packet on the right socket
Olivier Crête [Thu, 2 Jun 2016 23:00:17 +0000 (19:00 -0400)]
agent: Parse TURN packet on the right socket

https://phabricator.freedesktop.org/T99

8 years agotests: Add TURN test
Olivier Crête [Thu, 2 Jun 2016 21:34:27 +0000 (17:34 -0400)]
tests: Add TURN test

This test depends on rfc5766-turn-server which must
be installed for this test to run.

8 years agoconncheck: mark discovered pairs with TCP passive as valid
Jakub Adam [Tue, 31 May 2016 11:42:44 +0000 (11:42 +0000)]
conncheck: mark discovered pairs with TCP passive as valid

Doing so similarly to priv_process_response_check_for_reflexive(),
which also sets valid flag on discovered peer reflexive pairs.

Fixes a regression in previously working scenario.
Differential Revision: https://phabricator.freedesktop.org/D1035

8 years agotest-icetcp: don't be sensitive to the signal order
Jakub Adam [Wed, 1 Jun 2016 08:52:41 +0000 (08:52 +0000)]
test-icetcp: don't be sensitive to the signal order

"new-selected-pair" may be emitted after "component-state-changed"
to READY, by which time the main loop might have gotten quit in
cb_component_state_changed(). Consequently, cb_new_selected_pair() could
miss to register the selected pair, ultimately leading to an assertion
failure in main().

We should wait for both selected pair and state change events to occur
before stopping the main loop.

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

8 years agoRevert "WIP"
Olivier Crête [Tue, 31 May 2016 21:31:18 +0000 (17:31 -0400)]
Revert "WIP"

This reverts commit 01519677ba4d8df46e2c07bc20a5ef03ee2d9c3a.

8 years agoWIP
Olivier Crête [Tue, 31 May 2016 21:31:12 +0000 (17:31 -0400)]
WIP

8 years agoconncheck: fix pruning conn checks with TCP active sockets
Jakub Adam [Tue, 31 May 2016 09:27:03 +0000 (09:27 +0000)]
conncheck: fix pruning conn checks with TCP active sockets

TCP active socket makes a NiceSocket for each peer in conn_check_send()
and this new socket is then stored as CandidateCheckPair's 'sockptr'.
We thus have to look also at the 'sockptr' value when eliminating
sockets which have received HUP from connection checks.
Differential Revision: https://phabricator.freedesktop.org/D1034

8 years agoagent: Remove socket on read error
Olivier Crête [Tue, 8 Mar 2016 20:37:05 +0000 (15:37 -0500)]
agent: Remove socket on read error

If a socket returned an error, remove it.

8 years agocomponent: Add API to cleanly remove a base socket
Olivier Crête [Sat, 16 Jan 2016 03:40:27 +0000 (22:40 -0500)]
component: Add API to cleanly remove a base socket

8 years agoagent: Fix udp-turn-over-tcp
Olivier Crête [Sat, 27 Feb 2016 08:35:27 +0000 (03:35 -0500)]
agent: Fix udp-turn-over-tcp

The TCP-based turns don't come pre-parsed unlike
the UDP variants!

8 years agoagent: Add force-relay property to force messages through the relay
Olivier Crête [Wed, 27 Jan 2016 23:56:13 +0000 (18:56 -0500)]
agent: Add force-relay property to force messages through the relay

This allows implementing WebRTC privacy mode.

8 years agoconncheck: Start conncheck on server reply if needed
Olivier Crête [Wed, 10 Feb 2016 21:29:57 +0000 (16:29 -0500)]
conncheck: Start conncheck on server reply if needed

This only really applies in the force relay mode where there are
no local candidates.

8 years agoReplace g_malloc/g_new with g_alloca where possible
Olivier Crête [Mon, 8 Feb 2016 21:44:47 +0000 (16:44 -0500)]
Replace g_malloc/g_new with g_alloca where possible

This should reduce the overhead a bit.

8 years agoconncheck: explain some corner cases
Fabrice Bellet [Wed, 20 Apr 2016 10:17:05 +0000 (10:17 +0000)]
conncheck: explain some corner cases

This patch give details why some exceptions to the ICE spec are needed.

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

8 years agoconncheck: add a debug dump of the whole stream check list
Fabrice Bellet [Fri, 27 May 2016 23:15:39 +0000 (19:15 -0400)]
conncheck: add a debug dump of the whole stream check list

https://phabricator.freedesktop.org/D814

8 years agoconncheck: fix the replay of early incoming connchecks
Olivier Crête [Fri, 27 May 2016 22:50:59 +0000 (18:50 -0400)]
conncheck: fix the replay of early incoming connchecks

This patch fixes a bug in the way the list of incoming checks
is handled. The code purges this list too early, before all ichecks
for a given component are processed. It happens because the component
is computed from each pair of the check list, instead of being passed
as a fixed parameter of the function.

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

8 years agostun: fix ice role conflict handling
Fabrice Bellet [Wed, 20 Apr 2016 09:23:14 +0000 (09:23 +0000)]
stun: fix ice role conflict handling

This patch fixes the role conflict handling in stun ICE usage,
according to RFC 5245, by adding including missing cases in the
test. The role switch not only depends of the comparison of the
stun ice-controlling/controlled attrib with the agent tie breaker
value, but it also depends on the current role of the agent.

This patch also changes the value returned by
stun_usage_ice_conncheck_create_reply() when a role conflict exists
but doesn't change the role of the agent, causing an error stun
response. Previously, this case could not be differenciated by the
caller from a case with no role conflict. Now by examinating the
return value, and whether the control param changed, the caller
can check the four possibles situations. The stun test suite is
updated to match this change.

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

8 years agoconncheck: Make previous commit compile
Olivier Crête [Fri, 27 May 2016 21:26:06 +0000 (17:26 -0400)]
conncheck: Make previous commit compile

https://phabricator.freedesktop.org/T3324

8 years agodiscovery: Make sure each candidate has a unique priority
Olivier Crête [Mon, 8 Feb 2016 23:49:42 +0000 (18:49 -0500)]
discovery: Make sure each candidate has a unique priority

This should fix compliance with RFC 5245 Section 4.1.2

https://phabricator.freedesktop.org/T3324

8 years agoagent: Restrict transitions to gathering
Olivier Crête [Sun, 20 Sep 2015 20:53:26 +0000 (16:53 -0400)]
agent: Restrict transitions to gathering

Only allow transitions to gathering from disconnected or
failed states.

8 years agoconncheck: fix TCP active relay handling
Olivier Crête [Fri, 27 May 2016 18:06:24 +0000 (14:06 -0400)]
conncheck: fix TCP active relay handling

TCP active relay candidates use UDP TURN for their underlying socket.
Since 0a6c779f1f, socket->fileno of UDP TURN sockets is always NULL,
which caused a wrong code path to be chosen in conn_check_send().

We have to update the if-expression accordingly.

Maniphest Tasks: T7442
Differential Revision: https://phabricator.freedesktop.org/D1017

8 years agoagent: ignore gathering failures on auto-generated IPs
Olivier Crête [Fri, 27 May 2016 15:29:22 +0000 (11:29 -0400)]
agent: ignore gathering failures on auto-generated IPs

Candidate gathering is stopped when discovery_add_local_host_candidate()
returns HOST_CANDIDATE_CANT_CREATE_SOCKET. This may be too radical
a measure when other local addresses can still be able to generate
usable candidates.

The issue was observed by a user who had an IPv6 address with tentative
flag on one of the interfaces. That single failing address was causing
the whole gathering process to end with no candidates found.

Still, don't do this if nice_agent_add_local_address() has been called.
In that case, the user really cares about the addresses and if there's
any problem, the process should fail.

https://phabricator.freedesktop.org/D1016

8 years agocandidate: Give lower priority to TCP relayed candidates
Olivier Crête [Tue, 1 Mar 2016 20:27:46 +0000 (15:27 -0500)]
candidate: Give lower priority to TCP relayed candidates

8 years agoudp-turn: Fix binding timeout leak
Olivier Crête [Mon, 29 Feb 2016 21:11:18 +0000 (16:11 -0500)]
udp-turn: Fix binding timeout leak

8 years agoconncheck: Update selected pair if necessary
Olivier Crête [Thu, 25 Feb 2016 03:53:08 +0000 (22:53 -0500)]
conncheck: Update selected pair if necessary

8 years agoconncheck: Don't reset keepalive timer on next keepalive
Olivier Crête [Tue, 23 Feb 2016 00:36:58 +0000 (19:36 -0500)]
conncheck: Don't reset keepalive timer on next keepalive

If the keepalive is still being re-send, just let the retries do their
job. If they don't get a reply, then declare the attempt failed.

8 years agoconncheck: Separate valid and succeded states
Olivier Crête [Thu, 26 May 2016 20:05:36 +0000 (16:05 -0400)]
conncheck: Separate valid and succeded states

RFC 5245 specifies that when a mapped-address differs from the address
from the request was sent, the mapped-address is used to select the
valid pair, but the source address of the check is used to select the
pair that succeeded, so they are not the same.

8 years agoudp-turn: Don't expose GSocket
Olivier Crête [Sat, 20 Feb 2016 01:47:08 +0000 (20:47 -0500)]
udp-turn: Don't expose GSocket

UDP turn sockets should never be read frm directly.
Because they may share the same socket with the non-relay,
so the incoming data may not be relayed and then the NiceSocket
API doesn't allow returning the base socket as the source.

8 years agoconncheck: Make very frequent debug verbose-only
Olivier Crête [Thu, 18 Feb 2016 19:20:52 +0000 (14:20 -0500)]
conncheck: Make very frequent debug verbose-only

8 years agodebug: Enable based on G_MESSAGES_DEBUG
Olivier Crête [Tue, 16 Feb 2016 00:09:58 +0000 (19:09 -0500)]
debug: Enable based on G_MESSAGES_DEBUG

8 years agoagent: Don't emit signal in the middle of recv call
Olivier Crête [Fri, 12 Feb 2016 06:01:37 +0000 (01:01 -0500)]
agent: Don't emit signal in the middle of recv call

8 years agoagent: Update type of peer-reflexive candidate on trickled candidate
Olivier Crête [Thu, 11 Feb 2016 00:38:52 +0000 (19:38 -0500)]
agent: Update type of peer-reflexive candidate on trickled candidate

If a remote candidate matches an already discovered peer-reflexive candidate,
then the type can be updated to the real type and the foundation
can be set correctly.

8 years agoagent: Only try to use the address of the same family to connect to TURN
Olivier Crête [Tue, 9 Feb 2016 17:52:45 +0000 (12:52 -0500)]
agent: Only try to use the address of the same family to connect to TURN

Using a IPv6 local address to connect to a IPv4 relay just creates an
extra discovery attempt that will not provide something useful.

8 years agostun turn usage: Only send the username if short term creds or nonce present
Olivier Crête [Mon, 8 Feb 2016 00:48:07 +0000 (19:48 -0500)]
stun turn usage: Only send the username if short term creds or nonce present

This is recommended by the STUN RFC 5389.

8 years agoturn: Cache the nonce & realm to remove useless round trips
Olivier Crête [Mon, 8 Feb 2016 00:41:52 +0000 (19:41 -0500)]
turn: Cache the nonce & realm to remove useless round trips

Instead of re-discovering the nonce and realm for every request, cache them
in th socket.

8 years agoconncheck: Stay READY if a new nominated pairs comes in
Olivier Crête [Tue, 9 Feb 2016 16:18:30 +0000 (11:18 -0500)]
conncheck: Stay READY if a new nominated pairs comes in

8 years agoconncheck: Deduplicate conncheck stopping code
Olivier Crête [Tue, 9 Feb 2016 02:04:24 +0000 (21:04 -0500)]
conncheck: Deduplicate conncheck stopping code

8 years agoReset to connecting if reconnected after failed
Olivier Crête [Tue, 9 Feb 2016 00:41:28 +0000 (19:41 -0500)]
Reset to connecting if reconnected after failed

8 years agoagent: Add warning on ignored result
Olivier Crête [Thu, 14 Jan 2016 22:59:16 +0000 (17:59 -0500)]
agent: Add warning on ignored result

8 years agoconncheck: display controlling mode of stun requests
Fabrice Bellet [Mon, 4 Apr 2016 22:02:52 +0000 (23:02 +0100)]
conncheck: display controlling mode of stun requests

This patch makes the debug log more explicit about the agent
controlling role for each stun request sent. It helps to debug
role conflict resolution.

Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D877

8 years agoagent: remove newline from debug output
Fabrice Bellet [Mon, 4 Apr 2016 21:38:07 +0000 (22:38 +0100)]
agent: remove newline from debug output

Just a cosmetic fix.

Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D872

8 years agosocket: refactor nice_socket_is_base_of()
Jakub Adam [Mon, 4 Apr 2016 20:52:29 +0000 (21:52 +0100)]
socket: refactor nice_socket_is_base_of()

• rename to nice_socket_is_based_on() and swap the order of arguments
   accordingly; the implementation doesn't have to use the confusing
   'return other->is_base_of()' pattern anymore
 • fix potential NULL dereferences

The argument order in agent_recv_message_unlocked() was already wrongly
swapped in 1732c7d6 and thus this commit isn't changing it back because
that order has become the correct one.

Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D866

8 years agosocket: fix wrong function called in nice_socket_is_base_of()
Jakub Adam [Mon, 4 Apr 2016 20:46:05 +0000 (21:46 +0100)]
socket: fix wrong function called in nice_socket_is_base_of()

We have to call is_base_of "virtual function pointer" of 'other'
object, not 'sock', since 'other' is the structure whose base
NiceSocket we need to get from its private data.

For instance calling nice_socket_is_base_of() with 'sock' and 'other'
being respectively pseudo-SSL and UDP-TURN-over-TCP invoked is_base_of
variant for pseudo-SSL, casting other->priv into PseudoSSLPriv *, but
other->priv is actually TurnTcpPriv *. It must be called the other way
around.

https://phabricator.freedesktop.org/T7335
https://phabricator.freedesktop.org/T7336

Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Reviewed-by: José Antonio Santos Cadenas <santoscadenas@gmail.com>
Reviewed-by: Philip Withnall <philip@tecnocode.co.uk>
Reviewed-by: José Antonio Santos Cadenas <santoscadenas@gmail.com>
Differential Revision: https://phabricator.freedesktop.org/D785

8 years agoconncheck: implement a "triggered queue" list
Fabrice Bellet [Mon, 4 Apr 2016 20:38:59 +0000 (21:38 +0100)]
conncheck: implement a "triggered queue" list

The checks should not be sent immediately in priv_conn_check_initiate(),
but be put into the "triggered queue", see  "7.2.1.4 Triggered Checks".
This patch implements this triggered checks list, and uses it to enforce a
pacing of STUN transactions, no more than one per Ta ms, according to
"B.1. Pacing of STUN Transactions".

Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Reviewed-by: Philip Withnall <philip@tecnocode.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D802

8 years agoagent: Fix argument order
Olivier Crête [Sun, 6 Mar 2016 20:16:18 +0000 (15:16 -0500)]
agent: Fix argument order

Fixes crash reported on https://phabricator.freedesktop.org/D786

8 years agoice: fix the debug of the presence of the controlling/controlled attrib
Fabrice Bellet [Sat, 5 Mar 2016 18:46:48 +0000 (18:46 +0000)]
ice: fix the debug of the presence of the controlling/controlled attrib

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

8 years agoagent: fix relay candidate discovery on hosts having several IPs
Jakub Adam [Wed, 2 Mar 2016 00:01:19 +0000 (00:01 +0000)]
agent: fix relay candidate discovery on hosts having several IPs

When a message is received from a TURN server and we manage to find a
local relay candidate with matching stream and component IDs, we should
also check whether the message came from the candidate's respective
socket.

We should do this because there might still be some pending TURN
candidate discovery with the same server from a different local host IP
and the message may be a response to our allocate request. If
nice_udp_turn_socket_parse_recv_message() is passed such request, it can
make some wrong assumptions and modify it like in the case of reliable
UDP-TURN-OVER-TCP by removing (supposed) RFC4571 framing, which in turn
causes the reply to be unrecognized and discarded.

Because of this, any subsequent replies following the first successful
allocate response from that server couldn't create any additional relay
candidates.

Maniphest Tasks: https://phabricator.freedesktop.org/T7336

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

8 years agobuild: Update autogen.sh from GNOME template
Philip Withnall [Tue, 1 Mar 2016 23:50:11 +0000 (23:50 +0000)]
build: Update autogen.sh from GNOME template

https://wiki.gnome.org/Projects/GnomeCommon/Migration#autogen.sh

8 years agocomponent.c: Fix memory leak
Olivier Crête [Tue, 1 Mar 2016 23:29:10 +0000 (23:29 +0000)]
component.c: Fix memory leak

If nicesocket is not added to a component it will be leaked.

This is the case of active tcp sockets

Change-Id: I57fefffef71d35ce9871139ee1064181f6fe125b
Reviewed-by: José Antonio Santos Cadenas <santoscadenas@gmail.com>
Differential Revision: https://phabricator.freedesktop.org/D822

8 years agoagent: Use provided CandidatePair rather than re-finding a pair
Philip Withnall [Tue, 1 Mar 2016 23:23:14 +0000 (23:23 +0000)]
agent: Use provided CandidatePair rather than re-finding a pair

In priv_update_selected_pair(), commit 57393333 changed the code to
re-find a CandidatePair matching the given lfoundation and rfoundation.
However, the foundation does not uniquely identify candidate pairs,
and if we’re aiming to set a specific candidate pair as the selected
pair, this could result in the wrong pair being selected.

This can happen when handling multiple similar candidate pairs, such as
when generating peer reflexive candidates from multiple sources.

See https://tools.ietf.org/html/rfc5245#section-2.4.

Originally spotted by Fabrice Bellet in
https://phabricator.freedesktop.org/T3557.

Reviewed-by: José Antonio Santos Cadenas <santoscadenas@gmail.com>
Differential Revision: https://phabricator.freedesktop.org/D742

8 years agosimple-example: transmission can begin earlier than in ready state
Philip Withnall [Tue, 1 Mar 2016 23:05:20 +0000 (23:05 +0000)]
simple-example: transmission can begin earlier than in ready state

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

8 years agotest-new-dribble: wait until ragent reaches state completed
Philip Withnall [Tue, 1 Mar 2016 23:04:14 +0000 (23:04 +0000)]
test-new-dribble: wait until ragent reaches state completed

The test didn't let enough time for ragent to reach the completed state
after obtaining its remote candidates and switching to connecting state.

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

8 years agoconncheck: reorder the connection list when priorities are updated
Philip Withnall [Tue, 1 Mar 2016 23:02:52 +0000 (23:02 +0000)]
conncheck: reorder the connection list when priorities are updated

The update of pairs priorities due to agent role change requires the
conncheck list to be reordered to reflect this modification.

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

8 years agoconncheck: fix keepalive stun agent initialisation
Philip Withnall [Tue, 1 Mar 2016 23:01:14 +0000 (23:01 +0000)]
conncheck: fix keepalive stun agent initialisation

With this patch, we send keepalive binding requests using agent
compatibility flags, instead of RFC 3489 classic stun. The peer stun
agent will known how to handle it, and won't be confused by the
uncompatible RFC 3489 message, causing "no cookie" errors in the debug
log.

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

8 years agoconncheck: foundations are shared across streams
Philip Withnall [Tue, 1 Mar 2016 22:58:15 +0000 (22:58 +0000)]
conncheck: foundations are shared across streams

This patch fixes a bug where the foundation definition shouldn't take
into account the stream the pair belongs to. This is important, because
the ordinary checks algorithm will change pair state from Frozen to
Waiting, by selecting pairs from other streams sharing the same
foundation than already succeeded pairs.

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

8 years agotest-priority: ignore the local preference
Philip Withnall [Tue, 1 Mar 2016 22:37:33 +0000 (22:37 +0000)]
test-priority: ignore the local preference

The local preference depends on the rank of the IP address in the list
of all IP addresses available of the box running the test. As this value
is not fixed we ignore it in the test.

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

8 years agoconncheck: nominate only one matching pair
Philip Withnall [Tue, 1 Mar 2016 22:33:51 +0000 (22:33 +0000)]
conncheck: nominate only one matching pair

This patch fixes a bug in priv_mark_pair_nominated(), where the local
candidate was not passed to the function, so removing the possibility to
find which local candidate the check was sent to.

Reviewed-by: Philip Withnall <philip@tecnocode.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D808

8 years agoconncheck: add more debug information
Philip Withnall [Tue, 1 Mar 2016 22:28:35 +0000 (22:28 +0000)]
conncheck: add more debug information

Add a more debug details, specifically in some places, it is interesting
to have the src and dst IP addresses of the pairs being checked, and
also to make the difference between log related to different stream ids.

Reviewed-by: Philip Withnall <philip@tecnocode.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D803

8 years agoagent: Fix not setting UPnP timeout on second gather_candidates()
Mike Ruprecht [Mon, 18 Jan 2016 12:42:46 +0000 (12:42 +0000)]
agent: Fix not setting UPnP timeout on second gather_candidates()

If the first call to nice_agent_gather_candidates() partially succeeds
(setting a UPnP agent and timeout), then fails before starting
gathering, a second call to nice_agent_gather_candidates() would fail to
set a new UPnP timeout because the UPnP initialisation block would be
skipped. That means gathering would never succeed due to timing out on
UPnP.

Fix that by setting the UPnP timeout whenever a new pending UPnP mapping
is added.

https://phabricator.freedesktop.org/T3534

Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
8 years agoconfigure.ac: Update glib version
Jose Antonio Santos Cadenas [Thu, 3 Dec 2015 14:01:35 +0000 (15:01 +0100)]
configure.ac: Update glib version

As udp-bsd.ccode is using G_IO_ERROR_CONNECTION_CLOSED glib 2.44
is required.

Change-Id: I1bb63f2484c513c58eeec312ba0835164604c40c
Reviewed-by: Philip Withnall <philip@tecnocode.co.uk>
https://phabricator.freedesktop.org/T3492

8 years agopseudotcp: Use labs() rather than abs() for handling long integers
Philip Withnall [Wed, 7 Oct 2015 18:03:58 +0000 (19:03 +0100)]
pseudotcp: Use labs() rather than abs() for handling long integers

This fixes a compiler warning and prevents a possible truncation.

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

8 years agotests: Enable G_MESSAGES_DEBUG for all unit tests
Philip Withnall [Mon, 22 Jun 2015 10:30:31 +0000 (11:30 +0100)]
tests: Enable G_MESSAGES_DEBUG for all unit tests

Now that we’re using automake’s parallel test harness, it automatically
redirects all the debug log spew away from the console, so we should
always have it enabled.

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

8 years agobuild: Set repository callsign in .arcconfig
Philip Withnall [Thu, 1 Oct 2015 16:52:08 +0000 (17:52 +0100)]
build: Set repository callsign in .arcconfig

This fixes `arc diff` to select the right repository when submitting
patches.

8 years agoagent: Correctly namespace Component and its methods
Philip Withnall [Wed, 30 Sep 2015 13:57:10 +0000 (14:57 +0100)]
agent: Correctly namespace Component and its methods

Remove all references to the old, unnamespaced versions. This should
cause no functional changes.

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

8 years agoagent: Correctly namespace Stream and its methods
Philip Withnall [Wed, 30 Sep 2015 13:34:34 +0000 (14:34 +0100)]
agent: Correctly namespace Stream and its methods

Remove all references to the old, unnamespaced versions. This should
cause no functional changes.

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

8 years agoagent: Turn Component into a GObject
Philip Withnall [Wed, 30 Sep 2015 13:11:14 +0000 (14:11 +0100)]
agent: Turn Component into a GObject

This makes it reference-counted. This will be useful for allowing
GDatagramBased and GIOStream objects to hold references to the stream
and component they are interested in, allowing removal of the global
NiceAgent lock previously needed to look up the component for every I/O
operation.

Deprecate all the old methods until it’s properly namespaced.

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

8 years agoagent: Turn Stream into a GObject
Philip Withnall [Wed, 30 Sep 2015 13:10:32 +0000 (14:10 +0100)]
agent: Turn Stream into a GObject

This makes it reference-counted. This will be useful for allowing
GDatagramBased and GIOStream objects to hold references to the stream
and component they are interested in, allowing removal of the global
NiceAgent lock previously needed to look up the component for every I/O
operation.

It also means that nice_stream_close() could eventually become
asynchronous, which would fix a few race conditions.

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

8 years agotests: Update expected priority values in test-priority
Philip Withnall [Wed, 30 Sep 2015 16:59:04 +0000 (17:59 +0100)]
tests: Update expected priority values in test-priority

This is a follow up to T3324, to update the test case to match the new
values generated.

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

8 years agotests: Use g_assert_cmpuint() to make test failures easier to diagnose
Philip Withnall [Wed, 30 Sep 2015 16:54:21 +0000 (17:54 +0100)]
tests: Use g_assert_cmpuint() to make test failures easier to diagnose

Now we can actually see the priority numbers which are unequal.

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

8 years agotests: Set candidate addresses in test-priority
Philip Withnall [Wed, 30 Sep 2015 16:53:14 +0000 (17:53 +0100)]
tests: Set candidate addresses in test-priority

This avoids an assertion failure in nice_address_to_string() when the
addresses are compared for priority.

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

8 years agoagent: Remove redundant GLIB_CHECK_VERSION macros
Philip Withnall [Wed, 30 Sep 2015 16:46:47 +0000 (17:46 +0100)]
agent: Remove redundant GLIB_CHECK_VERSION macros

We depend on GLib 2.36.0, which is a higher version than any of these
version checks cared about, so they were all trivially true or false.

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

8 years agotests: Remove g_thread_init() calls
Philip Withnall [Wed, 30 Sep 2015 16:44:44 +0000 (17:44 +0100)]
tests: Remove g_thread_init() calls

We depend on GLib 2.36.0; g_thread_init() has been deprecated since
2.32.0, when thread initialisation was changed to happen automatically.

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

8 years agotests: Remove g_type_init() calls
Philip Withnall [Wed, 30 Sep 2015 16:41:36 +0000 (17:41 +0100)]
tests: Remove g_type_init() calls

We depend on GLib 2.36.0, which deprecated g_type_init() since GType
initialisation is now done automatically.

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

8 years agoconncheck: rename priv_process_response_check_for_peer_reflexive()
Jakub Adam [Fri, 11 Sep 2015 10:57:54 +0000 (11:57 +0100)]
conncheck: rename priv_process_response_check_for_peer_reflexive()

Renamed the function to priv_process_response_check_for_reflexive()
because it now checks also for server reflexive candidates.

Updated the documentation to indicate that the function never returns
NULL.

Maniphest Tasks: https://phabricator.freedesktop.org/T115
Differential Revision: https://phabricator.freedesktop.org/D243
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
8 years agoconncheck: generate candidate pair for valid srflx candidate
Jakub Adam [Fri, 11 Sep 2015 10:56:02 +0000 (11:56 +0100)]
conncheck: generate candidate pair for valid srflx candidate

In priv_process_response_check_for_peer_reflexive(), mere presence of a candidate in local_candidates doesn't mean there's also some candidate
pair in conncheck_list using it - for instance that candidate may be server reflexive, for which no check pairs are initially created (see
conn_check_add_for_candidate_pair()).

If we fail to find corresponding pair upon receiving such candidate's IP in a conncheck response's XOR-MAPPED-ADDRESS attribute, we shall add a
new one in a similar way we would add a new pair for a just discovered peer reflexive candidate.

Previous priv_process_response_check_for_peer_reflexive() implementation would return NULL, causing a CandidateCheckPair with local candidate of
type HOST to be wrongly selected even though the local host IP might not be directly accessible by the remote counterpart (e.g. it's an address
on a private network segment). In practice this was coming through as a duplex connection that libnice was reporting as properly established,
but only one direction of the communication was actually working.

Maniphest Tasks: https://phabricator.freedesktop.org/T115
Differential Revision: https://phabricator.freedesktop.org/D242
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
8 years agoagent: check for base socket in _tcp_sock_is_writable()
Jakub Adam [Fri, 11 Sep 2015 10:33:51 +0000 (11:33 +0100)]
agent: check for base socket in _tcp_sock_is_writable()

The argument passed into the callback is always a base (TCP/UDP) socket,
which can't be directly compared with local candidate's sockptr (may be
TURN, http, or other socket wrapping another one). We're in fact
interested whether sock is a base socket of sockptr.

Maniphest Tasks: T114
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D241

8 years agosocket: add nice_socket_is_base_of()
Jakub Adam [Fri, 11 Sep 2015 10:29:39 +0000 (11:29 +0100)]
socket: add nice_socket_is_base_of()

This will be used in the next commit.

Maniphest Tasks: T114
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D240

8 years agobuild: Bump GLib dependency to 2.36
Philip Withnall [Thu, 10 Jul 2014 07:32:04 +0000 (08:32 +0100)]
build: Bump GLib dependency to 2.36

This is needed for G_IO_ERROR_BROKEN_PIPE, which is used in the I/O
stream code.

Reported by Emanuele Bizzarri <emabiz76@gmail.com> on the mailing list.

8 years agostun: Disable debug by default
Philip Withnall [Fri, 4 Sep 2015 07:14:08 +0000 (08:14 +0100)]
stun: Disable debug by default

To match debug_enable in agent/debug.c. Debug can still be enabled by
calling stun_debug_enable() or nice_debug_enable().

Spotted on the mailing list by Tom Chen.

8 years agoagent: Add assertions to check component state transitions are valid
Philip Withnall [Mon, 29 Jun 2015 15:30:12 +0000 (16:30 +0100)]
agent: Add assertions to check component state transitions are valid

There is no point in the NiceComponents having a state machine if the
state transition graph is not documented or enforced. Document and
enforce it.

http://phabricator.freedesktop.org/T120

8 years agoms-ice: ensure distinct candidate priority for multihomed hosts
Philip Withnall [Wed, 2 Sep 2015 15:44:45 +0000 (16:44 +0100)]
ms-ice: ensure distinct candidate priority for multihomed hosts

Summary:
Offering multiple host candidates with equal priorities could lead to unpredictable candidate pair selection by our counterparty.

Fixes call disconnection by MS Lync client after 30 seconds while VPN (2nd IP) was active on libnice host.

Maniphest Tasks: T3324

Reviewers: pwithnall

Projects: #libnice

Reviewed By: pwithnall

Subscribers: pwithnall

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