Add identifier to InvalidIdentifier error
This commit is contained in:
parent
e43a010704
commit
93eeb7c740
@ -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,
|
||||
|
||||
@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user