Expand description
Remote copy protocol and networking for distributed file operations
This crate provides the networking layer and protocol definitions for remote file copying in the RCP tools suite. It enables efficient distributed copying between remote hosts using SSH for orchestration and TCP for high-throughput data transfer.
§Overview
The remote copy system uses a three-node architecture:
Master (rcp)
├── SSH → Source Host (rcpd)
│ ├── TCP Server ← Master (control + tracing)
│ └── TCP Server ← Destination (control + data)
└── SSH → Destination Host (rcpd)
├── TCP Server ← Master (control + tracing)
└── TCP Client → Source (control + data)§Connection Flow
- Initialization: Master starts
rcpdprocesses on source and destination via SSH - Control Connections: Master connects to each
rcpd’s TCP listener (address read from the rcpd’s stderr over SSH) - Address Exchange: Source starts TCP listeners and sends addresses to Master
- Direct Connection: Master forwards addresses to Destination, which connects to Source
- Data Transfer: Files flow directly from Source to Destination (not through Master)
This design ensures efficient data transfer while allowing the Master to coordinate operations and monitor progress.
§Key Components
§SSH Session Management
The SshSession type represents an SSH connection to a remote host and is used to:
- Launch
rcpddaemons on remote hosts - Configure connection parameters (user, host, port)
§TCP Networking
TCP provides high-throughput bulk data transfer with:
- Connection pooling for parallel file transfers
- Configurable buffer sizes for different network profiles
- Length-delimited message framing for control messages
Key functions:
create_tcp_control_listener- Create TCP listener for control connectionscreate_tcp_data_listener- Create TCP listener for data connectionsconnect_tcp_control- Connect to a TCP control serverget_tcp_listener_addr- Get externally-routable address of a listenerconfigure_tcp_socket- Apply the standard socket options to every established connection
§Port Range Configuration
The port_ranges module allows restricting TCP to specific port ranges, useful for firewall-restricted environments:
let config = remote::TcpConfig {
port_ranges: Some("8000-8999".to_string()),
..remote::TcpConfig::default()
};
let listener = remote::create_tcp_control_listener(&config, None).await?;§Protocol Messages
The protocol module defines the message types exchanged between nodes:
MasterHello- Master → rcpd configurationSourceMasterHello- Source → Master address informationRcpdResult- rcpd → Master operation results
§Stream Communication
The streams module provides high-level abstractions over TCP streams:
streams::SendStream/streams::RecvStreamfor framed message passingstreams::ControlConnectionfor bidirectional control channels- Object serialization/deserialization using bitcode
§Remote Tracing
The tracelog module enables distributed logging and progress tracking:
- Forward tracing events from remote
rcpdprocesses to Master - Aggregate progress information across multiple remote operations
- Display unified progress for distributed operations
§Security Model
The remote copy system provides multiple security layers:
- SSH Authentication: All remote operations require SSH authentication to spawn rcpd
- TLS Encryption: All TCP connections encrypted with TLS 1.3 by default
- Certificate Pinning: Self-signed certificates with fingerprint verification
- Mutual Authentication: Source↔Destination connections use mutual TLS
How it works:
- Each rcpd generates an ephemeral self-signed certificate
- rcpd outputs its certificate fingerprint to stderr (read by master over the trusted SSH channel)
- Master connects to rcpd as TLS client, verifies fingerprint
- Master distributes fingerprints to enable Source↔Destination mutual auth
Use --no-encryption to disable TLS for trusted networks where performance is critical.
§Network Troubleshooting
Common failure scenarios:
- SSH Connection Fails: Host unreachable or authentication failure
- Master Cannot Connect to rcpd: Firewall blocks TCP ports
- Destination Cannot Connect to Source: Use
--port-rangesto specify allowed ports
§Module Organization
port_ranges- Port range parsing and socket bindingprotocol- Protocol message definitions and serializationstreams- TCP stream wrappers with typed message passingtls- TLS certificate generation and configurationtracelog- Remote tracing and progress aggregation
Modules§
- port_
ranges - protocol
- Remote copy protocol definitions for source-destination communication.
- streams
- tls
- TLS support for encrypted and authenticated connections.
- tracelog
Structs§
- Abort
OnDrop Task - Owns a Tokio task and aborts it if its supervising future is cancelled.
- Prepared
Rcpd - Rcpd
Connection Info - Connection info received from rcpd after it starts listening.
- Rcpd
Process - Result of starting an rcpd process.
- Remote
Cleanup - Owns all blocking cleanup work started by one rcp invocation.
- Resolved
Remote Concurrency - Validated capacities used by the remote file-transfer pipeline.
- SshSession
- TcpConfig
- Configuration for TCP connections
Enums§
- Connection
Kind - What an rcp TCP connection carries, which decides whether
TCP_USER_TIMEOUTapplies. - Network
Profile - Network profile for TCP configuration tuning
Constants§
- DATACENTER_
REMOTE_ COPY_ BUFFER_ SIZE - Datacenter profile: buffer size for remote copy operations (16 MiB)
- DEFAULT_
COPY_ BUFFER_ RETENTION_ LIMIT - Default ceiling for retained receiver scratch per data connection. The effective default also respects smaller configured I/O chunks.
- DEFAULT_
MAX_ CONNECTIONS - Default ceiling for concurrent remote data connections.
- DEFAULT_
PENDING_ WRITES_ MULTIPLIER - Default multiplier for pending writes (4× max_connections).
- DEFAULT_
REMOTE_ KEEPALIVE_ SEC - Default liveness budget for an rcp TCP connection (seconds).
- INTERNET_
REMOTE_ COPY_ BUFFER_ SIZE - Internet profile: buffer size for remote copy operations (2 MiB)
- RCPD_
STARTUP_ ERROR_ PREFIX - Prefix for an intentional daemon refusal in place of a readiness record.
- TCP_
KEEPALIVE_ RETRIES - Number of unacknowledged keepalive probes tolerated before a connection is declared dead.
Functions§
- accept_
tcp_ control - Accept one TCP control connection, applying the standard socket options before returning it.
- accept_
tcp_ data - Accept one TCP data connection, applying the standard socket options before returning it.
- configure_
tcp_ socket - Configure an rcp TCP connection: no-delay, buffer sizes, and dead-peer detection.
- connect_
tcp_ control - Connect to a TCP control server, applying the connect timeout and the standard socket options
- connect_
tcp_ data - Connect a TCP data connection, applying the standard socket options.
- create_
tcp_ control_ listener - Create a TCP listener for control connections
- create_
tcp_ data_ listener - Create a TCP listener for data connections (file transfers)
- format_
rcpd_ readiness - Format the first stderr record emitted by a successfully started rcpd.
- get_
random_ server_ name - Generate a random server name for identifying connections
- get_
remote_ home_ for_ session_ with_ timeout - Retrieve a remote home directory with a caller-selected bootstrap timeout.
- get_
tcp_ listener_ addr - Get the external address of a TCP listener
- is_
localhost - checks if a host string refers to the local machine.
returns true for
localhost,127.0.0.1,::1,[::1], or the actual hostname - prepare_
rcpd_ endpoints_ with_ timeout - Prepare two endpoints with a caller-selected remote bootstrap timeout.
- resolve_
remote_ concurrency - Resolve and validate all capacities that become Tokio semaphores in remote copy.
- wait_
for_ rcpd_ process