SipMSRPApi

Version 3 (Oliver Bril, 03/23/2009 11:35 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 1 Adrian Georgescu
The MSRP protocol is implemented by [http://devel.ag-projects.com/cgi-bin/darcsweb.cgi?r=python-msrplib;a=summary msrplib] Python package.
11 1 Adrian Georgescu
12 1 Adrian Georgescu
== Architecture ==
13 1 Adrian Georgescu
14 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
15 1 Adrian Georgescu
classes for establishing and managing MSRP connection.
16 1 Adrian Georgescu
17 1 Adrian Georgescu
The library consist of the following modules:
18 1 Adrian Georgescu
19 1 Adrian Georgescu
 '''msrplib.transport'''::
20 1 Adrian Georgescu
 Defines {{{MSRPTransport}}} class, which provides low level control over MSRP connection.
21 1 Adrian Georgescu
22 1 Adrian Georgescu
 '''msrplib.connect'''::
23 2 Redmine Admin
 Defines means to establish a connection, bind it, and provide an initialized {{{MSRPTransport}}} instance.
24 1 Adrian Georgescu
25 1 Adrian Georgescu
 '''msrplib.session'''::
26 1 Adrian Georgescu
 Defines {{{MSRPSession}}} class, which provides high level control over a MSRP connection.
27 1 Adrian Georgescu
28 1 Adrian Georgescu
 '''msrplib.protocol'''::
29 1 Adrian Georgescu
 Provides representation and parsing of MSRP entities - chunks and URIs.
30 1 Adrian Georgescu
31 1 Adrian Georgescu
 '''msrplib.trafficlog'''::
32 1 Adrian Georgescu
 Defines {{{Logger}}} class that is used through out the library to log the connection state.
33 1 Adrian Georgescu
  
34 1 Adrian Georgescu
== Usage ==
35 1 Adrian Georgescu
36 3 Oliver Bril
=== Establish a connection ===
37 3 Oliver Bril
38 1 Adrian Georgescu
{{{msrplib.connect}}} provides a number of classes to establish a connection, so the first
39 1 Adrian Georgescu
thing to do is to select which one applies to your situation:
40 1 Adrian Georgescu
41 1 Adrian Georgescu
    1. Calling endpoint, not using a relay ({{{ConnectorDirect}}})
42 1 Adrian Georgescu
    2. Answering endpoint, not using a relay ({{{AcceptorDirect}}})
43 1 Adrian Georgescu
    3. Calling endpoint, using a relay ({{{ConnectorRelay}}})
44 1 Adrian Georgescu
    4. Answering endpoint, using a relay ({{{AcceptorRelay}}})
45 1 Adrian Georgescu
46 1 Adrian Georgescu
The answering endpoint may skip using the relay if sure that it's accessible
47 1 Adrian Georgescu
directly. The calling endpoint is unlikely to need the relay.
48 1 Adrian Georgescu
49 1 Adrian Georgescu
Once you have an instance of the right class (use the convenience functions
50 1 Adrian Georgescu
{{{get_connector()}}} and {{{get_acceptor()}}} to get one), the procedure to establish the
51 1 Adrian Georgescu
connection is the same:
52 1 Adrian Georgescu
53 1 Adrian Georgescu
{{{
54 1 Adrian Georgescu
full_local_path = connector.prepare()
55 1 Adrian Georgescu
try:
56 1 Adrian Georgescu
    ... put full_local_path in SDP 'a:path' attribute
57 1 Adrian Georgescu
    ... get full_remote_path from remote's 'a:path: attribute
58 1 Adrian Georgescu
    ... (the order of the above steps is reversed if you're the
59 1 Adrian Georgescu
    ... answering party, but that does not affect connector's usage)
60 1 Adrian Georgescu
    msrptransport = connector.complete(full_remote_path)
61 1 Adrian Georgescu
finally:
62 1 Adrian Georgescu
    connector.cleanup()
63 1 Adrian Georgescu
}}}
64 1 Adrian Georgescu
65 1 Adrian Georgescu
To customize connection's parameters, create a new {{{protocol.URI}}} object and pass
66 1 Adrian Georgescu
it to prepare() function, e.g.
67 1 Adrian Georgescu
{{{
68 1 Adrian Georgescu
local_uri = protocol.URI(use_tls=False, port=5000)
69 1 Adrian Georgescu
connector.prepare(local_uri)
70 1 Adrian Georgescu
}}}
71 1 Adrian Georgescu
72 1 Adrian Georgescu
{{{prepare()}}} may update {{{local_uri}}} in place with the actual connection parameters
73 1 Adrian Georgescu
used (e.g. if you specified port=0). 'port' attribute of {{{local_uri}}} is currently
74 1 Adrian Georgescu
only respected by {{{AcceptorDirect}}}.
75 1 Adrian Georgescu
76 1 Adrian Georgescu
Note that, acceptors and connectors are one-use only. Which means, that {{{AcceptorDirect}}}
77 1 Adrian Georgescu
will open a port just to handle one incoming connection and close it right after.
78 1 Adrian Georgescu
If your application behaves more like a server, i.e. opens a port and listens on it
79 1 Adrian Georgescu
constantly, use {{{MSRPServer}}} class.
80 1 Adrian Georgescu
81 1 Adrian Georgescu
== Components ==
82 1 Adrian Georgescu
83 1 Adrian Georgescu
=== a connector or acceptor ===
84 1 Adrian Georgescu
85 1 Adrian Georgescu
==== attributes ====
86 1 Adrian Georgescu
==== methods ====
87 1 Adrian Georgescu
88 1 Adrian Georgescu
=== transport.MSRPTransport ===
89 3 Oliver Bril
90 3 Oliver Bril
Low level access to MSRP connection.
91 3 Oliver Bril
92 1 Adrian Georgescu
==== attributes ====
93 3 Oliver Bril
94 1 Adrian Georgescu
==== methods ====
95 3 Oliver Bril
96 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}}})::
97 3 Oliver Bril
 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''. 
98 3 Oliver Bril
 [[BR]]''contflag'':[[BR]]
99 3 Oliver Bril
 MSRP chunk's continuation flag ({{{'$'}}}, {{{'+'}}} or {{{'#'}}}). Default is {{{'$'}}}, unless you have a partial {{{SEND}}} chunk, in which case it is {{{'+'}}}
100 1 Adrian Georgescu
101 1 Adrian Georgescu
=== session.MSRPSession ===
102 1 Adrian Georgescu
==== attributes ====
103 1 Adrian Georgescu
==== methods ====
104 1 Adrian Georgescu
105 1 Adrian Georgescu
=== connect.MSRPServer ===
106 1 Adrian Georgescu
==== attributes ====
107 1 Adrian Georgescu
==== methods ====