Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Protocol

The protobuf definitions in proto/irsync/v1/ (common.proto, control.proto, data.proto, admin.proto, session.proto) are normative. This page summarises the constants, the streams and the messages; where it disagrees with the .proto files, they win. The Rust types are generated from them in the irsync-proto crate. Networking explains the layers below these messages, and walks through a real session message by message.

The protocol and the on-disk state (index, session records) change without compatibility paths until the first release. A client that speaks another version is refused with VERSION_MISMATCH.

Any change to the wire format bumps PROTOCOL_VERSION (crates/irsync-proto/src/lib.rs), in the same change: a message or field added, removed or renumbered, a field’s type changed, an enum value added or renumbered, or a field’s meaning changed. Two peers of one version always read each other’s frames the same way. session.proto is not on the wire; a change to it needs no new version.

Constants

ItemValue
ALPNirsync/1
PROTOCOL_VERSION8, carried in Hello.protocol_version
FramingA protobuf varint length (at most 4 bytes for MAX_FRAME), then that many bytes of one protobuf message: protobuf’s standard length-delimited form
MAX_FRAME16 MiB. A longer length is refused before anything is allocated for it.
Content hashBLAKE3, 32 bytes, for chunks and whole files
ChunkingFastCDC 2020, normalisation level 1; minimum 64 KiB, average 256 KiB, maximum 1 MiB
Chunk list partAt most 32,768 records in a ChunkListStart or ChunkListMore
Chunk listAt most 2^24 records. Every chunk but a file’s last is at least 64 KiB; the receiver refuses a list with a shorter one.
List room2^24 records per connection, across all files
NeedChunksAt most 2^18 chunk indices and 16 entries of held per message; the sender treats more as a protocol error
SyncRequest.filtersAt most 16,384 rules; a pattern at most 4,096 bytes; all patterns together at most 1 MiB. The daemon refuses a Hello with more.
Path in PlanItem and CheckLinkAt most 64 KiB, and a valid relative path; anything else is a protocol error
Chunk basisBlocks of 512 B to 4 KiB, at most 8,192 blocks; at most 32 MiB of bases held per session
DataChunkA piece of one chunk, at most 64 KiB of data; or the operations that rebuild one whole chunk
HeartbeatAt most one every 500 ms
Hello timeoutThe daemon waits 10 s for Hello

The chunking parameters travel in the handshake (SyncRequest.chunk_min, chunk_avg, chunk_max); a client with others is refused with VERSION_MISMATCH. A file’s chunk list and whole-file hash are a pure function of its bytes and these parameters.

Connection

A client opens one QUIC connection to the daemon’s EndpointId. Before it accepts any stream, the daemon reads its grants afresh and looks up the verified key of the client. A key that no grant names, or a configuration that cannot be read, gets the connection closed with application code 1 (unauthorized) and no message. See Identity and trust.

Close codes:

CodeReasonClient’s response
0doneNone.
1unauthorized: the key has no grantFinal.
2rejected after an Error, or hello timeoutFinal.
3superseded: a newer connection resumed this sessionFinal.
4idle: the inactivity watchdog firedRedial and resume.

Streams

A session uses two bidirectional streams, both opened by the client, and many unidirectional ones.

  • The control stream is the first bidirectional stream. It carries Hello and the HelloReply, then Control frames.
  • The listing stream is the second. The client opens it right after HelloAck and starts it with a ListingStreamHeader naming the session. Each half then carries one side’s listing as ListingFrames: an entry (a FileEntry, without dev and inode, which are the lister’s own) per path, in path order; an error (a PathError) wherever entries are missing (a directory that could not be read, right after its own entry; an entry that could not be stat’ed); one end (a ListingEnd, with the count of entries and an incomplete flag); and the end of the half. A side that does not list, a receiver resuming a complete plan, ends its half without a frame. The listing has its own stream so that a planner that stops taking it, while it waits for files in flight to finish, stalls only the listing and never the frames that finish those files.
  • Data streams are unidirectional, from sender to receiver, one per run of contiguous requested chunks of one file, a run being cut at 64 MiB. Each starts with a DataStreamHeader (session id, file id, offset, length, index of the first chunk) and carries each chunk’s bytes in DataChunk frames of at most 64 KiB, in order; a frame never runs into the next chunk. The offset is the first chunk’s, or inside it when the receiver already holds that chunk’s first bytes (see Requests, bases and operations). A sender keeps at most --parallel of them open, 128 by default; a daemon that sends always uses 128.

Handshake

The client sends Hello on the control stream: protocol_version, its build (BuildInfo: package version, short git commit, dirty flag), its W3C trace context (traceparent and tracestate, empty: no trace; a daemon that exports traces makes its session span a child of it), and exactly one request:

RequestMeaning
pushA SyncRequest: a session in which the client sends.
pullA SyncRequest: a session in which the daemon sends.
list_exportsNo session: the exports this key may use.
probeNo session: what Probe.path is on the daemon.
adminThe control stream becomes an admin session.

The daemon answers with one HelloReply, which holds exactly one of error (a refusal, then close code 2), ack (a HelloAck, for a push or a pull), exports (an ExportList), path_info (a PathInfo) or admin_ready. A Hello without a request is refused with BAD_REQUEST. Hello.protocol_version and HelloReply.error keep their field numbers in every version, so a client of another version still reads why it was refused.

A SyncRequest holds:

  • session_id: 16 bytes to resume a session, empty for a new one;
  • the three chunking parameters;
  • path, the remote PATH as typed, which the daemon resolves (see Remote addresses); contents_only, the trailing-slash rule; and on a push of a source without a trailing slash, name, its basename;
  • single_file: the session copies one file. name is then the source’s basename on a push, and the name the file gets on the client on a pull; it must be one path component. The daemon treats the directory that holds the file as the session root, so nothing else in it is listed or deleted. --delete and its relatives are ignored. On a push the daemon decides the file’s name on its side by rsync’s rules and returns it in HelloAck.single_name, which can differ from name (a file named T);
  • preserve, the client’s preserve flags (-l -p -t -g -o -D -H -S), which the daemon honours in both directions; it refuses a push or a pull whose request lacks them;
  • recursive and dirs: -r and -d, which both sides’ listings follow;
  • the include and exclude rules, compiled and in order. A sending daemon walks with them; a receiving daemon protects what they exclude from deletion;
  • the receiver-side options, which the daemon honours only when it receives: the deletion mode, --delete-excluded, --max-delete, -n, -u, -c, --inplace, --append or --append-verify, --partial-dir (relative and inside the destination, or refused), --no-rename-detection (no_rename_detection), --fsync (an export’s fsync = true flushes whatever the client sent). -i, --ignore-errors and --numeric-ids apply in both directions;
  • paranoid: --paranoid. Both roles take part in the final re-check, which the receiver asks for with Settle, so a daemon honours it in both directions. Only the sending side clones or hashes each file again, so on a push the daemon does neither;
  • bwlimit: --bwlimit in bytes per second. The side that sends the file data paces it, so the daemon honours it only when it sends (a pull); on a push the client paces itself. Absent or 0 means no limit.

A push or a pull is answered with ack: a HelloAck with the session id, whether the session was resumed, the daemon’s BuildInfo and, on a single-file push, single_name. Each side logs the other’s build at info level once the session is up.

list_exports is answered with exports: the exports this key may use with their paths and effective access, sorted by name. The daemon then closes the connection.

A probe opens no session. The daemon resolves Probe.path as it would for a pull, applies the same access checks, and answers with path_info, whose kind is MISSING, DIRECTORY or FILE (anything that is not a directory, a symlink included), then closes. A client uses it to learn whether a pull without a trailing slash names a file.

An admin request turns the control stream into an admin session, defined in admin.proto. A key without admin gets an error with UNAUTHORIZED and the message not allowed. Otherwise the daemon answers with admin_ready; the client then sends AdminRequest frames and the daemon answers each with an AdminReply:

MessageDirectionMeaning
Changeclient to daemonOne change: an export, grant or client add, remove, rename or set. Held, not applied. No reply.
Commitclient to daemonApply the held changes, all or nothing: answered with Ack (one result line per change) or Nack. At most 100 changes; a session idle for 10 minutes is closed.
Readclient to daemonReadView for the exports, clients and daemon facts, or ReadConfig for one key (empty: every key). Answered with View or ConfigText, from the saved config. Needs admin ro or rw.
Nackdaemon to clientNothing was applied. change is the 1-based number of the change at fault, or 0 for the whole transaction (busy, not allowed, own admin right, too many changes).

A request the daemon refuses inside the session (one it cannot read, a read of a key that does not exist, a request too large) gets an AdminReply whose refused holds the Error.

Errors

An Error is a code and a message. It refuses a Hello (in HelloReply), refuses an admin request (in AdminReply), or, as the error of a Control frame, ends a session that failed: either side may send that one, with INTERNAL.

CodeSent when
UNSPECIFIEDNever sent.
UNAUTHORIZEDThe key has grants, but none for an export that contains the path. The message is no access to PATH.
READ_ONLYA push to an export that is read_only or that this key may only read.
BAD_PATHThe path has a .. component or a NUL byte, or the session’s root cannot be prepared.
VERSION_MISMATCHAnother protocol version or other chunking parameters.
BAD_SESSIONA resume of a session the daemon does not know, that is finished, or that another key started. The client starts a fresh session at once.
INTERNALThe daemon failed, for example opening the export’s index; or a session failed (in Control).
BAD_REQUESTA malformed request: a Hello without a request, rules over the limits, an admin request that cannot be read.

The answer for a path a key may not use is the same whether the path lies outside every export, inside an export without a grant, or does not exist at all, so a key cannot probe the daemon’s layout. READ_ONLY and a BAD_PATH about the root go only to a key that may use the export.

Control messages

MessageDirectionMeaning
PlanItemreceiver to senderSend this file: WHOLE (nothing to reuse at that path), DELTA (the receiver holds an old version) or APPEND (the receiver trusts its first append_from bytes).
ChunkListStartsender to receiverThe start of a file’s chunk list: its total record count, the whole-file hash, the first records, and the stat the file was hashed under (SourceStat: size, mtime, change time, inode, mode, uid and gid, with the names of the owner and group). The receiver places the file with the size, mtime, mode, owner and group instead of the walk’s. The change time and inode are for the link check (CheckLink).
ChunkListMoresender to receiverThe next records of a file’s chunk list.
WithdrawChunkListsender to receiverDrop the file’s chunk list and free its room: a new list follows.
ListRoomreceiver to senderRoom for this many more chunk records, freed by lists the receiver dropped.
ChunkBasisreceiver to senderBlock signatures over a region of the receiver’s old file, for one chunk.
NeedChunksreceiver to senderThe chunks to send; empty means none.
MayPlacereceiver to senderThe file is verified against chunk list number gen; may it be placed?
PlaceVerdictsender to receiverThe answer: changed if the source differs from the stat it was hashed under. The receiver places the file only when it is unchanged; otherwise it drops it and waits for the new chunk list, or for a SourceError. A MayPlace about a list older than the sender’s latest is always answered changed.
FileAckreceiver to senderHow the file ended: DONE, HASH_MISMATCH or WRITE_ERROR (UNSPECIFIED is never sent; the sender takes it as a protocol error). DONE carries the bytes the receiver did not take from the sender.
SourceErrorsender to receiverThe sender cannot read the file, and says why. The receiver drops it without a reply.
Itemizedreceiver to senderOne rsync -i line, for a client that pushes with -i.
HeartbeateitherThis side is busy; see below.
Settlereceiver to senderWith --paranoid (not on a dry run), once, in place of the first SessionDone: every path is planned and no file is in flight. The sender stats every file it listed again.
Replansender to receiverAfter Settle: a listed file that changed since it was listed or last hashed: its entry as it is now, path included. The receiver plans it again, under a new file id.
Settledsender to receiverThe re-check is over: the listed files that vanished, and those it could not stat. The receiver sends SessionDone once the re-planned files are done.
CheckLinkreceiver to senderWith -H (not on a dry run), once every path is planned, no file is in flight and the re-check (if any) is over: one per hard link about to be made to a file sent in this session, on this connection or an earlier one. It carries the name and the stat its target was hashed under.
CheckLinksEndreceiver to senderThe last CheckLink has been sent. With -H it is always sent, even with no links to check, before SessionDone.
Unlinkedsender to receiverA name that is no longer exactly the file its target was hashed as: its stat differs (inode, size, times, mode, owner or group), or it is gone or no longer a regular file the walk would list. The receiver does not link it. If it is still a regular file, entry holds it as it is now, and the receiver plans it as a file of its own, as for Replan. Otherwise failed holds the name, which fails.
LinksCheckedsender to receiverThe link check is over. The receiver makes the other links, then sends SessionDone.
SessionDonereceiver to senderThe session’s totals (files_placed, placed_size, bytes_received, created), errors and deletions (deleted_paths, would_delete_paths, capped, with counts of the rest), and what the sender’s listing held (listed): a sender that resumed from the receiver’s stored plan listed nothing itself and reports these counts.
ErroreitherThe session failed on this side, with INTERNAL and why; it ends the session.

Every message on the control stream is a Control frame with exactly one of these set. A file costs a PlanItem, a ChunkListStart (and ChunkListMores for a long list), a NeedChunks, a MayPlace, a PlaceVerdict and a FileAck; the room its list took comes back in a ListRoom, which may cover several files.

Chunk lists

A chunk list travels as one ChunkListStart and then ChunkListMore frames, in order, each with at most 32,768 records; an empty file’s list is one ChunkListStart without records. The start carries the file id, the total record count, the whole-file hash and the stat the file was hashed under; each ChunkListMore carries the file id and the index of its first record. A ChunkRecord is a length and a hash: its offset is the sum of the lengths before it, from 0, or from append_from for an APPEND tail. The list is complete once total records have come. The receiver reassembles them and fails the file when a sequence skips or announces more records than 2^24 or than the size allows at the minimum chunk length. The stat (SourceStat) is the size, mtime, change time, inode, mode, uid and gid, and the start also holds the names of the uid and gid on the sender. These replace the walk’s for the file, and the names are mapped to the receiver’s ids as for a listing entry (not with --numeric-ids). An APPEND tail’s list carries the whole file’s stat.

Lists travel in room the receiver grants. Each connection starts with room for 2^24 records on both sides; a list’s start takes its whole total of it, and a sender sends a list only once it fits. The receiver gives room back with ListRoom when it drops a list: the file was placed, failed or replaced. A start that does not fit, or a grant above the starting room, is a protocol error. A start for a file that already has a list replaces that list; a sender that lists a file again first sends a WithdrawChunkList, so the old list is dropped without waiting for room.

For an APPEND, the list covers only the tail from append_from and carries no whole-file hash; the receiver folds the hash from the bytes it places. Every other list carries one.

Requests, bases and operations

NeedChunks names chunk indices; a request for more than 2^18 comes as several, which the sender treats as one. Before the NeedChunks that names a chunk of a DELTA file, the receiver may send a ChunkBasis for it: a region of its old file named by its offset there, cut into blocks of 512 B to 4 KiB, and per block a 32-bit rolling sum and the first 8 bytes of the block’s BLAKE3 hash. The control stream is ordered, so a basis precedes the request that uses it. The sender keeps a basis for that one request and drops it; a chunk asked for again comes raw. A malformed basis is ignored. A sender that holds more than 32 MiB of bases fails the session.

NeedChunks.held names chunks of the request whose first bytes the receiver already holds, with how many: the pieces an earlier connection delivered before it dropped, at most 16 chunks per file. The sender starts such a chunk’s data there, raw, in a stream of its own whose offset is inside the chunk. The receiver writes each piece into the .part as it arrives and verifies the chunk against its hash once it is whole; a chunk that fails is asked for again from its start. The receiver sends no basis for a chunk it holds bytes of. In place (--inplace) it holds none: only verified chunks reach the file there.

A chunk with a basis may arrive as DataChunk.ops instead of data: a list of literals and copies (offset, len in the receiver’s old file) that add up to the chunk. The sender uses operations only when they are at least a quarter smaller than the chunk. A copy must be a run of whole blocks of the basis the receiver sent for that chunk: it starts on a block of the region and its length is a multiple of the block length. The receiver refuses any other copy, and any operations for a chunk it sent no basis for, and asks for the chunk again without a basis. This keeps a sender from finding out what the old file holds by asking for single bytes of it. The receiver rebuilds the chunk and verifies it against the chunk’s hash like any other. How the receiver chooses and uses bases is in Receiving a changed file.

Heartbeats

A Heartbeat means “I am busy”. A side sends one every 500 ms in which it made progress: hashing, writing, finalizing, deleting, or traffic. It carries what the other side cannot otherwise see: the directory this side’s walk is in, the bytes its planner found up to date, and its deletion count (deleted_count). An idle side sends none, so a stuck side still times out. The receiver sends none after SessionDone, which is the last message on its control stream. A receiver that resumes its stored plan sends one extra Heartbeat before its first request, with listed, the totals of the sender’s listing on the first connection, and listed_settled, how many of those bytes need nothing more: files found up to date or already placed. Nothing is listed again, and the sender shows its progress from these. See Sessions and resume.

Persisted state

session.proto describes what each side stores in its index for a session that may resume: the plan (SessionPlan, with PlanEntry per file) and the progress (SessionProgress). These messages never go on the wire. Partial files are stored as PartialRanges (of Ranges): the verified bytes, and the first bytes of chunks that did not finish (held); a RangeSet is the verified bytes alone. See Sessions and resume.

Cross-implementation check

crates/irsync-proto/tests/golden/chunk_1mib.json is a golden vector: the whole-file hash and the exact chunk boundaries (offset, length, BLAKE3 hash) of 1 MiB from the xorshift64 generator seeded with 0x9E3779B97F4A7C15 (see crates/irsync-proto/tests/chunk.rs). An independent implementation must reproduce it exactly to interoperate, because chunk boundaries decide which chunks a client and a daemon consider equal. crates/irsync-proto/tests/golden_bytes.rs pins PROTOCOL_VERSION and the exact wire bytes of several messages, so a change of field number or wire type shows, and with it a version that was not bumped.