Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 0 additions & 29 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
79 changes: 1 addition & 78 deletions src/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -115,75 +110,6 @@ pub mod transmission_control_block;
#[cfg(test)]
pub mod socket_tests;

struct LoggingEvents {
parent: Rc<RefCell<dyn EventSink>>,
name: String,
now: Rc<RefCell<SocketTime>>,
}

impl LoggingEvents {
pub fn new(
parent: Rc<RefCell<dyn EventSink>>,
name: String,
now: Rc<RefCell<SocketTime>>,
) -> 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<SocketEvent> {
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
Expand Down Expand Up @@ -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<RefCell<Events>> = Rc::new(RefCell::new(Events::new()));
let events: Rc<RefCell<dyn EventSink>> =
Rc::new(RefCell::new(LoggingEvents::new(events, name.into(), Rc::clone(&now))));
let events: Rc<RefCell<dyn EventSink>> = Rc::new(RefCell::new(Events::new()));
let sqe = Rc::clone(&events);
let ctx = Context {
options: options.clone(),
Expand Down Expand Up @@ -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) => {
Expand Down
Loading