DesignXMPP im

Version 4 (Anonymous, 02/29/2012 04:45 pm)

1 1
= Gateway for Instant Messaging=
2 1
3 1
[[TOC(DesignXMPP_im, depth=2)]]
4 1
5 2
In XMPP there are several types of messages which lead to different semantics when exchanging XMPP ''message stanzas'' between 2 endpoints. This section focuses only on message types that allow 2 endpoints to send instant messages to each other.
6 2
7 2
Message types:
8 2
9 2
 * Normal: the default message type. A reply is not expected from the recipient.
10 2
 * Chat: This message type implies both parties have engaged a conversation.
11 2
 * Headline: An endpoint receiving this type of message should never reply, since it's meant to be used by servers or other entities to deliver announcements.
12 2
13 2
In SIP there are currently 2 ways of doing Instant Messaging:
14 2
15 2
 * SIP MESSAGE (RFC 3428)
16 2
 * MSRP (RFC 4975)
17 2
18 2
The first one is session-less and the latter is session based.
19 2
20 2
The mechanisms described here follow the currently available specifications for SIP-XMPP interoperability:
21 2
22 2
 * http://xmpp.org/internet-drafts/draft-saintandre-sip-xmpp-im-01.html
23 2
 * http://xmpp.org/internet-drafts/draft-saintandre-sip-xmpp-chat-03.html
24 2
25 2
26 2
== XMPP single message <-> SIP MESSAGE ==
27 2
28 2
XMPP single messages are mapped directly to SIP MESSAGE requests and ''vice versa''.
29 2
30 3
[[Image(xmppgq_im_normal.png)]]
31 3
32 3
=== Overview ===
33 3
34 4
The mechanism for translating XMPP normal message stanzas and SIP MESSAGE requests is straightforward, they map one to one as stated in http://xmpp.org/internet-drafts/draft-saintandre-sip-xmpp-im-01.html. However, since SIP is used mainly with UDP as a transport, if a  XMPP stanza is bigger than 1500 bytes it will be chunked into smaller pieces to avoid ethernet fragmentation related issues.
35 3
36 3
Since SIP MESSAGE is a non INVITE transaction, it has to be replied immediately, because there is no way to avoid retransmissions. This means that the SIP-XMPP gateway will reply on the SIP side before knowing if the message was actually delivered to the XMPP side. In order to express this a "202 Accepted" reply will be sent to the SIP request instead of a "200 OK".
37 3
38 1
On the other hand, when an XMPP stanza is translated into a SIP MESSAGE request the SIP-XMPP gateway is able to report back the result (in case of error) by using a message stanza of type ''error''. This is possible because of the asynchronous nature of stanza processing in the XMPP protocol.
39 4
40 4
== Defining an XMPP chat session ==
41 4
42 4
In SIP a ''session'' is started by creating a dialog with the INVITE method and it's ended by terminating the dialog with a BYE request. In XMPP there is no universal mechanism to indicate that a chat session has started or ended. Because of this, the SIP-XMPP gateway will try its best to correlate the state on the SIP side with the one on the XMPP side.
43 4
44 4
There are different mechanisms by which the start and end of an XMPP chat session can be stated, but unfortunately none of them seem to be implemented in the most widely used XMPP clients, so relaying on them would lead to trouble.
45 4
46 4
 * ''XEP-0155: Stanza Session Negotiation''. This XEP has been in draft form since 2008 and even if implementation is encouraged none of the widely used XMPP clients implements it.
47 4
 * ''XEP-0201: Best Practices for Message Threads''. This XEP is more recent and some many clients implement it. Unfortunately, the concept of a "chat session" according to this XEP doesn't match the one on SIP because message threads last far longer, they can be resumed even after being offline for a while.