~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to doc/developers/network-protocol.txt

  • Committer: Martin Pool
  • Date: 2008-05-02 02:31:14 UTC
  • mfrom: (3399 +trunk)
  • mto: (3408.1.1 doc)
  • mto: This revision was merged to the branch mainline in revision 3409.
  • Revision ID: mbp@sourcefrog.net-20080502023114-y2gcg3w3jc770j9m
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
 
119
119
  REQUEST := MESSAGE_V1
120
120
  RESPONSE := MESSAGE_V1
121
 
  MESSAGE_V1 := ARGS BODY
 
121
  MESSAGE_V1 := ARGS [BODY]
122
122
 
123
123
  ARGS := ARG [MORE_ARGS] NEWLINE
124
124
  MORE_ARGS := SEP ARG [MORE_ARGS]
144
144
 
145
145
The response protocol is::
146
146
 
147
 
  RESPONSE_V2 := "bzr response 2" NEWLINE MESSAGE_V2
 
147
  RESPONSE_V2 := "bzr response 2" NEWLINE RESPONSE_STATUS NEWLINE MESSAGE_V2
 
148
  RESPONSE_STATUS := "success" | "failed"
148
149
 
149
150
Future versions should follow this structure, like version two does::
150
151
 
160
161
 
161
162
Version two of the message protocol is::
162
163
 
163
 
  MESSAGE_V2 := ARGS BODY
 
164
  MESSAGE_V2 := ARGS [BODY_V2]
164
165
  BODY_V2 := BODY | STREAMED_BODY
165
166
 
166
167
That is, a version one length-prefixed body, or a version two streamed
174
175
 
175
176
  STREAMED_BODY := "chunked" NEWLINE CHUNKS TERMINATOR
176
177
  CHUNKS := CHUNK [CHUNKS]
177
 
  CHUNK := CHUNK_LENGTH CHUNK_CONTENT
178
 
  CHUNK_LENGTH := HEX_DIGITS NEWLINE
 
178
  CHUNK := HEX_LENGTH CHUNK_CONTENT
 
179
  HEX_LENGTH := HEX_DIGITS NEWLINE
179
180
  CHUNK_CONTENT := bytes
180
181
  
181
182
  TERMINATOR := SUCCESS_TERMINATOR | ERROR_TERMINATOR
196
197
same for a given request method.  Only new request methods introduced in
197
198
Bazaar 0.91 and later use streamed bodies.
198
199
 
 
200
Version three
 
201
-------------
 
202
 
 
203
.. note::
 
204
  
 
205
  For some discussion of the requirements that led to this new protocol
 
206
  version, see `bug #83935`_.
 
207
 
 
208
.. _bug #83935: https://bugs.launchpad.net/bzr/+bug/83935
 
209
 
 
210
Version three has bencoding of most protocol structures, to make parsing
 
211
simpler.  For extra parsing convenience, these structures are length
 
212
prefixed::
 
213
 
 
214
  LENGTH_PREFIX := 32-bit unsigned integer in network byte order
 
215
 
 
216
Unlike earlier versions, clients and servers are no longer required to
 
217
know which request verbs and responses will have bodies attached.  Because
 
218
of length-prefixing and other changes, it is always possible to know when
 
219
a complete request or response has been read, even if the server
 
220
implements no verbs.
 
221
 
 
222
The underlying message format is::
 
223
 
 
224
  MESSAGE := "bzr message 3" NEWLINE HEADERS MESSAGE_PARTS
 
225
  HEADERS := LENGTH_PREFIX bencoded_dict
 
226
  MESSAGE_PARTS := MESSAGE_PART [MORE_MESSAGE_PARTS]
 
227
  MORE_MESSAGE_PARTS := END_MESSAGE_PARTS | MESSAGE_PARTS
 
228
  END_MESSAGE_PARTS := "e"
 
229
 
 
230
  MESSAGE_PART := ONE_BYTE | STRUCTURE | BYTES
 
231
  ONE_BYTE := "o" byte
 
232
  STRUCTURE := "s" LENGTH_PREFIX bencoded_structure
 
233
  BYTES := "b" LENGTH_PREFIX bytes
 
234
 
 
235
This format allows an arbitrary sequence of message parts to be encoded
 
236
in a single message.
 
237
 
 
238
Headers
 
239
~~~~~~~
 
240
 
 
241
Each request and response will have “headers”, a dictionary of key-value pairs.
 
242
The keys must be strings, not any other type of value.
 
243
 
 
244
Currently, the only defined header is “Software version”.  Both the client and
 
245
the server should include a “Software version” header, with a value of a
 
246
free-form string such as “bzrlib 1.5”, to aid debugging and logging.  Clients
 
247
and servers **should not** vary behaviour based on this string.
 
248
 
 
249
Conventional requests and responses
 
250
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
251
 
 
252
By convention, most requests and responses have a simple “arguments plus
 
253
optional body” structure, as in earlier protocol versions.  This section
 
254
describes how such messages are encoded.  All requests and responses
 
255
defined by earlier protocol versions must be encoded in this way.
 
256
 
 
257
Conventional requests will send a sequence of:
 
258
 
 
259
* Arguments (a STRUCTURE of a tuple)
 
260
 
 
261
* (Optional) body
 
262
 
 
263
  * Single body (BYTES), or
 
264
 
 
265
  * Streamed body (multiple BYTES parts), followed by a status (ONE_BYTE)
 
266
 
 
267
    * if status is "E", followed by an Error (STRUCTURE)
 
268
 
 
269
Conventional responses will send a sequence of:
 
270
 
 
271
* Status (ONE_BYTE)
 
272
 
 
273
* Arguments (a STRUCTURE of a tuple)
 
274
 
 
275
* (Optional) body
 
276
 
 
277
  * Single body (BYTES), or
 
278
 
 
279
  * Streamed body (multiple BYTES parts), followed by a status (ONE_BYTE)
 
280
 
 
281
    * if status is "E", followed by an Error (STRUCTURE)
 
282
 
 
283
In all cases, the ONE_BYTE status is either "S" for Success or "E" for
 
284
Error.  Note that the streamed body from version two is now just multiple
 
285
BYTES parts.
 
286
 
 
287
For new methods, these sequences are just a convention and may be varied
 
288
if appropriate for a particular request or response.  However, each
 
289
request should at least start with a STRUCTURE encoding the arguments
 
290
tuple.  The first element of that tuple must be a string that names the
 
291
request method.  (Note that arguments in this protocol version are
 
292
bencoded.  As a result, unlike previous protocol versions, arguments in
 
293
this version are 8-bit clean.)
 
294
 
 
295
For errors (where the Status byte of a response or a streamed body is
 
296
"E"), the situation is analagous to requests.  The first item in the
 
297
encoded sequence must be a string of the error name.  The other arguments
 
298
supply details about the error, and their number and types will depend on
 
299
the type of error (as identified by the error name).
 
300
 
199
301
Paths
200
302
=====
201
303
 
230
332
Contributions welcome!
231
333
 
232
334
 
 
335
Recognised errors
 
336
=================
 
337
 
 
338
The first argument of an error response specifies the error type.
 
339
 
 
340
One possible error name is ``UnknownMethod``, which means the server does
 
341
not recognise the verb used by the client's request.  This error was
 
342
introduced in version three.
 
343
 
 
344
**XXX**: ideally the error types should be documented here.  Contributions
 
345
welcome!
 
346
 
233
347
..
234
348
   vim: ft=rst tw=74 ai
235
349