Skip to content

Commit

Permalink
Change tracing crate to log
Browse files Browse the repository at this point in the history
  • Loading branch information
SajjadPourali committed Mar 18, 2024
1 parent 528ac24 commit ad83467
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ repository = 'https://github.com/narrowlink/ipstack'
# homepage = 'https://github.com/narrowlink/ipstack'
readme = "README.md"

[features]
default = []
log = ["tracing/log"]

[dependencies]
tokio = { version = "1.36", features = [
"sync",
Expand All @@ -23,9 +19,7 @@ tokio = { version = "1.36", features = [
], default-features = false }
etherparse = { version = "0.14", default-features = false, features = ["std"] }
thiserror = { version = "1.0", default-features = false }
tracing = { version = "0.1", default-features = false, features = [
"log",
], optional = true }
log = { version = "0.4", default-features = false}
rand = {version = "0.8.5", default-features = false, features = ["std","std_rng"] }

[dev-dependencies]
Expand Down
8 changes: 2 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use tokio::{
select,
sync::mpsc::{self, UnboundedReceiver, UnboundedSender},
};
#[cfg(feature = "log")]
use tracing::{error, trace};

use log::{error, trace};

use crate::{
packet::IpStackPacketProtocol,
Expand Down Expand Up @@ -110,7 +110,6 @@ impl IpStack {
match streams.entry(packet.network_tuple()){
Occupied(entry) =>{
if let Err(_x) = entry.get().send(packet){
#[cfg(feature = "log")]
trace!("Send packet error \"{}\"", _x);
}
}
Expand All @@ -124,11 +123,9 @@ impl IpStack {
}
Err(e) => {
if matches!(e,IpStackError::InvalidTcpPacket){
#[cfg(feature = "log")]
trace!("Invalid TCP packet");
continue;
}
#[cfg(feature = "log")]
error!("IpStackTcpStream::new failed \"{}\"", e);
}
}
Expand All @@ -152,7 +149,6 @@ impl IpStack {
}
#[allow(unused_mut)]
let Ok(mut packet_byte) = packet.to_bytes() else{
#[cfg(feature = "log")]
trace!("to_bytes error");
continue;
};
Expand Down
16 changes: 7 additions & 9 deletions src/stream/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use tokio::{
io::{AsyncRead, AsyncWrite},
sync::mpsc::{self, UnboundedReceiver, UnboundedSender},
};
#[cfg(feature = "log")]
use tracing::{trace, warn};

use log::{trace, warn};

use crate::packet::NetworkPacket;

Expand Down Expand Up @@ -218,7 +218,6 @@ impl AsyncRead for IpStackTcpStream {
let min = cmp::min(self.tcb.get_available_read_buffer_size() as u16, u16::MAX);
self.tcb.change_recv_window(min);
if matches!(Pin::new(&mut self.tcb.timeout).poll(cx), Poll::Ready(_)) {
#[cfg(feature = "log")]
trace!("timeout reached for {:?}", self.dst_addr);
self.packet_sender
.send(self.create_rev_packet(RST | ACK, TTL, None, Vec::new())?)
Expand Down Expand Up @@ -489,14 +488,13 @@ impl AsyncWrite for IpStackTcpStream {
.or(Err(ErrorKind::UnexpectedEof))?;
self.tcb.retransmission = None;
} else if let Some(_i) = self.tcb.retransmission {
#[cfg(feature = "log")]
{
warn!(_i);
warn!(self.tcb.seq);
warn!(self.tcb.last_ack);
warn!(self.tcb.ack);
warn!("{}",_i);
warn!("{}",self.tcb.seq);
warn!("{}",self.tcb.last_ack);
warn!("{}",self.tcb.ack);
for p in self.tcb.inflight_packets.iter() {
warn!(p.seq);
warn!("{}",p.seq);
warn!("{}", p.payload.len());
}
}
Expand Down

0 comments on commit ad83467

Please sign in to comment.