mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-28 22:43:26 -08:00
Cargo fmt
This commit is contained in:
@@ -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 {
|
||||||
@@ -237,7 +237,7 @@ impl SocketBoundEndpoint {
|
|||||||
+ SocketBoundEndpoint::IPV6_SIZE
|
+ SocketBoundEndpoint::IPV6_SIZE
|
||||||
+ SocketBoundEndpoint::PORT_SIZE
|
+ SocketBoundEndpoint::PORT_SIZE
|
||||||
+ SocketBoundEndpoint::SCOPE_ID_SIZE;
|
+ SocketBoundEndpoint::SCOPE_ID_SIZE;
|
||||||
|
|
||||||
pub fn new(socket: SocketPtr, addr: SocketAddr) -> Self {
|
pub fn new(socket: SocketPtr, addr: SocketAddr) -> Self {
|
||||||
let bytes = Self::to_bytes(&socket, &addr);
|
let bytes = Self::to_bytes(&socket, &addr);
|
||||||
Self {
|
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 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")
|
||||||
|
|||||||
@@ -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()?
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user