Add initial protocol documentation.
[doldaconnect.git] / doc / protocol / protocol.tex
CommitLineData
4ae8ca60
FT
1\documentclass[twoside,a4paper,11pt]{article}
2
3\newcommand{\url}[1]{\texttt{<#1>}}
4\newcommand{\unix}{\textsc{Unix}}
5
6\title{Dolda Connect protocol}
7\author{Fredrik Tolf\\\texttt{<fredrik@dolda2000.com>}}
8
9\begin{document}
10
11\maketitle
12
13\section{Introduction}
14Dolda Connect consists partly of a daemon (a.k.a. server) that runs in
15the background and carries out all the actual work, and a number of
16client programs (a.k.a. user interfaces) that connect to the daemon in
17order to tell it what to do. In order for the daemon and the clients
18to be able to talk to each other, a protocol is needed. This document
19intends to document that protocol, so that third parties can write
20their own client programs.
21
22It is worthy of note that there exists a library, called
23\texttt{libdcui} that carries out much of the low level work of
24speaking the protocol, facilitating the creation of new client
25programs. In itself, \texttt{libdcui} is written in the C programming
26language and is intended to be used by other programs written in C,
27but there also exist wrapper libraries for both GNU Guile (the GNU
28project's Scheme interpreter) and for Python. The former is
29distributed with the main Dolda Connect source tree, while the latter
30is distributed separately (for technical reasons). To get a copy,
31please refer to Dolda Connect's homepage at
32\url{http://www.dolda2000.com}.
33
34\section{Transport format}
35The protocol can be spoken over any channel that features a
36byte-oriented, reliable virtual (or not) circuit. Usually, it is
37spoken over a TCP connection or a byte-oriented \unix\ socket. The
38usual port number for TCP connections is 1500, but any port could be
39used\footnote{However, port 1500 is what the \texttt{libdcui} library
40 uses if no port is explicitly stated, so it is probably to be
41 preferred}. What follows hereon is an informal description of the
42protocol.
43
44On top of the provided byte-oriented connection, the most basic level
45of the protocol is a stream of Unicode characters, encoded with
46UTF-8. The Unicode stream is then grouped in two levels: lines
47consisting of words (a.k.a. tokens). Lines are separated by CRLF
48sequences (\emph{not} just CR or LF), and words are separated by
49whitespace. Both whitespace and CRLFs can be quoted, however,
50overriding their normal interpretation of separators and allowing them
51to be parts of words. NUL characters are not allowed to be transferred
52at all, but all other Unicode codepoints are allowed.
53
54Lines transmitted from the daemon to the client are slightly
55different, however. They all start with a three-digit code, followed
56by either a space or a dash\footnote{Yes, this is inspired by FTP and
57 SMTP.}, followed by the normal sequence of words. The three-digit
58code identifies that type of line. Overall, the protocol is a
59lock-step protocol, where the clients sends one line that is
60interpreted as a request, and the daemon replies with one or more
61lines. In a multi-line response, all lines except the last have the
62three-digit code followed by a dash. The last line of a multi-line
63response and the only line of a single-line response have the
64three-digit code followed by a space. All lines of a multi-line
65response have the same three-digit code. The client is not allowed to
66send another request until the last line of the previous response has
67been received.
68
69\end{document}