Forcing the use of the Host ICE Candidate in WebRTC - webrtc

Is anyone aware of a way I could force WebRTC to only try ICE connection establishment via the host candidate?
Right now, I'm looking at non-intrusive ways, such as filtering outgoing traffic to block STUN/TURN servers during ICE candidate gathering. However, this is causing the gathering process to take quite long as this particular stack does not support trickle ICE. If I can do this with only a network change, that would be ideal (whereby any device behind this network must use the host candidate).
Without trickle ICE, I'm wondering if there is a way to filter out the STUN/TURN addresses while also setting the ICE candidate gathering timeout to a low value. This would cause STUN/TURN candidates to be put into a 'Failed' state, and then only the host candidate would inevitable be sent over.

Related

How to log/view ICE connectivity check messages in Chrome for WebRTC application?

My understanding:
In WebRTC, SDP is used to relay ice candidates to remote peers after they are gathered by the local peer. The connectivity checks thereafter are performed using STUN binding requests. I can log the SDP received/sent using Javascript but these are merely ICE candidates.
Question:
How do I log or view the ICE connectivity check (STUN, RFC 5389) messages in Chrome? I understand that I can install Wireshark or some such tool to log all network traffic but I think there must be a better direct way to do this.
One way is to visit chrome://webrtc-internals and click "Download the PeerConnection updates and stats data" Button.
There isn't a way you can get the STUN packets directly, but you can somewhat monitor what is going on via the getStats API!
RTCIceCandidatePairStats you have requestsReceived and requestsSent so you can figure out some stuff from that.
I don't think we will ever get an API to actually get the packets though.

Query on Signalling and STUN/TURN flow

If a client is behind NAT, when does STUN/TURN come into play?
1. After Peer connection object is created?
2. After setting local SDPs and sending it to the other client?
3. Before sending ice candidates?
(2) -- setting the local description causes the ice process to kick off and that process includes gathering srflx candidates from the stun server and relay candidates from the turn server.
It is possible to kick this off at the peerconnection creation -- see iceCandidatePoolsize in the specification.
This sample page illustrates the process.

Establishing WebRTC peer connection

I have started to look into WebRTC a bit and I am using it to build a simple peer to peer chat application using the data channel. I have the following questions:
Do I need to establish a RTCPeerConnection to each peer I want to talk to? So if there are three peers they each need 2 RTCPeerConnections (unless I use one of the peers as a sort of ad-hoc server).
If peer A sends out a candidate and sdp when creating a offer to peer B. Can peer B connect to peer A using that info and send its answer (with candidate and its sdp) over the RTCPeerConnection, i.e. using the RTCPeerConnection (before it's been completely established) as a signaling channel? I would assume that when the offer is created by peer A it starts to listen for connections on some port.
My understanding of WebRTC is a bit limited so if I've missunderstood some concept of WebRTC in my questions above please point them out!
Yes, as a direct P2P protocol everybody must be directly connected to everybody else if they want to communicate; unless you create some kind of mesh network in which one peer forwards messages to other peers.
No, the SDP offer and answer and ICE candidates all need to be exchanged through a signalling server; the connection cannot be established until both peers have actually agreed on a specific session configuration and ICE route to use, so you cannot send the SDP answer over a connection which isn't complete yet.
Especially for a simple text-only chat, going through a server is often easier than using P2P; the processing and bandwidth requirements are so minimal that the complications of P2P connections are probably not worth it. And you need a signalling server anyway. P2P only becomes really interesting once you start sending large files or audio/video streams.
In principle it is possible to establish a WebRTC connection without a signalling server, but that requires an out of band exchange of session tokens between the peers. I.e. the user would have to copy a token from the application, somehow send it to another user and the other user would have to paste it.
Additionally those tokens cannot be reused, so this procedure would have to be repeated every time peers want to establish a connection.
So while theoretically possible webrtc is not distributed in practical terms.
There is some noise about specifying support for incoming connections and reusable peer contacts, but the progress on that is unclear.

What are the reasons of ICE failure?

What are the possible reasons of ICE failure ?
I am particularly interested in the case of failure- when all remote candidates are added( with relay candidates ), remote offer/answer SDP set.
One of the reasons of P2P connection failure between two peers is that peer failed in gathering the suitable ice candidates and this is what we called "ICE failure"
So if you mean by ICE failure that the client application not able to get the suitable ice candidates from the ice server so that could happen for many reasons. For Example:
ICE server down
P2P connections blocked by Firewall
Symmetric NAT which does not reuse session address binding. This results some NAT Traversal techniques failing in traverse packets through NAT devices

What are common UDP usecases?

Can anyone tell be where to use the UDP protocol except live streaming of music/video? What are default usecases for UDP?
UDP is also good for broadcast, such as service discovery - finding that newly plugged in printer.
Also of note is that broadcast is anonymous, you don't need to specify target hosts, as such it can form the foundation of a convenient plug-and-play or high-availability network.
UDP is stateless and is good for applications that have large numbers of clients connecting to a server such as time servers or DNS. The fact that no connection has to established and maintained reduces the memory required by the server. There is no handshaking involved and so this reduces the traffic on the network. On the downside, if the information transferred requires multiple packets there is no transmission control to ensure that all packets arrive and in the correct order - but in games packets lost are probably better than late or disordered.
Anything else where you need performance but can survive if a packet gets lost along the way. Multiplayer games come to mind, for example.
A very common use case is DNS, since the overhead of creating a TCP connection would by far outweight the actual payload.
Additional use cases are NTP (network time service) and most video games.
I use UDP to add chat capabilities to our applications. No need to create a server. It is also useful to dispatch events to all users of our applications.