//! The Tabellarius relay: holds ciphertext addressed to a mailbox until its owner fetches and //! acknowledges it. Stores exactly `docs/PROTOCOL.md` ยง5 and logs no request. pub mod http; pub mod store; use std::net::SocketAddr; use std::path::PathBuf; /// Loopback unless told otherwise: a relay reachable from outside is a deliberate choice (F23). pub const DEFAULT_LISTEN: &str = "127.0.0.1:8470"; pub const DEFAULT_DB: &str = "tabellarius-relay.db"; #[derive(Debug, PartialEq, Eq)] pub struct Args { pub listen: SocketAddr, pub db: PathBuf, } /// `--listen `, `--db `. Anything else is refused with a usage line. pub fn parse_args>(args: I) -> Result { let usage = "usage: tabellarius-relay [--listen 127.0.0.1:8470] [--db tabellarius-relay.db]"; let mut listen: SocketAddr = DEFAULT_LISTEN.parse().map_err(|_| usage.to_string())?; let mut db = PathBuf::from(DEFAULT_DB); let mut it = args.into_iter(); while let Some(arg) = it.next() { match arg.as_str() { "--listen" => { listen = it .next() .and_then(|v| v.parse().ok()) .ok_or_else(|| usage.to_string())?; } "--db" => { db = it .next() .map(PathBuf::from) .ok_or_else(|| usage.to_string())? } _ => return Err(usage.to_string()), } } Ok(Args { listen, db }) }