Today, all relay candidates from Pion have the same priority.
This PR attempts to reproduce libwebrtc's behavior, where the
TURN servers candidates priority is based on the underlying
relay protocol. UDP are preferred over TCP, which are preferred
over the TLS options.
Relay candidates have an additional field "relayProtocol"
which is not marshaled and hence not copied by the
candidateBase's copy() method.
This change is required to properly expose the relay
protocol for via the agents GetSelectedCandidatePair()
function as it internally copies the candidates.
The webrtc-stats spec defines this field as:
> It is the protocol used by the endpoint to communicate with the TURN
> server. This is only present for local candidates. Valid values are
> "udp", "tcp", or "tls".
https://w3.org/TR/webrtc-stats/#dom-rtcicecandidatestats-relayprotocol
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
This implementation is not fully tested, and we don't
handle all error case yet. We will continue to work on it though.
Tests for send/recv and shutdown are in the works.
Relates to #47
This change will allow us to have custom logic and members
per interface type. Relay candidates will have a completely different
read loop, and candidate specific state.
Relates to #47