Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
xarantolus committed Dec 26, 2023
1 parent 79bc881 commit 1645146
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
22 changes: 11 additions & 11 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,19 @@ impl MystiClient {
let socket = {
let mut fail_count = 0;
loop {
match connect_async(moved_server_url.clone()).await {
Ok((socket, _)) => break socket,
Err(e) => {
if fail_count % 12 == 0 {
eprintln!("Failed to connect to server: {}", e);
}
fail_count += 1;

match connect_async(moved_server_url.clone()).await {
Ok((socket, _)) => break socket,
Err(e) => {
if fail_count % 12 == 0 {
eprintln!("Failed to connect to server: {}", e);
tokio::time::sleep(Duration::from_secs(5)).await;
}
fail_count += 1;

tokio::time::sleep(Duration::from_secs(5)).await;
}
};
}};
};
}
};

println!("Connected to server");

Expand Down
25 changes: 14 additions & 11 deletions server/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{net::IpAddr, str::FromStr, path::Display};
use std::{net::IpAddr, str::FromStr};

use anyhow::{Context, Result};
use macaddr::MacAddr6;
Expand All @@ -11,7 +11,6 @@ pub struct Config {
pub token: String,
}


#[derive(Deserialize, Debug, Clone)]
pub struct WakeOnLanConfig {
pub target_addr: ParseableMacAddr,
Expand Down Expand Up @@ -48,20 +47,18 @@ impl<'de> serde::Deserialize<'de> for ParseableMacAddr {
use serde::de::Error;

let mac = String::deserialize(deserializer).and_then(|s| {
MacAddr6::from_str(&s).map_err(|e| match e {
MacAddr6::from_str(&s).map_err(|e| match e {
ParseError::InvalidLength(_) => Error::invalid_length(s.len(), &"17"),
ParseError::InvalidCharacter(c, _) => Error::invalid_value(
serde::de::Unexpected::Char(c),
&"a valid hex character"
),
ParseError::InvalidCharacter(c, _) => {
Error::invalid_value(serde::de::Unexpected::Char(c), &"a valid hex character")
}
})
})?;

Ok(ParseableMacAddr(mac))
}
}


#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -71,8 +68,14 @@ mod tests {
assert_eq!(config.web_port, 9138);
assert_eq!(config.token, "some_token");

assert_eq!(config.wake_on_lan.target_addr.0, MacAddr6::new(0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA));
assert_eq!(config.wake_on_lan.router_addr.unwrap(), IpAddr::from_str("255.255.255.255").unwrap());
assert_eq!(
config.wake_on_lan.target_addr.0,
MacAddr6::new(0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA)
);
assert_eq!(
config.wake_on_lan.router_addr.unwrap(),
IpAddr::from_str("255.255.255.255").unwrap()
);
}

#[test]
Expand All @@ -98,6 +101,6 @@ mod tests {
target_addr = "AA:AA:AA:aa:AA:AA"
router_addr = "255.255.255.255""#;

assert_config(config_str);
assert_config(config_str);
}
}

0 comments on commit 1645146

Please sign in to comment.