mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-26 00:01:33 +00:00
chore: enforce unreachable_pub
lint
The `unreachable_pub` lint makes us aware of uses of `pub` that are not actually reachable from the crate root. This is considered good because it means reading a `pub` somewhere means it is actually public API. Some of our crates are quite large and keeping their entire API surface in your head is difficult. We should strive for most items being `pub(crate)`. This lint helps us enforce that. Pull-Request: #3735.
This commit is contained in:
@ -22,9 +22,9 @@ mod error;
|
||||
|
||||
pub(crate) mod pool;
|
||||
|
||||
pub use error::{
|
||||
ConnectionError, PendingConnectionError, PendingInboundConnectionError,
|
||||
PendingOutboundConnectionError,
|
||||
pub use error::ConnectionError;
|
||||
pub(crate) use error::{
|
||||
PendingConnectionError, PendingInboundConnectionError, PendingOutboundConnectionError,
|
||||
};
|
||||
|
||||
use crate::handler::{
|
||||
@ -85,16 +85,16 @@ impl ConnectionId {
|
||||
|
||||
/// Information about a successfully established connection.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Connected {
|
||||
pub(crate) struct Connected {
|
||||
/// The connected endpoint, including network address information.
|
||||
pub endpoint: ConnectedPoint,
|
||||
pub(crate) endpoint: ConnectedPoint,
|
||||
/// Information obtained from the transport.
|
||||
pub peer_id: PeerId,
|
||||
pub(crate) peer_id: PeerId,
|
||||
}
|
||||
|
||||
/// Event generated by a [`Connection`].
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Event<T> {
|
||||
pub(crate) enum Event<T> {
|
||||
/// Event generated by the [`ConnectionHandler`].
|
||||
Handler(T),
|
||||
/// Address of the remote has changed.
|
||||
@ -102,7 +102,7 @@ pub enum Event<T> {
|
||||
}
|
||||
|
||||
/// A multiplexed connection to a peer with an associated [`ConnectionHandler`].
|
||||
pub struct Connection<THandler>
|
||||
pub(crate) struct Connection<THandler>
|
||||
where
|
||||
THandler: ConnectionHandler,
|
||||
{
|
||||
@ -167,7 +167,7 @@ where
|
||||
{
|
||||
/// Builds a new `Connection` from the given substream multiplexer
|
||||
/// and connection handler.
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
muxer: StreamMuxerBox,
|
||||
handler: THandler,
|
||||
substream_upgrade_protocol_override: Option<upgrade::Version>,
|
||||
@ -186,19 +186,19 @@ where
|
||||
}
|
||||
|
||||
/// Notifies the connection handler of an event.
|
||||
pub fn on_behaviour_event(&mut self, event: THandler::InEvent) {
|
||||
pub(crate) fn on_behaviour_event(&mut self, event: THandler::InEvent) {
|
||||
self.handler.on_behaviour_event(event);
|
||||
}
|
||||
|
||||
/// Begins an orderly shutdown of the connection, returning the connection
|
||||
/// handler and a `Future` that resolves when connection shutdown is complete.
|
||||
pub fn close(self) -> (THandler, impl Future<Output = io::Result<()>>) {
|
||||
pub(crate) fn close(self) -> (THandler, impl Future<Output = io::Result<()>>) {
|
||||
(self.handler, self.muxing.close())
|
||||
}
|
||||
|
||||
/// Polls the handler and the substream, forwarding events from the former to the latter and
|
||||
/// vice versa.
|
||||
pub fn poll(
|
||||
pub(crate) fn poll(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Result<Event<THandler::OutEvent>, ConnectionError<THandler::Error>>> {
|
||||
@ -369,16 +369,16 @@ where
|
||||
|
||||
/// Borrowed information about an incoming connection currently being negotiated.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct IncomingInfo<'a> {
|
||||
pub(crate) struct IncomingInfo<'a> {
|
||||
/// Local connection address.
|
||||
pub local_addr: &'a Multiaddr,
|
||||
pub(crate) local_addr: &'a Multiaddr,
|
||||
/// Address used to send back data to the remote.
|
||||
pub send_back_addr: &'a Multiaddr,
|
||||
pub(crate) send_back_addr: &'a Multiaddr,
|
||||
}
|
||||
|
||||
impl<'a> IncomingInfo<'a> {
|
||||
/// Builds the [`ConnectedPoint`] corresponding to the incoming connection.
|
||||
pub fn create_connected_point(&self) -> ConnectedPoint {
|
||||
pub(crate) fn create_connected_point(&self) -> ConnectedPoint {
|
||||
ConnectedPoint::Listener {
|
||||
local_addr: self.local_addr.clone(),
|
||||
send_back_addr: self.send_back_addr.clone(),
|
||||
|
@ -78,11 +78,11 @@ impl<THandlerErr> From<io::Error> for ConnectionError<THandlerErr> {
|
||||
/// Note: Addresses for an outbound connection are dialed in parallel. Thus, compared to
|
||||
/// [`PendingInboundConnectionError`], one or more [`TransportError`]s can occur for a single
|
||||
/// connection.
|
||||
pub type PendingOutboundConnectionError =
|
||||
pub(crate) type PendingOutboundConnectionError =
|
||||
PendingConnectionError<Vec<(Multiaddr, TransportError<io::Error>)>>;
|
||||
|
||||
/// Errors that can occur in the context of a pending incoming `Connection`.
|
||||
pub type PendingInboundConnectionError = PendingConnectionError<TransportError<io::Error>>;
|
||||
pub(crate) type PendingInboundConnectionError = PendingConnectionError<TransportError<io::Error>>;
|
||||
|
||||
/// Errors that can occur in the context of a pending `Connection`.
|
||||
#[derive(Debug)]
|
||||
|
@ -84,7 +84,7 @@ impl ExecSwitch {
|
||||
}
|
||||
|
||||
/// A connection `Pool` manages a set of connections for each peer.
|
||||
pub struct Pool<THandler>
|
||||
pub(crate) struct Pool<THandler>
|
||||
where
|
||||
THandler: ConnectionHandler,
|
||||
{
|
||||
@ -140,7 +140,7 @@ where
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EstablishedConnection<TInEvent> {
|
||||
pub(crate) struct EstablishedConnection<TInEvent> {
|
||||
endpoint: ConnectedPoint,
|
||||
/// Channel endpoint to send commands to the task.
|
||||
sender: mpsc::Sender<task::Command<TInEvent>>,
|
||||
@ -157,7 +157,7 @@ impl<TInEvent> EstablishedConnection<TInEvent> {
|
||||
/// `poll_ready_notify_handler` without another intervening execution
|
||||
/// of `notify_handler`, it only fails if the connection is now about
|
||||
/// to close.
|
||||
pub fn notify_handler(&mut self, event: TInEvent) -> Result<(), TInEvent> {
|
||||
pub(crate) fn notify_handler(&mut self, event: TInEvent) -> Result<(), TInEvent> {
|
||||
let cmd = task::Command::NotifyHandler(event);
|
||||
self.sender.try_send(cmd).map_err(|e| match e.into_inner() {
|
||||
task::Command::NotifyHandler(event) => event,
|
||||
@ -171,14 +171,17 @@ impl<TInEvent> EstablishedConnection<TInEvent> {
|
||||
///
|
||||
/// Returns `Err(())` if the background task associated with the connection
|
||||
/// is terminating and the connection is about to close.
|
||||
pub fn poll_ready_notify_handler(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), ()>> {
|
||||
pub(crate) fn poll_ready_notify_handler(
|
||||
&mut self,
|
||||
cx: &mut Context<'_>,
|
||||
) -> Poll<Result<(), ()>> {
|
||||
self.sender.poll_ready(cx).map_err(|_| ())
|
||||
}
|
||||
|
||||
/// Initiates a graceful close of the connection.
|
||||
///
|
||||
/// Has no effect if the connection is already closing.
|
||||
pub fn start_close(&mut self) {
|
||||
pub(crate) fn start_close(&mut self) {
|
||||
// Clone the sender so that we are guaranteed to have
|
||||
// capacity for the close command (every sender gets a slot).
|
||||
match self.sender.clone().try_send(task::Command::Close) {
|
||||
@ -221,7 +224,7 @@ impl<THandler: ConnectionHandler> fmt::Debug for Pool<THandler> {
|
||||
|
||||
/// Event that can happen on the `Pool`.
|
||||
#[derive(Debug)]
|
||||
pub enum PoolEvent<THandler: ConnectionHandler> {
|
||||
pub(crate) enum PoolEvent<THandler: ConnectionHandler> {
|
||||
/// A new connection has been established.
|
||||
ConnectionEstablished {
|
||||
id: ConnectionId,
|
||||
@ -306,7 +309,7 @@ where
|
||||
{
|
||||
/// Creates a new empty `Pool`.
|
||||
#[allow(deprecated)]
|
||||
pub fn new(local_id: PeerId, config: PoolConfig, limits: ConnectionLimits) -> Self {
|
||||
pub(crate) fn new(local_id: PeerId, config: PoolConfig, limits: ConnectionLimits) -> Self {
|
||||
let (pending_connection_events_tx, pending_connection_events_rx) = mpsc::channel(0);
|
||||
let executor = match config.executor {
|
||||
Some(exec) => ExecSwitch::Executor(exec),
|
||||
@ -332,12 +335,12 @@ where
|
||||
}
|
||||
|
||||
/// Gets the dedicated connection counters.
|
||||
pub fn counters(&self) -> &ConnectionCounters {
|
||||
pub(crate) fn counters(&self) -> &ConnectionCounters {
|
||||
&self.counters
|
||||
}
|
||||
|
||||
/// Gets an established connection from the pool by ID.
|
||||
pub fn get_established(
|
||||
pub(crate) fn get_established(
|
||||
&mut self,
|
||||
id: ConnectionId,
|
||||
) -> Option<&mut EstablishedConnection<THandler::InEvent>> {
|
||||
@ -349,13 +352,13 @@ where
|
||||
/// Returns true if we are connected to the given peer.
|
||||
///
|
||||
/// This will return true only after a `NodeReached` event has been produced by `poll()`.
|
||||
pub fn is_connected(&self, id: PeerId) -> bool {
|
||||
pub(crate) fn is_connected(&self, id: PeerId) -> bool {
|
||||
self.established.contains_key(&id)
|
||||
}
|
||||
|
||||
/// Returns the number of connected peers, i.e. those with at least one
|
||||
/// established connection in the pool.
|
||||
pub fn num_peers(&self) -> usize {
|
||||
pub(crate) fn num_peers(&self) -> usize {
|
||||
self.established.len()
|
||||
}
|
||||
|
||||
@ -364,7 +367,7 @@ where
|
||||
/// All connections to the peer, whether pending or established are
|
||||
/// closed asap and no more events from these connections are emitted
|
||||
/// by the pool effective immediately.
|
||||
pub fn disconnect(&mut self, peer: PeerId) {
|
||||
pub(crate) fn disconnect(&mut self, peer: PeerId) {
|
||||
if let Some(conns) = self.established.get_mut(&peer) {
|
||||
for (_, conn) in conns.iter_mut() {
|
||||
conn.start_close();
|
||||
@ -381,7 +384,7 @@ where
|
||||
}
|
||||
|
||||
/// Returns an iterator over all established connections of `peer`.
|
||||
pub fn iter_established_connections_of_peer(
|
||||
pub(crate) fn iter_established_connections_of_peer(
|
||||
&mut self,
|
||||
peer: &PeerId,
|
||||
) -> impl Iterator<Item = ConnectionId> + '_ {
|
||||
@ -392,7 +395,7 @@ where
|
||||
}
|
||||
|
||||
/// Checks whether we are currently dialing the given peer.
|
||||
pub fn is_dialing(&self, peer: PeerId) -> bool {
|
||||
pub(crate) fn is_dialing(&self, peer: PeerId) -> bool {
|
||||
self.pending.iter().any(|(_, info)| {
|
||||
matches!(info.endpoint, PendingPoint::Dialer { .. }) && info.is_for_same_remote_as(peer)
|
||||
})
|
||||
@ -400,7 +403,7 @@ where
|
||||
|
||||
/// Returns an iterator over all connected peers, i.e. those that have
|
||||
/// at least one established connection in the pool.
|
||||
pub fn iter_connected(&self) -> impl Iterator<Item = &PeerId> {
|
||||
pub(crate) fn iter_connected(&self) -> impl Iterator<Item = &PeerId> {
|
||||
self.established.keys()
|
||||
}
|
||||
|
||||
@ -410,7 +413,7 @@ where
|
||||
/// Returns an error if the limit of pending outgoing connections
|
||||
/// has been reached.
|
||||
#[allow(deprecated)]
|
||||
pub fn add_outgoing(
|
||||
pub(crate) fn add_outgoing(
|
||||
&mut self,
|
||||
dials: Vec<
|
||||
BoxFuture<
|
||||
@ -465,7 +468,7 @@ where
|
||||
/// Returns an error if the limit of pending incoming connections
|
||||
/// has been reached.
|
||||
#[allow(deprecated)]
|
||||
pub fn add_incoming<TFut>(
|
||||
pub(crate) fn add_incoming<TFut>(
|
||||
&mut self,
|
||||
future: TFut,
|
||||
info: IncomingInfo<'_>,
|
||||
@ -503,7 +506,7 @@ where
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub fn spawn_connection(
|
||||
pub(crate) fn spawn_connection(
|
||||
&mut self,
|
||||
id: ConnectionId,
|
||||
obtained_peer_id: PeerId,
|
||||
@ -548,7 +551,7 @@ where
|
||||
}
|
||||
|
||||
/// Polls the connection pool for events.
|
||||
pub fn poll(&mut self, cx: &mut Context<'_>) -> Poll<PoolEvent<THandler>>
|
||||
pub(crate) fn poll(&mut self, cx: &mut Context<'_>) -> Poll<PoolEvent<THandler>>
|
||||
where
|
||||
THandler: ConnectionHandler + 'static,
|
||||
<THandler as ConnectionHandler>::OutboundOpenInfo: Send,
|
||||
@ -832,7 +835,7 @@ where
|
||||
///
|
||||
/// On drop, this type send the connection back to the [`Pool`] where it will be gracefully closed.
|
||||
#[derive(Debug)]
|
||||
pub struct NewConnection {
|
||||
pub(crate) struct NewConnection {
|
||||
connection: Option<StreamMuxerBox>,
|
||||
drop_sender: Option<oneshot::Sender<StreamMuxerBox>>,
|
||||
}
|
||||
@ -1101,20 +1104,16 @@ impl ConnectionLimits {
|
||||
///
|
||||
/// The default configuration specifies no dedicated task executor, a
|
||||
/// task event buffer size of 32, and a task command buffer size of 7.
|
||||
pub struct PoolConfig {
|
||||
pub(crate) struct PoolConfig {
|
||||
/// Executor to use to spawn tasks.
|
||||
pub executor: Option<Box<dyn Executor + Send>>,
|
||||
|
||||
pub(crate) executor: Option<Box<dyn Executor + Send>>,
|
||||
/// Size of the task command buffer (per task).
|
||||
pub task_command_buffer_size: usize,
|
||||
|
||||
pub(crate) task_command_buffer_size: usize,
|
||||
/// Size of the pending connection task event buffer and the established connection task event
|
||||
/// buffer.
|
||||
pub per_connection_event_buffer_size: usize,
|
||||
|
||||
pub(crate) per_connection_event_buffer_size: usize,
|
||||
/// Number of addresses concurrently dialed for a single outbound connection attempt.
|
||||
pub dial_concurrency_factor: NonZeroU8,
|
||||
|
||||
pub(crate) dial_concurrency_factor: NonZeroU8,
|
||||
/// The configured override for substream protocol upgrades, if any.
|
||||
substream_upgrade_protocol_override: Option<libp2p_core::upgrade::Version>,
|
||||
|
||||
@ -1125,7 +1124,7 @@ pub struct PoolConfig {
|
||||
}
|
||||
|
||||
impl PoolConfig {
|
||||
pub fn new(executor: Option<Box<dyn Executor + Send>>) -> Self {
|
||||
pub(crate) fn new(executor: Option<Box<dyn Executor + Send>>) -> Self {
|
||||
Self {
|
||||
executor,
|
||||
task_command_buffer_size: 32,
|
||||
@ -1143,7 +1142,7 @@ impl PoolConfig {
|
||||
/// When the buffer for a particular connection is full, `notify_handler` will no
|
||||
/// longer be able to deliver events to the associated [`Connection`](super::Connection),
|
||||
/// thus exerting back-pressure on the connection and peer API.
|
||||
pub fn with_notify_handler_buffer_size(mut self, n: NonZeroUsize) -> Self {
|
||||
pub(crate) fn with_notify_handler_buffer_size(mut self, n: NonZeroUsize) -> Self {
|
||||
self.task_command_buffer_size = n.get() - 1;
|
||||
self
|
||||
}
|
||||
@ -1154,19 +1153,19 @@ impl PoolConfig {
|
||||
/// When the buffer is full, the background tasks of all connections will stall.
|
||||
/// In this way, the consumers of network events exert back-pressure on
|
||||
/// the network connection I/O.
|
||||
pub fn with_per_connection_event_buffer_size(mut self, n: usize) -> Self {
|
||||
pub(crate) fn with_per_connection_event_buffer_size(mut self, n: usize) -> Self {
|
||||
self.per_connection_event_buffer_size = n;
|
||||
self
|
||||
}
|
||||
|
||||
/// Number of addresses concurrently dialed for a single outbound connection attempt.
|
||||
pub fn with_dial_concurrency_factor(mut self, factor: NonZeroU8) -> Self {
|
||||
pub(crate) fn with_dial_concurrency_factor(mut self, factor: NonZeroU8) -> Self {
|
||||
self.dial_concurrency_factor = factor;
|
||||
self
|
||||
}
|
||||
|
||||
/// Configures an override for the substream upgrade protocol to use.
|
||||
pub fn with_substream_upgrade_protocol_override(
|
||||
pub(crate) fn with_substream_upgrade_protocol_override(
|
||||
mut self,
|
||||
v: libp2p_core::upgrade::Version,
|
||||
) -> Self {
|
||||
@ -1177,7 +1176,7 @@ impl PoolConfig {
|
||||
/// The maximum number of inbound streams concurrently negotiating on a connection.
|
||||
///
|
||||
/// See [`Connection::max_negotiating_inbound_streams`].
|
||||
pub fn with_max_negotiating_inbound_streams(mut self, v: usize) -> Self {
|
||||
pub(crate) fn with_max_negotiating_inbound_streams(mut self, v: usize) -> Self {
|
||||
self.max_negotiating_inbound_streams = v;
|
||||
self
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ type Dial = BoxFuture<
|
||||
),
|
||||
>;
|
||||
|
||||
pub struct ConcurrentDial {
|
||||
pub(crate) struct ConcurrentDial {
|
||||
dials: FuturesUnordered<Dial>,
|
||||
pending_dials: Box<dyn Iterator<Item = Dial> + Send>,
|
||||
errors: Vec<(Multiaddr, TransportError<std::io::Error>)>,
|
||||
|
@ -41,7 +41,7 @@ use void::Void;
|
||||
|
||||
/// Commands that can be sent to a task driving an established connection.
|
||||
#[derive(Debug)]
|
||||
pub enum Command<T> {
|
||||
pub(crate) enum Command<T> {
|
||||
/// Notify the connection handler of an event.
|
||||
NotifyHandler(T),
|
||||
/// Gracefully close the connection (active close) before
|
||||
@ -49,7 +49,7 @@ pub enum Command<T> {
|
||||
Close,
|
||||
}
|
||||
|
||||
pub enum PendingConnectionEvent {
|
||||
pub(crate) enum PendingConnectionEvent {
|
||||
ConnectionEstablished {
|
||||
id: ConnectionId,
|
||||
output: (PeerId, StreamMuxerBox),
|
||||
@ -66,7 +66,7 @@ pub enum PendingConnectionEvent {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum EstablishedConnectionEvent<THandler: ConnectionHandler> {
|
||||
pub(crate) enum EstablishedConnectionEvent<THandler: ConnectionHandler> {
|
||||
/// A node we are connected to has changed its address.
|
||||
AddressChange {
|
||||
id: ConnectionId,
|
||||
@ -91,7 +91,7 @@ pub enum EstablishedConnectionEvent<THandler: ConnectionHandler> {
|
||||
},
|
||||
}
|
||||
|
||||
pub async fn new_for_pending_outgoing_connection(
|
||||
pub(crate) async fn new_for_pending_outgoing_connection(
|
||||
connection_id: ConnectionId,
|
||||
dial: ConcurrentDial,
|
||||
abort_receiver: oneshot::Receiver<Void>,
|
||||
@ -127,7 +127,7 @@ pub async fn new_for_pending_outgoing_connection(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn new_for_pending_incoming_connection<TFut>(
|
||||
pub(crate) async fn new_for_pending_incoming_connection<TFut>(
|
||||
connection_id: ConnectionId,
|
||||
future: TFut,
|
||||
abort_receiver: oneshot::Receiver<Void>,
|
||||
@ -167,7 +167,7 @@ pub async fn new_for_pending_incoming_connection<TFut>(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn new_for_established_connection<THandler>(
|
||||
pub(crate) async fn new_for_established_connection<THandler>(
|
||||
connection_id: ConnectionId,
|
||||
peer_id: PeerId,
|
||||
mut connection: crate::connection::Connection<THandler>,
|
||||
|
@ -31,8 +31,7 @@ impl Executor for ThreadPool {
|
||||
not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown"))
|
||||
))]
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
pub struct TokioExecutor;
|
||||
|
||||
pub(crate) struct TokioExecutor;
|
||||
#[cfg(all(
|
||||
feature = "tokio",
|
||||
not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown"))
|
||||
@ -48,8 +47,7 @@ impl Executor for TokioExecutor {
|
||||
not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown"))
|
||||
))]
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
pub struct AsyncStdExecutor;
|
||||
|
||||
pub(crate) struct AsyncStdExecutor;
|
||||
#[cfg(all(
|
||||
feature = "async-std",
|
||||
not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown"))
|
||||
@ -62,8 +60,7 @@ impl Executor for AsyncStdExecutor {
|
||||
|
||||
#[cfg(feature = "wasm-bindgen")]
|
||||
#[derive(Default, Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct WasmBindgenExecutor;
|
||||
|
||||
pub(crate) struct WasmBindgenExecutor;
|
||||
#[cfg(feature = "wasm-bindgen")]
|
||||
impl Executor for WasmBindgenExecutor {
|
||||
fn exec(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>) {
|
||||
|
@ -42,7 +42,7 @@ use std::{cmp::Ordering, collections::VecDeque, num::NonZeroUsize};
|
||||
/// it is removed from the collection.
|
||||
///
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Addresses {
|
||||
pub(crate) struct Addresses {
|
||||
/// The ranked sequence of addresses, from highest to lowest score.
|
||||
///
|
||||
/// By design, the number of finitely scored addresses stored here is
|
||||
@ -171,7 +171,7 @@ pub enum AddAddressResult {
|
||||
impl Addresses {
|
||||
/// Create a new ranked address collection with the given size limit
|
||||
/// for [finitely scored](AddressScore::Finite) addresses.
|
||||
pub fn new(limit: NonZeroUsize) -> Self {
|
||||
pub(crate) fn new(limit: NonZeroUsize) -> Self {
|
||||
Addresses {
|
||||
registry: SmallVec::new(),
|
||||
limit,
|
||||
@ -189,7 +189,7 @@ impl Addresses {
|
||||
/// as per this limited history has its score reduced by the amount
|
||||
/// used in this prior report, with removal from the collection
|
||||
/// occurring when the score drops to 0.
|
||||
pub fn add(&mut self, addr: Multiaddr, score: AddressScore) -> AddAddressResult {
|
||||
pub(crate) fn add(&mut self, addr: Multiaddr, score: AddressScore) -> AddAddressResult {
|
||||
// If enough reports (i.e. address additions) occurred, reduce
|
||||
// the score of the least-recently added address.
|
||||
if self.reports.len() == self.limit.get() {
|
||||
@ -240,7 +240,7 @@ impl Addresses {
|
||||
///
|
||||
/// Returns `true` if the address existed in the collection
|
||||
/// and was thus removed, false otherwise.
|
||||
pub fn remove(&mut self, addr: &Multiaddr) -> bool {
|
||||
pub(crate) fn remove(&mut self, addr: &Multiaddr) -> bool {
|
||||
if let Some(pos) = self.registry.iter().position(|r| &r.addr == addr) {
|
||||
self.registry.remove(pos);
|
||||
true
|
||||
@ -252,7 +252,7 @@ impl Addresses {
|
||||
/// Return an iterator over all [`Multiaddr`] values.
|
||||
///
|
||||
/// The iteration is ordered by descending score.
|
||||
pub fn iter(&self) -> AddressIter<'_> {
|
||||
pub(crate) fn iter(&self) -> AddressIter<'_> {
|
||||
AddressIter {
|
||||
items: &self.registry,
|
||||
offset: 0,
|
||||
@ -262,7 +262,7 @@ impl Addresses {
|
||||
/// Return an iterator over all [`Multiaddr`] values.
|
||||
///
|
||||
/// The iteration is ordered by descending score.
|
||||
pub fn into_iter(self) -> AddressIntoIter {
|
||||
pub(crate) fn into_iter(self) -> AddressIntoIter {
|
||||
AddressIntoIter {
|
||||
items: self.registry,
|
||||
}
|
||||
@ -271,7 +271,7 @@ impl Addresses {
|
||||
|
||||
/// An iterator over [`Multiaddr`] values.
|
||||
#[derive(Clone)]
|
||||
pub struct AddressIter<'a> {
|
||||
pub(crate) struct AddressIter<'a> {
|
||||
items: &'a [AddressRecord],
|
||||
offset: usize,
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ use std::task::{Context, Poll};
|
||||
/// A `MockBehaviour` is a `NetworkBehaviour` that allows for
|
||||
/// the instrumentation of return values, without keeping
|
||||
/// any further state.
|
||||
pub struct MockBehaviour<THandler, TOutEvent>
|
||||
pub(crate) struct MockBehaviour<THandler, TOutEvent>
|
||||
where
|
||||
THandler: ConnectionHandler + Clone,
|
||||
THandler::OutEvent: Clone,
|
||||
@ -42,13 +42,13 @@ where
|
||||
{
|
||||
/// The prototype protocols handler that is cloned for every
|
||||
/// invocation of `new_handler`.
|
||||
pub handler_proto: THandler,
|
||||
pub(crate) handler_proto: THandler,
|
||||
/// The addresses to return from `addresses_of_peer`.
|
||||
pub addresses: HashMap<PeerId, Vec<Multiaddr>>,
|
||||
pub(crate) addresses: HashMap<PeerId, Vec<Multiaddr>>,
|
||||
/// The next action to return from `poll`.
|
||||
///
|
||||
/// An action is only returned once.
|
||||
pub next_action: Option<ToSwarm<TOutEvent, THandler::InEvent>>,
|
||||
pub(crate) next_action: Option<ToSwarm<TOutEvent, THandler::InEvent>>,
|
||||
}
|
||||
|
||||
impl<THandler, TOutEvent> MockBehaviour<THandler, TOutEvent>
|
||||
@ -57,7 +57,7 @@ where
|
||||
THandler::OutEvent: Clone,
|
||||
TOutEvent: Send + 'static,
|
||||
{
|
||||
pub fn new(handler_proto: THandler) -> Self {
|
||||
pub(crate) fn new(handler_proto: THandler) -> Self {
|
||||
MockBehaviour {
|
||||
handler_proto,
|
||||
addresses: HashMap::new(),
|
||||
@ -147,29 +147,31 @@ where
|
||||
/// A `CallTraceBehaviour` is a `NetworkBehaviour` that tracks
|
||||
/// invocations of callback methods and their arguments, wrapping
|
||||
/// around an inner behaviour. It ensures certain invariants are met.
|
||||
pub struct CallTraceBehaviour<TInner>
|
||||
pub(crate) struct CallTraceBehaviour<TInner>
|
||||
where
|
||||
TInner: NetworkBehaviour,
|
||||
{
|
||||
inner: TInner,
|
||||
|
||||
pub handle_pending_inbound_connection: Vec<(ConnectionId, Multiaddr, Multiaddr)>,
|
||||
pub handle_pending_outbound_connection:
|
||||
pub(crate) handle_pending_inbound_connection: Vec<(ConnectionId, Multiaddr, Multiaddr)>,
|
||||
pub(crate) handle_pending_outbound_connection:
|
||||
Vec<(Option<PeerId>, Vec<Multiaddr>, Endpoint, ConnectionId)>,
|
||||
pub handle_established_inbound_connection: Vec<(PeerId, ConnectionId, Multiaddr, Multiaddr)>,
|
||||
pub handle_established_outbound_connection: Vec<(PeerId, Multiaddr, Endpoint, ConnectionId)>,
|
||||
pub on_connection_established: Vec<(PeerId, ConnectionId, ConnectedPoint, usize)>,
|
||||
pub on_connection_closed: Vec<(PeerId, ConnectionId, ConnectedPoint, usize)>,
|
||||
pub on_connection_handler_event: Vec<(PeerId, ConnectionId, THandlerOutEvent<TInner>)>,
|
||||
pub on_dial_failure: Vec<Option<PeerId>>,
|
||||
pub on_new_listener: Vec<ListenerId>,
|
||||
pub on_new_listen_addr: Vec<(ListenerId, Multiaddr)>,
|
||||
pub on_new_external_addr: Vec<Multiaddr>,
|
||||
pub on_expired_listen_addr: Vec<(ListenerId, Multiaddr)>,
|
||||
pub on_expired_external_addr: Vec<Multiaddr>,
|
||||
pub on_listener_error: Vec<ListenerId>,
|
||||
pub on_listener_closed: Vec<(ListenerId, bool)>,
|
||||
pub poll: usize,
|
||||
pub(crate) handle_established_inbound_connection:
|
||||
Vec<(PeerId, ConnectionId, Multiaddr, Multiaddr)>,
|
||||
pub(crate) handle_established_outbound_connection:
|
||||
Vec<(PeerId, Multiaddr, Endpoint, ConnectionId)>,
|
||||
pub(crate) on_connection_established: Vec<(PeerId, ConnectionId, ConnectedPoint, usize)>,
|
||||
pub(crate) on_connection_closed: Vec<(PeerId, ConnectionId, ConnectedPoint, usize)>,
|
||||
pub(crate) on_connection_handler_event: Vec<(PeerId, ConnectionId, THandlerOutEvent<TInner>)>,
|
||||
pub(crate) on_dial_failure: Vec<Option<PeerId>>,
|
||||
pub(crate) on_new_listener: Vec<ListenerId>,
|
||||
pub(crate) on_new_listen_addr: Vec<(ListenerId, Multiaddr)>,
|
||||
pub(crate) on_new_external_addr: Vec<Multiaddr>,
|
||||
pub(crate) on_expired_listen_addr: Vec<(ListenerId, Multiaddr)>,
|
||||
pub(crate) on_expired_external_addr: Vec<Multiaddr>,
|
||||
pub(crate) on_listener_error: Vec<ListenerId>,
|
||||
pub(crate) on_listener_closed: Vec<(ListenerId, bool)>,
|
||||
pub(crate) poll: usize,
|
||||
}
|
||||
|
||||
impl<TInner> CallTraceBehaviour<TInner>
|
||||
@ -177,7 +179,7 @@ where
|
||||
TInner: NetworkBehaviour,
|
||||
THandlerOutEvent<TInner>: Clone,
|
||||
{
|
||||
pub fn new(inner: TInner) -> Self {
|
||||
pub(crate) fn new(inner: TInner) -> Self {
|
||||
Self {
|
||||
inner,
|
||||
handle_pending_inbound_connection: Vec::new(),
|
||||
@ -200,7 +202,7 @@ where
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn reset(&mut self) {
|
||||
pub(crate) fn reset(&mut self) {
|
||||
self.handle_pending_inbound_connection = Vec::new();
|
||||
self.handle_pending_outbound_connection = Vec::new();
|
||||
self.handle_established_inbound_connection = Vec::new();
|
||||
@ -217,11 +219,11 @@ where
|
||||
self.poll = 0;
|
||||
}
|
||||
|
||||
pub fn inner(&mut self) -> &mut TInner {
|
||||
pub(crate) fn inner(&mut self) -> &mut TInner {
|
||||
&mut self.inner
|
||||
}
|
||||
|
||||
pub fn num_connections_to_peer(&self, peer: PeerId) -> usize {
|
||||
pub(crate) fn num_connections_to_peer(&self, peer: PeerId) -> usize {
|
||||
self.on_connection_established
|
||||
.iter()
|
||||
.filter(|(peer_id, _, _, _)| *peer_id == peer)
|
||||
@ -237,7 +239,7 @@ where
|
||||
/// given number of expected disconnections have been received as well.
|
||||
///
|
||||
/// Returns if the first condition is met.
|
||||
pub fn assert_disconnected(
|
||||
pub(crate) fn assert_disconnected(
|
||||
&self,
|
||||
expected_closed_connections: usize,
|
||||
expected_disconnections: usize,
|
||||
@ -260,7 +262,7 @@ where
|
||||
/// a given number of expected connections have been received as well.
|
||||
///
|
||||
/// Returns if the first condition is met.
|
||||
pub fn assert_connected(
|
||||
pub(crate) fn assert_connected(
|
||||
&self,
|
||||
expected_established_connections: usize,
|
||||
expected_connections: usize,
|
||||
|
Reference in New Issue
Block a user