-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.rs
More file actions
78 lines (71 loc) · 2.35 KB
/
Copy pathconfig.rs
File metadata and controls
78 lines (71 loc) · 2.35 KB
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
70
71
72
73
74
75
76
77
78
use crate::{Action, Bijection};
use alloc::{string::String, vec::Vec};
use ipnet::Ipv4Net;
use macaddr::MacAddr6;
use serde::{Deserialize, Serialize};
use std::{
net::{Ipv4Addr, SocketAddrV4},
path::PathBuf,
};
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum DhcpMode {
/// Unknown clients will be assigned IPs in the specified range.
Static(Ipv4Addr, Ipv4Addr),
/// Unknown clients are assumed to receive an IP address by another DHCP server.
/// The specified IP must belong to the network on which the other DHCP server gives IPs,
/// and the DHCP interface must have an IP on this network.
Proxy(Ipv4Addr),
}
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, Clone)]
pub struct InterfaceConfig {
/// Listen on address
pub network: Ipv4Net,
/// DHCP server.
pub dhcp: DhcpMode,
/// Speed in bytes/second used to broadcast chunks.
pub broadcast_speed: u32,
}
/// Registered clients will always be assigned an IP in the form
/// 10.{group_id}.{column_id}.{row_id}.
/// Note that for this to work, the specified network interface must have an IP on the 10.0.0.0/8
/// subnet; BEWARE that dnsmasq can be picky about the order of IP addresses.
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, Clone)]
pub struct HostsConfig {
/// Interfaces to operate on.
pub interfaces: Vec<InterfaceConfig>,
/// Hosts file to use for DHCP hostnames.
pub hostsfile: Option<PathBuf>,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct HttpConfig {
pub listen_on: SocketAddrV4,
pub password: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Config {
pub hosts: HostsConfig,
pub http: HttpConfig,
pub groups: Bijection<String, u8>,
pub images: Vec<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Unit {
pub mac: MacAddr6,
pub group: u8,
pub row: u8,
pub col: u8,
pub curr_action: Option<Action>,
pub curr_progress: Option<(usize, usize)>,
pub next_action: Action,
pub image: String,
#[serde(default)]
pub last_ping_timestamp: u64,
#[serde(default)]
pub last_ping_comment: Vec<u8>,
}
impl Unit {
pub fn static_ip(&self) -> Ipv4Addr {
Ipv4Addr::new(10, self.group, self.row, self.col)
}
}