|
NAMEopenrsync —
rsync wire protocol
DESCRIPTIONTheopenrsync protocol described in this relates to the
BSD-licensed
openrsync(1),
a re-implementation of the GPL-licensed reference utility
rsync(1).
It is compatible with version 27 of the reference.
In this document, the “client process” refers to the utility as run on the operator's local computer. The “server process” is run either on the local or remote computer, depending upon the command-line given file locations. There are a number of options in the protocol that are dictated by
command-line flags. These will be noted as Data typesThe binary protocol encodes all data in little-endian format. Integers are signed 32-bit, shorts are signed 16-bit, bytes are unsigned 8-bit. A long is variable-length. For values less than the maximum integer, the value is transmitted and read as a 32-bit integer. For values greater, the value is transmitted first as a maximum integer, then a 64-bit signed integer.There are three types of checksums: long (slow), short (fast), and whole-file. The fast checksum is a derivative of Adler-32. The slow checksum is MD4, made over the checksum seed first (serialised in little-endian format), then the data. The whole-file applies MD4 to the file first, then the checksum seed at the end (also serialised in little-endian format). MultiplexingMostopenrsync transmissions are wrapped in a
multiplexing envelope protocol. It is composed as follows:
The first byte of the envelope header consists of a tag. If the
tag is 7, the payload is normal data. Otherwise, the payload is out-of-band
server messages. If the tag is 1, it is an error on the sender's part and
must trigger an exit. This limits message payloads to 24 bit integer size,
The only data not using this envelope are the initial handshake between client and server. File listA central part of the protocol is the file list, which is generated by the sender. It consists of all files that must be sent to the receiver, either explicitly as given or recursively generated.The file list itself consists of filenames and attributes (mode, time, size, etc.). Filenames must be relative to the destination root and not be absolute or contain backtracking. So if a file is given to the sender as ../../foo/bar, it must be sent as foo/bar. The file list should be cleaned of inappropriate files prior to
sending. For example, if The receiver must not assume that the file list is clean. It should not omit inappropriate files from the file list (which would affect the indexing), but may omit them during processing. Prior to be sent from sender to receiver, and upon being received, the file list must be lexicographically sorted such as with strcmp(3). Subsequent references to the file are by index in the sorted list. Client processThe client can operate in sender or receiver mode depending upon the command-line source and destination.If the destination directory (sink) is remote, the client is in sender mode: the client will push its data to the server. If the source file is remote, it is in receiver mode: the server pushes to the client. If neither are remote, the client operates in sender mode. These are all mutually exclusive. When the client starts, regardless its mode, it first handshakes the server. This exchange is not multiplexed.
Following this, the client multiplexes when reading from the server. Transmissions sent from client to server are not multiplexed. It then enters the Update exchange protocol. Server processThe server can operate in sender or receiver mode depending upon how the client starts the server. This may be directly from the parent process (when invoked for local files) or indirectly via a remote shell.When in sender mode, the server pushes data to the client. (This is equivalent to receiver mode for the client.) In receiver, the opposite is true. When the server starts, regardless the mode, it first handshakes the client. This exchange is not multiplexed.
Following this, the server multiplexes when writing to the client. (Transmissions received from the client are not multiplexed.) It then enters the Update exchange protocol. Update exchangeWhen the client or server is in sender mode, it begins by conditionally sending the exclusion list. At this time, this is always empty.
It then sends the File list. Prior to being sent, the file list should be lexicographically sorted.
The status byte may consist of the following bits and determines which of the optional fields are transmitted.
If the status byte is zero, the file-list has terminated. If
The same sequence is then sent for groups if
The sender then sends any IO error values, which for openrsync(1) is always zero.
The server sender then reads the exclusion list, which is always zero.
Following that, the sender receives data regarding the receiver's copy of the file list contents. This data is not ordered in any way. Each of these requests starts as follows:
The phase starts in phase 1, then proceeds to phase 2, and phase 3 signals an end of transmission (no subsequent blocks). If a phase change occurs, the sender must write back the -1 constant integer value and increment its phase state. Blocks are read as follows:
In (
And for each block:
The client then compares the two files, block by block, and updates the server with mismatches as follows.
Then for each block:
Following this sequence, the sender sends the followng:
The sender then either handles the next queued file or, if the receiver has written a phase change, the phase change step. If the sender is the server and
Finally, the sender must read a final constant-value integer.
If in receiver mode, the inverse above (write instead of read, read instead of write) is performed. The receiver begins by conditionally writing, then reading, the exclusion list count, which is always zero.
The receiver then proceeds with reading the File list as already defined. Following the list, the receiver reads the IO error, which must be zero.
The receiver must then sort the file names lexicographically. If there are no files in the file list at this time, the receiver must exit prior to sending per-file data. It then proceeds with the file blocks. For file blocks, the receiver must look at each file that is not up to date, defined by having the same file size and timestamp, and send it to the server. Symbolic links and directory entries are never sent to the server. After the second phase has completed and prior to writing the
end-of-data signal, the client receiver reads statistics. This is only
performed with (
Finally, the receiver must send the constant end-of-sequence marker.
Sender and receiver asynchronyThe sender and receiver need not work in lockstep. The receiver may send file update requests as quickly as it parses them, and respond to the sender's update notices on demand. Similarly, the sender may read as many update requests as it can, and service them in any order it wishes.The sender and receiver synchronise state only at the end of phase. The reference rsync(1) takes advantage of this with a two-process receiver, one for sending update requests (the generator) and another for receiving. openrsync(1) uses an event-loop model instead. SEE ALSOopenrsync(1), rsync(1), openrsyncd(5)BUGSTime values are sent as 32-bit integers.When in server mode and when communicating to a client with a newer protocol (>27), the phase change integer (-1) acknowledgement must be sent twice by the sender. The is probably a bug in the reference implementation.
Visit the GSP FreeBSD Man Page Interface. |