Cargo fmt

This commit is contained in:
Prabhpreet Dua
2024-04-16 11:18:47 +05:30
parent 8420d953eb
commit 9396784c0f
3 changed files with 34 additions and 13 deletions

View File

@@ -218,7 +218,7 @@ pub struct SocketBoundEndpoint {
/// Just the address /// Just the address
addr: SocketAddr, addr: SocketAddr,
/// identifier /// identifier
bytes: (usize,[u8;SocketBoundEndpoint::BUFFER_SIZE]) bytes: (usize, [u8; SocketBoundEndpoint::BUFFER_SIZE]),
} }
impl std::fmt::Display for SocketBoundEndpoint { impl std::fmt::Display for SocketBoundEndpoint {
@@ -247,7 +247,10 @@ impl SocketBoundEndpoint {
} }
} }
fn to_bytes(socket: &SocketPtr, addr: &SocketAddr) -> (usize, [u8; SocketBoundEndpoint::BUFFER_SIZE]) { fn to_bytes(
socket: &SocketPtr,
addr: &SocketAddr,
) -> (usize, [u8; SocketBoundEndpoint::BUFFER_SIZE]) {
let mut buf = [0u8; SocketBoundEndpoint::BUFFER_SIZE]; let mut buf = [0u8; SocketBoundEndpoint::BUFFER_SIZE];
let addr = match addr { let addr = match addr {
SocketAddr::V4(addr) => { SocketAddr::V4(addr) => {
@@ -258,8 +261,7 @@ impl SocketBoundEndpoint {
SocketAddr::V6(addr) => addr.clone(), SocketAddr::V6(addr) => addr.clone(),
}; };
let mut len: usize = 0; let mut len: usize = 0;
buf[len..len + SocketBoundEndpoint::SOCKET_SIZE] buf[len..len + SocketBoundEndpoint::SOCKET_SIZE].copy_from_slice(&socket.0.to_be_bytes());
.copy_from_slice(&socket.0.to_be_bytes());
len += SocketBoundEndpoint::SOCKET_SIZE; len += SocketBoundEndpoint::SOCKET_SIZE;
buf[len..len + SocketBoundEndpoint::IPV6_SIZE].copy_from_slice(&addr.ip().octets()); buf[len..len + SocketBoundEndpoint::IPV6_SIZE].copy_from_slice(&addr.ip().octets());
len += SocketBoundEndpoint::IPV6_SIZE; len += SocketBoundEndpoint::IPV6_SIZE;
@@ -724,8 +726,7 @@ impl AppServer {
) -> Result<crate::protocol::HandleMsgResult> { ) -> Result<crate::protocol::HandleMsgResult> {
match endpoint { match endpoint {
Endpoint::SocketBoundAddress(socket) => { Endpoint::SocketBoundAddress(socket) => {
self.crypt self.crypt.handle_msg_under_load(&rx, &mut *tx, socket)
.handle_msg_under_load(&rx, &mut *tx, socket)
} }
Endpoint::Discovery(_) => { Endpoint::Discovery(_) => {
anyhow::bail!("Host-path discovery is not supported under load") anyhow::bail!("Host-path discovery is not supported under load")

View File

@@ -932,7 +932,7 @@ impl CryptoServer {
let mut rx_cookie = [0u8; COOKIE_SIZE]; let mut rx_cookie = [0u8; COOKIE_SIZE];
let mut rx_mac = [0u8; MAC_SIZE]; let mut rx_mac = [0u8; MAC_SIZE];
let mut rx_sid = [0u8; 4]; let mut rx_sid = [0u8; 4];
let msg_type : Result<MsgType,_> = rx_buf[0].try_into(); let msg_type: Result<MsgType, _> = rx_buf[0].try_into();
for cookie_secret in self.active_or_retired_cookie_secrets() { for cookie_secret in self.active_or_retired_cookie_secrets() {
if let Some(cookie_secret) = cookie_secret { if let Some(cookie_secret) = cookie_secret {
@@ -963,7 +963,11 @@ impl CryptoServer {
//If valid cookie is found, process message //If valid cookie is found, process message
if constant_time::memcmp(&rx_cookie, &expected) { if constant_time::memcmp(&rx_cookie, &expected) {
log::debug!("Rx {:?} from {} under load, valid cookie", msg_type, host_identification); log::debug!(
"Rx {:?} from {} under load, valid cookie",
msg_type,
host_identification
);
let result = self.handle_msg(rx_buf, tx_buf)?; let result = self.handle_msg(rx_buf, tx_buf)?;
return Ok(result); return Ok(result);
} }
@@ -977,7 +981,11 @@ impl CryptoServer {
bail!("No active cookie value found"); bail!("No active cookie value found");
} }
log::debug!("Rx {:?} from {} under load, tx cookie reply message", msg_type, host_identification); log::debug!(
"Rx {:?} from {} under load, tx cookie reply message",
msg_type,
host_identification
);
let cookie_value = active_cookie_value.unwrap(); let cookie_value = active_cookie_value.unwrap();
let cookie_key = hash_domains::cookie_key()? let cookie_key = hash_domains::cookie_key()?

View File

@@ -1,4 +1,10 @@
use std::{fs::{self, write}, net::UdpSocket, path::PathBuf, process::Stdio, time::Duration}; use std::{
fs::{self, write},
net::UdpSocket,
path::PathBuf,
process::Stdio,
time::Duration,
};
use clap::Parser; use clap::Parser;
use rosenpass::{app_server::AppServerTestBuilder, cli::CliArgs}; use rosenpass::{app_server::AppServerTestBuilder, cli::CliArgs};
@@ -137,9 +143,15 @@ fn check_exchange_under_dos() {
let mut log_builder = env_logger::Builder::from_default_env(); // sets log level filter from environment (or defaults) let mut log_builder = env_logger::Builder::from_default_env(); // sets log level filter from environment (or defaults)
log_builder.filter_level(log::LevelFilter::Debug); log_builder.filter_level(log::LevelFilter::Debug);
log_builder.format_timestamp_nanos(); log_builder.format_timestamp_nanos();
log_builder.format(|buf, record| { log_builder.format(|buf, record| {
let ts_format = buf.timestamp_nanos().to_string(); let ts_format = buf.timestamp_nanos().to_string();
writeln!(buf, "\x1b[1m{:?}\x1b[0m {}: {}", std::thread::current().id(), &ts_format[18..], record.args()) writeln!(
buf,
"\x1b[1m{:?}\x1b[0m {}: {}",
std::thread::current().id(),
&ts_format[18..],
record.args()
)
}); });
let _ = log_builder.try_init(); let _ = log_builder.try_init();