ripsync_core/net/server.rs
1//! The `ripsync --server` peer: speaks the protocol over stdin/stdout.
2//!
3//! Spawned on the remote host by the initiator's ssh command. It plays the
4//! opposite role to whatever the initiator asked for: for [`Role::Push`] it is
5//! the receiver (writing into the remote destination), for [`Role::Pull`] it is
6//! the sender (reading the remote source). Every path it touches is confined under
7//! the negotiated root by the receiver's containment checks.
8
9use crate::filter::Filter;
10use crate::net::run_responder;
11use crate::net::transport::IoDuplex;
12use crate::report::{Reporter, Stats};
13use crate::{Result, RunControl};
14
15/// Run the server peer to completion, reading the protocol from stdin and writing
16/// it to stdout. Diagnostics must go to stderr (never stdout, which is the wire).
17///
18/// # Errors
19///
20/// Returns a handshake, protocol, walk, or I/O error.
21pub fn run_server<R: Reporter>(
22 threads: usize,
23 control: &RunControl,
24 reporter: &R,
25) -> Result<Stats> {
26 let stdin = std::io::stdin();
27 let stdout = std::io::stdout();
28 let mut conn = IoDuplex::new(stdin.lock(), stdout.lock());
29 // The server applies no local filter; the initiator filters its own walk.
30 let filter = Filter::none();
31 run_responder(&mut conn, &filter, threads, control, reporter)
32}