SipMSRPApi

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