diff options
author | hozan23 <hozan23@proton.me> | 2023-11-22 12:42:00 +0300 |
---|---|---|
committer | hozan23 <hozan23@proton.me> | 2023-11-22 12:49:45 +0300 |
commit | 34b0a91dbb107962dae4f593a36d30a29ea87c45 (patch) | |
tree | ad03f71e8dbb0f8c1884bc2be6ac6368219ce55d /p2p/src/connection.rs | |
parent | 542897ce2ed7fb8a8627ec8ba8b3490acb29149f (diff) |
p2p: Improve error handling during handshake:
Introduce a new entry status, INCOMPATIBLE_ENTRY. Entries with this
status will not increase the failure attempts, instead, they will persist in
the routing table until replaced by a new peer. This feature is useful for
seeding and the lookup process.
Add a boolean value to the VerAck message to indicate whether the
version is accepted or not.
Diffstat (limited to 'p2p/src/connection.rs')
-rw-r--r-- | p2p/src/connection.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/p2p/src/connection.rs b/p2p/src/connection.rs index 7c81aa2..8ec2617 100644 --- a/p2p/src/connection.rs +++ b/p2p/src/connection.rs @@ -1,10 +1,12 @@ -use smol::{channel::Sender, lock::Mutex}; use std::{collections::VecDeque, fmt, sync::Arc}; -use karyons_core::async_utils::CondVar; +use smol::{channel::Sender, lock::Mutex}; +use karyons_core::async_utils::CondVar; use karyons_net::Conn; +use crate::Result; + /// Defines the direction of a network connection. #[derive(Clone, Debug)] pub enum ConnDirection { @@ -24,7 +26,7 @@ impl fmt::Display for ConnDirection { pub struct NewConn { pub direction: ConnDirection, pub conn: Conn, - pub disconnect_signal: Sender<()>, + pub disconnect_signal: Sender<Result<()>>, } /// Connection queue @@ -42,7 +44,7 @@ impl ConnQueue { } /// Push a connection into the queue and wait for the disconnect signal - pub async fn handle(&self, conn: Conn, direction: ConnDirection) { + pub async fn handle(&self, conn: Conn, direction: ConnDirection) -> Result<()> { let (disconnect_signal, chan) = smol::channel::bounded(1); let new_conn = NewConn { direction, @@ -51,7 +53,10 @@ impl ConnQueue { }; self.queue.lock().await.push_back(new_conn); self.conn_available.signal(); - let _ = chan.recv().await; + if let Ok(result) = chan.recv().await { + return result; + } + Ok(()) } /// Receive the next connection in the queue |