Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated dependencies, binary sizes improvement and updated logger #20

Merged
merged 7 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
258 changes: 67 additions & 191 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
[package]
name = "diode"
version = "1.3.1"
version = "1.3.3"
edition = "2021"
license = "GPL-3.0"

[dependencies]
clap = "4"
crossbeam-channel = "0.5"
crossbeam-utils = "0.8"
fasthash = "0.4"
libc = "0.2"
log = "0.4"
rand = "0.8"
crossbeam-channel = "0"
crossbeam-utils = "0"
fasthash = "0"
libc = "0"
log = "0"
rand = "0"
raptorq = "2"
simple_logger = "5"
simplelog = "0"

[profile.release]
opt-level = "z"
lto = true
opt-level = 3
debug = false
strip = true
panic = "abort"

[workspace]
members = [".", "diode-file-bindings"]
2 changes: 1 addition & 1 deletion diode-file-bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unsafe_code)]

use diode::aux::{self,file};
use diode::aux::{self, file};
use std::{
ffi::{c_char, CStr},
net::SocketAddr,
Expand Down
13 changes: 2 additions & 11 deletions src/bin/diode-flood-test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::{Arg, ArgGroup, Command};
use rand::RngCore;
use rand::Rng;
use std::{env, io::Write, net, os::unix, path, str::FromStr};

fn main() {
Expand Down Expand Up @@ -40,7 +40,7 @@ fn main() {
.map(|s| path::PathBuf::from_str(s).expect("to_unix must point to a valid path"));
let buffer_size = *args.get_one::<usize>("buffer_size").expect("default");

init_logger();
diode::init_logger();

if let Some(to_tcp) = to_tcp {
log::debug!("TCP connect to {}", to_tcp);
Expand Down Expand Up @@ -71,12 +71,3 @@ where
diode.write_all(&buffer).expect("write");
}
}

fn init_logger() {
if env::var("RUST_LOG").is_ok() {
simple_logger::init_with_env()
} else {
simple_logger::init_with_level(log::Level::Info)
}
.expect("logger initialization")
}
11 changes: 1 addition & 10 deletions src/bin/diode-receive-file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,9 @@ fn main() {
hash,
};

init_logger();
diode::init_logger();

if let Err(e) = file::receive::receive_files(&config, &output_directory) {
log::error!("{e}");
}
}

fn init_logger() {
if env::var("RUST_LOG").is_ok() {
simple_logger::init_with_env()
} else {
simple_logger::init_with_level(log::Level::Info)
}
.expect("logger initialization")
}
11 changes: 1 addition & 10 deletions src/bin/diode-receive-udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,9 @@ fn main() {
buffer_size: u16::MAX as usize,
};

init_logger();
diode::init_logger();

if let Err(e) = udp::receive::receive(&config, to_udp_bind, to_udp) {
log::error!("{e}");
}
}

fn init_logger() {
if env::var("RUST_LOG").is_ok() {
simple_logger::init_with_env()
} else {
simple_logger::init_with_level(log::Level::Info)
}
.expect("logger initialization")
}
11 changes: 1 addition & 10 deletions src/bin/diode-receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl TryFrom<&ClientConfig> for Client {
fn main() {
let config = command_args();

init_logger();
diode::init_logger();

log::info!("sending traffic to {}", config.to);

Expand All @@ -251,12 +251,3 @@ fn main() {
}
});
}

fn init_logger() {
if env::var("RUST_LOG").is_ok() {
simple_logger::init_with_env()
} else {
simple_logger::init_with_level(log::Level::Info)
}
.expect("logger initialization")
}
11 changes: 1 addition & 10 deletions src/bin/diode-send-file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,9 @@ fn main() {
hash,
};

init_logger();
diode::init_logger();

if let Err(e) = file::send::send_files(&config, &files) {
log::error!("{e}");
}
}

fn init_logger() {
if env::var("RUST_LOG").is_ok() {
simple_logger::init_with_env()
} else {
simple_logger::init_with_level(log::Level::Info)
}
.expect("logger initialization")
}
11 changes: 1 addition & 10 deletions src/bin/diode-send-udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,9 @@ fn main() {
buffer_size: u16::MAX as usize,
};

init_logger();
diode::init_logger();

if let Err(e) = udp::send::send(&config, from_udp) {
log::error!("{e}");
}
}

fn init_logger() {
if env::var("RUST_LOG").is_ok() {
simple_logger::init_with_env()
} else {
simple_logger::init_with_level(log::Level::Info)
}
.expect("logger initialization")
}
11 changes: 1 addition & 10 deletions src/bin/diode-send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ fn tcp_listener_loop(
fn main() {
let config = command_args();

init_logger();
diode::init_logger();

let sender = send::Sender::new(send::Config {
nb_clients: config.nb_clients,
Expand Down Expand Up @@ -314,12 +314,3 @@ fn main() {
}
});
}

fn init_logger() {
if env::var("RUST_LOG").is_ok() {
simple_logger::init_with_env()
} else {
simple_logger::init_with_level(log::Level::Info)
}
.expect("logger initialization")
}
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

pub mod aux;
pub mod protocol;
pub mod receive;
Expand All @@ -12,3 +14,26 @@ pub mod sock_utils;
// libc functions recv_mmsg and send_mmsg.
#[allow(unsafe_code)]
pub mod udp;

pub fn init_logger() {
let level_filter = std::env::var("RUST_LOG")
.map_err(|_| ())
.and_then(|rust_log| simplelog::LevelFilter::from_str(&rust_log).map_err(|_| ()))
.unwrap_or(simplelog::LevelFilter::Info);

let config = simplelog::ConfigBuilder::new()
.set_level_padding(simplelog::LevelPadding::Right)
.set_target_level(simplelog::LevelFilter::Off)
.set_thread_level(simplelog::LevelFilter::Info)
.set_thread_mode(simplelog::ThreadLogMode::Names)
.set_time_format_rfc2822()
.build();

simplelog::TermLogger::init(
level_filter,
config,
simplelog::TerminalMode::Mixed,
simplelog::ColorChoice::Auto,
)
.expect("failed to initialize termlogger");
}
6 changes: 4 additions & 2 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//! is of type `Heartbeat`, `Abort` or `End`. Then the `data_length` will be set to 0 by the
//! message constructor and the data chunk will be fully padded with zeros.

use std::{fmt, io};
use std::{fmt, io, sync};

pub enum Error {
Io(io::Error),
Expand Down Expand Up @@ -95,8 +95,10 @@ const ID_END: u8 = 0x04;

pub(crate) type ClientId = u32;

static CLIENT_ID_COUNTER: sync::atomic::AtomicU32 = sync::atomic::AtomicU32::new(0);

pub(crate) fn new_client_id() -> ClientId {
rand::random::<ClientId>()
CLIENT_ID_COUNTER.fetch_add(1, sync::atomic::Ordering::Relaxed)
}

pub struct Message(Vec<u8>);
Expand Down
2 changes: 1 addition & 1 deletion src/receive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ where

for i in 0..self.config.nb_clients {
thread::Builder::new()
.name(format!("client_{i}"))
.name(format!("receive_thread_{i}"))
.spawn_scoped(scope, || clients::start(self))?;
}

Expand Down
2 changes: 1 addition & 1 deletion src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ where

for i in 0..self.config.nb_clients {
thread::Builder::new()
.name(format!("client_{i}"))
.name(format!("send_thread_{i}"))
.spawn_scoped(scope, || server::start(self))?;
}

Expand Down