[relay] Calls: a long-poll on the fetch route, TURN credentials for coturn, wakes every 10 s; the module passes the TURN secret by systemd credential
This commit is contained in:
+22
-1
@@ -1,9 +1,11 @@
|
||||
//! 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 arrivals;
|
||||
pub mod http;
|
||||
pub mod join;
|
||||
pub mod store;
|
||||
pub mod turn;
|
||||
pub mod wake;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
@@ -20,6 +22,10 @@ pub struct Args {
|
||||
pub limits: store::Limits,
|
||||
/// `--push-loopback`: accept and wake `http://` loopback push endpoints. Tests only.
|
||||
pub push_loopback: bool,
|
||||
/// `--turn-secret-file <path>`: the secret shared with the TURN server (calls); none means no TURN route.
|
||||
pub turn_secret_file: Option<PathBuf>,
|
||||
/// `--turn-url <url>` (repeatable): the TURN servers named in each credential.
|
||||
pub turn_urls: Vec<String>,
|
||||
}
|
||||
|
||||
/// `--listen <addr:port>`, `--db <path>`, the relay-wide quotas `--max-bytes`, `--max-mailboxes`,
|
||||
@@ -27,11 +33,13 @@ pub struct Args {
|
||||
/// (tests). Anything else is refused with a usage line.
|
||||
pub fn parse_args<I: IntoIterator<Item = String>>(args: I) -> Result<Args, String> {
|
||||
let usage = "usage: tabellarius-relay [--listen 127.0.0.1:8470] [--db tabellarius-relay.db] \
|
||||
[--max-bytes 1073741824] [--max-mailboxes 100000] [--max-invites 10000] \n [--max-files 10000] [--max-file-bytes 4294967296] [--push-loopback]";
|
||||
[--max-bytes 1073741824] [--max-mailboxes 100000] [--max-invites 10000] \n [--max-files 10000] [--max-file-bytes 4294967296] [--push-loopback] [--turn-secret-file <path> --turn-url <turn:host:port?transport=udp> ...]";
|
||||
let mut listen: SocketAddr = DEFAULT_LISTEN.parse().map_err(|_| usage.to_string())?;
|
||||
let mut db = PathBuf::from(DEFAULT_DB);
|
||||
let mut limits = store::Limits::default();
|
||||
let mut push_loopback = false;
|
||||
let mut turn_secret_file = None;
|
||||
let mut turn_urls = Vec::new();
|
||||
let mut it = args.into_iter();
|
||||
let positive = |v: Option<String>| -> Result<i64, String> {
|
||||
v.and_then(|v| v.parse::<i64>().ok())
|
||||
@@ -46,6 +54,13 @@ pub fn parse_args<I: IntoIterator<Item = String>>(args: I) -> Result<Args, Strin
|
||||
"--max-files" => limits.files = positive(it.next())?,
|
||||
"--max-file-bytes" => limits.file_bytes = positive(it.next())?,
|
||||
"--push-loopback" => push_loopback = true,
|
||||
"--turn-secret-file" => {
|
||||
turn_secret_file = Some(it.next().map(PathBuf::from).ok_or_else(|| usage.to_string())?)
|
||||
}
|
||||
"--turn-url" => {
|
||||
let url = it.next().filter(|u| u.starts_with("turn:") || u.starts_with("turns:"));
|
||||
turn_urls.push(url.ok_or_else(|| usage.to_string())?);
|
||||
}
|
||||
"--listen" => {
|
||||
listen = it
|
||||
.next()
|
||||
@@ -61,10 +76,16 @@ pub fn parse_args<I: IntoIterator<Item = String>>(args: I) -> Result<Args, Strin
|
||||
_ => return Err(usage.to_string()),
|
||||
}
|
||||
}
|
||||
// A secret without a URL, or URLs without a secret, is a mistake in the deployment.
|
||||
if turn_secret_file.is_some() != !turn_urls.is_empty() {
|
||||
return Err(usage.to_string());
|
||||
}
|
||||
Ok(Args {
|
||||
listen,
|
||||
db,
|
||||
limits,
|
||||
push_loopback,
|
||||
turn_secret_file,
|
||||
turn_urls,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user