chore(net): extract NetworkHandle methods for launching node to traits (#9966)

This commit is contained in:
Emilia Hane
2024-08-01 18:44:23 +02:00
committed by GitHub
parent f3fac56fd9
commit b10517b3bf
56 changed files with 985 additions and 776 deletions

View File

@@ -1,14 +1,16 @@
//! Represents an established session.
use crate::{
message::{NewBlockMessage, PeerMessage, PeerRequest, PeerResponse, PeerResponseResult},
session::{
conn::EthRlpxConnection,
handle::{ActiveSessionMessage, SessionCommand},
SessionId,
},
};
use core::sync::atomic::Ordering;
use std::{
collections::VecDeque,
future::Future,
net::SocketAddr,
pin::Pin,
sync::{atomic::AtomicU64, Arc},
task::{ready, Context, Poll},
time::{Duration, Instant},
};
use futures::{stream::Fuse, SinkExt, StreamExt};
use reth_eth_wire::{
capability::Capabilities,
@@ -21,15 +23,6 @@ use reth_network_p2p::error::RequestError;
use reth_network_peers::PeerId;
use reth_network_types::session::config::INITIAL_REQUEST_TIMEOUT;
use rustc_hash::FxHashMap;
use std::{
collections::VecDeque,
future::Future,
net::SocketAddr,
pin::Pin,
sync::{atomic::AtomicU64, Arc},
task::{ready, Context, Poll},
time::{Duration, Instant},
};
use tokio::{
sync::{mpsc::error::TrySendError, oneshot},
time::Interval,
@@ -38,6 +31,15 @@ use tokio_stream::wrappers::ReceiverStream;
use tokio_util::sync::PollSender;
use tracing::{debug, trace};
use crate::{
message::{NewBlockMessage, PeerMessage, PeerRequest, PeerResponse, PeerResponseResult},
session::{
conn::EthRlpxConnection,
handle::{ActiveSessionMessage, SessionCommand},
SessionId,
},
};
// Constants for timeout updating.
/// Minimum timeout value

View File

@@ -1,5 +1,10 @@
//! Connection types for a session
use std::{
pin::Pin,
task::{Context, Poll},
};
use futures::{Sink, Stream};
use reth_ecies::stream::ECIESStream;
use reth_eth_wire::{
@@ -8,10 +13,6 @@ use reth_eth_wire::{
multiplex::{ProtocolProxy, RlpxSatelliteStream},
EthMessage, EthStream, EthVersion, P2PStream,
};
use std::{
pin::Pin,
task::{Context, Poll},
};
use tokio::net::TcpStream;
/// The type of the underlying peer network connection.

View File

@@ -1,24 +1,27 @@
//! Session handles.
use crate::{
message::PeerMessage,
session::{conn::EthRlpxConnection, Direction, SessionId},
PendingSessionHandshakeError,
};
use std::{io, net::SocketAddr, sync::Arc, time::Instant};
use reth_ecies::ECIESError;
use reth_eth_wire::{
capability::{Capabilities, CapabilityMessage},
errors::EthStreamError,
DisconnectReason, EthVersion, Status,
};
use reth_network_api::{PeerInfo, PeerKind};
use reth_network_api::PeerInfo;
use reth_network_peers::{NodeRecord, PeerId};
use std::{io, net::SocketAddr, sync::Arc, time::Instant};
use reth_network_types::PeerKind;
use tokio::sync::{
mpsc::{self, error::SendError},
oneshot,
};
use crate::{
message::PeerMessage,
session::{conn::EthRlpxConnection, Direction, SessionId},
PendingSessionHandshakeError,
};
/// A handler attached to a peer session that's not authenticated yet, pending Handshake and hello
/// message which exchanges the `capabilities` of the peer.
///

View File

@@ -1,12 +1,36 @@
//! Support for handling peer sessions.
use crate::{message::PeerMessage, metrics::SessionManagerMetrics, session::active::ActiveSession};
mod active;
mod conn;
mod counter;
mod handle;
pub use conn::EthRlpxConnection;
pub use handle::{
ActiveSessionHandle, ActiveSessionMessage, PendingSessionEvent, PendingSessionHandle,
SessionCommand,
};
pub use crate::message::PeerRequestSender;
pub use reth_network_api::{Direction, PeerInfo};
use std::{
collections::HashMap,
future::Future,
net::SocketAddr,
sync::{atomic::AtomicU64, Arc},
task::{Context, Poll},
time::{Duration, Instant},
};
use counter::SessionCounter;
use futures::{future::Either, io, FutureExt, StreamExt};
use reth_ecies::{stream::ECIESStream, ECIESError};
use reth_eth_wire::{
capability::{Capabilities, CapabilityMessage},
errors::EthStreamError,
multiplex::RlpxProtocolMultiplexer,
DisconnectReason, EthVersion, HelloMessageWithProtocols, Status, UnauthedEthStream,
UnauthedP2PStream,
};
@@ -17,14 +41,6 @@ use reth_primitives::{ForkFilter, ForkId, ForkTransition, Head};
use reth_tasks::TaskSpawner;
use rustc_hash::FxHashMap;
use secp256k1::SecretKey;
use std::{
collections::HashMap,
future::Future,
net::SocketAddr,
sync::{atomic::AtomicU64, Arc},
task::{Context, Poll},
time::{Duration, Instant},
};
use tokio::{
io::{AsyncRead, AsyncWrite},
net::TcpStream,
@@ -34,19 +50,13 @@ use tokio_stream::wrappers::ReceiverStream;
use tokio_util::sync::PollSender;
use tracing::{debug, instrument, trace};
mod active;
mod conn;
mod counter;
mod handle;
pub use crate::message::PeerRequestSender;
use crate::protocol::{IntoRlpxSubProtocol, RlpxSubProtocolHandlers, RlpxSubProtocols};
pub use conn::EthRlpxConnection;
pub use handle::{
ActiveSessionHandle, ActiveSessionMessage, PendingSessionEvent, PendingSessionHandle,
SessionCommand,
use crate::{
message::PeerMessage,
metrics::SessionManagerMetrics,
protocol::{IntoRlpxSubProtocol, RlpxSubProtocolHandlers, RlpxSubProtocols},
session::active::ActiveSession,
};
use reth_eth_wire::multiplex::RlpxProtocolMultiplexer;
pub use reth_network_api::{Direction, PeerInfo};
/// Internal identifier for active sessions.
#[derive(Debug, Clone, Copy, PartialOrd, PartialEq, Eq, Hash)]
pub struct SessionId(usize);