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