1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#![feature(iterator_try_collect)]
#![feature(never_type)]
pub mod server;
use clap::{Parser, Subcommand};
use serde::Deserialize;
use server::server;
use std::{fs::read_to_string, net::SocketAddr, path::PathBuf};
pub type Serial = u64;
#[derive(Parser)]
struct Args {
config: PathBuf,
#[clap(subcommand)]
action: Action,
}
#[derive(Subcommand)]
enum Action {
Daemon,
Restore { id: String, destination: PathBuf },
Backup { path: PathBuf },
}
#[derive(Deserialize)]
pub struct Config {
storage: StorageConfig,
server: ServerConfig,
peer: Vec<PeerConfig>,
}
#[derive(Deserialize)]
pub struct PeerConfig {
name: String,
address: SocketAddr,
shared_secret: String,
}
#[derive(Deserialize)]
pub struct ServerConfig {
address: String,
}
#[derive(Deserialize)]
pub struct StorageConfig {
root: PathBuf,
size: u64,
versions: usize,
upload_cooldown: u64,
download_cooldown: u64,
upload_speed: usize,
download_speed: usize,
}
fn main() -> anyhow::Result<()> {
env_logger::init_from_env("LOG");
let args = Args::parse();
let config = read_to_string(&args.config)?;
let config = toml::from_str::<Config>(&config)?;
match args.action {
Action::Daemon => server(config.into())?,
Action::Restore { id, destination } => todo!(),
Action::Backup { path } => todo!(),
}
Ok(())
}
|