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
addr: SocketAddr,
/// identifier
bytes: (usize,[u8;SocketBoundEndpoint::BUFFER_SIZE])
bytes: (usize, [u8; SocketBoundEndpoint::BUFFER_SIZE]),
}
impl std::fmt::Display for SocketBoundEndpoint {
@@ -237,7 +237,7 @@ impl SocketBoundEndpoint {
+ SocketBoundEndpoint::IPV6_SIZE
+ SocketBoundEndpoint::PORT_SIZE
+ SocketBoundEndpoint::SCOPE_ID_SIZE;
pub fn new(socket: SocketPtr, addr: SocketAddr) -> Self {
let bytes = Self::to_bytes(&socket, &addr);
Self {
@@ -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 addr = match addr {
SocketAddr::V4(addr) => {
@@ -258,8 +261,7 @@ impl SocketBoundEndpoint {
SocketAddr::V6(addr) => addr.clone(),
};
let mut len: usize = 0;
buf[len..len + SocketBoundEndpoint::SOCKET_SIZE]
.copy_from_slice(&socket.0.to_be_bytes());
buf[len..len + SocketBoundEndpoint::SOCKET_SIZE].copy_from_slice(&socket.0.to_be_bytes());
len += SocketBoundEndpoint::SOCKET_SIZE;
buf[len..len + SocketBoundEndpoint::IPV6_SIZE].copy_from_slice(&addr.ip().octets());
len += SocketBoundEndpoint::IPV6_SIZE;
@@ -724,8 +726,7 @@ impl AppServer {
) -> Result<crate::protocol::HandleMsgResult> {
match endpoint {
Endpoint::SocketBoundAddress(socket) => {
self.crypt
.handle_msg_under_load(&rx, &mut *tx, socket)
self.crypt.handle_msg_under_load(&rx, &mut *tx, socket)
}
Endpoint::Discovery(_) => {
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_mac = [0u8; MAC_SIZE];
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() {
if let Some(cookie_secret) = cookie_secret {
@@ -963,7 +963,11 @@ impl CryptoServer {
//If valid cookie is found, process message
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)?;
return Ok(result);
}
@@ -977,7 +981,11 @@ impl CryptoServer {
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_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 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)
log_builder.filter_level(log::LevelFilter::Debug);
log_builder.format_timestamp_nanos();
log_builder.format(|buf, record| {
log_builder.format(|buf, record| {
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();