MSRP Target Path
Posted by Ben Campbell on Wed, Feb 03, 2010 @ 09:36 AM
My last post described how MSRP endpoints use SDP to setup sessions. Today, we'll discuss how the MSRP protocol uses the results of the SDP offer/answer exchange.
Each endpoint builds a "target path" that it will use for all MSRP communication with its peer. If an endpoint does not use a relay, then the target path is exactly the same as the SDP path attribute value it received from its peer. On the other hand, if the endpoint does use a relay, then it forms the target path by prepending the URI that it got from each relay to the peer's SDP path attribute value. In both cases, the target path form a roadmap of how to get an MSRP request to the peer, i.e. a list of MSRP URIs showing each hop to visit on the way, ending with the URI of the destination device.
If you recall from last time, Alice sent Bob an SDP offer containing the following:
a=path:msrps://alice.example.com:7654/asfd34;tcp
Bob responded with an SDP answer containing this:
a=path:msrps://relay.example.net:8211/asfioef;tcp msrps://bob.example.net:6581/asfd34;tcp
Since Alice didn't introduce a relay (Bob's relay doesn't count here), she's got life easy. Her target path is exactly what Bob sent her:
msrps://relay.example.net:8211/asfioef;tcp msrps://bob.example.net:6581/asfd34;tcp
Okay, I lied a little bit about Bob's relay not counting. The relay clearly exists in the path, because Bob put it there. But since Alice did not introduce a relay on her own behalf, she uses Bob's path value as-is, without worrying about relays in general.
On the other hand, Bob did introduce a relay. So to get his target path, he takes the path Alice sent him, and prepends his own relay, and gets this:
msrps://relay.example.net:8211/asfioef;tcp msrps://alice.example.com:7654/asfd34;tcp
Alice and Bob are now almost ready to exchange MSRP messages. But there's one more step that must happen first. Alice must open a TCP connection towards Bob. Note that RFC 4975 says the offerer always opens the connection towards the answerer. There's work afoot to allow MSRP endpoints to negotiate the connection direction using COMEDIA, but for now lets assume Alice and Bob are using RFC 49752 as-is.
Alice connects to the first device in her target path. In this case, that's Bob's relay. She uses the DNS to get an IP address for "relay.example.net" and opens a TCP connection to port 8211, and starts sending messages. That's assuming she doesn't already have such a connection--for example, she might already have an MSRP session in progress with someone else that uses the same relay as Bob. In that case, she just uses the connection she already has.
Now, lets pretend for just a moment that things were reversed, and Bob had sent the original offer. The first device in his target path is also "relay.example.net". But since he already set up a connection to that relay when he authenticated with it, he doesn't need to setup a new one. He just reuses the one he already has. The relay would establish a connection to the next hop (Alice, in this case) on demand.
When either endpoint wants to send a message to the other, it constructs a SEND request with the message content in its payload. The endpoint puts its target path in a To-Path header field, and its own URI in the From-Path header field. It then sends the request to the first device in the To-Path. If that device is the peer, then that's pretty much all there is to it. If the first device is a relay, the relay removes its own URI from the To-Path and prepends it to the From-Path, then relays the request downstream.
Here's a picture for Alice and Bob. I've replaced the actual URIs with the symbols "Alice", "Bob", and "Relay" to try to keep it readable.
At this point, you are probably (and rightly) wondering what the point of a relay moving its URI to the From-Path header field when it relays a request. This allows a downstream device to send a response to a SEND request, in the form of a REPORT request. Don't confuse this with a message from the human Bob in response to a message from the human Alice. That would simply be another SEND request in the opposite direction. Instead REPORT requests carry delivery information about the original request.
The peer device, and any relays in between can originate a REPORT request back to the endpoint that sent a SEND request. They do this by inserting the From-Path that they observed in the Send request into the To-Path of the REPORT request. Here's a picture showing a REPORT request sent by Bob, and another by Bob's relay.

That's enough for now. Next time, I'll talk about how MSRP messages can be broken into "chunks" in order to multiplex multiple sessions across the same connection.