SipMSRPApi

Version 4 (Oliver Bril, 03/31/2009 11:42 am)

1 1 Adrian Georgescu
= MSRP API =
2 1 Adrian Georgescu
3 1 Adrian Georgescu
[[TOC(WikiStart, Sip*, depth=3)]]
4 1 Adrian Georgescu
5 1 Adrian Georgescu
Message Session Relay Protocol (MSRP) is a protocol for transmitting a series of related instant messages in the context of a session. Message sessions are treated like any other media stream when set up via a rendezvous or session creation protocol such as the Session Initiation Protocol (SIP). 
6 1 Adrian Georgescu
7 1 Adrian Georgescu
 * MSRP sessions are defined in [http://tools.ietf.org/html/rfc4975 RFC 4975].
8 1 Adrian Georgescu
 * MSRP relay extension used for NAT traversal of instant messaging and file transfer sessions is defined in [http://tools.ietf.org/html/rfc4976 RFC 4976].
9 1 Adrian Georgescu
10 4 Oliver Bril
The MSRP protocol is implemented by [http://devel.ag-projects.com/cgi-bin/darcsweb.cgi?r=python-msrplib;a=summary msrplib] Python package. On top {{{sipsimple}}} provides
11 4 Oliver Bril
higher level classes integrated into middleware notification and configuration systems:
12 1 Adrian Georgescu
13 4 Oliver Bril
 * {{{sipsimple.msrp.MSRPChat}}}
14 4 Oliver Bril
 * {{{sipsimple.msrp.MSRPFileTransfer}}}
15 4 Oliver Bril
 * {{{sipsimple.msrp.MSRPDesktopSharing}}}
16 1 Adrian Georgescu
17 4 Oliver Bril
== MSRPChat ==
18 4 Oliver Bril
19 4 Oliver Bril
{{{sipsimple.msrp.MSRPChat}}} 
20 4 Oliver Bril
21 4 Oliver Bril
== MSRPFileTransfer ==
22 4 Oliver Bril
23 4 Oliver Bril
== MSRPDesktopSharing ==
24 4 Oliver Bril
25 4 Oliver Bril
== msrplib ==
26 4 Oliver Bril
27 4 Oliver Bril
=== Architecture ===
28 4 Oliver Bril
29 1 Adrian Georgescu
{{{msrplib}}} is based upon [http://twistedmatrix.com twisted] and [http://devel.ag-projects.com/~denis/eventlet/ eventlet] and provides a set of
30 1 Adrian Georgescu
classes for establishing and managing MSRP connection.
31 1 Adrian Georgescu
32 1 Adrian Georgescu
The library consist of the following modules:
33 1 Adrian Georgescu
34 1 Adrian Georgescu
 '''msrplib.transport'''::
35 1 Adrian Georgescu
 Defines {{{MSRPTransport}}} class, which provides low level control over MSRP connection.
36 2 Redmine Admin
37 1 Adrian Georgescu
 '''msrplib.connect'''::
38 1 Adrian Georgescu
 Defines means to establish a connection, bind it, and provide an initialized {{{MSRPTransport}}} instance.
39 1 Adrian Georgescu
40 1 Adrian Georgescu
 '''msrplib.session'''::
41 1 Adrian Georgescu
 Defines {{{MSRPSession}}} class, which provides high level control over a MSRP connection.
42 1 Adrian Georgescu
43 1 Adrian Georgescu
 '''msrplib.protocol'''::
44 1 Adrian Georgescu
 Provides representation and parsing of MSRP entities - chunks and URIs.
45 1 Adrian Georgescu
46 1 Adrian Georgescu
 '''msrplib.trafficlog'''::
47 1 Adrian Georgescu
 Defines {{{Logger}}} class that is used through out the library to log the connection state.
48 1 Adrian Georgescu
  
49 4 Oliver Bril
=== Usage ===
50 1 Adrian Georgescu
51 4 Oliver Bril
==== Establish a connection ====
52 3 Oliver Bril
53 1 Adrian Georgescu
{{{msrplib.connect}}} provides a number of classes to establish a connection, so the first
54 1 Adrian Georgescu
thing to do is to select which one applies to your situation:
55 1 Adrian Georgescu
56 1 Adrian Georgescu
    1. Calling endpoint, not using a relay ({{{ConnectorDirect}}})
57 1 Adrian Georgescu
    2. Answering endpoint, not using a relay ({{{AcceptorDirect}}})
58 1 Adrian Georgescu
    3. Calling endpoint, using a relay ({{{ConnectorRelay}}})
59 1 Adrian Georgescu
    4. Answering endpoint, using a relay ({{{AcceptorRelay}}})
60 1 Adrian Georgescu
61 1 Adrian Georgescu
The answering endpoint may skip using the relay if sure that it's accessible
62 1 Adrian Georgescu
directly. The calling endpoint is unlikely to need the relay.
63 1 Adrian Georgescu
64 1 Adrian Georgescu
Once you have an instance of the right class (use the convenience functions
65 1 Adrian Georgescu
{{{get_connector()}}} and {{{get_acceptor()}}} to get one), the procedure to establish the
66 1 Adrian Georgescu
connection is the same:
67 1 Adrian Georgescu
68 1 Adrian Georgescu
{{{
69 1 Adrian Georgescu
full_local_path = connector.prepare()
70 1 Adrian Georgescu
try:
71 1 Adrian Georgescu
    ... put full_local_path in SDP 'a:path' attribute
72 1 Adrian Georgescu
    ... get full_remote_path from remote's 'a:path: attribute
73 1 Adrian Georgescu
    ... (the order of the above steps is reversed if you're the
74 1 Adrian Georgescu
    ... answering party, but that does not affect connector's usage)
75 1 Adrian Georgescu
    msrptransport = connector.complete(full_remote_path)
76 1 Adrian Georgescu
finally:
77 1 Adrian Georgescu
    connector.cleanup()
78 1 Adrian Georgescu
}}}
79 1 Adrian Georgescu
80 1 Adrian Georgescu
To customize connection's parameters, create a new {{{protocol.URI}}} object and pass
81 1 Adrian Georgescu
it to prepare() function, e.g.
82 1 Adrian Georgescu
{{{
83 1 Adrian Georgescu
local_uri = protocol.URI(use_tls=False, port=5000)
84 1 Adrian Georgescu
connector.prepare(local_uri)
85 1 Adrian Georgescu
}}}
86 1 Adrian Georgescu
87 1 Adrian Georgescu
{{{prepare()}}} may update {{{local_uri}}} in place with the actual connection parameters
88 1 Adrian Georgescu
used (e.g. if you specified port=0). 'port' attribute of {{{local_uri}}} is currently
89 1 Adrian Georgescu
only respected by {{{AcceptorDirect}}}.
90 1 Adrian Georgescu
91 1 Adrian Georgescu
Note that, acceptors and connectors are one-use only. Which means, that {{{AcceptorDirect}}}
92 1 Adrian Georgescu
will open a port just to handle one incoming connection and close it right after.
93 1 Adrian Georgescu
If your application behaves more like a server, i.e. opens a port and listens on it
94 1 Adrian Georgescu
constantly, use {{{MSRPServer}}} class.
95 3 Oliver Bril
96 4 Oliver Bril
=== Components ===
97 1 Adrian Georgescu
98 4 Oliver Bril
==== a connector or acceptor ====
99 3 Oliver Bril
100 4 Oliver Bril
===== attributes =====
101 4 Oliver Bril
===== methods =====
102 1 Adrian Georgescu
103 4 Oliver Bril
==== transport.MSRPTransport ====
104 1 Adrian Georgescu
105 1 Adrian Georgescu
Low level access to MSRP connection.
106 1 Adrian Georgescu
107 4 Oliver Bril
===== attributes =====
108 3 Oliver Bril
109 4 Oliver Bril
===== methods =====
110 3 Oliver Bril
111 3 Oliver Bril
 '''make_chunk'''(''self'', ''transaction_id''={{{None}}}, ''method''={{{'SEND'}}}, ''code''={{{None}}}, ''comment''={{{None}}}, ''data''={{{''}}}, ''contflag''={{{None}}}, ''start''={{{1}}}, ''end''={{{None}}}, ''length''={{{None}}}, ''message_id''={{{None}}})::
112 1 Adrian Georgescu
 Make a new chunk ({{{protocol.MSRPData}}} instance) with proper {{{From-Path}}}, {{{To-Path}}}, {{{Byte-Range}}} and {{{Message-ID}}} headers set up based on MSRPTransport's state and the parameters provided. Use ''data'' for payload, and ''start''/''end''/''length'' to generate {{{Byte-Range}}} header. Generate new random strings for default values of ''transaction_id'' and ''message_id''. 
113 1 Adrian Georgescu
 [[BR]]''contflag'':[[BR]]
114 1 Adrian Georgescu
 MSRP chunk's continuation flag ({{{'$'}}}, {{{'+'}}} or {{{'#'}}}). Default is {{{'$'}}}, unless you have a partial {{{SEND}}} chunk, in which case it is {{{'+'}}}
115 1 Adrian Georgescu
116 4 Oliver Bril
==== session.MSRPSession ====
117 4 Oliver Bril
===== attributes =====
118 4 Oliver Bril
===== methods =====
119 1 Adrian Georgescu
120 4 Oliver Bril
==== connect.MSRPServer ====
121 4 Oliver Bril
===== attributes =====
122 4 Oliver Bril
===== methods =====