Commit Graph

107 Commits

Author SHA1 Message Date
Kyle Carberry
427ac0fddb Fix goroutine leak for closing while gathering
The "gatherCandidates()" function could previously leak after
close, because the WaitGroup was left unchecked.
2022-03-01 19:53:05 -05:00
Mikhail Bragin
2d70ec8e3c Support UDP muxing for SRFLX candidates
The original UDPMux only works for the HOST candidates.
UniversalUDPMux adds support for SRFLX candidates
and will later support Relay candidates.
UniversalUDPMux embeds UDPMuxDefault and
handles STUN server packets to discover XORMappedAddr
forwarding the remaining packets for muxing to UDPMuxDefault.
2022-02-20 12:29:29 -08:00
Kyle Carberry
b9fa7ab3e6 Fix goroutine leak after close
It was possible for the Close() function to exit without all goroutines
existing. By closing these channels before the after function, all
goroutines are forced to exit before.
2022-01-30 22:12:27 -05:00
Sean DuBois
d3a5bf5488 Clean ufrag from UDP/TCP Mux during ICERestart
TCP/UDP Mux would have old entries of closed PacketConns from restarted
ICE Agents. Move cleanup code from Closing the ICE Agent into a shared
function and also call it during Restart.
2022-01-23 23:09:16 -05:00
Kyle Carberry
444e6c46fb Fix race condition when closing agent after gather
A data race would occur where the context cancel would
be called and overwritten at the same time.
2022-01-23 23:07:33 -05:00
hn8
161b670ac4 Fix duplicate TCP candidates
Duplicate TCP candidates share the same candidateConn,
which would be closed if started before checking.
2021-07-23 10:53:16 -04:00
David Zhao
86d69d6ce5 Single port handling via UDPMux
Allows for ICE to handle connections on a single UDP port
2021-04-12 20:42:10 -07:00
Sean DuBois
6e4403794a Implement GetSelectedCandidatePair
Related to pion/webrtc#1713
2021-04-10 16:52:52 -07:00
ZHENK
7c897626c1 Accept nil Candidate in AddRemoteCandidate
Allow a user to pass a nil Candidate. We perform no actions off of this
currently. Until browsers implement end-of-candidates consistently it
isn't something we can do.

Relates to pion/webrtc#1212 and #271
2020-12-08 20:50:37 -08:00
Sean DuBois
302290a784 Use candidate context in validateNonSTUNTraffic
This operation needs to be cancelled when the candidate is closed.
Before it was only cancelled when the Agent was closed.

Resolves #299
2020-11-16 11:59:06 -08:00
Assad Obaid
64a2cf0c47 Add proxy dialer interface
Enable user to implement the golang.org/x/net/proxy
dialer interface in order to have a customized dialer.
The customized dialer could be one that connect through
a corporate HTTP/HTTPS proxy.

Resolves #284
2020-10-09 12:09:21 -07:00
Pion
d3e1775d73 Update CI configs to v0.4.7
Update lint scripts and CI configs.
2020-09-26 08:54:24 -07:00
JooYoung
435c65f61d Update checkKeepalive to also check LastReceived
Ping Candidate if remote.LastReceived is over
than keepaliveInterval
2020-08-27 19:14:09 -07:00
Sidney San Martín
71ac5557ab Don't leak goroutines via mDNS queries
mDNSConn.Query() will block indefinitely until something replies. Much
of the time, nothing will, and the goroutines making these queries will
block forever. By passing the CandidateHost's context, the queries will
at least be cancelled when the host disconnects.
2020-08-15 21:55:22 -07:00
Jerko Steiner
3b9a989177 Remove global state for ICE TCP
This addresses a few points issue of #245:

 - Take a net.Listener instead of having global state
 - Expose a net.TCPMux based API

Also, the unused closeChannel was removed from tcp_mux.go

Closes #253.
2020-08-01 09:28:28 +02:00
Jerko Steiner
12f44e93f1 Add support for passive ICE TCP candidate
Closes #196
2020-07-15 07:51:55 +02:00
Sean DuBois
ac027bafb5 Remove CandidateSelectionTimeout
The code that uses this field was removed in
e264665676 but the field
wasn't properly removed from the public API.
2020-07-06 00:13:44 -07:00
Atsushi Watanabe
553df099a0 Prevent multiple gathering in parallel
Multiple candidate gathering routine were executed in parallel
when Restart() called immediately after previous start of gathering.
Cancel previous gathering by context to prevent mixing candidates
from two routines.
2020-07-06 14:33:02 +09:00
Sam Lancia
a4a53ab443 Agent: Frequent candidate check when connecting
Previously in the connecting phase, a gathered peer reflexive candidate
which is by default nominated after 500mS, would have to wait 2s
(default taskLoopInterval) before being nominated.
2020-07-05 17:45:01 +09:00
Atsushi Watanabe
77a072692c Fix deadlock in SelectedCandidatePairChange
Call handler in different routine.
2020-07-05 16:05:45 +09:00
Atsushi Watanabe
06922c1601 Refactor agent task runner
- Control blocking tasks by context
- Add tests to check deadlock by calling Close/Restart in
  state change callback
- Remove unnecessary chan
2020-07-05 16:05:45 +09:00
Atsushi Watanabe
84957eb8da Flush state change/candidate callback
After closing the channels.
2020-07-03 23:05:59 -07:00
Sean DuBois
caa80e3027 Don't re-create chanCandidate every gather
Instead keep the channel around the entire time, and use
the same thread to distribute state changes and candidates.

Resolves #217
Resolves #218
2020-07-03 23:05:59 -07:00
Sean DuBois
bd57bd814c Make Credential getters thread safe
GetRemoteUserCredentials and GetLocalUserCredentials were
not thread safe. This puts them both behind a .run
2020-06-29 19:37:25 -07:00
Sean DuBois
bc8f00d8e0 Add GetRemoteUserCredentials
Need by pion/webrtc for ICE Restarts

Relates to pion/webrtc#1251
2020-06-29 08:34:18 -07:00
Atsushi Watanabe
e670416dcc Fix random generators
Seeding random generator each time limits number of generated sequence
to 31-bits, and caused collision.
Use global random generator seeded by crypto grade random.

Use crypto/rand for cryptographic values,
and math/rand for unique identifier.
- Use UUIDv4 for mDNS name
- Use crypto/rand for ICE pwd and user fragment
- Use properly seeded math/rand for UDP port,
  tie breaker and candidate ID
2020-06-28 11:44:46 +09:00
Atsushi Watanabe
d64ae4c32f Pause candidate recvLoop until init
Avoid using uninitialized object on receiving packet.
2020-06-26 11:16:59 -07:00
Atsushi Watanabe
83f76d7b00 Fix startConnectivityChecks multiple run guard
It should use mutex, otherwise it can enter twice before setting
haveStarted to true.
2020-06-25 19:51:30 -07:00
Sean DuBois
3b47033146 Remove non-trickle ICE
pion/webrtc@v3 will be trickle by default, so removing
support from here.  Users can easily simulate non-trickle
by setting a OnICECandidate callback.

This just reduces the amount of things we need to test/worry about.
2020-06-25 00:16:58 -07:00
Sean DuBois
5a7603837b Set defaultKeepaliveInterval to 2 seconds
This should be lower then defaultDisconnectTimeout otherwise
we are going to enter disconnected.

Also rename defaultDisconnectTimeout -> defaultDisconnectedTimeout
to make the tense consistent with other options

Resolves #190
2020-06-25 00:16:58 -07:00
Sean DuBois
5cab987ca4 Add an additional done to Agent.run
Callers of run need to be able to cancel their waiting individually.
This would cause hung threads during restart if we attempted to close
a candidate while processing a packet for it.

Before the run would be canceled by the global close, but we can't
depend on that anymore.

Resolves #190
2020-06-25 00:16:58 -07:00
Sean DuBois
f195edb4c1 Implement SetRemoteCredentials and Restart
Add simple tests that check it works E2E

Resolves #190
2020-06-25 00:16:58 -07:00
Sean DuBois
e264665676 Move Checking -> Failed handling out of Selection
Selection before was written in a way that wouldn't work for restarts.
This moves the code out and makes it stateless. In the future we will be
able to clear the candidates and update the ConnectionState and
everything will restart properly.

Relates to #190
2020-06-25 00:16:58 -07:00
Sean DuBois
330f9098dd Move initExtIPMapping to agent_config
Put all config logic in a dedicated file
2020-06-25 00:16:58 -07:00
Sean DuBois
2180d41780 Move Agent stats to its own file
No changes, just bringing down the size of the Agent
2020-06-25 00:16:58 -07:00
Sean DuBois
2536409ce1 Move AgentConfig to dedicated file
Trying to reduce some complexity from the Agent
2020-06-21 01:06:53 -07:00
Sean DuBois
c97476bb42 Add Failed state to Agent
This is currently fatal because you can't do an restart.

Resolves #189
2020-06-21 01:06:53 -07:00
Sean DuBois
0c308ea365 Rename ConnectionTimeout -> DisconnectTimeout
ICE has two distinct states `Disconnected` and `Failed`. We need to
split out these arguments so that we can control (and test) both.

Relates to #190
2020-06-21 01:06:53 -07:00
Sean DuBois
b1fbbcc01e Don't unset the selected pair on timeout
The selected pair must NEVER be cleared. Instead we
should keep sending connectivity checks on it. If we go to failed the
user will then create a new PeerConnection or do an iceRestart.
In the future we may support nominations, but not standardized yet.

This test asserts that we can move from
Connected -> Disconnected -> Connected

Resolves #186
2020-05-22 22:35:55 -07:00
Ori Bernstein
61849bec47 Make mDNS opportunistic
It seems like mDNS was intended to be opportunistic, but right now,
if creating an mDNS client fails, the whole ICE connection fails.
This allows pion to work in more restricted network namespaces,
or on less supported environments like 9front.

This fixes webwormhole on 9front.
2020-05-13 09:45:58 -07:00
Atsushi Watanabe
88b716cb3b Don't run agent task after close
Fix send on closed channel panic.
2020-05-02 21:56:09 -07:00
Atsushi Watanabe
15a09e3307 Asynchronously add remote candidate
As same as mDNS candidate.
2020-04-04 16:51:42 +09:00
Atsushi Watanabe
e1e28e8a83 Fix asynchronous task processing
Make callback handler atomic/Value.
Launch candidate callback loop in gatherCandidates().
2020-04-04 16:51:42 +09:00
Atsushi Watanabe
6ee96d4632 Fix candidate/state callback order
Call callbacks serially instead of running asynchronously.
2020-04-04 12:10:58 +09:00
Sean DuBois
f1bfc8fea1 Start Agent performance refactor
Remove taskChan and make .run just take an Agent wide mutex and run the
function. These is now a blocking operation so all channels used to
communicate from it must be buffered.

After this we will slowly remove usage of .run and make things more
thread safe.

Relates to #80, #67, #2
2020-03-01 20:25:45 -08:00
Sean DuBois
bf81fb5154 Implement TLS and DTLS Gathering
Also add tests to cover.

Resolves #133
2020-02-24 21:25:32 -08:00
Sean DuBois
50bd9f60bd Close sockets if error during gathering
Add logic that if we hit errors close the socket
we are using that hasn't been moved into a a candidate yet.

Resolves #102
2020-02-23 22:05:13 -08:00
Sean DuBois
cf1f69772b Move Role to dedicated file
Relates to #118
2020-02-23 22:05:13 -08:00
Sean DuBois
086024fde6 Remove addCandidate duplication
Every caller to addCandidate does the same things. Move all this code
into addCandidate.

Relates to #118
2020-02-23 22:05:13 -08:00
Sean DuBois
aa3fe7c6a3 Add error message when no pairs
Add error message if pingAllCandidates is called and we
have no candidate pairs. This may help users when debugging.
2020-02-21 16:45:15 -08:00