SipMSRPApi » History » Version 1
Adrian Georgescu, 03/12/2009 07:50 PM
| 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 | Defines means to establish a connection, bind it, and provide a usable {{{MSRPTransport}}} instance. |
||
| 24 | |||
| 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 | {{{msrplib.connect}}} provides a number of classes to establish a connection, so the first |
||
| 37 | thing to do is to select which one applies to your situation: |
||
| 38 | |||
| 39 | 1. Calling endpoint, not using a relay ({{{ConnectorDirect}}}) |
||
| 40 | 2. Answering endpoint, not using a relay ({{{AcceptorDirect}}}) |
||
| 41 | 3. Calling endpoint, using a relay ({{{ConnectorRelay}}}) |
||
| 42 | 4. Answering endpoint, using a relay ({{{AcceptorRelay}}}) |
||
| 43 | |||
| 44 | The answering endpoint may skip using the relay if sure that it's accessible |
||
| 45 | directly. The calling endpoint is unlikely to need the relay. |
||
| 46 | |||
| 47 | Once you have an instance of the right class (use the convenience functions |
||
| 48 | {{{get_connector()}}} and {{{get_acceptor()}}} to get one), the procedure to establish the |
||
| 49 | connection is the same: |
||
| 50 | |||
| 51 | {{{ |
||
| 52 | full_local_path = connector.prepare() |
||
| 53 | try: |
||
| 54 | ... put full_local_path in SDP 'a:path' attribute |
||
| 55 | ... get full_remote_path from remote's 'a:path: attribute |
||
| 56 | ... (the order of the above steps is reversed if you're the |
||
| 57 | ... answering party, but that does not affect connector's usage) |
||
| 58 | msrptransport = connector.complete(full_remote_path) |
||
| 59 | finally: |
||
| 60 | connector.cleanup() |
||
| 61 | }}} |
||
| 62 | |||
| 63 | To customize connection's parameters, create a new {{{protocol.URI}}} object and pass |
||
| 64 | it to prepare() function, e.g. |
||
| 65 | {{{ |
||
| 66 | local_uri = protocol.URI(use_tls=False, port=5000) |
||
| 67 | connector.prepare(local_uri) |
||
| 68 | }}} |
||
| 69 | |||
| 70 | {{{prepare()}}} may update {{{local_uri}}} in place with the actual connection parameters |
||
| 71 | used (e.g. if you specified port=0). 'port' attribute of {{{local_uri}}} is currently |
||
| 72 | only respected by {{{AcceptorDirect}}}. |
||
| 73 | |||
| 74 | Note that, acceptors and connectors are one-use only. Which means, that {{{AcceptorDirect}}} |
||
| 75 | will open a port just to handle one incoming connection and close it right after. |
||
| 76 | If your application behaves more like a server, i.e. opens a port and listens on it |
||
| 77 | constantly, use {{{MSRPServer}}} class. |
||
| 78 | |||
| 79 | == Components == |
||
| 80 | |||
| 81 | === a connector or acceptor === |
||
| 82 | |||
| 83 | ==== attributes ==== |
||
| 84 | ==== methods ==== |
||
| 85 | |||
| 86 | === transport.MSRPTransport === |
||
| 87 | ==== attributes ==== |
||
| 88 | ==== methods ==== |
||
| 89 | |||
| 90 | === session.MSRPSession === |
||
| 91 | ==== attributes ==== |
||
| 92 | ==== methods ==== |
||
| 93 | |||
| 94 | === connect.MSRPServer === |
||
| 95 | ==== attributes ==== |
||
| 96 | ==== methods ==== |