From b03380b1cafb3148ed268ccaac36ec6ad5c8a1c0 Mon Sep 17 00:00:00 2001 From: Victor Boivie Date: Mon, 16 Nov 2026 11:59:01 +0100 Subject: [PATCH] Stop logging packets and socket events Every sent and received packet and every socket event was logged at info level through the log crate. Callers got these logs if they had configured a logger and enabled info level logging for this library. Everything that was logged passes through the public API, so callers that want these logs can generate them outside the library: sent packets and events are returned by poll_event, and received packets are passed in through handle_input. --- CHANGELOG.md | 4 +++ src/lib.rs | 29 ----------------- src/socket/mod.rs | 79 +---------------------------------------------- 3 files changed, 5 insertions(+), 107 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5153596..7f0511a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to ## Unreleased +### Removed + + - Removed logging of packets and events at info level. + ## 0.1.18 - 2026-11-13 ### Changed diff --git a/src/lib.rs b/src/lib.rs index e3f497a..c4759ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,35 +53,6 @@ pub mod fuzzer; #[cfg(feature = "cxx")] pub mod ffi; -pub(crate) mod logging { - use crate::api::SocketTime; - #[cfg(not(test))] - use log::info; - use std::fmt::Write; - #[cfg(test)] - use std::println as info; - use std::string::String; - - pub fn log_packet(name: &str, ts: SocketTime, sent: bool, data: &[u8]) { - let s = data.iter().fold(String::new(), |mut output, c| { - let _ = write!(output, " {c:02x}"); - output - }); - let prefix = if sent { "O" } else { "I" }; - let mut remaining = ((ts - SocketTime::zero()).as_millis() % (24 * 60 * 60 * 1000)) as u64; - let hours = remaining / (60 * 60 * 1000); - remaining %= 60 * 60 * 1000; - let minutes = remaining / (60 * 1000); - remaining %= 60 * 1000; - let seconds = remaining / 1000; - let ms = remaining % 1000; - info!( - "{} {:02}:{:02}:{:02}.{:03} 0000{} # SCTP_PACKET {}", - prefix, hours, minutes, seconds, ms, s, name - ); - } -} - pub(crate) mod math { macro_rules! round_up_to_4 { ($a: expr) => { diff --git a/src/socket/mod.rs b/src/socket/mod.rs index 119a9f1..9473840 100644 --- a/src/socket/mod.rs +++ b/src/socket/mod.rs @@ -34,7 +34,6 @@ use crate::api::handover::HandoverReadiness; use crate::api::handover::HandoverSocketState; use crate::api::handover::SocketHandoverState; use crate::events::Events; -use crate::logging::log_packet; use crate::math::round_down_to_4; use crate::packet::SerializableTlv; use crate::packet::abort_chunk::AbortChunk; @@ -90,14 +89,10 @@ use crate::tx::send_queue::SendQueue; use crate::types::Tsn; use bytes::Bytes; #[cfg(not(test))] -use log::info; -#[cfg(not(test))] use log::warn; use std::cell::RefCell; use std::cmp::min; #[cfg(test)] -use std::println as info; -#[cfg(test)] use std::println as warn; use std::rc::Rc; @@ -115,75 +110,6 @@ pub mod transmission_control_block; #[cfg(test)] pub mod socket_tests; -struct LoggingEvents { - parent: Rc>, - name: String, - now: Rc>, -} - -impl LoggingEvents { - pub fn new( - parent: Rc>, - name: String, - now: Rc>, - ) -> LoggingEvents { - Self { parent, name, now } - } -} - -impl EventSink for LoggingEvents { - fn add(&mut self, event: SocketEvent) { - match event { - SocketEvent::SendPacket(ref e) => { - let now = *self.now.borrow(); - log_packet(&self.name, now, true, e); - } - SocketEvent::OnConnected() => info!("OnConnected"), - SocketEvent::OnError(kind, ref e) => info!("OnError: {:?}, {}", kind, e), - SocketEvent::OnBufferedAmountLow(e) => info!("OnBufferedAmountLow: {}", e), - SocketEvent::OnTotalBufferedAmountLow() => info!("OnTotalBufferedAmountLow"), - SocketEvent::OnLifecycleMessageFullySent(ref id) => { - info!("OnLifecycleMessageFullySent({})", id); - } - SocketEvent::OnLifecycleMessageExpired(ref id) => { - info!("OnLifecycleMessageExpired({})", id); - } - SocketEvent::OnLifecycleMessageMaybeExpired(ref id) => { - info!("OnLifecycleMessageMaybeExpired({})", id); - } - SocketEvent::OnLifecycleMessageDelivered(ref id) => { - info!("OnLifecycleMessageDelivered({})", id); - } - SocketEvent::OnLifecycleEnd(ref id) => { - info!("OnLifecycleEnd({})", id); - } - SocketEvent::OnStreamsResetFailed(ref streams) => { - info!("OnStreamsResetFailed({:?})", streams); - } - SocketEvent::OnStreamsResetPerformed(ref streams) => { - info!("OnStreamsResetPerformed({:?})", streams); - } - SocketEvent::OnIncomingStreamReset(ref streams) => { - info!("OnIncomingStreamReset({:?})", streams); - } - SocketEvent::OnClosed() => { - info!("OnClosed()"); - } - SocketEvent::OnAborted(ref error, ref reason) => { - info!("OnAborted({:?}, {})", error, reason); - } - SocketEvent::OnConnectionRestarted() => { - info!("OnConnectionRestarted()"); - } - } - self.parent.borrow_mut().add(event); - } - - fn next_event(&mut self) -> Option { - self.parent.borrow_mut().next_event() - } -} - /// An SCTP socket. /// /// The socket is the main entry point for using the `dcsctp` library. It is used to send and @@ -213,9 +139,7 @@ impl Socket { /// is the initial time, used as a basline for all time-based operations. pub fn new(name: &str, options: &Options) -> Self { let now = Rc::new(RefCell::new(SocketTime::zero())); - let events: Rc> = Rc::new(RefCell::new(Events::new())); - let events: Rc> = - Rc::new(RefCell::new(LoggingEvents::new(events, name.into(), Rc::clone(&now)))); + let events: Rc> = Rc::new(RefCell::new(Events::new())); let sqe = Rc::clone(&events); let ctx = Context { options: options.clone(), @@ -487,7 +411,6 @@ impl DcSctpSocket for Socket { fn handle_input(&mut self, packet: Bytes) { self.ctx.rx_packets_count += 1; let now = *self.now.borrow(); - log_packet(&self.name, now, false, &packet); match SctpPacket::from_bytes(packet, &self.ctx.options) { Err(_e) => {