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 → Master (control)
│ └── TCP Server (accepts data connections from Destination)
└── SSH → Destination Host (rcpd)
└── TCP → Master (control)
└── TCP Client → Source (data transfer)§Connection Flow
- Initialization: Master starts
rcpdprocesses on source and destination via SSH - Control Connections: Both
rcpdprocesses connect back to Master via TCP - 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 listener
§Port Range Configuration
The port_ranges module allows restricting TCP to specific port ranges, useful for firewall-restricted environments:
let config = remote::TcpConfig::default().with_port_ranges("8000-8999");
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 resultsTracingHello- rcpd → Master tracing initialization
§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 SSH stdout (trusted 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
- rcpd Cannot Connect to Master: 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§
- deploy
- Binary deployment for rcpd
- port_
ranges - protocol
- Remote copy protocol definitions for source-destination communication.
- streams
- tls
- TLS support for encrypted and authenticated connections.
- tracelog
Structs§
- Rcpd
Connection Info - Connection info received from rcpd after it starts listening.
- Rcpd
Process - Result of starting an rcpd process.
- SshSession
- TcpConfig
- Configuration for TCP connections
Enums§
- 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_
PENDING_ WRITES_ MULTIPLIER - Default multiplier for pending writes (4× max_connections)
- INTERNET_
REMOTE_ COPY_ BUFFER_ SIZE - Internet profile: buffer size for remote copy operations (2 MiB)
Functions§
- configure_
tcp_ buffers - Configure TCP socket buffer sizes for high throughput
- connect_
tcp_ control - Connect to a TCP control server with timeout
- create_
tcp_ control_ listener - Create a TCP listener for control connections
- create_
tcp_ data_ listener - Create a TCP listener for data connections (file transfers)
- get_
random_ server_ name - Generate a random server name for identifying connections
- get_
remote_ home - Validate and retrieve HOME directory on remote host
- get_
remote_ home_ for_ session - 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 - start_
rcpd - wait_
for_ rcpd_ process