diff --git a/Cargo.lock b/Cargo.lock index 89246d5..ebadece 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anstream" -version = "0.6.14" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", @@ -19,36 +19,36 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -63,26 +63,20 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "clap" -version = "4.5.9" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.9" +version = "4.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" dependencies = [ "anstream", "anstyle", @@ -92,25 +86,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "colorchoice" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" - -[[package]] -name = "colored" -version = "2.1.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" -dependencies = [ - "lazy_static", - "windows-sys 0.48.0", -] +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "crossbeam-channel" @@ -138,7 +122,7 @@ dependencies = [ [[package]] name = "diode" -version = "1.3.1" +version = "1.3.3" dependencies = [ "clap", "crossbeam-channel", @@ -146,9 +130,9 @@ dependencies = [ "fasthash", "libc", "log", - "rand 0.8.5", + "rand", "raptorq", - "simple_logger", + "simplelog", ] [[package]] @@ -164,7 +148,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "032213946b4eaae09117ec63f020322b78ca7a31d8aa2cf64df3032e1579690f" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "fasthash-sys", "num-traits", "seahash", @@ -192,22 +176,11 @@ version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itoa" @@ -215,17 +188,11 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "log" @@ -263,12 +230,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - [[package]] name = "proc-macro2" version = "1.0.86" @@ -280,9 +241,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -300,27 +261,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.4", -] - [[package]] name = "rand_core" version = "0.3.1" @@ -336,15 +276,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - [[package]] name = "raptorq" version = "2.0.0" @@ -368,18 +299,18 @@ checksum = "58f57ca1d128a43733fd71d583e837b1f22239a37ebea09cde11d8d9a9080f47" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -387,15 +318,14 @@ dependencies = [ ] [[package]] -name = "simple_logger" -version = "5.0.0" +name = "simplelog" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c5dfa5e08767553704aa0ffd9d9794d527103c736aba9854773851fd7497eb" +checksum = "16257adbfaef1ee58b1363bdc0664c9b8e1e30aed86049635fb5f147d065a9c0" dependencies = [ - "colored", "log", + "termcolor", "time", - "windows-sys 0.48.0", ] [[package]] @@ -406,15 +336,24 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.70" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "time" version = "0.3.36" @@ -460,12 +399,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "winapi" version = "0.3.9" @@ -483,19 +416,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "winapi-util" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys", +] [[package]] -name = "windows-sys" -version = "0.48.0" +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" @@ -503,22 +436,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -527,46 +445,28 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -579,48 +479,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.6" @@ -633,5 +509,5 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0eeda34baec49c4f1eb2c04d59b761582fd6330010f9330ca696ca1a355dfcd" dependencies = [ - "rand 0.4.6", + "rand", ] diff --git a/Cargo.toml b/Cargo.toml index 2b7b27e..9c3866f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/diode-file-bindings/src/lib.rs b/diode-file-bindings/src/lib.rs index 562f486..ad0c739 100644 --- a/diode-file-bindings/src/lib.rs +++ b/diode-file-bindings/src/lib.rs @@ -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, diff --git a/src/bin/diode-flood-test.rs b/src/bin/diode-flood-test.rs index 53cdb3e..d5d8d5a 100644 --- a/src/bin/diode-flood-test.rs +++ b/src/bin/diode-flood-test.rs @@ -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() { @@ -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::("buffer_size").expect("default"); - init_logger(); + diode::init_logger(); if let Some(to_tcp) = to_tcp { log::debug!("TCP connect to {}", to_tcp); @@ -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") -} diff --git a/src/bin/diode-receive-file.rs b/src/bin/diode-receive-file.rs index 0138f83..a4360c9 100644 --- a/src/bin/diode-receive-file.rs +++ b/src/bin/diode-receive-file.rs @@ -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") -} diff --git a/src/bin/diode-receive-udp.rs b/src/bin/diode-receive-udp.rs index 3160e70..72db1b2 100644 --- a/src/bin/diode-receive-udp.rs +++ b/src/bin/diode-receive-udp.rs @@ -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") -} diff --git a/src/bin/diode-receive.rs b/src/bin/diode-receive.rs index b1803a7..9396297 100644 --- a/src/bin/diode-receive.rs +++ b/src/bin/diode-receive.rs @@ -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); @@ -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") -} diff --git a/src/bin/diode-send-file.rs b/src/bin/diode-send-file.rs index e603c3b..07ec97f 100644 --- a/src/bin/diode-send-file.rs +++ b/src/bin/diode-send-file.rs @@ -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") -} diff --git a/src/bin/diode-send-udp.rs b/src/bin/diode-send-udp.rs index a2c8428..af0cb41 100644 --- a/src/bin/diode-send-udp.rs +++ b/src/bin/diode-send-udp.rs @@ -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") -} diff --git a/src/bin/diode-send.rs b/src/bin/diode-send.rs index a0da03e..006f4a5 100644 --- a/src/bin/diode-send.rs +++ b/src/bin/diode-send.rs @@ -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, @@ -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") -} diff --git a/src/lib.rs b/src/lib.rs index 5735a9d..d2ada33 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +use std::str::FromStr; + pub mod aux; pub mod protocol; pub mod receive; @@ -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"); +} diff --git a/src/protocol.rs b/src/protocol.rs index 54bc39d..8dfabf9 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -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), @@ -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::() + CLIENT_ID_COUNTER.fetch_add(1, sync::atomic::Ordering::Relaxed) } pub struct Message(Vec); diff --git a/src/receive/mod.rs b/src/receive/mod.rs index 6e4c1fd..9a174d0 100644 --- a/src/receive/mod.rs +++ b/src/receive/mod.rs @@ -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))?; } diff --git a/src/send/mod.rs b/src/send/mod.rs index 478350d..a4a9950 100644 --- a/src/send/mod.rs +++ b/src/send/mod.rs @@ -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))?; }