Hi Matthew,<div><br></div><div>Thanks for the detailed writeup. My <a href="http://rtc-web.alvestrand.com/papers/juberti-p2ptransport-api.pdf?attredirects=0">previous proposal</a> was an example of what you call model "B" - I believe this represents the most flexible option, as candidates can be exchanged through any suitable mechanism, including XmlHttpRequest, WebSockets, an existing p2p connection, IFPC, etc. </div>

<div><br></div><div>It does require a bit more understanding from the programmer to figure out what to do with these callbacks, but I this concept of objects firing callbacks with blobs that need to be sent to the other side will recur in other parts of this API. One such place is in the setup of calls, where the app will need to send SDP-ish blobs to the other side over the aforementioned low-bandwidth channel.</div>

<div><br></div><div>--justin<br><br><div class="gmail_quote">On Tue, Jan 4, 2011 at 6:01 PM, Matthew Kaufman <span dir="ltr"><<a href="mailto:matthew.kaufman@skype.net">matthew.kaufman@skype.net</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I spent the holidays thinking about various ways of dealing with the connection API problem, and I thought I might put those thoughts out for some discussion rather than trying to pick one and write it up as a draft specification.<br>


<br>
There's obviously a few models one might build upon for how to represent the peer-to-peer connections and bring them to life. The WebSockets API ( <a href="http://dev.w3.org/html5/websockets/" target="_blank">http://dev.w3.org/html5/websockets/</a> ) is a solution to the client-server connection problem, and the way Flash Player extended its NetConnection and NetStream objects to support peer-to-peer connectivity over RTMFP ( <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html" target="_blank">http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html</a> ) is another model. And of course draft-alvestrand-dispatch-rtcweb-datagram ( <a href="http://tools.ietf.org/html/draft-alvestrand-dispatch-rtcweb-datagram-00" target="_blank">http://tools.ietf.org/html/draft-alvestrand-dispatch-rtcweb-datagram-00</a> ) hints at how a URL scheme might be applied to some of this problem.<br>


<br>
I believe the following items are givens, though feedback is of course welcome on these points as well:<br>
<br>
1. When it is possible to establish a peer-to-peer connection for media, that should be supported (and is probably preferred)<br>
<br>
2. Supporting peer-to-peer connections for media in the face of NA(P)T and firewalls will require UDP, and UDP hole-punching techniques (UDP is also preferable for delay-sensitive media)<br>
<br>
3. Enabling a browser to send UDP datagrams to script- or server-designated IP addresses and ports is unsafe unless a handshake is used to verify that the other end is a willing participant<br>
<br>
4. STUN Connectivity Check probes and responses (with short-term credentials) are a sufficiently strong handshake for the above (and this then suggests that ICE or a variant thereof is a good approach for the NAT traversal)<br>


<br>
5. Given NAT and firewalls, it will also be necessary to support relayed UDP traffic; that is to say, a traffic flow which is peer-relay server-peer<br>
<br>
6. Given NAT and firewalls, it will further be necessary to support transporting the same media traffic over a TCP connection, for cases where UDP is blocked. This could be a TCP tunnel of the UDP datagrams, WebSockets, or something else.<br>


<br>
-----<br>
<br>
<br>
A few possible programming models to support this then present themselves, though this is by no means an exhaustive list...<br>
<br>
A. A single connection object which can magically make everything work<br>
<br>
In this scenario the API is essentially "var connection = new PeerConnection(destinationSpecifier);".<br>
<br>
The destinationSpecifier would contain enough information for the PeerConnection object's implementation to: use ICE to attempt to open a direct or relayed connection over UDP, or failing that, TCP. It would contain the information necessary to communicate with an intermediary server as the ICE negotiation proceeds as well (a "low bandwidth" signaling channel is required between a pair of peers in many cases for exchange of pertinent information before the media connection can be established).<br>


<br>
B. A single connection object which does most of the magic, but with the low-bandwidth signaling made external though events<br>
<br>
In this case, the API is the same as above, but rather than providing in the destiniationSpecifier some sort of server address for the "low bandwidth signaling" the connection object would instead fire events containing (essentially opaque to the channel, but in an agreed format) the data which needed to be transported to the other side. A corresponding API on the far end's "listening" connection object would allow for the data to be injected at the far end. The script implementer would simply need to wire the event up to an existing transport mechanism (HTTP, WebSockets).<br>


<br>
C. A connection object which does most of the magic, but with a parent object that is the connection to the signaling mechanism<br>
<br>
This is the approach Flash Player has taken. The NetConnection is opened to the rendezvous-handling server (which can also act as a media relay), NetStreams are then opened either to that relaying server or directly to other peers. These peer-to-peer NetStreams use the open NetConnection for the peer setup signaling (determining the far IP addresses, requesting NAT hole-punching, etc.)<br>


<br>
D. Multiple connection objects<br>
<br>
In this case, the API is similar to case A for the UDP peer-to-peer channel but a *different* API and connection object (perhaps an extension of the existing WebSocket API) is used for the client-server fallback cases. This requires the script to determine when a direct connection cannot be made (which sometimes cannot be determined without trying it out). Makes the programming model more complex, but avoids duplication, as existing client-server models can be used for all relayed (and server-based) media cases without there being two (or more) different ways to move real-time media from a server to a browser (and vice versa).<br>


<br>
E. Script-intensive (but flexible) components<br>
<br>
In this model, an API exists which exposes a nearly bare UDP socket, but with permissions restricted such that traffic may not be sent unless handshake probes are sent and received. Maximum flexibility, at some significant cost in script complexity (though this could be encapsulated into well-known, even open-source, libraries).<br>


<br>
An example API for this is would be:<br>
  var connection = new PeerConnection(ICEusernameString, ICEpasswordString);<br>
     opens the local UDP port, nothing is permitted at this point<br>
  PeerConnection.testConnectivity(farSockaddrString, farUsernameString, farPasswordString);<br>
     sends STUN connectivity checks<br>
  PeerConnection.onConnectivityTest(receivedSockaddrString, usenameString);<br>
     event that fires when a connectivity test is received with valid credentials. Browser also automatically generates the transaction response.<br>
  PeerConnection.onConnectivitySuccess(receivedSockaddrString, reflexiveAddrString, usernameString);<br>
     event that fires when the connectivity test transaction response arrives... Browser then adds this destination to a whitelist of addresses that media streams may be sent to<br>
  PeerConnection.openMediaSession(sockaddrString)<br>
     fails immediately if the address isn't on the whitelist, otherwise starts a DTLS handshake with the specified address<br>
<br>
----<br>
<br>
Hopefully this will stimulate discussion and/or additional ideas from other folks who are working on designing and/or implementing solutions to this problem.<br>
<br>
Matthew Kaufman<br>
<a href="mailto:matthew.kaufman@skype.net" target="_blank">matthew.kaufman@skype.net</a><br>
Skype: atmatthewat<br>
<br>
<br>
_______________________________________________<br>
RTC-Web mailing list<br>
<a href="mailto:RTC-Web@alvestrand.no" target="_blank">RTC-Web@alvestrand.no</a><br>
<a href="http://www.alvestrand.no/mailman/listinfo/rtc-web" target="_blank">http://www.alvestrand.no/mailman/listinfo/rtc-web</a><br>
</blockquote></div><br></div>