From a2489004b2de45eeea84ff3a1297929c0cf6fac1 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 17 Dec 2024 13:29:58 +0200 Subject: [PATCH 1/4] poc: Refactor Kad Engine to poll based implementation Signed-off-by: Alexandru Vasile --- src/protocol/libp2p/kademlia/mod.rs | 24 ++++++++---- .../libp2p/kademlia/query/find_node.rs | 37 ++++++++++++++++++- src/protocol/libp2p/kademlia/query/mod.rs | 34 ++++++++++++++++- 3 files changed, 85 insertions(+), 10 deletions(-) diff --git a/src/protocol/libp2p/kademlia/mod.rs b/src/protocol/libp2p/kademlia/mod.rs index 03b98ea2..5c0f1404 100644 --- a/src/protocol/libp2p/kademlia/mod.rs +++ b/src/protocol/libp2p/kademlia/mod.rs @@ -319,7 +319,7 @@ impl Kademlia { match pending_action.take() { None => { - tracing::trace!( + tracing::warn!( target: LOG_TARGET, ?peer, ?substream_id, @@ -877,14 +877,22 @@ impl Kademlia { tracing::debug!(target: LOG_TARGET, "starting kademlia event loop"); loop { - // poll `QueryEngine` for next actions. - while let Some(action) = self.engine.next_action() { - if let Err((query, peer)) = self.on_query_action(action).await { - self.disconnect_peer(peer, Some(query)).await; - } - } + // // poll `QueryEngine` for next actions. + // while let Some(action) = self.engine.next_action() { + // if let Err((query, peer)) = self.on_query_action(action).await { + // self.disconnect_peer(peer, Some(query)).await; + // } + // } tokio::select! { + action = self.engine.next() => { + if let Some(action) = action { + if let Err((query, peer)) = self.on_query_action(action).await { + self.disconnect_peer(peer, Some(query)).await; + } + } + }, + event = self.service.next() => match event { Some(TransportEvent::ConnectionEstablished { peer, .. }) => { if let Err(error) = self.on_connection_established(peer) { @@ -966,7 +974,7 @@ impl Kademlia { "failed to read message from substream", ); - self.disconnect_peer(peer, query_id).await; + // self.disconnect_peer(peer, query_id).await; } } }, diff --git a/src/protocol/libp2p/kademlia/query/find_node.rs b/src/protocol/libp2p/kademlia/query/find_node.rs index ce63f95a..2086b4f8 100644 --- a/src/protocol/libp2p/kademlia/query/find_node.rs +++ b/src/protocol/libp2p/kademlia/query/find_node.rs @@ -19,6 +19,7 @@ // DEALINGS IN THE SOFTWARE. use bytes::Bytes; +use futures::Stream; use crate::{ protocol::libp2p::kademlia::{ @@ -29,7 +30,11 @@ use crate::{ PeerId, }; -use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; +use std::{ + collections::{BTreeMap, HashMap, HashSet, VecDeque}, + pin::Pin, + task::{Context, Poll}, +}; /// Logging target for the file. const LOG_TARGET: &str = "litep2p::ipfs::kademlia::query::find_node"; @@ -91,6 +96,9 @@ pub struct FindNodeContext>> { /// These represent the number of peers added to the `Self::pending` minus the number of peers /// that have failed to respond within the `Self::peer_timeout` pending_responses: usize, + + is_done: bool, + waker: Option, } impl>> FindNodeContext { @@ -116,6 +124,9 @@ impl>> FindNodeContext { peer_timeout: DEFAULT_PEER_TIMEOUT, pending_responses: 0, + + is_done: false, + waker: None, } } @@ -298,6 +309,30 @@ impl>> FindNodeContext { } } +impl> + Unpin> Stream for FindNodeContext { + type Item = QueryAction; + + fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + if self.is_done { + return Poll::Ready(None); + } + + let action = self.next_action(); + match action { + Some(QueryAction::QueryFailed { .. }) | Some(QueryAction::QuerySucceeded { .. }) => { + self.is_done = true; + } + None => { + self.waker = Some(cx.waker().clone()); + return Poll::Pending; + } + _ => (), + }; + + Poll::Ready(action) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/protocol/libp2p/kademlia/query/mod.rs b/src/protocol/libp2p/kademlia/query/mod.rs index 9f14a6de..45d6f607 100644 --- a/src/protocol/libp2p/kademlia/query/mod.rs +++ b/src/protocol/libp2p/kademlia/query/mod.rs @@ -34,8 +34,13 @@ use crate::{ }; use bytes::Bytes; +use futures::{Stream, StreamExt}; -use std::collections::{HashMap, VecDeque}; +use std::{ + collections::{HashMap, VecDeque}, + pin::Pin, + task::{Context, Poll}, +}; use self::find_many_nodes::FindManyNodesContext; @@ -599,6 +604,33 @@ impl QueryEngine { } } +impl Stream for QueryEngine { + type Item = QueryAction; + + fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + for (_, state) in self.queries.iter_mut() { + let result = match state { + QueryType::FindNode { context } => context.poll_next_unpin(cx), + _ => continue, + }; + + match result { + Poll::Ready(Some(QueryAction::QuerySucceeded { query })) => { + return Poll::Ready(Some(self.on_query_succeeded(query))); + } + Poll::Ready(Some(QueryAction::QueryFailed { query })) => { + return Poll::Ready(Some(self.on_query_failed(query))); + } + Poll::Ready(Some(action)) => return Poll::Ready(Some(action)), + Poll::Ready(None) => panic!("Should never happen, we handle the result"), + Poll::Pending => {} + } + } + + Poll::Pending + } +} + #[cfg(test)] mod tests { use multihash::{Code, Multihash}; From fcbdb00e86d8b57b94edb035e00fec4e6471706f Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 17 Dec 2024 13:48:36 +0200 Subject: [PATCH 2/4] kad: Reutilize substreams instead of askig yamux for new ones Signed-off-by: Alexandru Vasile --- src/protocol/libp2p/kademlia/mod.rs | 48 +++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/protocol/libp2p/kademlia/mod.rs b/src/protocol/libp2p/kademlia/mod.rs index 5c0f1404..0f99cf08 100644 --- a/src/protocol/libp2p/kademlia/mod.rs +++ b/src/protocol/libp2p/kademlia/mod.rs @@ -151,6 +151,9 @@ pub(crate) struct Kademlia { /// Pending outbound substreams. pending_substreams: HashMap, + /// Established substreams of connected peers. + established_substreams: HashMap, + /// Pending dials. pending_dials: HashMap>, @@ -205,6 +208,8 @@ impl Kademlia { pending_dials: HashMap::new(), executor: QueryExecutor::new(), pending_substreams: HashMap::new(), + established_substreams: HashMap::new(), + update_mode: config.update_mode, validation_mode: config.validation_mode, record_ttl: config.record_ttl, @@ -245,7 +250,7 @@ impl Kademlia { context.add_pending_action(substream_id, action); } Err(error) => { - tracing::debug!( + tracing::warn!( target: LOG_TARGET, ?peer, ?action, @@ -326,7 +331,7 @@ impl Kademlia { "pending action doesn't exist for peer, closing substream", ); - let _ = substream.close().await; + self.established_substreams.insert(peer, substream); return Ok(()); } Some(PeerAction::SendFindNode(query)) => { @@ -347,11 +352,11 @@ impl Kademlia { } // query finished while the substream was being opened None => { - let _ = substream.close().await; + self.established_substreams.insert(peer, substream); } action => { tracing::warn!(target: LOG_TARGET, ?query, ?peer, ?action, "unexpected action for `FIND_NODE`"); - let _ = substream.close().await; + self.established_substreams.insert(peer, substream); debug_assert!(false); } } @@ -744,15 +749,32 @@ impl Kademlia { /// Handle next query action. async fn on_query_action(&mut self, action: QueryAction) -> Result<(), (QueryId, PeerId)> { match action { - QueryAction::SendMessage { query, peer, .. } => { - if self - .open_substream_or_dial(peer, PeerAction::SendFindNode(query), Some(query)) - .is_err() - { - // Announce the error to the query engine. - self.engine.register_response_failure(query, peer); + QueryAction::SendMessage { + query, + peer, + message, + } => { + if let Some(substream) = self.established_substreams.remove(&peer) { + tracing::trace!( + target: LOG_TARGET, + ?peer, + query = ?query, + "start sending message to peer", + ); + + self.executor.send_request_read_response(peer, Some(query), message, substream); + + Ok(()) + } else { + if self + .open_substream_or_dial(peer, PeerAction::SendFindNode(query), Some(query)) + .is_err() + { + // Announce the error to the query engine. + self.engine.register_response_failure(query, peer); + } + Ok(()) } - Ok(()) } QueryAction::FindNodeQuerySucceeded { target, @@ -943,7 +965,7 @@ impl Kademlia { query = ?query_id, "message sent to peer", ); - let _ = substream.close().await; + self.established_substreams.insert(peer, substream); } QueryResult::ReadSuccess { substream, message } => { tracing::trace!(target: LOG_TARGET, From 93ba8df8920c9072e699d3e85a239ce422008fe2 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 17 Dec 2024 13:50:53 +0200 Subject: [PATCH 3/4] Revert "kad: Reutilize substreams instead of askig yamux for new ones" This reverts commit fcbdb00e86d8b57b94edb035e00fec4e6471706f. --- src/protocol/libp2p/kademlia/mod.rs | 48 ++++++++--------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/src/protocol/libp2p/kademlia/mod.rs b/src/protocol/libp2p/kademlia/mod.rs index 0f99cf08..5c0f1404 100644 --- a/src/protocol/libp2p/kademlia/mod.rs +++ b/src/protocol/libp2p/kademlia/mod.rs @@ -151,9 +151,6 @@ pub(crate) struct Kademlia { /// Pending outbound substreams. pending_substreams: HashMap, - /// Established substreams of connected peers. - established_substreams: HashMap, - /// Pending dials. pending_dials: HashMap>, @@ -208,8 +205,6 @@ impl Kademlia { pending_dials: HashMap::new(), executor: QueryExecutor::new(), pending_substreams: HashMap::new(), - established_substreams: HashMap::new(), - update_mode: config.update_mode, validation_mode: config.validation_mode, record_ttl: config.record_ttl, @@ -250,7 +245,7 @@ impl Kademlia { context.add_pending_action(substream_id, action); } Err(error) => { - tracing::warn!( + tracing::debug!( target: LOG_TARGET, ?peer, ?action, @@ -331,7 +326,7 @@ impl Kademlia { "pending action doesn't exist for peer, closing substream", ); - self.established_substreams.insert(peer, substream); + let _ = substream.close().await; return Ok(()); } Some(PeerAction::SendFindNode(query)) => { @@ -352,11 +347,11 @@ impl Kademlia { } // query finished while the substream was being opened None => { - self.established_substreams.insert(peer, substream); + let _ = substream.close().await; } action => { tracing::warn!(target: LOG_TARGET, ?query, ?peer, ?action, "unexpected action for `FIND_NODE`"); - self.established_substreams.insert(peer, substream); + let _ = substream.close().await; debug_assert!(false); } } @@ -749,32 +744,15 @@ impl Kademlia { /// Handle next query action. async fn on_query_action(&mut self, action: QueryAction) -> Result<(), (QueryId, PeerId)> { match action { - QueryAction::SendMessage { - query, - peer, - message, - } => { - if let Some(substream) = self.established_substreams.remove(&peer) { - tracing::trace!( - target: LOG_TARGET, - ?peer, - query = ?query, - "start sending message to peer", - ); - - self.executor.send_request_read_response(peer, Some(query), message, substream); - - Ok(()) - } else { - if self - .open_substream_or_dial(peer, PeerAction::SendFindNode(query), Some(query)) - .is_err() - { - // Announce the error to the query engine. - self.engine.register_response_failure(query, peer); - } - Ok(()) + QueryAction::SendMessage { query, peer, .. } => { + if self + .open_substream_or_dial(peer, PeerAction::SendFindNode(query), Some(query)) + .is_err() + { + // Announce the error to the query engine. + self.engine.register_response_failure(query, peer); } + Ok(()) } QueryAction::FindNodeQuerySucceeded { target, @@ -965,7 +943,7 @@ impl Kademlia { query = ?query_id, "message sent to peer", ); - self.established_substreams.insert(peer, substream); + let _ = substream.close().await; } QueryResult::ReadSuccess { substream, message } => { tracing::trace!(target: LOG_TARGET, From 7615cc52ceed671c351e58c9ebeb7ec0a9453d3d Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 17 Dec 2024 17:29:25 +0200 Subject: [PATCH 4/4] error details, tuning of params, dep updates Signed-off-by: Alexandru Vasile --- Cargo.lock | 597 +++++++++++++----- Cargo.toml | 16 +- src/protocol/libp2p/kademlia/mod.rs | 63 +- .../libp2p/kademlia/query/find_node.rs | 44 +- src/protocol/mod.rs | 3 + src/protocol/protocol_set.rs | 14 +- src/protocol/transport_service.rs | 8 + src/transport/manager/address.rs | 43 +- src/transport/manager/handle.rs | 16 + src/transport/manager/mod.rs | 10 +- src/transport/mod.rs | 6 +- src/transport/websocket/stream.rs | 12 +- 12 files changed, 595 insertions(+), 237 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94693020..abc5912d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -305,7 +305,7 @@ dependencies = [ "nom", "num-traits", "rusticata-macros", - "thiserror", + "thiserror 1.0.61", "time", ] @@ -321,7 +321,7 @@ dependencies = [ "nom", "num-traits", "rusticata-macros", - "thiserror", + "thiserror 1.0.61", "time", ] @@ -345,7 +345,7 @@ checksum = "7378575ff571966e99a744addeff0bff98b8ada0dedf1956d59e634db95eaac1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", "synstructure 0.13.1", ] @@ -368,7 +368,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -420,7 +420,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -663,9 +663,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" +checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "cc" @@ -797,11 +797,21 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "core2" @@ -1006,9 +1016,9 @@ dependencies = [ [[package]] name = "crypto-mac" -version = "0.11.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +checksum = "25fab6889090c8133f3deb8f73ba3c65a7f456f66436fc012a1b1e272b1e103e" dependencies = [ "generic-array 0.14.7", "subtle", @@ -1073,7 +1083,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -1168,7 +1178,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -1179,7 +1189,7 @@ checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -1246,7 +1256,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -1270,7 +1280,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.68", + "syn 2.0.90", "termcolor", "toml 0.8.14", "walkdir", @@ -1381,7 +1391,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -1468,7 +1478,7 @@ dependencies = [ "prettyplease 0.2.20", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -1699,7 +1709,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -1933,7 +1943,7 @@ dependencies = [ "ipnet", "once_cell", "rand 0.8.5", - "thiserror", + "thiserror 1.0.61", "tinyvec", "tokio", "tracing", @@ -1956,7 +1966,7 @@ dependencies = [ "rand 0.8.5", "resolv-conf", "smallvec", - "thiserror", + "thiserror 1.0.61", "tokio", "tracing", ] @@ -1986,7 +1996,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" dependencies = [ - "crypto-mac 0.11.1", + "crypto-mac 0.11.0", "digest 0.9.0", ] @@ -2041,6 +2051,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -2048,7 +2069,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.12", "pin-project-lite 0.2.14", ] @@ -2080,7 +2101,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "http", + "http 0.2.12", "http-body", "httparse", "httpdate", @@ -2116,6 +2137,124 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "idna" version = "0.2.3" @@ -2139,12 +2278,23 @@ dependencies = [ [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", ] [[package]] @@ -2164,7 +2314,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6b0422c86d7ce0e97169cc42e04ae643caf278874a7a3c87b8150a220dc7e1e" dependencies = [ "async-io", - "core-foundation", + "core-foundation 0.9.4", "fnv", "futures", "if-addrs", @@ -2367,9 +2517,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.168" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" [[package]] name = "libp2p" @@ -2451,7 +2601,7 @@ dependencies = [ "rand 0.8.5", "rw-stream-sink", "smallvec", - "thiserror", + "thiserror 1.0.61", "unsigned-varint 0.7.2", "void", ] @@ -2488,7 +2638,7 @@ dependencies = [ "quick-protobuf", "quick-protobuf-codec", "smallvec", - "thiserror", + "thiserror 1.0.61", "void", ] @@ -2506,7 +2656,7 @@ dependencies = [ "quick-protobuf", "rand 0.8.5", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.61", "zeroize", ] @@ -2532,7 +2682,7 @@ dependencies = [ "rand 0.8.5", "sha2 0.10.8", "smallvec", - "thiserror", + "thiserror 1.0.61", "uint", "unsigned-varint 0.7.2", "void", @@ -2609,7 +2759,7 @@ dependencies = [ "sha2 0.10.8", "snow", "static_assertions", - "thiserror", + "thiserror 1.0.61", "x25519-dalek 1.1.1", "zeroize", ] @@ -2649,7 +2799,7 @@ dependencies = [ "quinn-proto", "rand 0.8.5", "rustls 0.20.9", - "thiserror", + "thiserror 1.0.61", "tokio", ] @@ -2730,7 +2880,7 @@ dependencies = [ "rcgen", "ring 0.16.20", "rustls 0.20.9", - "thiserror", + "thiserror 1.0.61", "webpki", "x509-parser 0.14.0", "yasna", @@ -2764,7 +2914,7 @@ dependencies = [ "futures", "libp2p-core", "log", - "thiserror", + "thiserror 1.0.61", "yamux", ] @@ -2864,6 +3014,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + [[package]] name = "litep2p" version = "0.8.4" @@ -2909,7 +3065,7 @@ dependencies = [ "socket2 0.5.7", "static_assertions", "str0m", - "thiserror", + "thiserror 2.0.7", "tokio", "tokio-stream", "tokio-tungstenite", @@ -3073,13 +3229,13 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -3132,7 +3288,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -3264,7 +3420,7 @@ dependencies = [ "anyhow", "byteorder", "paste", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -3278,7 +3434,7 @@ dependencies = [ "log", "netlink-packet-core", "netlink-sys", - "thiserror", + "thiserror 1.0.61", "tokio", ] @@ -3303,7 +3459,7 @@ checksum = "a4a43439bf756eed340bdf8feba761e2d50c7d47175d87545cd5cbe4a137c4d1" dependencies = [ "cc", "libc", - "thiserror", + "thiserror 1.0.61", "winapi", ] @@ -3484,7 +3640,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -3626,7 +3782,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d95f5254224e617595d2cc3cc73ff0a5eaf2637519e25f03388154e9378b6ffa" dependencies = [ - "crypto-mac 0.11.1", + "crypto-mac 0.11.0", ] [[package]] @@ -3680,7 +3836,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -3824,7 +3980,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -3846,7 +4002,7 @@ version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" dependencies = [ - "thiserror", + "thiserror 1.0.61", "toml 0.5.11", ] @@ -3885,9 +4041,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -3903,7 +4059,7 @@ dependencies = [ "lazy_static", "memchr", "parking_lot 0.12.3", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -3926,7 +4082,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -3998,7 +4154,7 @@ dependencies = [ "prost 0.13.1", "prost-types 0.13.1", "regex", - "syn 2.0.68", + "syn 2.0.90", "tempfile", ] @@ -4025,7 +4181,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -4038,7 +4194,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -4092,7 +4248,7 @@ dependencies = [ "asynchronous-codec 0.6.2", "bytes", "quick-protobuf", - "thiserror", + "thiserror 1.0.61", "unsigned-varint 0.7.2", ] @@ -4130,7 +4286,7 @@ dependencies = [ "quinn-udp", "rustc-hash", "rustls 0.20.9", - "thiserror", + "thiserror 1.0.61", "tokio", "tracing", "webpki", @@ -4148,7 +4304,7 @@ dependencies = [ "rustc-hash", "rustls 0.20.9", "slab", - "thiserror", + "thiserror 1.0.61", "tinyvec", "tracing", "webpki", @@ -4320,7 +4476,7 @@ checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ "getrandom 0.2.15", "libredox", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -4340,7 +4496,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -4459,7 +4615,7 @@ dependencies = [ "netlink-packet-route", "netlink-proto", "nix", - "thiserror", + "thiserror 1.0.61", "tokio", ] @@ -4540,44 +4696,43 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.12" +version = "0.23.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" +checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b" dependencies = [ - "log", - "ring 0.17.8", + "once_cell", + "rustls-pki-types", "rustls-webpki", - "sct", + "subtle", + "zeroize", ] [[package]] name = "rustls-native-certs" -version = "0.6.3" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +checksum = "7fcff2dd52b58a8d98a70243663a0d234c4e2b79235637849d15913394a247d3" dependencies = [ "openssl-probe", - "rustls-pemfile", + "rustls-pki-types", "schannel", "security-framework", ] [[package]] -name = "rustls-pemfile" -version = "1.0.4" +name = "rustls-pki-types" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" -dependencies = [ - "base64 0.21.7", -] +checksum = "d2bf47e6ff922db3825eb750c4e2ff784c6ff8fb9e13046ef6a1d1c5401b0b37" [[package]] name = "rustls-webpki" -version = "0.101.7" +version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ "ring 0.17.8", + "rustls-pki-types", "untrusted 0.9.0", ] @@ -4622,7 +4777,7 @@ dependencies = [ "log", "sp-core", "sp-wasm-interface", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -4676,7 +4831,7 @@ dependencies = [ "sp-runtime", "sp-state-machine", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -4711,7 +4866,7 @@ dependencies = [ "sc-allocator", "sp-maybe-compressed-blob", "sp-wasm-interface", - "thiserror", + "thiserror 1.0.61", "wasm-instrument", ] @@ -4770,7 +4925,7 @@ dependencies = [ "sp-core", "sp-runtime", "substrate-prometheus-endpoint", - "thiserror", + "thiserror 1.0.61", "unsigned-varint 0.7.2", "wasm-timer", "zeroize", @@ -4808,7 +4963,7 @@ dependencies = [ "sp-blockchain", "sp-core", "sp-runtime", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -4952,7 +5107,7 @@ dependencies = [ "log", "rand 0.8.5", "slab", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -4984,12 +5139,12 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.11.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +checksum = "e1415a607e92bec364ea2cf9264646dcce0f91e6d65281bd6f2819cca3bf39c8" dependencies = [ "bitflags 2.6.0", - "core-foundation", + "core-foundation 0.10.0", "core-foundation-sys", "libc", "security-framework-sys", @@ -4997,9 +5152,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" dependencies = [ "core-foundation-sys", "libc", @@ -5028,7 +5183,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -5152,9 +5307,9 @@ dependencies = [ [[package]] name = "simple-dns" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3625957337d21eb40a7125c2df5c92db5c0267195d66b297948c816ea9c33157" +checksum = "b8f1740a36513fc97c5309eb1b8e8f108b0e95899c66c23fd7259625d4fdb686" dependencies = [ "bitflags 2.6.0", ] @@ -5252,7 +5407,7 @@ dependencies = [ "sp-std 12.0.0", "sp-trie", "sp-version", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -5267,7 +5422,7 @@ dependencies = [ "proc-macro-crate 1.1.3", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -5330,7 +5485,7 @@ dependencies = [ "sp-database", "sp-runtime", "sp-state-machine", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -5346,7 +5501,7 @@ dependencies = [ "sp-inherents", "sp-runtime", "sp-state-machine", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -5408,7 +5563,7 @@ dependencies = [ "sp-storage", "ss58-registry", "substrate-bip39", - "thiserror", + "thiserror 1.0.61", "tiny-bip39", "tracing", "w3f-bls", @@ -5437,7 +5592,7 @@ checksum = "42ce3e6931303769197da81facefa86159fa1085dcd96ecb7e7407b5b93582a0" dependencies = [ "quote", "sp-core-hashing", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -5458,7 +5613,7 @@ checksum = "50535e1a5708d3ba5c1195b59ebefac61cc8679c2c24716b87a86e8b7ed2e4a1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -5485,7 +5640,7 @@ dependencies = [ "scale-info", "sp-runtime", "sp-std 12.0.0", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -5523,7 +5678,7 @@ dependencies = [ "parking_lot 0.12.3", "sp-core", "sp-externalities", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -5532,7 +5687,7 @@ version = "9.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8846768f036429227e49f6ab523fbee4bc6edfee278a361bf27999590fe020d4" dependencies = [ - "thiserror", + "thiserror 1.0.61", "zstd 0.12.4", ] @@ -5611,7 +5766,7 @@ dependencies = [ "proc-macro-crate 1.1.3", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -5631,7 +5786,7 @@ dependencies = [ "sp-panic-handler", "sp-std 12.0.0", "sp-trie", - "thiserror", + "thiserror 1.0.61", "tracing", "trie-db", ] @@ -5657,7 +5812,7 @@ dependencies = [ "sp-runtime", "sp-runtime-interface", "sp-std 12.0.0", - "thiserror", + "thiserror 1.0.61", "x25519-dalek 2.0.1", ] @@ -5719,7 +5874,7 @@ dependencies = [ "schnellru", "sp-core", "sp-std 12.0.0", - "thiserror", + "thiserror 1.0.61", "tracing", "trie-db", "trie-root", @@ -5740,7 +5895,7 @@ dependencies = [ "sp-runtime", "sp-std 12.0.0", "sp-version-proc-macro", - "thiserror", + "thiserror 1.0.61", ] [[package]] @@ -5752,7 +5907,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -5851,7 +6006,7 @@ dependencies = [ "sctp-proto", "serde", "sha1", - "thiserror", + "thiserror 1.0.61", "tracing", ] @@ -5877,15 +6032,15 @@ dependencies = [ "hyper", "log", "prometheus", - "thiserror", + "thiserror 1.0.61", "tokio", ] [[package]] name = "subtle" -version = "2.4.1" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -5900,9 +6055,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.68" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -5929,7 +6084,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -5939,7 +6094,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "system-configuration-sys", ] @@ -5998,7 +6153,16 @@ version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.61", +] + +[[package]] +name = "thiserror" +version = "2.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93605438cbd668185516ab499d589afb7ee1859ea3d5fc8f6b0755e1c7443767" +dependencies = [ + "thiserror-impl 2.0.7", ] [[package]] @@ -6009,7 +6173,18 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d8749b4531af2117677a5fcd12b1348a3fe2b81e36e61ffeac5c4aa3273e36" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", ] [[package]] @@ -6066,12 +6241,22 @@ dependencies = [ "rand 0.8.5", "rustc-hash", "sha2 0.10.8", - "thiserror", + "thiserror 1.0.61", "unicode-normalization", "wasm-bindgen", "zeroize", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.6.1" @@ -6089,48 +6274,47 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.38.0" +version = "1.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot 0.12.3", "pin-project-lite 0.2.14", "socket2 0.5.7", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] name = "tokio-rustls" -version = "0.24.1" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" dependencies = [ - "rustls 0.21.12", + "rustls 0.23.20", "tokio", ] [[package]] name = "tokio-stream" -version = "0.1.15" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" dependencies = [ "futures-core", "pin-project-lite 0.2.14", @@ -6139,14 +6323,15 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.20.1" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" +checksum = "c28562dd8aea311048ed1ab9372a6b9a59977e1b308afb87c985c1f2b3206938" dependencies = [ "futures-util", "log", - "rustls 0.21.12", + "rustls 0.23.20", "rustls-native-certs", + "rustls-pki-types", "tokio", "tokio-rustls", "tungstenite", @@ -6154,9 +6339,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.11" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" dependencies = [ "bytes", "futures-core", @@ -6246,7 +6431,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", ] [[package]] @@ -6372,7 +6557,7 @@ dependencies = [ "rand 0.8.5", "smallvec", "socket2 0.4.10", - "thiserror", + "thiserror 1.0.61", "tinyvec", "tokio", "tracing", @@ -6393,7 +6578,7 @@ dependencies = [ "parking_lot 0.12.3", "resolv-conf", "smallvec", - "thiserror", + "thiserror 1.0.61", "tokio", "tracing", "trust-dns-proto", @@ -6407,20 +6592,21 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tungstenite" -version = "0.20.1" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" +checksum = "326eb16466ed89221beef69dbc94f517ee888bae959895472133924a25f7070e" dependencies = [ "byteorder", "bytes", "data-encoding", - "http", + "http 1.2.0", "httparse", "log", "rand 0.8.5", - "rustls 0.21.12", + "rustls 0.23.20", + "rustls-pki-types", "sha1", - "thiserror", + "thiserror 2.0.7", "url", "utf-8", ] @@ -6528,12 +6714,12 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.2" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", - "idna 0.5.0", + "idna 1.0.3", "percent-encoding", ] @@ -6543,6 +6729,18 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "valuable" version = "0.1.0" @@ -6587,7 +6785,7 @@ dependencies = [ "rand_core 0.6.4", "sha2 0.10.8", "sha3", - "thiserror", + "thiserror 1.0.61", "zeroize", ] @@ -6643,7 +6841,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", "wasm-bindgen-shared", ] @@ -6677,7 +6875,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6795,7 +6993,7 @@ dependencies = [ "log", "object 0.30.4", "target-lexicon", - "thiserror", + "thiserror 1.0.61", "wasmparser", "wasmtime-cranelift-shared", "wasmtime-environ", @@ -6830,7 +7028,7 @@ dependencies = [ "object 0.30.4", "serde", "target-lexicon", - "thiserror", + "thiserror 1.0.61", "wasmparser", "wasmtime-types", ] @@ -6913,7 +7111,7 @@ checksum = "a4f6fffd2a1011887d57f07654dd112791e872e3ff4a2e626aee8059ee17f06f" dependencies = [ "cranelift-entity", "serde", - "thiserror", + "thiserror 1.0.61", "wasmparser", ] @@ -7271,6 +7469,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "wyz" version = "0.5.1" @@ -7317,7 +7527,7 @@ dependencies = [ "nom", "oid-registry 0.6.1", "rusticata-macros", - "thiserror", + "thiserror 1.0.61", "time", ] @@ -7334,7 +7544,7 @@ dependencies = [ "nom", "oid-registry 0.7.0", "rusticata-macros", - "thiserror", + "thiserror 1.0.61", "time", ] @@ -7361,6 +7571,30 @@ dependencies = [ "time", ] +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", + "synstructure 0.13.1", +] + [[package]] name = "zerocopy" version = "0.7.34" @@ -7378,7 +7612,28 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", +] + +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", + "synstructure 0.13.1", ] [[package]] @@ -7398,7 +7653,29 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.68", + "syn 2.0.90", +] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index bd66ab3b..4fdbf43c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,26 +27,26 @@ parking_lot = "0.12.3" pin-project = "1.1.0" prost = "0.12.6" quinn = { version = "0.9.3", default-features = false, features = ["tls-rustls", "runtime-tokio"], optional = true } -rand = { version = "0.8.0", features = ["getrandom"] } +rand = { version = "0.8.5", features = ["getrandom"] } rcgen = "0.10.0" ring = "0.16.20" serde = "1.0.158" sha2 = "0.10.8" -simple-dns = "0.7.0" +simple-dns = "0.9.1" smallvec = "1.13.2" snow = { version = "0.9.3", features = ["ring-resolver"], default-features = false } socket2 = { version = "0.5.7", features = ["all"] } str0m = { version = "0.6.2", optional = true } -thiserror = "1.0.61" -tokio-stream = "0.1.12" -tokio-tungstenite = { version = "0.20.0", features = ["rustls-tls-native-roots"], optional = true } -tokio-util = { version = "0.7.11", features = ["compat", "io", "codec"] } -tokio = { version = "1.26.0", features = ["rt", "net", "io-util", "time", "macros", "sync", "parking_lot"] } +thiserror = "2.0.7" +tokio-stream = "0.1.17" +tokio-tungstenite = { version = "0.25.0", features = ["rustls-tls-native-roots", "url"], optional = true } +tokio-util = { version = "0.7.13", features = ["compat", "io", "codec"] } +tokio = { version = "1.42.0", features = ["rt", "net", "io-util", "time", "macros", "sync", "parking_lot"] } tracing = { version = "0.1.40", features = ["log"] } hickory-resolver = "0.24.2" uint = "0.9.5" unsigned-varint = { version = "0.8.0", features = ["codec"] } -url = "2.4.0" +url = "2.5.4" webpki = { version = "0.22.4", optional = true } x25519-dalek = "2.0.0" x509-parser = "0.16.0" diff --git a/src/protocol/libp2p/kademlia/mod.rs b/src/protocol/libp2p/kademlia/mod.rs index 5c0f1404..18ceb72e 100644 --- a/src/protocol/libp2p/kademlia/mod.rs +++ b/src/protocol/libp2p/kademlia/mod.rs @@ -21,6 +21,7 @@ //! [`/ipfs/kad/1.0.0`](https://github.com/libp2p/specs/blob/master/kad-dht/README.md) implementation. use crate::{ + addresses, error::{Error, ImmediateDialError, SubstreamError}, protocol::{ libp2p::kademlia::{ @@ -41,8 +42,9 @@ use crate::{ }; use bytes::{Bytes, BytesMut}; -use futures::StreamExt; +use futures::{sink::Close, StreamExt}; use multiaddr::Multiaddr; +use rustls::client; use tokio::sync::mpsc::{Receiver, Sender}; use std::{ @@ -245,7 +247,7 @@ impl Kademlia { context.add_pending_action(substream_id, action); } Err(error) => { - tracing::debug!( + tracing::error!( target: LOG_TARGET, ?peer, ?action, @@ -410,6 +412,25 @@ impl Kademlia { } } + fn closest_peers(&mut self, target: &Key) -> Vec { + // Find closest peers from kademlia. + let mut closest_peers = self.routing_table.closest(target, self.replication_factor); + + // Get the true addresses of the peers. + let mut peer_to_addresses = + self.service.peer_addresses(closest_peers.iter().map(|p| p.peer)); + + // Update the addresses of the peers. + for closest in closest_peers.iter_mut() { + if let Some(addresses) = peer_to_addresses.remove(&closest.peer) { + closest.addresses = addresses; + } else { + closest.addresses = Vec::new(); + } + } + closest_peers + } + /// Handle received message. async fn on_message_received( &mut self, @@ -448,11 +469,8 @@ impl Kademlia { "handle `FIND_NODE` request", ); - let message = KademliaMessage::find_node_response( - &target, - self.routing_table - .closest(&Key::new(target.as_ref()), self.replication_factor), - ); + let peers = self.closest_peers(&Key::new(target.as_ref())); + let message = KademliaMessage::find_node_response(&target, peers); self.executor.send_message(peer, message.into(), substream); } } @@ -500,9 +518,7 @@ impl Kademlia { ); let value = self.store.get(&key).cloned(); - let closest_peers = self - .routing_table - .closest(&Key::new(key.as_ref()), self.replication_factor); + let closest_peers = self.closest_peers(&Key::new(key.as_ref())); let message = KademliaMessage::get_value_response(key, closest_peers, value); @@ -612,9 +628,7 @@ impl Kademlia { p.addresses = self.service.public_addresses().get_addresses(); }); - let closer_peers = self - .routing_table - .closest(&Key::new(key.as_ref()), self.replication_factor); + let closer_peers = self.closest_peers(&Key::new(key.as_ref())); let message = KademliaMessage::get_providers_response(providers, &closer_peers); @@ -667,7 +681,7 @@ impl Kademlia { } /// Handle dial failure. - fn on_dial_failure(&mut self, peer: PeerId, address: Multiaddr) { + fn on_dial_failure(&mut self, peer: PeerId, address: Multiaddr, reason: String) { tracing::trace!(target: LOG_TARGET, ?peer, ?address, "failed to dial peer"); let Some(actions) = self.pending_dials.remove(&peer) else { @@ -681,6 +695,7 @@ impl Kademlia { ?peer, query = ?query_id, ?address, + ?reason, "report failure for pending query", ); @@ -928,8 +943,8 @@ impl Kademlia { Some(TransportEvent::SubstreamOpenFailure { substream, error }) => { self.on_substream_open_failure(substream, error).await; } - Some(TransportEvent::DialFailure { peer, address, .. }) => - self.on_dial_failure(peer, address), + Some(TransportEvent::DialFailure { peer, address, reason }) => + self.on_dial_failure(peer, address, reason), None => return Err(Error::EssentialTaskClosed), }, context = self.executor.next() => { @@ -988,12 +1003,11 @@ impl Kademlia { "starting `FIND_NODE` query", ); + let closest = self.closest_peers(&Key::from(peer)); self.engine.start_find_node( query_id, peer, - self.routing_table - .closest(&Key::from(peer), self.replication_factor) - .into() + closest.into(), ); } Some(KademliaCommand::PutRecord { mut record, query_id }) => { @@ -1017,10 +1031,11 @@ impl Kademlia { self.store.put(record.clone()); + let closest = self.closest_peers(&key); self.engine.start_put_record( query_id, record, - self.routing_table.closest(&key, self.replication_factor).into(), + closest.into(), ); } Some(KademliaCommand::PutRecordToPeers { @@ -1083,14 +1098,14 @@ impl Kademlia { }; self.store.put_provider(key.clone(), provider.clone()); + let key_saved = key.clone(); + let closest = self.closest_peers(&Key::new(key)); self.engine.start_add_provider( query_id, - key.clone(), + key_saved, provider, - self.routing_table - .closest(&Key::new(key), self.replication_factor) - .into(), + closest.into(), ); } Some(KademliaCommand::StopProviding { diff --git a/src/protocol/libp2p/kademlia/query/find_node.rs b/src/protocol/libp2p/kademlia/query/find_node.rs index 2086b4f8..eb7d8b4e 100644 --- a/src/protocol/libp2p/kademlia/query/find_node.rs +++ b/src/protocol/libp2p/kademlia/query/find_node.rs @@ -97,6 +97,8 @@ pub struct FindNodeContext>> { /// that have failed to respond within the `Self::peer_timeout` pending_responses: usize, + start_time: std::time::Instant, + is_done: bool, waker: Option, } @@ -127,11 +129,15 @@ impl>> FindNodeContext { is_done: false, waker: None, + + start_time: std::time::Instant::now(), } } /// Register response failure for `peer`. pub fn register_response_failure(&mut self, peer: PeerId) { + tracing::warn!(target: LOG_TARGET, query = ?self.config.query, ?peer, "peer failed to respond"); + let Some((peer, instant)) = self.pending.remove(&peer) else { tracing::debug!(target: LOG_TARGET, query = ?self.config.query, ?peer, "pending peer doesn't exist during response failure"); return; @@ -140,7 +146,8 @@ impl>> FindNodeContext { tracing::trace!(target: LOG_TARGET, query = ?self.config.query, ?peer, elapsed = ?instant.elapsed(), "peer failed to respond"); - self.queried.insert(peer.peer); + // Add a retry mechanism for failure responses. + // self.queried.insert(peer.peer); } /// Register `FIND_NODE` response from `peer`. @@ -160,25 +167,7 @@ impl>> FindNodeContext { // always mark the peer as queried to prevent it getting queried again self.queried.insert(peer.peer); - - if self.responses.len() < self.config.replication_factor { - self.responses.insert(distance, peer); - } else { - // Update the furthest peer if this response is closer. - // Find the furthest distance. - let furthest_distance = - self.responses.last_entry().map(|entry| *entry.key()).unwrap_or(distance); - - // The response received from the peer is closer than the furthest response. - if distance < furthest_distance { - self.responses.insert(distance, peer); - - // Remove the furthest entry. - if self.responses.len() > self.config.replication_factor { - self.responses.pop_last(); - } - } - } + self.responses.insert(distance, peer); let to_query_candidate = peers.into_iter().filter_map(|peer| { // Peer already produced a response. @@ -241,6 +230,18 @@ impl>> FindNodeContext { /// Get next action for a `FIND_NODE` query. pub fn next_action(&mut self) -> Option { + // if self.start_time.elapsed() > std::time::Duration::from_secs(10) { + // return if self.responses.is_empty() { + // Some(QueryAction::QueryFailed { + // query: self.config.query, + // }) + // } else { + // Some(QueryAction::QuerySucceeded { + // query: self.config.query, + // }) + // }; + // } + // If we cannot make progress, return the final result. // A query failed when we are not able to identify one single peer. if self.is_done() { @@ -495,7 +496,8 @@ mod tests { let in_peers_set: HashSet<_> = [peer_a, peer_b, peer_c].into_iter().collect(); assert_eq!(in_peers_set.len(), 3); - let in_peers = [peer_a, peer_b, peer_c].iter().map(|peer| peer_to_kad(*peer)).collect(); + let in_peers: VecDeque = + [peer_a, peer_b, peer_c].iter().map(|peer| peer_to_kad(*peer)).collect(); let mut context = FindNodeContext::new(config, in_peers); // Schedule peer queries. diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 9fcf5432..291d0751 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -84,6 +84,9 @@ pub enum TransportEvent { /// Dialed address. address: Multiaddr, + + /// Reason for the dial failure. + reason: String, }, /// Substream opened for `peer`. diff --git a/src/protocol/protocol_set.rs b/src/protocol/protocol_set.rs index c7bec04d..28e4d98c 100644 --- a/src/protocol/protocol_set.rs +++ b/src/protocol/protocol_set.rs @@ -90,6 +90,9 @@ pub enum InnerTransportEvent { /// Dialed address. address: Multiaddr, + + /// Reason for the failure. + reason: String, }, /// Substream opened for `peer`. @@ -144,8 +147,15 @@ pub enum InnerTransportEvent { impl From for TransportEvent { fn from(event: InnerTransportEvent) -> Self { match event { - InnerTransportEvent::DialFailure { peer, address } => - TransportEvent::DialFailure { peer, address }, + InnerTransportEvent::DialFailure { + peer, + address, + reason, + } => TransportEvent::DialFailure { + peer, + address, + reason, + }, InnerTransportEvent::SubstreamOpened { peer, protocol, diff --git a/src/protocol/transport_service.rs b/src/protocol/transport_service.rs index b9a3241a..65613d11 100644 --- a/src/protocol/transport_service.rs +++ b/src/protocol/transport_service.rs @@ -480,6 +480,14 @@ impl TransportService { self.transport_handle.add_known_address(peer, addresses.into_iter()); } + // Get peer addresses from the manager. + pub fn peer_addresses( + &self, + wanted_peers: impl IntoIterator, + ) -> HashMap> { + self.transport_handle.peer_addresses(wanted_peers) + } + /// Open substream to `peer`. /// /// Call fails if there is no connection open to `peer` or the channel towards diff --git a/src/transport/manager/address.rs b/src/transport/manager/address.rs index 30a13a4b..518ee844 100644 --- a/src/transport/manager/address.rs +++ b/src/transport/manager/address.rs @@ -203,6 +203,9 @@ impl AddressStore { pub fn insert(&mut self, record: AddressRecord) { if let Entry::Occupied(mut occupied) = self.addresses.entry(record.address.clone()) { occupied.get_mut().update_score(record.score); + // if occupied.get().score < 0 { + // occupied.remove(); + // } return; } @@ -213,20 +216,20 @@ impl AddressStore { // - if the store is at capacity, the worst address will be evicted. // - an address that is not dialed yet (with score zero) will be preferred over an address // that already failed (with negative score). - if self.addresses.len() >= self.max_capacity { - let min_record = self - .addresses - .values() - .min() - .cloned() - .expect("There is at least one element checked above; qed"); - - // The lowest score is better than the new record. - if record.score < min_record.score { - return; - } - self.addresses.remove(min_record.address()); - } + // if self.addresses.len() >= self.max_capacity { + // let min_record = self + // .addresses + // .values() + // .min() + // .cloned() + // .expect("There is at least one element checked above; qed"); + + // // The lowest score is better than the new record. + // if record.score < min_record.score { + // return; + // } + // self.addresses.remove(min_record.address()); + // } // Insert the record. self.addresses.insert(record.address.clone(), record); @@ -236,7 +239,17 @@ impl AddressStore { pub fn addresses(&self, limit: usize) -> Vec { let mut records = self.addresses.values().cloned().collect::>(); records.sort_by(|lhs, rhs| rhs.score.cmp(&lhs.score)); - records.into_iter().take(limit).map(|record| record.address).collect() + records + .into_iter() + .filter_map(|record| { + if record.score >= 0 { + Some(record.address) + } else { + None + } + }) + .take(limit) + .collect() } } diff --git a/src/transport/manager/handle.rs b/src/transport/manager/handle.rs index 26dad579..122e48b7 100644 --- a/src/transport/manager/handle.rs +++ b/src/transport/manager/handle.rs @@ -171,6 +171,22 @@ impl TransportManagerHandle { self.listen_addresses.read().contains(&address) } + // Get peer addresses from the manager. + pub fn peer_addresses( + &self, + wanted_peers: impl IntoIterator, + ) -> HashMap> { + let peers = self.peers.read(); + wanted_peers + .into_iter() + .filter_map(|peer| { + peers + .get(&peer) + .map(|PeerContext { addresses, .. }| (peer, addresses.addresses(16))) + }) + .collect() + } + /// Add one or more known addresses for peer. /// /// If peer doesn't exist, it will be added to known peers. diff --git a/src/transport/manager/mod.rs b/src/transport/manager/mod.rs index d7eba036..a991f3e5 100644 --- a/src/transport/manager/mod.rs +++ b/src/transport/manager/mod.rs @@ -1098,9 +1098,10 @@ impl TransportManager { match context.tx.try_send(InnerTransportEvent::DialFailure { peer, address: address.clone(), + reason: error.to_string(), }) { Ok(()) => {} - Err(_) => { + Err(err) => { tracing::trace!( target: LOG_TARGET, ?connection_id, @@ -1114,6 +1115,7 @@ impl TransportManager { .send(InnerTransportEvent::DialFailure { peer, address: address.clone(), + reason: format!("channel clogged err ({:?}) original error: {:?}", err, error.to_string()), }) .await; } @@ -1219,8 +1221,10 @@ impl TransportManager { } } TransportEvent::OpenFailure { connection_id, errors } => { + let mut report_error = "".to_string(); for (address, error) in &errors { self.update_address_on_dial_failure(address.clone(), error); + report_error.push_str(&format!("({}: {}), ", address, error)); } match self.on_open_failure(transport, connection_id) { @@ -1245,9 +1249,10 @@ impl TransportManager { .try_send(InnerTransportEvent::DialFailure { peer, address: Multiaddr::empty(), + reason: report_error.to_string(), }) { Ok(_) => Ok(()), - Err(_) => { + Err(err) => { tracing::trace!( target: LOG_TARGET, ?peer, @@ -1261,6 +1266,7 @@ impl TransportManager { .send(InnerTransportEvent::DialFailure { peer, address: Multiaddr::empty(), + reason: format!("channel clogged open-err ({:?}) original error: {:?}", err, report_error), }) .await } diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 1d61ca9d..cfb39e09 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -42,13 +42,13 @@ pub(crate) mod manager; pub use manager::limits::{ConnectionLimitsConfig, ConnectionLimitsError}; /// Timeout for opening a connection. -pub(crate) const CONNECTION_OPEN_TIMEOUT: Duration = Duration::from_secs(10); +pub(crate) const CONNECTION_OPEN_TIMEOUT: Duration = Duration::from_secs(3); /// Timeout for opening a substream. -pub(crate) const SUBSTREAM_OPEN_TIMEOUT: Duration = Duration::from_secs(5); +pub(crate) const SUBSTREAM_OPEN_TIMEOUT: Duration = Duration::from_secs(3); /// Timeout for connection waiting new substreams. -pub(crate) const KEEP_ALIVE_TIMEOUT: Duration = Duration::from_secs(5); +pub(crate) const KEEP_ALIVE_TIMEOUT: Duration = Duration::from_secs(3); /// Maximum number of parallel dial attempts. pub(crate) const MAX_PARALLEL_DIALS: usize = 8; diff --git a/src/transport/websocket/stream.rs b/src/transport/websocket/stream.rs index 268d39e1..8c092feb 100644 --- a/src/transport/websocket/stream.rs +++ b/src/transport/websocket/stream.rs @@ -113,7 +113,8 @@ impl futures::AsyncWrite for BufferedStream { - match self.stream.start_send_unpin(Message::Binary(to_write.clone())) { + // TODO: Optimize this code! + match self.stream.start_send_unpin(Message::binary(to_write.clone())) { Ok(_) => { self.state = State::FlushPending; continue; @@ -156,7 +157,14 @@ impl futures::AsyncRead for BufferedStream if self.read_buffer.is_none() { match self.stream.poll_next_unpin(cx) { Poll::Ready(Some(Ok(chunk))) => match chunk { - Message::Binary(chunk) => self.read_buffer.replace(chunk.into()), + Message::Binary(chunk) => { + let buffer= match chunk { + tokio_tungstenite::tungstenite::protocol::frame::Payload::Owned(bytes_mut) => bytes_mut.freeze(), + tokio_tungstenite::tungstenite::protocol::frame::Payload::Shared(bytes) => bytes, + tokio_tungstenite::tungstenite::protocol::frame::Payload::Vec(vec) => vec.into(), + }; + self.read_buffer = Some(buffer); + } _event => return Poll::Ready(Err(std::io::ErrorKind::Unsupported.into())), }, Poll::Ready(Some(Err(_error))) =>