SipMSRPApi
Version 51 (Luci Stanescu, 04/15/2010 04:52 pm)
1 | 1 | Adrian Georgescu | = MSRP API = |
---|---|---|---|
2 | 1 | Adrian Georgescu | |
3 | 48 | Luci Stanescu | [[TOC(SipMSRPApi, SipDeveloperGuide, depth=2)]] |
4 | 1 | Adrian Georgescu | |
5 | 31 | 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 | 25 | Adrian Georgescu | * MSRP sessions are defined in [http://tools.ietf.org/html/rfc4975 RFC 4975] |
8 | 25 | 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 | 32 | Adrian Georgescu | The MSRP protocol stack is implemented by [http://devel.ag-projects.com/cgi-bin/darcsweb.cgi?r=python-msrplib;a=summary msrplib] Python package. |
11 | 4 | Oliver Bril | |
12 | 33 | Adrian Georgescu | {{{msrplib}}} is based upon [http://twistedmatrix.com twisted] and [http://download.ag-projects.com/SipClient/ eventlet] and provides a set of classes for establishing and managing MSRP connections. |
13 | 1 | Adrian Georgescu | |
14 | 28 | Adrian Georgescu | The library consists of the following modules: |
15 | 1 | Adrian Georgescu | |
16 | 1 | Adrian Georgescu | '''msrplib.transport''':: |
17 | 27 | Adrian Georgescu | Defines {{{MSRPTransport}}} class, which provides low level control over MSRP connections. |
18 | 2 | Redmine Admin | |
19 | 1 | Adrian Georgescu | '''msrplib.connect''':: |
20 | 1 | Adrian Georgescu | Defines means to establish a connection, bind it, and provide an initialized {{{MSRPTransport}}} instance. |
21 | 1 | Adrian Georgescu | |
22 | 1 | Adrian Georgescu | '''msrplib.session''':: |
23 | 1 | Adrian Georgescu | Defines {{{MSRPSession}}} class, which provides high level control over a MSRP connection. |
24 | 1 | Adrian Georgescu | |
25 | 1 | Adrian Georgescu | '''msrplib.protocol''':: |
26 | 42 | Luci Stanescu | Provides representation and parsing of MSRP entities - chunks and MSRP URIs. |
27 | 1 | Adrian Georgescu | |
28 | 48 | Luci Stanescu | == URI == |
29 | 39 | Luci Stanescu | |
30 | 44 | Luci Stanescu | This class is implemented in the {{{msrplib.protocol}}} module and is used to represent an MSRP URI. |
31 | 1 | Adrian Georgescu | |
32 | 49 | Adrian Georgescu | ==== methods ==== |
33 | 1 | Adrian Georgescu | |
34 | 39 | Luci Stanescu | '''!__init!__'''(''self'', '''host'''={{{None}}}, '''use_tls'''={{{False}}}, '''user'''={{{None}}}, '''port'''={{{None}}}, '''session_id'''={{{None}}}, '''parameters'''={{{None}}}, '''credentials'''={{{None}}}):: |
35 | 39 | Luci Stanescu | Constructs a new {{{URI}}}. All the arguments specified here are also attributes on the object. For more information on these attributes, see RFC4975. |
36 | 39 | Luci Stanescu | [[BR]]''host'':[[BR]] |
37 | 39 | Luci Stanescu | The hostname or IP address which forms the URI. |
38 | 39 | Luci Stanescu | [[BR]]''use_tls'':[[BR]] |
39 | 39 | Luci Stanescu | Whether this identifies an msrps or msrp URI. |
40 | 39 | Luci Stanescu | [[BR]]''user'':[[BR]] |
41 | 39 | Luci Stanescu | The user part of the URI. |
42 | 39 | Luci Stanescu | [[BR]]''port'':[[BR]] |
43 | 39 | Luci Stanescu | The port in the URI. |
44 | 39 | Luci Stanescu | [[BR]]''session_id'':[[BR]] |
45 | 39 | Luci Stanescu | The session identifier part of the URI. |
46 | 1 | Adrian Georgescu | [[BR]]''parameters'':[[BR]] |
47 | 39 | Luci Stanescu | A {{{dict}}} containing the parameters which will be appended to the URI. |
48 | 39 | Luci Stanescu | [[BR]]''credentials'':[[BR]] |
49 | 1 | Adrian Georgescu | A {{{gnutls.interfaces.twisted.X509Credentials}}} object which will be used if this identifies a TLS URI to authenticate to the other endpoint. |
50 | 39 | Luci Stanescu | |
51 | 48 | Luci Stanescu | == MSRPRelaySettings == |
52 | 1 | Adrian Georgescu | |
53 | 45 | Luci Stanescu | This class is implemented in the {{{msrplib.connect}}} module and is used to specify the MSRP relay which will be used when connecting via a relay (using the {{{ConnectorRelay}}} or {{{AcceptorRelay}}} classes). |
54 | 39 | Luci Stanescu | |
55 | 49 | Adrian Georgescu | ==== methods ==== |
56 | 39 | Luci Stanescu | |
57 | 39 | Luci Stanescu | '''!__init!__'''(''self'', '''domain''', '''username''', '''password''', '''host'''={{{None}}}, '''use_tls'''={{{False}}}, '''port'''={{{None}}}, '''credentials'''={{{None}}}):: |
58 | 39 | Luci Stanescu | Constructs a new {{{URI}}}. All the arguments specified here are also attributes on the object. For more information on these attributes, see RFC4975. |
59 | 39 | Luci Stanescu | [[BR]]''domain'':[[BR]] |
60 | 39 | Luci Stanescu | The DNS domain in which to search for a MSRP relay using SRV queries. |
61 | 39 | Luci Stanescu | [[BR]]''username'':[[BR]] |
62 | 39 | Luci Stanescu | The username which will be used to authenticate to the relay. |
63 | 39 | Luci Stanescu | [[BR]]''password'':[[BR]] |
64 | 39 | Luci Stanescu | The password which will be used to authenticate to the relay. |
65 | 39 | Luci Stanescu | [[BR]]''host'':[[BR]] |
66 | 39 | Luci Stanescu | The hostname or IP address of the MSRP relay. |
67 | 1 | Adrian Georgescu | [[BR]]''use_tls'':[[BR]] |
68 | 39 | Luci Stanescu | Whether this identifies an msrps or msrp URI. |
69 | 39 | Luci Stanescu | [[BR]]''port'':[[BR]] |
70 | 1 | Adrian Georgescu | The port in the URI. |
71 | 39 | Luci Stanescu | [[BR]]''credentials'':[[BR]] |
72 | 39 | Luci Stanescu | A {{{gnutls.interfaces.twisted.X509Credentials}}} object which will be used to authenticate to the relay if TLS is used. |
73 | 39 | Luci Stanescu | |
74 | 48 | Luci Stanescu | == ConnectorDirect == |
75 | 39 | Luci Stanescu | |
76 | 44 | Luci Stanescu | This class is implemented in the {{{msrplib.connect}}} module and is used for outbound MSRP connections without a relay. |
77 | 39 | Luci Stanescu | |
78 | 49 | Adrian Georgescu | ==== methods ==== |
79 | 39 | Luci Stanescu | |
80 | 39 | Luci Stanescu | '''!__init!__'''(''self'', '''loger'''={{{None}}}):: |
81 | 44 | Luci Stanescu | Constructs a new ConnectorDirect. |
82 | 39 | Luci Stanescu | [[BR]]''logger'':[[BR]] |
83 | 39 | Luci Stanescu | The logger which will be used for this MSRP connection. See the [wiki:SipMSRPApi#Logging Logging] section for more information. |
84 | 39 | Luci Stanescu | |
85 | 39 | Luci Stanescu | '''prepare'''(''self'', '''local_uri'''={{{None}}}):: |
86 | 39 | Luci Stanescu | This method returns a full local path - list of {{{protocol.URI}}} instances, suitable to be put in SDP {{{'a:path'}}} attribute. |
87 | 39 | Luci Stanescu | [[BR]]''local_uri'':[[BR]] |
88 | 39 | Luci Stanescu | This attribute will be used to construct the local path, but other than that it is not used anywhere else in case of the ConnectorDirect. If not provided, one |
89 | 39 | Luci Stanescu | will be automatically generated |
90 | 1 | Adrian Georgescu | |
91 | 1 | Adrian Georgescu | '''complete'''(''self'', '''full_remote_path'''):: |
92 | 39 | Luci Stanescu | This method establishes the connection and binds it (sends an empty chunk to verify each other's From-Path and To-Path). It returns {{{transport.MSRPTransport}}} instance, ready to read and send chunks. |
93 | 1 | Adrian Georgescu | [[BR]]''full_remote_path'':[[BR]] |
94 | 39 | Luci Stanescu | A list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party. |
95 | 1 | Adrian Georgescu | |
96 | 39 | Luci Stanescu | '''cleanup'''(''self''):: |
97 | 39 | Luci Stanescu | This method cleans up after {{{prepare()}}}; it should be called if {{{complete()}}} will not be called for whatever reason. |
98 | 1 | Adrian Georgescu | |
99 | 48 | Luci Stanescu | == ConnectorRelay == |
100 | 1 | Adrian Georgescu | |
101 | 44 | Luci Stanescu | This class is implemented in the {{{msrplib.connect}}} module and is used for outbound MSRP connections using a relay. |
102 | 1 | Adrian Georgescu | |
103 | 49 | Adrian Georgescu | ==== methods ==== |
104 | 39 | Luci Stanescu | |
105 | 39 | Luci Stanescu | '''!__init!__'''(''self'', '''relay''', '''loger'''={{{None}}}):: |
106 | 39 | Luci Stanescu | Constructs a new ConnectorRelay. |
107 | 39 | Luci Stanescu | [[BR]]''relay'':[[BR]] |
108 | 39 | Luci Stanescu | An instance of {{{MSRPRelaySettings}}} which identifies the relay which is to be used. |
109 | 39 | Luci Stanescu | [[BR]]''logger'':[[BR]] |
110 | 39 | Luci Stanescu | The logger which will be used for this MSRP connection. See the [wiki:SipMSRPApi#Logging Logging] section for more information. |
111 | 39 | Luci Stanescu | |
112 | 39 | Luci Stanescu | '''prepare'''(''self'', '''local_uri'''={{{None}}}):: |
113 | 39 | Luci Stanescu | This method returns a full local path - list of {{{protocol.URI}}} instances, suitable to be put in SDP {{{'a:path'}}} attribute. |
114 | 39 | Luci Stanescu | [[BR]]''local_uri'':[[BR]] |
115 | 1 | Adrian Georgescu | This attribute will be used to construct the local path, but other than that it is not used anywhere else in case of the ConnectorRelay. If not provided, one |
116 | 39 | Luci Stanescu | will be automatically generated |
117 | 39 | Luci Stanescu | |
118 | 1 | Adrian Georgescu | '''complete'''(''self'', '''full_remote_path'''):: |
119 | 39 | Luci Stanescu | This method establishes the connection to the relay and binds it (sends an empty chunk to verify each other's From-Path and To-Path). It returns {{{transport.MSRPTransport}}} instance, ready to read and send chunks. |
120 | 39 | Luci Stanescu | [[BR]]''full_remote_path'':[[BR]] |
121 | 39 | Luci Stanescu | A list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party. |
122 | 39 | Luci Stanescu | |
123 | 1 | Adrian Georgescu | '''cleanup'''(''self''):: |
124 | 39 | Luci Stanescu | This method cleans up after {{{prepare()}}}; it should be called if {{{complete()}}} will not be called for whatever reason. |
125 | 1 | Adrian Georgescu | |
126 | 48 | Luci Stanescu | == AcceptorDirect == |
127 | 1 | Adrian Georgescu | |
128 | 44 | Luci Stanescu | This class is implemented in the {{{msrplib.connect}}} module and is used for inbound MSRP connections without using a relay. |
129 | 1 | Adrian Georgescu | |
130 | 49 | Adrian Georgescu | ==== methods ==== |
131 | 39 | Luci Stanescu | |
132 | 39 | Luci Stanescu | '''!__init!__'''(''self'', '''loger'''={{{None}}}):: |
133 | 39 | Luci Stanescu | Constructs a new AcceptorDirect. |
134 | 39 | Luci Stanescu | [[BR]]''logger'':[[BR]] |
135 | 39 | Luci Stanescu | The logger which will be used for this MSRP connection. See the [wiki:SipMSRPApi#Logging Logging] section for more information. |
136 | 39 | Luci Stanescu | |
137 | 39 | Luci Stanescu | '''prepare'''(''self'', '''local_uri'''={{{None}}}):: |
138 | 1 | Adrian Georgescu | This method starts listening on a socket identified by the parameters in the {{{local_uri}}} argument. It returns a full local path - list of {{{protocol.URI}}} instances, suitable to be put in SDP {{{'a:path'}}} attribute. |
139 | 39 | Luci Stanescu | [[BR]]''local_uri'':[[BR]] |
140 | 39 | Luci Stanescu | This attribute will be used to construct the local path and to listen for incomming connections. If not provided, one |
141 | 1 | Adrian Georgescu | will be automatically generated |
142 | 39 | Luci Stanescu | |
143 | 39 | Luci Stanescu | '''complete'''(''self'', '''full_remote_path'''):: |
144 | 39 | Luci Stanescu | This method waits for an incoming connection and a chunk sent by the other party. It returns {{{transport.MSRPTransport}}} instance, ready to read and send chunks. |
145 | 39 | Luci Stanescu | [[BR]]''full_remote_path'':[[BR]] |
146 | 39 | Luci Stanescu | A list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party. This is checked agains the From-Path header in the binding chunk. |
147 | 39 | Luci Stanescu | |
148 | 39 | Luci Stanescu | '''cleanup'''(''self''):: |
149 | 39 | Luci Stanescu | This method cleans up after {{{prepare()}}}; it should be called if {{{complete()}}} will not be called for whatever reason. |
150 | 39 | Luci Stanescu | |
151 | 48 | Luci Stanescu | == AcceptorRelay == |
152 | 39 | Luci Stanescu | |
153 | 44 | Luci Stanescu | This class is implemented in the {{{msrplib.connect}}} module and is used for inbound MSRP connections using a relay. |
154 | 39 | Luci Stanescu | |
155 | 49 | Adrian Georgescu | ==== methods ==== |
156 | 39 | Luci Stanescu | |
157 | 39 | Luci Stanescu | '''!__init!__'''(''self'', '''relay''', '''loger'''={{{None}}}):: |
158 | 39 | Luci Stanescu | Constructs a new AcceptorRelay. |
159 | 39 | Luci Stanescu | [[BR]]''relay'':[[BR]] |
160 | 39 | Luci Stanescu | An instance of {{{MSRPRelaySettings}}} which identifies the relay which is to be used. |
161 | 39 | Luci Stanescu | [[BR]]''logger'':[[BR]] |
162 | 1 | Adrian Georgescu | The logger which will be used for this MSRP connection. See the [wiki:SipMSRPApi#Logging Logging] section for more information. |
163 | 39 | Luci Stanescu | |
164 | 39 | Luci Stanescu | '''prepare'''(''self'', '''local_uri'''={{{None}}}):: |
165 | 1 | Adrian Georgescu | This method connects to the relay specified in {{{__init__}}}. It returns a full local path - list of {{{protocol.URI}}} instances, suitable to be put in SDP {{{'a:path'}}} attribute. |
166 | 39 | Luci Stanescu | [[BR]]''local_uri'':[[BR]] |
167 | 39 | Luci Stanescu | This attribute will be used to construct the local path. If not provided, one will be automatically generated |
168 | 39 | Luci Stanescu | |
169 | 39 | Luci Stanescu | '''complete'''(''self'', '''full_remote_path'''):: |
170 | 39 | Luci Stanescu | This method waits for an incoming chunk sent by the other party. It returns {{{transport.MSRPTransport}}} instance, ready to read and send chunks. |
171 | 39 | Luci Stanescu | [[BR]]''full_remote_path'':[[BR]] |
172 | 39 | Luci Stanescu | A list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party. This is checked agains the From-Path header in the binding chunk. |
173 | 39 | Luci Stanescu | |
174 | 39 | Luci Stanescu | '''cleanup'''(''self''):: |
175 | 39 | Luci Stanescu | This method cleans up after {{{prepare()}}}; it should be called if {{{complete()}}} will not be called for whatever reason. |
176 | 39 | Luci Stanescu | |
177 | 51 | Luci Stanescu | == MSRPData == |
178 | 51 | Luci Stanescu | |
179 | 51 | Luci Stanescu | This class is implemented in the {{{msrplib.protocol}}} module and represents an MSRP chunk, either a request or a response. |
180 | 51 | Luci Stanescu | |
181 | 51 | Luci Stanescu | ==== attributes ==== |
182 | 51 | Luci Stanescu | |
183 | 51 | Luci Stanescu | The following attributes are read-only. |
184 | 51 | Luci Stanescu | |
185 | 51 | Luci Stanescu | '''content_type''':: |
186 | 51 | Luci Stanescu | The MIME type of the payload carried by this chunk, which is stored in the Content-Type header. |
187 | 51 | Luci Stanescu | |
188 | 51 | Luci Stanescu | '''message_id''':: |
189 | 51 | Luci Stanescu | The ID of the message this chunk is part of, which is stored in the Message-ID header. |
190 | 51 | Luci Stanescu | |
191 | 51 | Luci Stanescu | '''byte_range''':: |
192 | 51 | Luci Stanescu | A 3-tuple containing the start, end and length values (in this order) from the Byte-Range header. |
193 | 51 | Luci Stanescu | |
194 | 51 | Luci Stanescu | '''status''':: |
195 | 51 | Luci Stanescu | The value of the Status header. |
196 | 51 | Luci Stanescu | |
197 | 51 | Luci Stanescu | '''failure_report''':: |
198 | 51 | Luci Stanescu | The value of the Failure-Report header, whether it exists or it is implied; one of {{{'yes'}}}, {{{'no'}}}, {{{'partial'}}}. |
199 | 51 | Luci Stanescu | |
200 | 51 | Luci Stanescu | '''success_report''':: |
201 | 51 | Luci Stanescu | The value of the Success-Report header, whether it exists or it is implied; one of {{{'yes'}}} or {{{'no'}}}. |
202 | 51 | Luci Stanescu | |
203 | 51 | Luci Stanescu | '''size''':: |
204 | 51 | Luci Stanescu | The size of the payload of this chunk, in bytes. |
205 | 51 | Luci Stanescu | |
206 | 51 | Luci Stanescu | ==== methods ==== |
207 | 51 | Luci Stanescu | |
208 | 51 | Luci Stanescu | '''!__init!__'''(''self'', '''transaction_id''', '''method'''={{{None}}}, '''code'''={{{None}}}, '''comment'''={{{None}}}, '''headers'''={{{None}}}, '''data'''={{{''}}}, '''contflag'''={{{'$'}}}):: |
209 | 51 | Luci Stanescu | Initializes a new MSRPData instance. All the arguments are also available as attributes. |
210 | 51 | Luci Stanescu | [[BR]]''transaction_id'':[[BR]] |
211 | 51 | Luci Stanescu | The transaction identified of this chunk. |
212 | 51 | Luci Stanescu | [[BR]]''method'':[[BR]] |
213 | 51 | Luci Stanescu | The method of this chunk if it a request and {{{None}}} if it is a response. |
214 | 51 | Luci Stanescu | [[BR]]''code'':[[BR]] |
215 | 51 | Luci Stanescu | The status code of this chunk if it is a response and {{{None}}} if it is a request. |
216 | 51 | Luci Stanescu | [[BR]]''comment'':[[BR]] |
217 | 51 | Luci Stanescu | The comment of this chunk if it is a response and {{{None}}} if it is a request. |
218 | 51 | Luci Stanescu | [[BR]]''headers'':[[BR]] |
219 | 51 | Luci Stanescu | A dict containing the headers which are to be added to this chunk, or {{{None}}} if no headers are to be added. |
220 | 51 | Luci Stanescu | [[BR]]''data'':[[BR]] |
221 | 51 | Luci Stanescu | The payload of this chunk, or an empty string if no payload is to be added. |
222 | 51 | Luci Stanescu | [[BR]]''contflag'':[[BR]] |
223 | 51 | Luci Stanescu | The MSRP continuation flag of this chunk, one of {{{'$'}}}, {{{'#'}}} or {{{'+'}}}. |
224 | 51 | Luci Stanescu | |
225 | 51 | Luci Stanescu | '''copy'''(''self''):: |
226 | 51 | Luci Stanescu | Returns a new MSRPData instance with exactly the same attributes as this object. |
227 | 51 | Luci Stanescu | |
228 | 51 | Luci Stanescu | '''add_header'''(''self'', '''header'''):: |
229 | 51 | Luci Stanescu | Add a MSRP header to this chunk. |
230 | 51 | Luci Stanescu | [[BR]]''header'':[[BR]] |
231 | 51 | Luci Stanescu | The header object which is to be added to this chunk. |
232 | 51 | Luci Stanescu | |
233 | 51 | Luci Stanescu | '''verify_headers'''(''self''):: |
234 | 51 | Luci Stanescu | Verifies that the chunk contains a To-Path and a From-Path header and that all the headers are valid. |
235 | 51 | Luci Stanescu | |
236 | 51 | Luci Stanescu | '''encode_start'''(''self''):: |
237 | 51 | Luci Stanescu | Returns a string containing the MSRP header of this chunk. |
238 | 51 | Luci Stanescu | |
239 | 51 | Luci Stanescu | '''encode_end'''(''self'', '''continuation'''):: |
240 | 51 | Luci Stanescu | Returns a string containing the MSRP end line of this chunk: 7 commas followed by the transaction identifier and the continuation flag specified. |
241 | 51 | Luci Stanescu | [[BR]]''continuation'':[[BR]] |
242 | 51 | Luci Stanescu | The continuation flag which is to be used in the end line. |
243 | 51 | Luci Stanescu | |
244 | 51 | Luci Stanescu | '''encode'''(''self''): |
245 | 51 | Luci Stanescu | Returns a string containing the whole of this MSRP chunk. |
246 | 51 | Luci Stanescu | |
247 | 51 | Luci Stanescu | |
248 | 14 | Oliver Bril | == MSRPTransport == |
249 | 1 | Adrian Georgescu | |
250 | 51 | Luci Stanescu | This class is implemented in the {{{msrplib.transport}}} module and provies low level access to the MSRP connection. This class should not be constructed directly, but rather its intances should be obtained by using the various connector/acceptor classes documented above. |
251 | 1 | Adrian Georgescu | |
252 | 1 | Adrian Georgescu | ==== methods ==== |
253 | 1 | Adrian Georgescu | |
254 | 1 | Adrian Georgescu | '''make_chunk'''(''self'', '''transaction_id'''={{{None}}}, '''method'''={{{'SEND'}}}, '''code'''={{{None}}}, '''comment'''={{{None}}}, '''data'''={{{''}}}, '''contflag'''={{{None}}}, '''start'''={{{1}}}, '''end'''={{{None}}}, '''length'''={{{None}}}, '''message_id'''={{{None}}}):: |
255 | 51 | Luci Stanescu | Creates a new chunk ({{{protocol.MSRPData}}} instance), which is either an MSRP request or a response. Proper {{{From-Path}}}, {{{To-Path}}}, {{{Byte-Range}}} and {{{Message-ID}}} headers are added based on MSRPTransport's state and the parameters provided. Use ''data'' for payload, and ''start''/''end''/''length'' to generate the {{{Byte-Range}}} header. |
256 | 51 | Luci Stanescu | [[BR]]''transaction_id'':[[BR]] |
257 | 51 | Luci Stanescu | The transaction id which will be put in the chunk. If it is not provided, one will be randomly generated. |
258 | 51 | Luci Stanescu | [[BR]]''method'':[[BR]] |
259 | 51 | Luci Stanescu | The method of the new MSRP request, or {{{None}}} if a response is required. |
260 | 51 | Luci Stanescu | [[BR]]''code'':[[BR]] |
261 | 51 | Luci Stanescu | The code of the new MSRP response, or {{{None}}} if a request is required. |
262 | 51 | Luci Stanescu | [[BR]]''code'':[[BR]] |
263 | 51 | Luci Stanescu | The comment of the new MSRP response, or {{{None}}} if a request is required or a comment on the response is not. |
264 | 51 | Luci Stanescu | [[BR]]''data'':[[BR]] |
265 | 51 | Luci Stanescu | The payload of the new chunk, or an empty string if no payload is required. |
266 | 1 | Adrian Georgescu | [[BR]]''contflag'':[[BR]] |
267 | 51 | Luci Stanescu | MSRP chunk's continuation flag ({{{'$'}}}, {{{'+'}}} or {{{'#'}}}). Default is {{{'$'}}} for a full message, unless a partial {{{SEND}}} chunk required, in which case it should be set to {{{'+'}}}. If {{{None}}} is provided, either {{{'$'}}} or {{{'+'}}} will be used depending on whether this chunk seems to carry the last part of the message data. |
268 | 51 | Luci Stanescu | [[BR]]''start'':[[BR]] |
269 | 51 | Luci Stanescu | The first byte's index within the whole message payload this chunk will carry as its own payload. |
270 | 51 | Luci Stanescu | [[BR]]''end'':[[BR]] |
271 | 51 | Luci Stanescu | The last byte's index within the whole message payload this chunk will carry as its own payload. Note that this is an inclusive index. If this is not provided, it's computed based on the number of bytes in data and {{{start}}}. |
272 | 51 | Luci Stanescu | [[BR]]''length'':[[BR]] |
273 | 51 | Luci Stanescu | The total number of bytes of the whole message payload. If this is not provided, it is computed as if this chunk carries that last part of the message payload. |
274 | 51 | Luci Stanescu | [[BR]]''message_id'':[[BR]] |
275 | 51 | Luci Stanescu | The ID of the message this chunk is part of. If it is not provided, one will be randomly generated. |
276 | 1 | Adrian Georgescu | |
277 | 51 | Luci Stanescu | '''write_chunk'''(''self'', '''chunk''', '''wait'''={{{True}}}):: |
278 | 51 | Luci Stanescu | Writes the chunk provided to the underlying socket. |
279 | 51 | Luci Stanescu | [[BR]]''chunk'':[[BR]] |
280 | 51 | Luci Stanescu | The chunk which is to be written, an instance of {{{MSRPData}}}. |
281 | 51 | Luci Stanescu | [[BR]]''wait'':[[BR]] |
282 | 51 | Luci Stanescu | If {{{True}}}, waits for the operation to complete. |
283 | 1 | Adrian Georgescu | |
284 | 51 | Luci Stanescu | '''write_response'''(''self'', '''chunk''', '''code''', '''comment''', '''wait'''={{{True}}}): |
285 | 51 | Luci Stanescu | Creates a response which is suitable as a reply to the specified chunk and writes it to the underlying socket. |
286 | 51 | Luci Stanescu | [[BR]]''chunk'':[[BR]] |
287 | 51 | Luci Stanescu | The chunk for which to create a response. |
288 | 51 | Luci Stanescu | [[BR]]''code'':[[BR]] |
289 | 51 | Luci Stanescu | The status code of the response which is to be created. |
290 | 51 | Luci Stanescu | [[BR]]''comment'':[[BR]] |
291 | 51 | Luci Stanescu | The comment of the response which is to be created. |
292 | 51 | Luci Stanescu | [[BR]]''wait'':[[BR]] |
293 | 51 | Luci Stanescu | If {{{True}}}, waits for the operation to complete. |
294 | 51 | Luci Stanescu | |
295 | 27 | Adrian Georgescu | '''read_chunk'''(''self'', '''size'''={{{None}}}):: |
296 | 1 | Adrian Georgescu | Waits for a new chunk and returns it. |
297 | 15 | Oliver Bril | If there was an error, closes the connection and raises {{{ChunkParseError}}}. |
298 | 27 | Adrian Georgescu | |
299 | 15 | Oliver Bril | In case of unintelligible input, loses the connection and returns {{{None}}}. |
300 | 39 | Luci Stanescu | When the connection is closed, raises the reason of the closure (e.g. {{{ConnectionDone}}}). |
301 | 15 | Oliver Bril | |
302 | 1 | Adrian Georgescu | If the data already read exceeds ''size'', stops reading the data and returns |
303 | 15 | Oliver Bril | a "virtual" chunk, i.e. the one that does not actually correspond the the real |
304 | 1 | Adrian Georgescu | MSRP chunk. Such chunks have Byte-Range header changed to match the number of |
305 | 48 | Luci Stanescu | bytes read and continuation that is {{{'+'}}}; they also possess {{{segment}}} attribute, |
306 | 15 | Oliver Bril | an integer, starting with 1 and increasing with every new segment of the chunk. |
307 | 1 | Adrian Georgescu | |
308 | 1 | Adrian Georgescu | Note, that ''size'' only hints when to interrupt the segment but does not affect |
309 | 1 | Adrian Georgescu | how the data is read from socket. You may have segments bigger than ''size'' and it's |
310 | 44 | Luci Stanescu | legal to set ''size'' to zero (which would mean return a chunk as long as you get |
311 | 39 | Luci Stanescu | some data, regardless how small). |
312 | 51 | Luci Stanescu | |
313 | 51 | Luci Stanescu | [[BR]]''size'':[[BR]] |
314 | 51 | Luci Stanescu | The hint towards how much to read from the socket. If the data already read is larger, then all the data will be returned, even if it exceeds {{{size}}} bytes. |
315 | 41 | Luci Stanescu | |
316 | 1 | Adrian Georgescu | '''check_incoming_SEND_chunk'''(''self'', '''chunk'''):: |
317 | 1 | Adrian Georgescu | Checks the 'To-Path' and 'From-Path' of the incoming SEND chunk. |
318 | 1 | Adrian Georgescu | Returns None is the paths are valid for this connection. |
319 | 1 | Adrian Georgescu | If an error is detected an MSRPError is created and returned. |
320 | 1 | Adrian Georgescu | |
321 | 51 | Luci Stanescu | == OutgoingFile == |
322 | 51 | Luci Stanescu | |
323 | 51 | Luci Stanescu | This class is implemented in the {{{msrplib.session}}} module and represents a file which is to be sent via MSRP. |
324 | 51 | Luci Stanescu | |
325 | 51 | Luci Stanescu | ==== attributes ==== |
326 | 51 | Luci Stanescu | |
327 | 51 | Luci Stanescu | '''headers''':: |
328 | 51 | Luci Stanescu | A dict which maps header names to header objects. These headers will be sent in the MSRP message used to send the file. |
329 | 51 | Luci Stanescu | |
330 | 51 | Luci Stanescu | ==== methods ==== |
331 | 51 | Luci Stanescu | |
332 | 51 | Luci Stanescu | '''!__init!__'''(''self'', '''fileobj''', '''size''', '''content_type'''={{{None}}}, '''position'''={{{0}}}, '''message_id'''={{{None}}}):: |
333 | 51 | Luci Stanescu | Initializes a new OutgoingFile using the specified file object. All arguments are available as attributes, except for {{{content_type}}} which will be part of the {{{headers}}} attribute. |
334 | 51 | Luci Stanescu | [[BR]]''fileobj'':[[BR]] |
335 | 51 | Luci Stanescu | A file-like object which will be used for reading the data to be sent. |
336 | 51 | Luci Stanescu | [[BR]]''size'':[[BR]] |
337 | 51 | Luci Stanescu | The size of the whole file. |
338 | 51 | Luci Stanescu | [[BR]]''content_type'':[[BR]] |
339 | 51 | Luci Stanescu | The MIME type associated with the file's data. If provided, it will be added as a Content-Type header. |
340 | 51 | Luci Stanescu | [[BR]]''position'':[[BR]] |
341 | 51 | Luci Stanescu | The position within the file from which data will be sent. The file object must already be seeked to this position. |
342 | 51 | Luci Stanescu | [[BR]]''message_id'':[[BR]] |
343 | 51 | Luci Stanescu | The message ID which will be used for sending this file. |
344 | 51 | Luci Stanescu | |
345 | 1 | Adrian Georgescu | == MSRPSession == |
346 | 1 | Adrian Georgescu | |
347 | 1 | Adrian Georgescu | This class is implemented in the {{{msrplib.session}}} module and provides a high level API for MSRP sessions. |
348 | 1 | Adrian Georgescu | |
349 | 1 | Adrian Georgescu | ==== methods ==== |
350 | 1 | Adrian Georgescu | |
351 | 1 | Adrian Georgescu | '''!__init!__'''(''self'', '''msrptransport''', '''accept_types'''={{{['*']}}}, '''on_incoming_cb'''={{{None}}}):: |
352 | 51 | Luci Stanescu | Initializes MSRPSession instance over the specified transport. The incoming chunks are reported through the ''on_incoming_cb'' callback. |
353 | 51 | Luci Stanescu | [[BR]]''msrptransport'':[[BR]] |
354 | 51 | Luci Stanescu | An instance of {{{MSRPTransport}}} over which this session will operate. |
355 | 51 | Luci Stanescu | [[BR]]''accept_types'':[[BR]] |
356 | 51 | Luci Stanescu | A list of MIME types which are acceptable over this session. If data is received with a Content-Type header which doesn't match this list, a negative response is sent back and the application does not get the received data. The special strings {{{'*'}}} and {{{'<type>/*'}}} can be used to match multiple MIME types. |
357 | 51 | Luci Stanescu | [[BR]]''on_incoming_cb'':[[BR]] |
358 | 51 | Luci Stanescu | A function which receives two arguments, both optional with default values of {{{None}}}: ''chunk'' and ''error''. This will be called when a new chunk is received. |
359 | 1 | Adrian Georgescu | |
360 | 1 | Adrian Georgescu | '''send_chunk'''(''self'', '''chunk''', '''response_cb'''={{{None}}}):: |
361 | 51 | Luci Stanescu | Sends the specified chunk and reports the result via the ''response_cb'' callback. |
362 | 1 | Adrian Georgescu | |
363 | 1 | Adrian Georgescu | When ''response_cb'' argument is present, it will be used to report |
364 | 1 | Adrian Georgescu | the transaction response to the caller. When a response is received or generated |
365 | 1 | Adrian Georgescu | locally, ''response_cb'' is called with one argument. The function must do something |
366 | 38 | Adrian Georgescu | quickly and must not block, because otherwise it would block the reader greenlet. |
367 | 39 | Luci Stanescu | |
368 | 1 | Adrian Georgescu | If no response was received after {{{RESPONSE_TIMEOUT}}} seconds, |
369 | 1 | Adrian Georgescu | * 408 response is generated if Failure-Report was {{{'yes'}}} or absent |
370 | 1 | Adrian Georgescu | * 200 response is generated if Failure-Report was {{{'partial'}}} or {{{'no'}}} |
371 | 1 | Adrian Georgescu | |
372 | 1 | Adrian Georgescu | Note that it's rather wasteful to provide ''response_cb'' argument other than {{{None}}} |
373 | 1 | Adrian Georgescu | for chunks with Failure-Report='no' since it will always fire 30 seconds later |
374 | 1 | Adrian Georgescu | with 200 result (unless the other party is broken and ignores Failure-Report header) |
375 | 1 | Adrian Georgescu | |
376 | 51 | Luci Stanescu | If sending is not possible, {{{MSRPSessionError}}} is raised. |
377 | 1 | Adrian Georgescu | |
378 | 51 | Luci Stanescu | [[BR]]''chunk'':[[BR]] |
379 | 51 | Luci Stanescu | The chunk which is to be sent. It must be an instance of {{{MSRPData}}} which represents a request. |
380 | 51 | Luci Stanescu | [[BR]]''response_cb'':[[BR]] |
381 | 51 | Luci Stanescu | A function receiving a single argument which will be the response received for the sent chunk. |
382 | 51 | Luci Stanescu | |
383 | 1 | Adrian Georgescu | '''deliver_chunk'''(''self'', '''chunk''', '''event'''={{{None}}}):: |
384 | 51 | Luci Stanescu | Sends the specified chunk and waits for the transaction response (if Failure-Report header is not {{{'no'}}}). |
385 | 51 | Luci Stanescu | Returns the transaction response if it's a success or raise {{{MSRPTransactionError}}} if it's not. |
386 | 1 | Adrian Georgescu | |
387 | 1 | Adrian Georgescu | If chunk's Failure-Report is {{{'no'}}}, returns {{{None}}} immediately. |
388 | 1 | Adrian Georgescu | |
389 | 51 | Luci Stanescu | [[BR]]''chunk'':[[BR]] |
390 | 51 | Luci Stanescu | The chunk which is to be sent. It must be an intance of {{{MSRPData}}} which represents a request. |
391 | 51 | Luci Stanescu | [[BR]]''event'':[[BR]] |
392 | 51 | Luci Stanescu | The {{{eventlet.coros.event}}} object which will be used to wait for a response. It's send method will be called when a response is received. If it is not provided, one will be constructed automatically and used. |
393 | 51 | Luci Stanescu | |
394 | 51 | Luci Stanescu | '''send_file'''(''self'', '''outgoing_file'''):: |
395 | 51 | Luci Stanescu | Adds the specified file to the queue of files to be sent. The method returns immediately. |
396 | 51 | Luci Stanescu | [[BR]]''outgoing_file'':[[BR]] |
397 | 51 | Luci Stanescu | An instance of {{{OutgoingFile}}} which represents the file to be sent. |
398 | 51 | Luci Stanescu | |
399 | 44 | Luci Stanescu | '''shutdown'''(''self'', '''sync'''={{{True}}}):: |
400 | 1 | Adrian Georgescu | Sends the messages already in queue then closes the connection. |
401 | 44 | Luci Stanescu | |
402 | 44 | Luci Stanescu | == MSRPServer == |
403 | 44 | Luci Stanescu | |
404 | 1 | Adrian Georgescu | This class is implemented in the {{{msrplib.connect}}} module. |
405 | 44 | Luci Stanescu | |
406 | 39 | Luci Stanescu | MSRPServer solves the problem with AcceptorDirect: concurrent using of 2 |
407 | 39 | Luci Stanescu | or more AcceptorDirect instances on the same non-zero port is not possible. |
408 | 49 | Adrian Georgescu | If you initialize() those instances, one after another, one will listen on |
409 | 1 | Adrian Georgescu | the socket and another will get BindError. |
410 | 1 | Adrian Georgescu | |
411 | 1 | Adrian Georgescu | MSRPServer avoids the problem by sharing the listening socket between multiple connections. |
412 | 39 | Luci Stanescu | It has a slightly different interface from AcceptorDirect, so it cannot be considered a drop-in |
413 | 46 | Luci Stanescu | replacement. |
414 | 46 | Luci Stanescu | |
415 | 1 | Adrian Georgescu | It manages the listening sockets and binds incoming requests. |
416 | 1 | Adrian Georgescu | |
417 | 1 | Adrian Georgescu | ==== methods ==== |
418 | 1 | Adrian Georgescu | |
419 | 1 | Adrian Georgescu | '''!__init!__'''(''self'', '''logger'''):: |
420 | 51 | Luci Stanescu | Constructs a new MSRPServer which will be using the specifed logger for its connections. |
421 | 51 | Luci Stanescu | [[BR]]''logger'':[[BR]] |
422 | 51 | Luci Stanescu | The default logger which will be used for this object's MSRP connections. See the [wiki:SipMSRPApi#Logging Logging] section for more information. |
423 | 1 | Adrian Georgescu | |
424 | 1 | Adrian Georgescu | '''prepare'''(''self'', ''local_uri''={{{None}}}, ''logger''={{{None}}}):: |
425 | 1 | Adrian Georgescu | Starts a listening port specified by ''local_uri'' if there isn't one on that port/interface already. |
426 | 1 | Adrian Georgescu | Adds ''local_uri'' to the list of expected URIs, so that incoming connections featuring this URI won't be rejected. |
427 | 51 | Luci Stanescu | If ''logger'' is provided, it uses it for this connection instead of the one specified in {{{__init___}}}. |
428 | 51 | Luci Stanescu | [[BR]]''local_uri'':[[BR]] |
429 | 51 | Luci Stanescu | The URI which will be added to the list of expected URIs. Connections from this URI will be accepted. |
430 | 51 | Luci Stanescu | [[BR]]''logger'':[[BR]] |
431 | 51 | Luci Stanescu | The logger which will be used for connections from the specified URI. See the [wiki:SipMSRPApi#Logging Logging] section for more information. |
432 | 15 | Oliver Bril | |
433 | 1 | Adrian Georgescu | '''complete'''(''self'', ''full_remote_path''):: |
434 | 51 | Luci Stanescu | Waits until one of the incoming connections binds using the provided ''full_remote_path''. |
435 | 51 | Luci Stanescu | Returns the connected and bound {{{MSRPTransport}}} instance. |
436 | 51 | Luci Stanescu | If no such binding was made within {{{MSRPBindSessionTimeout.seconds}}}, {{{MSRPBindSessionTimeout}}} is raised. |
437 | 51 | Luci Stanescu | [[BR]]''full_remote_path'':[[BR]] |
438 | 51 | Luci Stanescu | A list of {{{protocol.URI}}} instances, obtained by parsing {{{'a:path'}}} put in SDP by the remote party. |
439 | 38 | Adrian Georgescu | |
440 | 38 | Adrian Georgescu | '''cleanup'''(''self'', ''local_uri''):: |
441 | 46 | Luci Stanescu | Removes ''local_uri'' from the list of expected URIs. |
442 | 51 | Luci Stanescu | [[BR]]''local_uri'':[[BR]] |
443 | 51 | Luci Stanescu | The URI which is to be removed from the list of expected URIs. |
444 | 49 | Adrian Georgescu | |
445 | 46 | Luci Stanescu | == Logging == |
446 | 46 | Luci Stanescu | |
447 | 46 | Luci Stanescu | Logging is done throughout the library using objects defined by the application, called loggers. If logging is not desired, the {{{application.python.Null}}} object of {{{python-application}}} can be used. These loggers must define the following methods: |
448 | 46 | Luci Stanescu | |
449 | 46 | Luci Stanescu | ==== methods ==== |
450 | 46 | Luci Stanescu | |
451 | 46 | Luci Stanescu | '''received_new_chunk'''('''data''', '''transport''', '''chunk'''):: |
452 | 46 | Luci Stanescu | This method is called when the start of a new chunk is received. |
453 | 46 | Luci Stanescu | [[BR]]''data'':[[BR]] |
454 | 46 | Luci Stanescu | The data which came along with the start of the chunk. |
455 | 46 | Luci Stanescu | [[BR]]''transport'':[[BR]] |
456 | 46 | Luci Stanescu | The {{{MSRPTransport}}} instance on which the chunk was received. |
457 | 46 | Luci Stanescu | [[BR]]''chunk'':[[BR]] |
458 | 46 | Luci Stanescu | The actual chunk object. |
459 | 46 | Luci Stanescu | |
460 | 46 | Luci Stanescu | '''received_chunk_data'''('''data''', '''transport''', '''transaction_id'''):: |
461 | 46 | Luci Stanescu | This method is called when data is received as part of a chunk previously announced via '''received_new_chunk'''. |
462 | 46 | Luci Stanescu | [[BR]]''data'':[[BR]] |
463 | 46 | Luci Stanescu | The data received as part of the chunk. |
464 | 47 | Luci Stanescu | [[BR]]''transport'':[[BR]] |
465 | 46 | Luci Stanescu | The {{{MSRPTransport}}} instance on which the chunk was received. |
466 | 46 | Luci Stanescu | [[BR]]''transaction_id'':[[BR]] |
467 | 46 | Luci Stanescu | The transaction ID which identifies the chunk for which data was received. |
468 | 46 | Luci Stanescu | |
469 | 46 | Luci Stanescu | '''received_chunk_end'''('''data''', '''transport''', '''transaction_id'''):: |
470 | 46 | Luci Stanescu | This method is called when the last data of a chunk is received. The chunk was previously announced via '''received_new_chunk'''. |
471 | 46 | Luci Stanescu | [[BR]]''data'':[[BR]] |
472 | 46 | Luci Stanescu | The last data received as part of the chunk. |
473 | 46 | Luci Stanescu | [[BR]]''transport'':[[BR]] |
474 | 46 | Luci Stanescu | The {{{MSRPTransport}}} instance on which the chunk was received. |
475 | 46 | Luci Stanescu | [[BR]]''transaction_id'':[[BR]] |
476 | 46 | Luci Stanescu | The transaction ID which identifies the chunk which was ended. |
477 | 46 | Luci Stanescu | |
478 | 46 | Luci Stanescu | '''sent_new_chunk'''('''data''', '''transport''', '''chunk'''):: |
479 | 46 | Luci Stanescu | This method is called when the start of a new chunk is sent. |
480 | 46 | Luci Stanescu | [[BR]]''data'':[[BR]] |
481 | 46 | Luci Stanescu | The data which was sent along with the start of the chunk. |
482 | 46 | Luci Stanescu | [[BR]]''transport'':[[BR]] |
483 | 46 | Luci Stanescu | The {{{MSRPTransport}}} instance on which the chunk was sent. |
484 | 46 | Luci Stanescu | [[BR]]''chunk'':[[BR]] |
485 | 46 | Luci Stanescu | The actual chunk object. |
486 | 46 | Luci Stanescu | |
487 | 46 | Luci Stanescu | '''sent_chunk_data'''('''data''', '''transport''', '''transaction_id'''):: |
488 | 46 | Luci Stanescu | This method is called when data is sent as part of a chunk previously announced via '''sent_new_chunk'''. |
489 | 46 | Luci Stanescu | [[BR]]''data'':[[BR]] |
490 | 46 | Luci Stanescu | The data sent as part of the chunk. |
491 | 47 | Luci Stanescu | [[BR]]''transport'':[[BR]] |
492 | 46 | Luci Stanescu | The {{{MSRPTransport}}} instance on which the chunk was sent. |
493 | 46 | Luci Stanescu | [[BR]]''transaction_id'':[[BR]] |
494 | 46 | Luci Stanescu | The transaction ID which identifies the chunk for which data was sent. |
495 | 46 | Luci Stanescu | |
496 | 46 | Luci Stanescu | '''sent_chunk_end'''('''data''', '''transport''', '''transaction_id'''):: |
497 | 46 | Luci Stanescu | This method is called when the last data of a chunk is sent. The chunk was previously announced via '''sent_new_chunk'''. |
498 | 46 | Luci Stanescu | [[BR]]''data'':[[BR]] |
499 | 46 | Luci Stanescu | The last data sent as part of the chunk. |
500 | 46 | Luci Stanescu | [[BR]]''transport'':[[BR]] |
501 | 46 | Luci Stanescu | The {{{MSRPTransport}}} instance on which the chunk was sent. |
502 | 46 | Luci Stanescu | [[BR]]''transaction_id'':[[BR]] |
503 | 46 | Luci Stanescu | The transaction ID which identifies the chunk which was ended. |
504 | 46 | Luci Stanescu | |
505 | 46 | Luci Stanescu | '''debug'''('''message'''):: |
506 | 46 | Luci Stanescu | This method is called when a debug level message is sent by the library. |
507 | 46 | Luci Stanescu | |
508 | 46 | Luci Stanescu | '''info'''('''message'''):: |
509 | 46 | Luci Stanescu | This method is called when a info level message is sent by the library. |
510 | 46 | Luci Stanescu | |
511 | 46 | Luci Stanescu | '''warn'''('''message'''):: |
512 | 46 | Luci Stanescu | This method is called when a warning level message is sent by the library. |
513 | 46 | Luci Stanescu | |
514 | 38 | Adrian Georgescu | '''error'''('''message'''):: |
515 | 39 | Luci Stanescu | This method is called when a error level message is sent by the library. |
516 | 38 | Adrian Georgescu | |
517 | 38 | Adrian Georgescu | '''fatal'''('''message'''):: |
518 | 38 | Adrian Georgescu | This method is called when a fatal level message is sent by the library. |
519 | 38 | Adrian Georgescu | |
520 | 38 | Adrian Georgescu | == Example == |
521 | 38 | Adrian Georgescu | |
522 | 38 | Adrian Georgescu | === Establish a connection === |
523 | 38 | Adrian Georgescu | |
524 | 38 | Adrian Georgescu | {{{msrplib.connect}}} provides a number of classes to establish a connection, so the first |
525 | 38 | Adrian Georgescu | thing to do is to select which one applies to your situation: |
526 | 38 | Adrian Georgescu | |
527 | 38 | Adrian Georgescu | 1. Calling endpoint, not using a relay ({{{ConnectorDirect}}}) |
528 | 38 | Adrian Georgescu | 2. Answering endpoint, not using a relay ({{{AcceptorDirect}}}) |
529 | 38 | Adrian Georgescu | 3. Calling endpoint, using a relay ({{{ConnectorRelay}}}) |
530 | 38 | Adrian Georgescu | 4. Answering endpoint, using a relay ({{{AcceptorRelay}}}) |
531 | 38 | Adrian Georgescu | |
532 | 38 | Adrian Georgescu | The answering endpoint may skip using the relay if sure that it's accessible directly, e.g is not behind a NAT. To be sure it works in any network topology a called end-point should always use a relay. |
533 | 38 | Adrian Georgescu | |
534 | 38 | Adrian Georgescu | The calling endpoint does not need a relay as the protocol mandates that it is establishing an outbound connection which always work from behind a NAT. |
535 | 38 | Adrian Georgescu | |
536 | 38 | Adrian Georgescu | Once you have an instance of the right class (use the convenience functions |
537 | 38 | Adrian Georgescu | {{{get_connector()}}} and {{{get_acceptor()}}} to get one), the procedure to establish the |
538 | 38 | Adrian Georgescu | connection is the same: |
539 | 38 | Adrian Georgescu | |
540 | 38 | Adrian Georgescu | {{{ |
541 | 38 | Adrian Georgescu | full_local_path = connector.prepare() |
542 | 38 | Adrian Georgescu | try: |
543 | 38 | Adrian Georgescu | ... put full_local_path in SDP 'a:path' attribute |
544 | 38 | Adrian Georgescu | ... get full_remote_path from remote's 'a:path: attribute |
545 | 38 | Adrian Georgescu | ... (the order of the above steps is reversed if you're the |
546 | 38 | Adrian Georgescu | ... answering party, but that does not affect connector's usage) |
547 | 38 | Adrian Georgescu | msrptransport = connector.complete(full_remote_path) |
548 | 38 | Adrian Georgescu | finally: |
549 | 38 | Adrian Georgescu | connector.cleanup() |
550 | 38 | Adrian Georgescu | }}} |
551 | 38 | Adrian Georgescu | |
552 | 38 | Adrian Georgescu | To customize connection's parameters, creates a new {{{protocol.URI}}} object and passes |
553 | 38 | Adrian Georgescu | it to prepare() function, e.g. |
554 | 38 | Adrian Georgescu | {{{ |
555 | 38 | Adrian Georgescu | local_uri = protocol.URI(use_tls=False, port=5000) |
556 | 38 | Adrian Georgescu | connector.prepare(local_uri) |
557 | 38 | Adrian Georgescu | }}} |
558 | 1 | Adrian Georgescu | |
559 | 1 | Adrian Georgescu | {{{prepare()}}} may update {{{local_uri}}} in place with the actual connection parameters |
560 | 1 | Adrian Georgescu | used (e.g. if you specified port=0). 'port' attribute of {{{local_uri}}} is currently |
561 | 1 | Adrian Georgescu | only respected by {{{AcceptorDirect}}}. |
562 | 1 | Adrian Georgescu | |
563 | 1 | Adrian Georgescu | Note that, acceptors and connectors are one-use only. Which means, that {{{AcceptorDirect}}} |
564 | 1 | Adrian Georgescu | will open a port just to handle one incoming connection and close it right after. |
565 | 1 | Adrian Georgescu | If your application behaves more like a server, i.e. opens a port and listens on it |
566 | 1 | Adrian Georgescu | constantly, use {{{MSRPServer}}} class. |