Skip to content

Commit

Permalink
emit warning for connection reset (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobkaufmann authored Mar 25, 2023
1 parent 0ac7a94 commit 973239b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/conn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::cmp;
use std::collections::VecDeque;
use std::fmt;
use std::io;
use std::time::{Duration, Instant};

Expand Down Expand Up @@ -28,6 +29,25 @@ enum Error {
TimedOut,
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
Self::EmptyDataPayload => "missing payload in DATA packet",
Self::InvalidAckNum => "received ACK for unsent packet",
Self::InvalidFin => "received multiple FIN packets with distinct sequence numbers",
Self::InvalidSeqNum => {
"received packet with sequence number outside of remote peer's [SYN,FIN] range"
}
Self::InvalidSyn => "received multiple SYN packets with distinct sequence numbers",
Self::Reset => "received RESET packet from remote peer",
Self::SynFromAcceptor => "received SYN packet from connection acceptor",
Self::TimedOut => "connection timed out",
};

write!(f, "{s}")
}
}

impl From<Error> for io::ErrorKind {
fn from(value: Error) -> Self {
use Error::*;
Expand Down Expand Up @@ -934,6 +954,7 @@ impl<const N: usize, P: ConnectionPeer> Connection<N, P> {
}

fn reset(&mut self, err: Error) {
tracing::warn!(?err, "resetting connection: {err}");
self.state = State::Closed { err: Some(err) }
}

Expand Down

0 comments on commit 973239b

Please sign in to comment.