diff --git a/p2p/p2p-core/src/client.rs b/p2p/p2p-core/src/client.rs index 458a3716..ab262cc7 100644 --- a/p2p/p2p-core/src/client.rs +++ b/p2p/p2p-core/src/client.rs @@ -1,10 +1,10 @@ -use futures::channel::oneshot; -use std::sync::Mutex; use std::{ fmt::{Debug, Display, Formatter}, - sync::Arc, + sync::{Arc, Mutex}, task::{ready, Context, Poll}, }; + +use futures::channel::oneshot; use tokio::{ sync::{mpsc, OwnedSemaphorePermit, Semaphore}, task::JoinHandle, @@ -14,6 +14,8 @@ use tower::{Service, ServiceExt}; use tracing::Instrument; use cuprate_helper::asynch::InfallibleOneshotReceiver; +use cuprate_pruning::PruningSeed; +use cuprate_wire::CoreSyncData; use crate::{ handles::{ConnectionGuard, ConnectionHandle}, @@ -27,8 +29,6 @@ mod request_handler; mod timeout_monitor; pub use connector::{ConnectRequest, Connector}; -use cuprate_pruning::PruningSeed; -use cuprate_wire::CoreSyncData; pub use handshaker::{DoHandshakeRequest, HandshakeError, HandshakerBuilder}; /// An internal identifier for a given peer, will be their address if known diff --git a/p2p/p2p-core/src/client/handshaker.rs b/p2p/p2p-core/src/client/handshaker.rs index 434c330f..13c55cc4 100644 --- a/p2p/p2p-core/src/client/handshaker.rs +++ b/p2p/p2p-core/src/client/handshaker.rs @@ -4,15 +4,15 @@ //! to complete a handshake with them. //! //! This module also contains a [`ping`] function that can be used to check if an address is reachable. -use futures::{FutureExt, SinkExt, Stream, StreamExt}; -use std::sync::Mutex; use std::{ future::Future, marker::PhantomData, pin::Pin, - sync::Arc, + sync::{Arc, Mutex}, task::{Context, Poll}, }; + +use futures::{FutureExt, SinkExt, Stream, StreamExt}; use tokio::{ sync::{mpsc, OwnedSemaphorePermit, Semaphore}, time::{error::Elapsed, timeout}, diff --git a/p2p/p2p/src/block_downloader/tests.rs b/p2p/p2p/src/block_downloader/tests.rs index 0dfe42bf..83dd417c 100644 --- a/p2p/p2p/src/block_downloader/tests.rs +++ b/p2p/p2p/src/block_downloader/tests.rs @@ -1,3 +1,12 @@ +use std::{ + fmt::{Debug, Formatter}, + future::Future, + pin::Pin, + sync::{Arc, Mutex}, + task::{Context, Poll}, + time::Duration, +}; + use futures::{FutureExt, StreamExt}; use indexmap::IndexMap; use monero_serai::{ @@ -5,15 +14,6 @@ use monero_serai::{ transaction::{Input, Timelock, Transaction, TransactionPrefix}, }; use proptest::{collection::vec, prelude::*}; -use std::sync::Mutex; -use std::{ - fmt::{Debug, Formatter}, - future::Future, - pin::Pin, - sync::Arc, - task::{Context, Poll}, - time::Duration, -}; use tokio::time::timeout; use tower::{service_fn, Service}; @@ -24,8 +24,10 @@ use cuprate_p2p_core::{ }; use cuprate_pruning::PruningSeed; use cuprate_types::{BlockCompleteEntry, TransactionBlobs}; -use cuprate_wire::protocol::{ChainResponse, GetObjectsResponse}; -use cuprate_wire::CoreSyncData; +use cuprate_wire::{ + protocol::{ChainResponse, GetObjectsResponse}, + CoreSyncData, +}; use crate::{ block_downloader::{download_blocks, BlockDownloaderConfig, ChainSvcRequest, ChainSvcResponse}, diff --git a/p2p/p2p/src/client_pool.rs b/p2p/p2p/src/client_pool.rs index bbf83a32..77d3b6e5 100644 --- a/p2p/p2p/src/client_pool.rs +++ b/p2p/p2p/src/client_pool.rs @@ -128,6 +128,11 @@ impl ClientPool { peers.iter().filter_map(|peer| self.borrow_client(peer)) } + /// Borrows all [`Client`]s from the pool that have claimed a higher cumulative difficulty than + /// the amount passed in. + /// + /// The [`Client`]s are wrapped in [`ClientPoolDropGuard`] which + /// will return the clients to the pool when they are dropped. pub fn clients_with_more_cumulative_difficulty( self: &Arc, cumulative_difficulty: u128,