-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_info.rs
34 lines (29 loc) · 985 Bytes
/
run_info.rs
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
use std::{
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
path::{Path, PathBuf},
};
use serde::{Deserialize};
use completion_tracker_lib::{
tracking::{Tracker, TrackingInfo},
utils,
};
const RUN_INFO_FILE: &'static str = "runInfo.json";
#[derive(Deserialize)]
pub struct RunInfo {
port: u16,
local_tracking_folder: PathBuf,
trackers: Vec<TrackingInfo>,
}
impl RunInfo {
pub fn new_default() -> Result<RunInfo, String> { Self::new(RUN_INFO_FILE) }
pub fn new(info_path: impl AsRef<Path>) -> Result<RunInfo, String> {
utils::read_json_file(info_path)
}
pub fn socket_addr(&self) -> SocketAddr {
// Set up shop on every available address (for non-local connections)
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, self.port))
}
pub fn trackers(&self) -> Result<Vec<Tracker>, String> {
Tracker::new_from_info(&self.local_tracking_folder, &self.trackers)
}
}