Expand description
Remote copy protocol definitions for source-destination communication.
§Protocol Overview
The remote copy protocol uses TCP for communication between source and destination. The source listens on two ports: a control port for bidirectional messages and a data port for file transfers. Both sides exchange messages to coordinate directory creation, file transfers, and completion.
See docs/remote_protocol.md for the full protocol specification.
§Message Flow
Source Destination
| |
| ---- Directory(root, meta) -------> | Create root, store metadata
| ---- Directory(child, meta) ------> | Create child, store metadata
| ---- Symlink(...) ----------------> | Create symlink
| ---- DirStructureComplete --------> | Structure complete
| |
| <--- DirectoryManifestChunk(root,..)| 0+ manifest chunks for reused dirs
| | under --overwrite/--ignore-existing,
| | sent BEFORE the trigger (FIFO)
| <--- DirectoryCreated(root) -------- | Pass-2 trigger
| <--- DirectoryCreated(child) ------- |
| |
| ~~~~ File(f) ~~~~~~~~~~~~~~~~~~~~~> | Write file (not in manifest / differs)
| ---- FileUnchanged(g) -----------> | identical g not transferred
| | All files done → apply metadata
| |
| <--- DestinationDone -------------- | Close send side
| (close send side) | (detect EOF)
| (detect EOF) | Close connection§Error Communication
The protocol uses asymmetric error communication:
- Source → Destination: Must communicate failures (
FileSkipped,SymlinkSkipped) so destination can track file counts correctly.FileUnchangedis also sent Source → Destination but is an optimization notification (not a failure): it signals the source skipped a file whose destination copy is already identical, and is counted asfiles_unchangedon the destination. - Destination → Source: Does NOT communicate failures. Destination handles errors locally and source continues sending the full structure.
§Shutdown Sequence
Shutdown is coordinated through TCP connection closure:
- Destination sends
DestinationDoneand closes its send side - Source detects EOF on recv, closes its send side
- Destination detects EOF on recv, closes connection
Structs§
- Existing
Entry - One pre-existing destination directory entry, sent in a
DirectoryManifestChunkso the source can skip transferring identical files.nameis the child name (serialized as aPathBuf, matching the rest of the protocol’s path handling).metadata/sizeare only meaningful whenis_file. - File
- File header sent on unidirectional streams, followed by raw file data.
- File
Metadata - Wrapper that includes size for comparison purposes.
- Metadata
- Rcpd
Config - Runtime
Stats - runtime statistics collected from a process (CPU time, memory usage)
- Source
Master Hello - SrcDst
- Tracing
Hello
Enums§
- Destination
Message - Messages sent from destination to source on the control stream.
- Master
Hello - Rcpd
Result - Rcpd
Role - Source
Message - Messages sent from source to destination on the control stream.
Constants§
- DEFAULT_
OVERWRITE_ MANIFEST_ MAX_ ENTRIES - Default cap on the number of pre-existing destination entries the destination will put in a
directory’s overwrite/ignore-existing manifest. Above this, the manifest is omitted and that
directory falls back to transferring-and-draining files (see
docs/remote_protocol.md). High by default — rcp typically runs on large hosts; the cap is a backstop, not a normal limit. - MANIFEST_
CHUNK_ BYTE_ BUDGET - Conservative byte budget for a single
DirectoryManifestChunk. Well under the control stream’s 8 MiBLengthDelimitedCodecframe limit, leaving ample margin for the message envelope and the worst-case final entry (a single ~PATH_MAXname).
Functions§
- chunk_
manifest - Split a directory manifest into chunks each estimated to stay within
byte_budget, so everyDirectoryManifestChunkframe fits under the control stream’s frame limit. A single entry larger than the budget still gets its own chunk (it cannot be split further); with the 4 MiB budget versus a worst-case ~4 KiB path, a chunk never approaches the 8 MiB frame limit.chunk_manifest(v, b).concat() == vfor anyv(no entries lost or reordered).
Type Aliases§
- Cert
Fingerprint - TLS certificate fingerprint (SHA-256 of DER-encoded certificate).