151144b61130e84e27cedf4c5bb53f5794d17b8f
[spider.git] / techdoc / protocol.pod
1 =head1 NAME
2
3 DXSpiderWeb Orthogonal Communications Protocol $Revision$
4
5 =head1 SYNOPSIS
6
7  <Origin>,<TimeSeq>,<Hop>,<FrmUser>,<To>,<ToUser>|<Tag>,<Data>...
8
9 =head1 ABSTRACT
10
11 For many years DX Clusters have used a protocol which was designed 
12 for a non-looped tree of nodes. This has probably never, reliably, 
13 been achieved in practice; certainly not recently. This document 
14 describes a complete replacement for that protocol. It allows a
15 fully looped network, is inherently extensible and should be simple
16 to implement (especially in perl).
17
18 All implementations of this protocol shall B<only> use this protocol
19 for inter-node communications. 
20
21 =head1 DESCRIPTION
22
23 This protocol is encoded in UTF8 with HTTP style escaping. It is
24 designed to be an extensible basis for any type of one to many
25 "instant" line-based communications tasks.
26
27 This protocol is designed to be flood routed in a meshed network in
28 as efficient a manner as possible.
29
30 Each message consists of a L</Routing Section> and a L</Command Section>. 
31 The two sections are separated with the '|' character and the whole
32 message is terminated in the standard RFC/Internet manner with the
33 ascii <carraige return><linefeed> characters. It follows that these
34 characters (as well as a small number of other reserved characters)
35 can only be sent escaped. This is described further in the 
36 L</Command Section>.
37
38 Most of this document is concerned with the L</Routing Section>, however
39 some L</Standard Commands> which all implementation should issue and
40 must accept are described.
41
42 =head1 Routing Section
43
44 The application that implements this protocol is essentially a line
45 oriented message router. One line equals one message. Each line is
46 effectively a datagram. 
47
48 It is assumed that nodes are connected to
49 each other using a "reliable" streaming protocol such as TCP/IP or
50 AX25. Having said that: in context, messages in this protocol could be 
51 multi/broadcast, either "as is" or wrapped in some other framing
52 protocol. 
53
54 Because this is an unreliable, best effort, "please route my packets
55 through your node" protocol, there is no guarantee that a message
56 will get to the other side of a mesh of nodes. There may be a
57 discontinuity either caused by outage or deliberate filtering. 
58
59 However, as it is envisaged that most messages will be flood routed or,
60 in the case of directed messages (those that have L</To> and/or
61 L</ToUser> fields) down some/most/all interfaces showing a route for that
62 direction, it is unlikely that messages will be lost in practice.
63
64 =head2 Field Description
65
66 Only the first three fields in the L</Routing Section> are compulsory
67 and indicate that this is a broadcast to be sent to all nodes coming
68 from the L</Origin>. If the message needs to be identified as coming
69 from a user on a node, then the L</FrmUser> field is added.
70
71 Adding a L</To> and/or L</ToUser> field will restrict the destinations
72 or recipients that receive this message. 
73
74 The L</Hop> field is incremented on receipt of a message on a node.
75
76 Fields are separated by the comma ',' character with the last field 
77 required followed by the vertical bar '|' character.
78
79 If trailing fields are missed out then superfluous commas can also
80 be left out. If intervening fields are missing then no space needs
81 to be left for the separating comma.  
82
83 The characters allowed in the routing section are restricted. Any 
84 invalid characters in any field will cause the whole message to be
85 silently dropped.
86
87 More detailed descriptions of the fields follow:
88
89 =over
90
91 =item B<Origin>
92
93 This is a compulsory field. It is the name of the originating node.
94 The field can contain up to 12 characters in the set [-A-Z0-9_] in
95 any order. Higher layers may restrict this further.
96
97 The field must not be changed by any other node.
98
99 =item B<TimeSeq>
100
101 This is a compulsory field. It is a 10 hexadecimal digit string which
102 consists of a day no (1-31), 
103 a flag to indicate NTP syncronisation in use,
104 seconds within that day (0-86399) [total of 6 hex digits] 
105 that are concatenated with a sequence number (0-65535)
106 [4 hex digits] making the total of 10 hexadecimal digits.
107
108 The date portion is constructed as:
109
110   my $date = ((((gmtime)[3] < 1) | $ntpflag) < 18) |  (time % 86400);
111
112 The sequence number is simply an unsigned short (or 16 bit) number
113 starting at 0. 
114
115 Each message originated at this node will increment the sequence
116 number.
117
118 =item B<Hop>
119
120 This is a compulsory field. It is the number of hops from the 
121 originating node. It is incremented immediately on receipt and
122 before determining its value. 
123
124 So the originating node sends a message with a L</Hop> of 0, the
125 neighbouring nodes must increment this field before passing
126 it on to higher layers for onward processing.
127
128 Implementations may have an upper limit to this field and may
129 silently drop incoming messages with a L</Hop> count greater than the
130 limit.
131
132 =item B<FrmUser>
133
134 This field is optional. It is the identifier of the originating
135 user.  If it is missing then the message is 
136 assumed to come from the originating node itself. 
137
138 It can consist of up to 12 characters in the set [-A-Z0-9_] 
139 in any order. Higher layers may restrict this further.
140
141 =item B<To>
142
143 This field is optional. It is a string of up to 12 characters 
144 in the set [-A-Z0-9_] in any order. 
145
146 This field is used either to indicate particular node destination
147 or to differentiate this broadcast in some way by making this
148 message as a member of a L</Channel>. Any message can be sent
149 down any L</Channel>. The names of L</Channel>s and their usage
150 is entirely up to the implementor.  
151
152 It is assumed that node names can be differentiated from user
153 names and L</Channel> names.
154
155 If the field is set to a particular node destination, it will
156 be routed (rather than broadcast) to that node. However, any
157 intervening nodes are free to duplicate the message and send
158 it down more than one, likely looking, interface - depending on any
159 network policies that may pertain. 
160
161 =item B<ToUser>
162
163 This field is optional. It is a string of up to 12 characters
164 in the set [-A-Z0-9_] in any order. Higher layers may restrict 
165 this further.
166
167 Conventionally this field is used to indicate the user to whom
168 this message is directed. In an ideal world the L</To> field
169 will be set, by the originating node, to the identifier of the node
170 on which this user resides. 
171
172 If the L</To> field is not set then this message will be 
173 broadcast. However, should a node become apparent (on route)
174 then nodes are free to fill in the L</To> field and proceed
175 with a more directed approach. 
176
177 If it becomes apparent (on route) that there may be more than
178 one possible L</To> destination for a L</ToUser> then a node
179 may duplicate the message (keeping the same L</TimeSeq>) and
180 route it onwards. Because of the L</DeDuplication> inherent in 
181 the system, it is indeterminate as to which destination will
182 receive the message. It is possible for all or just some 
183 destinations to receive the message. The tuple (L</Origin>,
184 L</TimeSeq>) will determine uniqueness. 
185
186 This field can, in the case where L</To>
187 is set to the name of a node, be set to a L</Channel>. If this
188 is the case then this will cause this message to be sent to
189 a L</Channel> on the L</To> node only.
190
191 =back 
192
193 =head2 Channel
194
195 Channels are a concept very similar to that on IRC. It is a 
196 way of segregating data flows in a network. In principle, subject
197 to local policy or application requirements, any data (or
198 L</Command Section>) can be sent down any channel.
199
200 It is up to the implementation whether to use this feature or not.  
201
202 =head2 Routing
203
204 It is assumed that nodes will be connected in a looped network with
205 more than one route available (in many cases) to another node.
206
207 In anycase, most traffic is not directed, but broadcast to all users
208 on all nodes.
209
210 Each message is uniquely identified by the (L</Origin>,L</TimeSeq>) 
211 tuple. The basic system will learn which interfaces can see what nodes
212 by looking at the tuple and merging that with the L</Hop> count. 
213 Each interface remembers the latest L</TimeSeq> with the lowest L</Hop>
214 for each L</Origin> that arrives on that interface. It also remembers
215 the number of messages for that L</Origin> that has been received on
216 that interface.
217
218 Any message for onward broadcast is duplicated and sent out on all
219 interfaces that it did not come in on. 
220
221 Any message that is directed to a particular node will be sent out on
222 the "best" interface based on routing information gathered so far. If there
223 is more than one possible route then, depending on network or local
224 policy, the message may be duplicated and sent on other interfaces
225 as well.
226
227 =head2 DeDuplication
228
229 On receipt of a message, its unique tuple (L</Origin>,L</TimeSeq>) is
230 checked against a hash table. If it exists: the message is silently
231 dropped. If it does not exist in the hash table then the tuple is
232 added.
233
234 The hash table is periodically cleaned, removing tuples that 
235 have expired. The length of time a tuple remains in the hash table
236 is implementation dependant but could easily be several days, if
237 required.
238
239 This mechanism only ensures that a message broadcast around the network
240 travels the least distance and through the fewest nodes possible. It
241 is up to higher layers to make sure that data carried is not, itself,
242 duplicated!
243
244 =head2 Examples
245
246  # on link startup from GB7BAA (both sides hello)
247  GB7TLH,3D02350001,0,GB7BAA|HELLO,Aranea,1.2,24.123
248  GB7BAA,3D02355421,1,GB7TLH|HELLO,Aranea,1.1,23.245
249
250  # on user startup to GB7TLH
251  GB7TLH,3D042506F2,0,G1TLH|HELLO,PClient,1.3
252
253  # on user disconnection
254  GB7TLH,3D9534F32D,0,G1TLH|BYE
255
256  # a talk (actually 'text') message to a user (some distance away
257  # from the origin node)
258  GB7TLH,3D03450019,3,G1TLH,GB7BAA,G8TIC|T,Hiya Mike what's happening?
259
260  # a talk/chat/text message to a channel or group
261  GB7TLH,0413525F23,2,G1TLH,VHF|T,2m is opening on MS
262
263  # a ping to find the whereabouts and distance of a user from a node
264  # the hex number on the end is the ping ID
265  GB7TLH,1512346543,0,,,G7BRN|PING,9F4D 
266
267  # the same from a user on GB7TLH
268  GB7TLH,1512346543,0,G1TLH,,G7BRN|PING,23
269
270  # this effectively asks whether the user is on-line on a particular node
271  GB7TLH,1512346543,0,G1TLH,GB7DJK,G7BRN|PING,35DE
272
273  # A possible reply, same ID as ping followed by the no of hops on the 
274  # ping that was received
275  GB7DJK,1512450534,3,G7BRN,GB7TLH,G1TLH|PONG,35DE,3 
276
277
278 =head1 Command Section
279
280 The L</Command Section> of the message contains the actual data being
281 passed. It is called the Command Section because all commands
282 are identified with a L</Tag> which is implemented by 
283 the software using this protocol.
284
285 The L</Tag> is separated from its data by a comma ','. All fields
286 in any subsequent data shall be separated by a comma ','.
287 All fields shall
288 be HTTP encoded such that reserved characters (comma ',', 
289 vertical bar '|',
290 percent '%', 
291 equals '=' 
292 and non printable characters less than 127 (or %7F in hex)
293 [including newline and carraige return] are tranlated to
294 their two hex digit equivalent preceeded by the percent '%' character.
295
296 For example:
297
298  "%0D%0A" is "<carriage return><linefeed>".
299  "hello%2C there" is "hello, there"
300
301 This is not standard CSV, fields are not quoted (delimited with either
302 ' or ").
303
304 All national characters above 127 are UTF8 encoded in the
305 standard perl 5.8.x way. It follows that all (perl) programs that
306 are written according to this specification must say:
307
308  use UTF8;
309
310 A message (or line) is terminated with <carriage return><linefeed>
311 0x0d 0x0a. Incoming messages must be accepted even when terminated
312 with just <linefeed>.
313
314 Care must be taken to make sure that fields have any reserved characters
315 encoded. In particular: it is perfectly permissible to have <linefeed>
316 characters in a field - so long as they are escaped.
317
318 Fields come in two styles: either simple fields (just containing
319 data) or B<key>=B<value> pairs. Each pair must be separated from
320 the next by a comma ','. The B<key> must consist of the set of
321 characters [a-z0-9_] (ie lowercase letters, digits and underscore),
322 with a leading letter. The B<value> must be HTTP encoded as
323 specified above and can otherwise contain any character.
324
325 There is no maximum size specified for a message. It is up to each
326 implimentation to enforce one (if only for their own protection).
327
328 =head2 Tag
329
330 The L</Tag> consists of string of uppercase letters and digits, starting
331 with a leading, uppercase, letter. Tags should be as short as is meaningful.
332
333 Valid tags would be:
334
335  DX
336  PC23
337  ANN
338
339 Invalid tags include:
340
341  1AAA
342  dx
343  Ann
344
345 =head2 Standard Commands
346
347 There are a number of L</Standard Commands> which must be accepted by 
348 all implementations.
349
350 =over
351
352 =item B<HELLO>,<software name>,<version>,<build>,<comments>
353
354 Command sent on connection to another node. Both sides send their information
355 to the other. All the possible arguments are optional, although some of the
356 arguments should be sent in order to help diagnose problems. This command is
357 broadcast.
358
359 =item B<BYE>,<comments>
360
361 Command sent to all connections when the software is shutting down. This is sent
362 by the node just before shutdown occurs. This is really only used to help the
363 network prune its routing tables. It isn't a requirement. The <comment> field
364 is optional. 
365
366 =item B<DISC>,<node name>,<comments>
367
368 Command sent when a node has disconnected from this node. This message is sent when
369 an interface shuts down. It need not be sent if a L<BYE> from an interface for
370 that node has just been received. This command should be broadcast.
371
372 The <node name> is mandatory and is the name of the interface that has just 
373 disconnected.
374
375 =item B<PING>,<ping id>
376
377 Command to send a ping to a node or user. This command is used both by the software
378 and users to determine a) whether a node or user exists and b) how good the path is
379 between them.
380
381 =item B<PONG>,<ping id>,<no of hops on ping>
382
383 Command to reply to a successful ping
384
385 =back
386
387 =head1 AUTHOR
388
389 Dirk Koopman, G1TLH, E<lt>djk@tobit.co.ukE<gt>
390
391 =head1 COPYRIGHT AND LICENSE
392
393 Copyright 2004 by Dirk Koopman, G1TLH
394
395 This library is free software; you can redistribute it and/or modify
396 it under the same terms as Perl itself.
397
398 $Revision$
399
400 =cut
401
402