~certify-web-dev/twisted/certify-staging

« back to all changes in this revision

Viewing changes to doc/specifications/banana.html

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-01-02 19:38:17 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100102193817-jphp464ppwh7dulg
Tags: 9.0.0-1
* python-twisted: Depend on the python-twisted-* 9.0 packages.
* python-twisted: Depend on python-zope.interface only. Closes: #557781.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><title>Twisted Documentation: Banana Protocol Specifications</title><link href="../howto/stylesheet.css" type="text/css" rel="stylesheet" /></head><body bgcolor="white"><h1 class="title">Banana Protocol Specifications</h1><div class="toc"><ol><li><a href="#auto0">Introduction</a></li><li><a href="#auto1">Banana Encodings</a></li><li><a href="#auto2">Element Types</a></li><ul><li><a href="#auto3">Examples</a></li></ul><li><a href="#auto4">Profiles</a></li><ul><li><a href="#auto5">The &quot;none&quot; Profile</a></li><li><a href="#auto6">The &quot;pb&quot; Profile</a></li></ul><li><a href="#auto7">Protocol Handshake and Behaviour</a></li></ol></div><div class="content"><span></span><h2>Introduction<a name="auto0"></a></h2><p>
 
1
<?xml version="1.0" encoding="utf-8"?>
 
2
<!DOCTYPE html
 
3
  PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
 
4
  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
 
5
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
 
6
  <head>
 
7
<title>Twisted Documentation: Banana Protocol Specifications</title>
 
8
<link href="../howto/stylesheet.css" rel="stylesheet" type="text/css"/>
 
9
  </head>
 
10
 
 
11
  <body bgcolor="white">
 
12
    <h1 class="title">Banana Protocol Specifications</h1>
 
13
    <div class="toc"><ol><li><a href="#auto0">Introduction</a></li><li><a href="#auto1">Banana Encodings</a></li><li><a href="#auto2">Element Types</a></li><ul><li><a href="#auto3">Examples</a></li></ul><li><a href="#auto4">Profiles</a></li><ul><li><a href="#auto5">The &quot;none&quot; Profile</a></li><li><a href="#auto6">The &quot;pb&quot; Profile</a></li></ul><li><a href="#auto7">Protocol Handshake and Behaviour</a></li></ol></div>
 
14
    <div class="content">
 
15
    <span/>
 
16
 
 
17
    <h2>Introduction<a name="auto0"/></h2>
 
18
 
 
19
    <p>
3
20
      Banana is an efficient, extendable protocol for sending and receiving s-expressions.
4
21
      A s-expression in this context is a list composed of byte strings, integers, 
5
22
      large integers, floats and/or s-expressions.
6
 
    </p><h2>Banana Encodings<a name="auto1"></a></h2><p>
 
23
    </p>
 
24
 
 
25
    <h2>Banana Encodings<a name="auto1"/></h2>
 
26
 
 
27
    <p>
7
28
      The banana protocol is a stream of data composed of elements. Each element has the
8
29
      following general structure - first, the length of element encoded in base-128, least signficant
9
30
      bit first. For example length 4674 will be sent as <code>0x42 0x24</code>. For certain element
10
31
      types the length will be omitted (e.g. float) or have a different meaning (it is the actual
11
32
      value of integer elements).
12
 
    </p><p>
 
33
    </p>
 
34
 
 
35
    <p>
13
36
      Following the length is a delimiter byte, which tells us what kind of element this
14
37
      is. Depending on the element type, there will then follow the number of bytes specified
15
38
      in the length. The byte's high-bit will always be set, so that we can differentiate
16
39
      between it and the length (since the length bytes use 128-base, their high bit will
17
40
      never be set).
18
 
    </p><h2>Element Types<a name="auto2"></a></h2><p>
 
41
    </p>
 
42
 
 
43
    <h2>Element Types<a name="auto2"/></h2>
 
44
 
 
45
    <p>
19
46
      Given a series of bytes that gave us length N, these are the different delimiter bytes:
20
 
    </p><dl><dt>List -- 0x80</dt><dd>The following bytes are a list of N elements.  Lists may be nested,
 
47
    </p>
 
48
 
 
49
    <dl>
 
50
      <dt>List -- 0x80</dt>
 
51
      
 
52
      <dd>The following bytes are a list of N elements.  Lists may be nested,
21
53
        and a child list counts as only one element to its parent (regardless
22
 
        of how many elements the child list contains). </dd><dt>Integer -- 0x81</dt><dd>The value of this element is the positive integer N. Following bytes are not part of this element. Integers can have values of 0 &lt;= N &lt;= 2147483647.</dd><dt>String -- 0x82</dt><dd>The following N bytes are a string element.</dd><dt>Negative Integer -- 0x83</dt><dd>The value of this element is the integer N * -1, i.e. -N. Following bytes are not part of this element. Negative integers can have values of 0 &gt;= -N &gt;= -2147483648.</dd><dt>Float - 0x84</dt><dd>The next 8 bytes are the float encoded in IEEE 754 floating-point <q>double format</q> bit layout.
 
54
        of how many elements the child list contains). </dd>
 
55
 
 
56
      <dt>Integer -- 0x81</dt>
 
57
      <dd>The value of this element is the positive integer N. Following bytes are not part of this element. Integers can have values of 0 &lt;= N &lt;= 2147483647.</dd>
 
58
 
 
59
      <dt>String -- 0x82</dt>
 
60
      <dd>The following N bytes are a string element.</dd>
 
61
 
 
62
      <dt>Negative Integer -- 0x83</dt>
 
63
      <dd>The value of this element is the integer N * -1, i.e. -N. Following bytes are not part of this element. Negative integers can have values of 0 &gt;= -N &gt;= -2147483648.</dd>
 
64
 
 
65
      <dt>Float - 0x84</dt>
 
66
      <dd>The next 8 bytes are the float encoded in IEEE 754 floating-point <q>double format</q> bit layout.
23
67
        No length bytes should have been defined.
24
 
      </dd><dt>Large Integer -- 0x85</dt><dd>The value of this element is the positive large integer N. Following bytes are not part of this element. Large integers have no size limitation.</dd><dt>Large Negative Integer -- 0x86</dt><dd>The value of this element is the negative large integer -N. Following bytes are not part of this element. Large integers have no size limitation.</dd></dl><p>
 
68
      </dd>
 
69
 
 
70
      <dt>Large Integer -- 0x85</dt>
 
71
      <dd>The value of this element is the positive large integer N. Following bytes are not part of this element. Large integers have no size limitation.</dd>
 
72
 
 
73
      <dt>Large Negative Integer -- 0x86</dt>
 
74
      <dd>The value of this element is the negative large integer -N. Following bytes are not part of this element. Large integers have no size limitation.</dd>
 
75
    </dl>
 
76
 
 
77
    <p>
25
78
      Large integers are intended for arbitary length integers. Regular integers types (positive and negative) are limited to 32-bit values.
26
 
    </p><h3>Examples<a name="auto3"></a></h3><p>
 
79
    </p>
 
80
 
 
81
    <h3>Examples<a name="auto3"/></h3>
 
82
 
 
83
    <p>
27
84
      Here are some examples of elements and their encodings - the type bytes are marked in bold:
28
 
    </p><dl><dt><code>1</code></dt><dd><code>0x01 <strong>0x81</strong></code></dd><dt><code>-1</code></dt><dd><code>0x01 <strong>0x83</strong></code></dd><dt><code>1.5</code></dt><dd><code><strong>0x84</strong> 0x3f 0xf8 0x00 0x00 0x00 0x00 0x00 0x00</code></dd><dt><code>&quot;hello&quot;</code></dt><dd><code>0x05 <strong>0x82</strong> 0x68 0x65 0x6c 0x6c 0x6f</code></dd><dt><code>[]</code></dt><dd><code>0x00 <strong>0x80</strong></code></dd><dt><code>[1, 23]</code></dt><dd><code>0x02 <strong>0x80</strong> 0x01 <strong>0x81</strong> 0x17 <strong>0x81</strong></code></dd><dt><code>123456789123456789</code></dt><dd><code>0x15 0x3e 0x41 0x66 0x3a 0x69 0x26 0x5b 0x01 <strong>0x85</strong></code></dd><dt><code>[1, [&quot;hello&quot;]]</code></dt><dd><code>0x02 <strong>0x80</strong> 0x01 <strong>0x81</strong> 0x01 <strong>0x80</strong> 0x05 <strong>0x82</strong> 0x68 0x65 0x6c 0x6c 0x6f</code></dd></dl><h2>Profiles<a name="auto4"></a></h2><p>
 
85
    </p>
 
86
 
 
87
    <dl>
 
88
      <dt><code>1</code></dt>
 
89
      <dd><code>0x01 <strong>0x81</strong></code></dd>
 
90
      <dt><code>-1</code></dt>
 
91
      <dd><code>0x01 <strong>0x83</strong></code></dd>
 
92
      <dt><code>1.5</code></dt>
 
93
      <dd><code><strong>0x84</strong> 0x3f 0xf8 0x00 0x00 0x00 0x00 0x00 0x00</code></dd>
 
94
      <dt><code>&quot;hello&quot;</code></dt>
 
95
      <dd><code>0x05 <strong>0x82</strong> 0x68 0x65 0x6c 0x6c 0x6f</code></dd>
 
96
      <dt><code>[]</code></dt>
 
97
      <dd><code>0x00 <strong>0x80</strong></code></dd>
 
98
      <dt><code>[1, 23]</code></dt>
 
99
      <dd><code>0x02 <strong>0x80</strong> 0x01 <strong>0x81</strong> 0x17 <strong>0x81</strong></code></dd>
 
100
      <dt><code>123456789123456789</code></dt>
 
101
      <dd><code>0x15 0x3e 0x41 0x66 0x3a 0x69 0x26 0x5b 0x01 <strong>0x85</strong></code></dd>
 
102
      <dt><code>[1, [&quot;hello&quot;]]</code></dt>
 
103
      <dd><code>0x02 <strong>0x80</strong> 0x01 <strong>0x81</strong> 0x01 <strong>0x80</strong> 0x05 <strong>0x82</strong> 0x68 0x65 0x6c 0x6c 0x6f</code></dd>
 
104
    </dl>
 
105
 
 
106
    <h2>Profiles<a name="auto4"/></h2>
 
107
    
 
108
    <p>
29
109
      The Banana protocol is extendable. Therefore, it supports the concept of profiles. Profiles allow
30
110
      developers to extend the banana protocol, adding new element types, while still keeping backwards
31
111
      compatability with implementations that don't support the extensions. The profile used in each
32
112
      session is determined at the handshake stage (see below.)
33
 
    </p><p>
 
113
    </p>
 
114
 
 
115
    <p>
34
116
      A profile is specified by a unique string. This specification defines two profiles
35
117
      - <code>&quot;none&quot;</code> and <code>&quot;pb&quot;</code>. The <code>&quot;none&quot;</code> profile is the standard
36
118
      profile that should be supported by all Banana implementations.
37
119
      Additional profiles may be added in the future.
38
 
    </p><h3>The <code>&quot;none&quot;</code> Profile<a name="auto5"></a></h3><p>
 
120
    </p>
 
121
    
 
122
    <h3>The <code>&quot;none&quot;</code> Profile<a name="auto5"/></h3>
 
123
 
 
124
    <p>
39
125
      The <code>&quot;none&quot;</code> profile is identical to the delimiter types listed above. It is highly recommended
40
126
      that all Banana clients and servers support the <code>&quot;none&quot;</code> profile.
41
 
    </p><h3>The <code>&quot;pb&quot;</code> Profile<a name="auto6"></a></h3><p>
 
127
    </p>
 
128
 
 
129
    <h3>The <code>&quot;pb&quot;</code> Profile<a name="auto6"/></h3>
 
130
 
 
131
    <p>
42
132
      The <code>&quot;pb&quot;</code> profile is intended for use with the Perspective Broker protocol, that runs on top
43
133
      of Banana. Basically, it converts commonly used PB strings into shorter versions, thus
44
 
      minimizing bandwidth usage. It does this by adding an additional delimiter byte, 0x87.
45
 
      This byte should not be prefixed by a length. It should be followed by a single byte, which
46
 
      tells us to which string element to convert it:
47
 
    </p><dl><dt>0x01</dt><dd>'None'</dd><dt>0x02</dt><dd>'class'</dd><dt>0x03</dt><dd>'dereference'</dd><dt>0x04</dt><dd>'reference'</dd><dt>0x05</dt><dd>'dictionary'</dd><dt>0x06</dt><dd>'function'</dd><dt>0x07</dt><dd>'instance'</dd><dt>0x08</dt><dd>'list'</dd><dt>0x09</dt><dd>'module'</dd><dt>0x0a</dt><dd>'persistent'</dd><dt>0x0b</dt><dd>'tuple'</dd><dt>0x0c</dt><dd>'unpersistable'</dd><dt>0x0d</dt><dd>'copy'</dd><dt>0x0e</dt><dd>'cache'</dd><dt>0x0f</dt><dd>'cached'</dd><dt>0x10</dt><dd>'remote'</dd><dt>0x11</dt><dd>'local'</dd><dt>0x12</dt><dd>'lcache'</dd><dt>0x13</dt><dd>'version'</dd><dt>0x14</dt><dd>'login'</dd><dt>0x15</dt><dd>'password'</dd><dt>0x16</dt><dd>'challenge'</dd><dt>0x17</dt><dd>'logged_in'</dd><dt>0x18</dt><dd>'not_logged_in'</dd><dt>0x19</dt><dd>'cachemessage'</dd><dt>0x1a</dt><dd>'message'</dd><dt>0x1b</dt><dd>'answer'</dd><dt>0x1c</dt><dd>'error'</dd><dt>0x1d</dt><dd>'decref'</dd><dt>0x1e</dt><dd>'decache'</dd><dt>0x1f</dt><dd>'uncache'</dd></dl><h2>Protocol Handshake and Behaviour<a name="auto7"></a></h2><p>
 
134
      minimizing bandwidth usage. It starts with a single byte, which tells us to which string element
 
135
      to convert it, and ends with the delimiter byte, <code>0x87</code>, which should not be prefixed
 
136
      by a length.
 
137
    </p>
 
138
    
 
139
    <dl>
 
140
      <dt>0x01</dt> <dd>'None'</dd>
 
141
      <dt>0x02</dt> <dd>'class'</dd>
 
142
      <dt>0x03</dt> <dd>'dereference'</dd>
 
143
      <dt>0x04</dt> <dd>'reference'</dd>
 
144
      <dt>0x05</dt> <dd>'dictionary'</dd>
 
145
      <dt>0x06</dt> <dd>'function'</dd>
 
146
      <dt>0x07</dt> <dd>'instance'</dd>
 
147
      <dt>0x08</dt> <dd>'list'</dd>
 
148
      <dt>0x09</dt> <dd>'module'</dd>
 
149
      <dt>0x0a</dt> <dd>'persistent'</dd>
 
150
      <dt>0x0b</dt> <dd>'tuple'</dd>
 
151
      <dt>0x0c</dt> <dd>'unpersistable'</dd>
 
152
      <dt>0x0d</dt> <dd>'copy'</dd>
 
153
      <dt>0x0e</dt> <dd>'cache'</dd>
 
154
      <dt>0x0f</dt> <dd>'cached'</dd>
 
155
      <dt>0x10</dt> <dd>'remote'</dd>
 
156
      <dt>0x11</dt> <dd>'local'</dd>
 
157
      <dt>0x12</dt> <dd>'lcache'</dd>
 
158
      <dt>0x13</dt> <dd>'version'</dd>
 
159
      <dt>0x14</dt> <dd>'login'</dd>
 
160
      <dt>0x15</dt> <dd>'password'</dd>
 
161
      <dt>0x16</dt> <dd>'challenge'</dd>
 
162
      <dt>0x17</dt> <dd>'logged_in'</dd>
 
163
      <dt>0x18</dt> <dd>'not_logged_in'</dd>
 
164
      <dt>0x19</dt> <dd>'cachemessage'</dd>
 
165
      <dt>0x1a</dt> <dd>'message'</dd>
 
166
      <dt>0x1b</dt> <dd>'answer'</dd>
 
167
      <dt>0x1c</dt> <dd>'error'</dd>
 
168
      <dt>0x1d</dt> <dd>'decref'</dd>
 
169
      <dt>0x1e</dt> <dd>'decache'</dd>
 
170
      <dt>0x1f</dt> <dd>'uncache'</dd>
 
171
      </dl>
 
172
 
 
173
    <h2>Protocol Handshake and Behaviour<a name="auto7"/></h2>
 
174
 
 
175
    <p>
48
176
      The initiating side of the connection will be referred to as <q>client</q>, and the other
49
177
      side as <q>server</q>.
50
 
    </p><p>
 
178
    </p>
 
179
 
 
180
    <p>
51
181
      Upon connection, the server will send the client a list of string elements, signifying
52
182
      the profiles it supports. It is recommended that <code>&quot;none&quot;</code> be included in this list. The client
53
183
      then sends the server a string from this list, telling the server which profile it wants to
54
184
      use. At this point the whole session will use this profile.
55
 
    </p><p>
 
185
    </p>
 
186
    
 
187
    <p>
56
188
      Once a profile has been established, the two sides may start exchanging elements. There is no
57
189
      limitation on order or dependencies of messages. Any such limitation (e.g. <q>server can only
58
190
      send an element to client in response to a request from client</q>) is application specific.
59
 
    </p><p>
 
191
    </p>
 
192
 
 
193
    <p>
60
194
      Upon receiving illegal messages, failed handshakes, etc., a Banana client or server should
61
195
      close its connection.
62
 
    </p></div><p><a href="../howto/index.html">Index</a></p><span class="version">Version: 8.2.0</span></body></html>
 
 
b'\\ No newline at end of file'
 
196
    </p>
 
197
 
 
198
  </div>
 
199
 
 
200
    <p><a href="../howto/index.html">Index</a></p>
 
201
    <span class="version">Version: 9.0.0</span>
 
202
  </body>
 
203
</html>
 
 
b'\\ No newline at end of file'