Add identifier to InvalidIdentifier error

This commit is contained in:
Sofia 2026-08-09 21:43:58 +03:00
parent e43a010704
commit 93eeb7c740
2 changed files with 15 additions and 9 deletions

View File

@ -108,7 +108,7 @@ impl<T: std::fmt::Debug + Clone + Serialize + DeserializeOwned + Send + Sync + '
let duration = now - conn.last_sent_ping; let duration = now - conn.last_sent_ping;
if duration > interval { if duration > interval {
match conn.state { match &conn.state {
ConnectionState::ReceivingConnection | ConnectionState::Connecting => { ConnectionState::ReceivingConnection | ConnectionState::Connecting => {
match self match self
.udp .udp
@ -140,7 +140,7 @@ impl<T: std::fmt::Debug + Clone + Serialize + DeserializeOwned + Send + Sync + '
} }
ConnectionState::Closing(reason) ConnectionState::Closing(reason)
| ConnectionState::ReceivingClosing(reason) => { | ConnectionState::ReceivingClosing(reason) => {
match self.udp.send_to(*addr, Package::<T>::Close(reason)) { match self.udp.send_to(*addr, Package::<T>::Close(reason.clone())) {
Ok(bytes) => { Ok(bytes) => {
conn.bytes_tx += bytes; conn.bytes_tx += bytes;
conn.last_sent_ping = now; conn.last_sent_ping = now;
@ -291,7 +291,9 @@ impl<T: std::fmt::Debug + Clone + Serialize + DeserializeOwned + Send + Sync + '
*addr, *addr,
Connection::from( Connection::from(
*addr, *addr,
ConnectionState::Closing(CloseReason::InvalidIdentifier), ConnectionState::Closing(CloseReason::InvalidIdentifier(
identifier,
)),
), ),
); );
} else { } else {
@ -431,10 +433,14 @@ impl<T: std::fmt::Debug + Clone + Serialize + DeserializeOwned + Send + Sync + '
let now = Instant::now(); let now = Instant::now();
self.connections.retain(|_, conn| { self.connections.retain(|_, conn| {
let retain = match conn.state { let retain = match &conn.state {
ConnectionState::ReceivingClosing(reason) => { ConnectionState::ReceivingClosing(reason) => {
if (now - conn.last_recv_close) > self.config.disconnect_timeout { if (now - conn.last_recv_close) > self.config.disconnect_timeout {
messages.push(PeerMessage::Disconnected(conn.clone(), None, reason)); messages.push(PeerMessage::Disconnected(
conn.clone(),
None,
reason.clone(),
));
false false
} else { } else {
true true
@ -664,7 +670,7 @@ impl<T: Clone> Connection<T> {
} }
/// State of the connection /// State of the connection
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
pub enum ConnectionState { pub enum ConnectionState {
/// Connection is currently attempting to connect to another peer /// Connection is currently attempting to connect to another peer
Connecting, Connecting,

View File

@ -11,7 +11,7 @@ pub(crate) enum Package<T: Clone> {
Messages(Messages<T>), Messages(Messages<T>),
} }
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub enum CloseReason { pub enum CloseReason {
NotAcceptingConnections, NotAcceptingConnections,
Kicked, Kicked,
@ -19,7 +19,7 @@ pub enum CloseReason {
ShuttingDown, ShuttingDown,
/// Closed because local peer initiated close /// Closed because local peer initiated close
SelfClosed, SelfClosed,
InvalidIdentifier, InvalidIdentifier(String),
} }
impl std::fmt::Display for CloseReason { impl std::fmt::Display for CloseReason {
@ -30,7 +30,7 @@ impl std::fmt::Display for CloseReason {
CloseReason::Error => write!(f, "Error"), CloseReason::Error => write!(f, "Error"),
CloseReason::ShuttingDown => write!(f, "Shutting down"), CloseReason::ShuttingDown => write!(f, "Shutting down"),
CloseReason::SelfClosed => write!(f, "Closed"), CloseReason::SelfClosed => write!(f, "Closed"),
CloseReason::InvalidIdentifier => write!(f, "Invalid Identifier"), CloseReason::InvalidIdentifier(_) => write!(f, "Invalid Identifier"),
} }
} }
} }