Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share one UDP socket with all UDP candidates #76

Open
enobufs opened this issue Jul 7, 2019 · 4 comments
Open

Share one UDP socket with all UDP candidates #76

enobufs opened this issue Jul 7, 2019 · 4 comments
Labels
mux UDP and TCP Mux related issues

Comments

@enobufs
Copy link
Member

enobufs commented Jul 7, 2019

Your environment.

  • Version: v0.4.3
  • Browser: n/a

What did you do?

During the work of #46, I noticed that a UDP socket was created for each 3 types of initial candidates, host, srflx and relay.

What did you expect?

All candidates (in the same address family) should share the base UDP socket (used for host candidate)

Current socket allocation:

 (udp soc 1) --------------- host candidate (192.168.1.2:5000)
 (udp soc 2) --------------- srflx candidate (27.1.1.1:49152 related 192.168.1.2:5001)
 (udp soc 3) --------------- relay candidate (1.2.3.4:5678 related 192.168.1.2:5002)

25 candidate pairs (or pings per period)

soc1 and 3 would create NAT binding, and these could be detected as prflx candidates.

Ideal socket allocation:

 (udp soc 1) -------+------- host candidate (192.168.1.2:5000)
                    +------- srflx candidate (27.1.1.1:49152 related 192.168.1.2:5000)
                    +------- relay candidate (1.2.3.4:5678 related 192.168.1.2:5000)

9 candidate pairs (or pings per period)

What happened?

  • Wasteful socket resource usage
  • Wasteful pings (connectivity checks)
  • Debug is hard.
@enobufs
Copy link
Member Author

enobufs commented Jul 8, 2019

Incoming packages should be demux/parsed like this:

Screen Shot 2019-07-08 at 12 43 56 AM

@enobufs
Copy link
Member Author

enobufs commented Jul 8, 2019

In order to make this possible, we will need to modify pion/stun and pion/turnc to use net.UDPConn which is not bound to a specific remote address, meaning, we should use net.ListenPacket(or net.ListenUDP). NOT net.DialUDP! (it creates a "connected" udp socket!)

Here's a demo

@enobufs
Copy link
Member Author

enobufs commented Jul 15, 2019

The new TURN Client (in pion/turn) is almost ready. (see pion/turn#75).

The new client will allow achieving what this PR is aiming for, but let's do it after pion/webrtc#712 successfully lands. (This does not strictly affect connectivity)

Here's what we need to do...
Since currently, all Candidate (concrete) classes share the parent (or embedded in a go's sense) struct, candidateBase which invokes a read-loop (goroutine) on start() - this needs to be changed.

Here's my plan:

  • Create a candidateBase per local IP address
  • candidataBase also has an instance of turn.Client.
  • Let candidateBase creates actuall candidates such as CandidateHost, CandidateServerReflexive, etc. In another word, candidataBase works as a "candidate factory". For instance, candidateBase would have these methods:
    • createCandidateHost()
    • createCandidateSrflx()
    • createCandidatePrflx()
    • createCandidateRelay()
  • When createCandidateRelay() is called, candidateBase also allocates a relay port on the TURN server.

@enobufs
Copy link
Member Author

enobufs commented Aug 30, 2019

At this point, we will have a proper STUN transaction (and with retransmits) with STUN server, as well as connectivity checking all done by the new turn.Client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mux UDP and TCP Mux related issues
Development

No branches or pull requests

2 participants