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
Related
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.
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.
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.
How to make use of IceConnectionState and IceGatheringState while sending the icecandiates to the peer in webrtc ?
ice gathering is the generation of the local candidates you will send to the remote peer either in the offer sdp (full ICE) or separately (trickle ICE).
ice gathering state is the state of the connection with the remote peer based on your trying of the remote candidates received through your chosen signaling method.
The ice gathering state is not so important, as the application logic does not care usually about those (the application might monitor the candidates and know if the gathering is done when a null candidate surfaces), the ice connection states are VERY important to know if a connection was established and your application should focus on that. The peer connection state can be stable, and all the handshake done, without media flowing if the ICE connection state is failed.
WebRTC DataChannels use SCTP. Looking at the graph of bits received from chrome://webrtc-internals, there is a regular sending of a small amount of data. Is this the SCTP heartbeat?
From what I understand, this is the ICE heartbeat.
I am just elaborating Sam's answer.
WebRTC DataChannel uses Stream Control Transport Protocol (SCTP) for sending
and receiving arbitrary data. Since, WebRTC requires that all WebRTC traffic be
encrypted, DTLS is used. However, most routers and NAT devices don't handle this
protocol well. Hence, SCTP is tunneled over DTLS and UDP. Now, even when two
peers are exchanging arbitrary data, it is happening over UDP. Hence, I too
believe that it is not a SCTP heartbeat.
As you might know, RTCPeerConnection uses ICE for resolving connectivity issues between
peers. ICE uses STUN keep-alives to check the connectivity status between
the peers. Currently, I believe chrome sends out STUN Binding Request every 450 ms to perform connectivity checks, but there is an ongoing discussion on extending that time interval.