diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 2 | ||||
-rw-r--r-- | src/routes/start.rs | 6 | ||||
-rw-r--r-- | src/services/ping.rs | 12 | ||||
-rw-r--r-- | src/storage.rs | 4 |
4 files changed, 13 insertions, 11 deletions
diff --git a/src/config.rs b/src/config.rs index bfb28be..7c91c08 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -7,7 +7,7 @@ use crate::auth; | |||
7 | pub struct Config { | 7 | pub struct Config { |
8 | pub serveraddr: String, | 8 | pub serveraddr: String, |
9 | pub pingtimeout: i64, | 9 | pub pingtimeout: i64, |
10 | pub pingthreshold: i64, | 10 | pub pingthreshold: u64, |
11 | pub timeoffset: i8, | 11 | pub timeoffset: i8, |
12 | pub auth: Auth, | 12 | pub auth: Auth, |
13 | } | 13 | } |
diff --git a/src/routes/start.rs b/src/routes/start.rs index 192a54a..e9436f1 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs | |||
@@ -16,7 +16,7 @@ use uuid::Uuid; | |||
16 | path = "/start/{id}", | 16 | path = "/start/{id}", |
17 | request_body = Option<SPayload>, | 17 | request_body = Option<SPayload>, |
18 | responses( | 18 | responses( |
19 | (status = 200, description = "start the device with the given id", body = [Response]) | 19 | (status = 200, description = "start device with the given id", body = [Response]) |
20 | ), | 20 | ), |
21 | params( | 21 | params( |
22 | ("id" = String, Path, description = "device id") | 22 | ("id" = String, Path, description = "device id") |
@@ -128,14 +128,14 @@ fn setup_ping(state: Arc<crate::AppState>, device: Device) -> String { | |||
128 | uuid_ret | 128 | uuid_ret |
129 | } | 129 | } |
130 | 130 | ||
131 | fn get_eta(times: Option<Vec<i64>>) -> i64 { | 131 | fn get_eta(times: Option<Vec<u64>>) -> u64 { |
132 | let times = if let Some(times) = times { | 132 | let times = if let Some(times) = times { |
133 | times | 133 | times |
134 | } else { | 134 | } else { |
135 | vec![0] | 135 | vec![0] |
136 | }; | 136 | }; |
137 | 137 | ||
138 | times.iter().sum::<i64>() / i64::try_from(times.len()).unwrap() | 138 | times.iter().sum::<u64>() / u64::try_from(times.len()).unwrap() |
139 | } | 139 | } |
140 | 140 | ||
141 | #[derive(Deserialize, ToSchema)] | 141 | #[derive(Deserialize, ToSchema)] |
diff --git a/src/services/ping.rs b/src/services/ping.rs index 4e0ffcf..69c911f 100644 --- a/src/services/ping.rs +++ b/src/services/ping.rs | |||
@@ -2,8 +2,8 @@ use crate::config::Config; | |||
2 | use crate::storage::Device; | 2 | use crate::storage::Device; |
3 | use dashmap::DashMap; | 3 | use dashmap::DashMap; |
4 | use ipnetwork::IpNetwork; | 4 | use ipnetwork::IpNetwork; |
5 | use std::fmt::Display; | 5 | use std::{fmt::Display, time::Instant}; |
6 | use time::{Duration, Instant}; | 6 | use time::Duration; |
7 | use tokio::sync::broadcast::Sender; | 7 | use tokio::sync::broadcast::Sender; |
8 | use tracing::{debug, error, trace}; | 8 | use tracing::{debug, error, trace}; |
9 | 9 | ||
@@ -12,7 +12,7 @@ pub type StatusMap = DashMap<String, Value>; | |||
12 | #[derive(Debug, Clone)] | 12 | #[derive(Debug, Clone)] |
13 | pub struct Value { | 13 | pub struct Value { |
14 | pub ip: IpNetwork, | 14 | pub ip: IpNetwork, |
15 | pub eta: i64, | 15 | pub eta: u64, |
16 | pub online: bool, | 16 | pub online: bool, |
17 | } | 17 | } |
18 | 18 | ||
@@ -56,12 +56,12 @@ pub async fn spawn( | |||
56 | 56 | ||
57 | let _ = tx.send(msg.clone()); | 57 | let _ = tx.send(msg.clone()); |
58 | if msg.command == BroadcastCommands::Success { | 58 | if msg.command == BroadcastCommands::Success { |
59 | if timer.elapsed().whole_seconds() > config.pingthreshold { | 59 | if timer.elapsed().as_secs() > config.pingthreshold { |
60 | let newtimes = if let Some(mut oldtimes) = device.times { | 60 | let newtimes = if let Some(mut oldtimes) = device.times { |
61 | oldtimes.push(timer.elapsed().whole_seconds()); | 61 | oldtimes.push(timer.elapsed().as_secs()); |
62 | oldtimes | 62 | oldtimes |
63 | } else { | 63 | } else { |
64 | vec![timer.elapsed().whole_seconds()] | 64 | vec![timer.elapsed().as_secs()] |
65 | }; | 65 | }; |
66 | 66 | ||
67 | let updatedev = Device { | 67 | let updatedev = Device { |
diff --git a/src/storage.rs b/src/storage.rs index 52c2e60..90ff1b4 100644 --- a/src/storage.rs +++ b/src/storage.rs | |||
@@ -19,7 +19,7 @@ pub struct Device { | |||
19 | pub mac: MacAddress, | 19 | pub mac: MacAddress, |
20 | pub broadcast_addr: String, | 20 | pub broadcast_addr: String, |
21 | pub ip: Option<IpNetwork>, | 21 | pub ip: Option<IpNetwork>, |
22 | pub times: Option<Vec<i64>>, | 22 | pub times: Option<Vec<u64>>, |
23 | } | 23 | } |
24 | 24 | ||
25 | impl Device { | 25 | impl Device { |
@@ -59,6 +59,8 @@ impl Device { | |||
59 | } | 59 | } |
60 | } | 60 | } |
61 | 61 | ||
62 | // Dead Code allowed because of use in OpenApi Macro (not really dead code) | ||
63 | #[allow(dead_code)] | ||
62 | #[derive(ToSchema)] | 64 | #[derive(ToSchema)] |
63 | #[schema(as = Device)] | 65 | #[schema(as = Device)] |
64 | pub struct DeviceSchema { | 66 | pub struct DeviceSchema { |