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

View File

@ -11,7 +11,7 @@ pub(crate) enum Package<T: Clone> {
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 {
NotAcceptingConnections,
Kicked,
@ -19,7 +19,7 @@ pub enum CloseReason {
ShuttingDown,
/// Closed because local peer initiated close
SelfClosed,
InvalidIdentifier,
InvalidIdentifier(String),
}
impl std::fmt::Display for CloseReason {
@ -30,7 +30,7 @@ impl std::fmt::Display for CloseReason {
CloseReason::Error => write!(f, "Error"),
CloseReason::ShuttingDown => write!(f, "Shutting down"),
CloseReason::SelfClosed => write!(f, "Closed"),
CloseReason::InvalidIdentifier => write!(f, "Invalid Identifier"),
CloseReason::InvalidIdentifier(_) => write!(f, "Invalid Identifier"),
}
}
}