Skip to main content

Crate remote

Crate remote 

Source
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

  1. Initialization: Master starts rcpd processes on source and destination via SSH
  2. Control Connections: Master connects to each rcpd’s TCP listener (address read from the rcpd’s stderr over SSH)
  3. Address Exchange: Source starts TCP listeners and sends addresses to Master
  4. Direct Connection: Master forwards addresses to Destination, which connects to Source
  5. 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 rcpd daemons 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:

§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 configuration
  • SourceMasterHello - Source → Master address information
  • RcpdResult - rcpd → Master operation results

§Stream Communication

The streams module provides high-level abstractions over TCP streams:

§Remote Tracing

The tracelog module enables distributed logging and progress tracking:

  • Forward tracing events from remote rcpd processes 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:

  1. Each rcpd generates an ephemeral self-signed certificate
  2. rcpd outputs its certificate fingerprint to stderr (read by master over the trusted SSH channel)
  3. Master connects to rcpd as TLS client, verifies fingerprint
  4. 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-ranges to specify allowed ports

§Module Organization

  • port_ranges - Port range parsing and socket binding
  • protocol - Protocol message definitions and serialization
  • streams - TCP stream wrappers with typed message passing
  • tls - TLS certificate generation and configuration
  • tracelog - 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§

AbortOnDropTask
Owns a Tokio task and aborts it if its supervising future is cancelled.
PreparedRcpd
RcpdConnectionInfo
Connection info received from rcpd after it starts listening.
RcpdProcess
Result of starting an rcpd process.
RemoteCleanup
Owns all blocking cleanup work started by one rcp invocation.
ResolvedRemoteConcurrency
Validated capacities used by the remote file-transfer pipeline.
SshSession
TcpConfig
Configuration for TCP connections

Enums§

ConnectionKind
What an rcp TCP connection carries, which decides whether TCP_USER_TIMEOUT applies.
NetworkProfile
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