[relay] F23: quotas (507), a NixOS module behind Caddy with TLS and no logs, and a VM test that no address is kept
This commit is contained in:
+16
-3
@@ -15,16 +15,29 @@ pub const DEFAULT_DB: &str = "tabellarius-relay.db";
|
||||
pub struct Args {
|
||||
pub listen: SocketAddr,
|
||||
pub db: PathBuf,
|
||||
pub limits: store::Limits,
|
||||
}
|
||||
|
||||
/// `--listen <addr:port>`, `--db <path>`. Anything else is refused with a usage line.
|
||||
/// `--listen <addr:port>`, `--db <path>`, and the relay-wide quotas `--max-bytes`,
|
||||
/// `--max-mailboxes`, `--max-invites` (positive integers). 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]";
|
||||
let usage = "usage: tabellarius-relay [--listen 127.0.0.1:8470] [--db tabellarius-relay.db] \
|
||||
[--max-bytes 1073741824] [--max-mailboxes 100000] [--max-invites 10000]";
|
||||
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 it = args.into_iter();
|
||||
let positive = |v: Option<String>| -> Result<i64, String> {
|
||||
v.and_then(|v| v.parse::<i64>().ok())
|
||||
.filter(|&n| n > 0)
|
||||
.ok_or_else(|| usage.to_string())
|
||||
};
|
||||
while let Some(arg) = it.next() {
|
||||
match arg.as_str() {
|
||||
"--max-bytes" => limits.total_bytes = positive(it.next())?,
|
||||
"--max-mailboxes" => limits.mailboxes = positive(it.next())?,
|
||||
"--max-invites" => limits.invites = positive(it.next())?,
|
||||
"--listen" => {
|
||||
listen = it
|
||||
.next()
|
||||
@@ -40,5 +53,5 @@ pub fn parse_args<I: IntoIterator<Item = String>>(args: I) -> Result<Args, Strin
|
||||
_ => return Err(usage.to_string()),
|
||||
}
|
||||
}
|
||||
Ok(Args { listen, db })
|
||||
Ok(Args { listen, db, limits })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user