Update libp2p (#3039)
Update libp2p. This corrects some gossipsub metrics.
This commit is contained in:
parent
f3c1dde898
commit
e88b18be09
401
Cargo.lock
generated
401
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -42,9 +42,7 @@ prometheus-client = "0.15.0"
|
|||||||
unused_port = { path = "../../common/unused_port" }
|
unused_port = { path = "../../common/unused_port" }
|
||||||
|
|
||||||
[dependencies.libp2p]
|
[dependencies.libp2p]
|
||||||
git = "https://github.com/sigp/rust-libp2p"
|
version = "0.43.0"
|
||||||
# branch libp2p-gossipsub-interval-hotfix
|
|
||||||
rev = "e213703e616eaba3c482d7714775e0d37c4ae8e5"
|
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["websocket", "identify", "mplex", "yamux", "noise", "gossipsub", "dns-tokio", "tcp-tokio", "plaintext", "secp256k1"]
|
features = ["websocket", "identify", "mplex", "yamux", "noise", "gossipsub", "dns-tokio", "tcp-tokio", "plaintext", "secp256k1"]
|
||||||
|
|
||||||
|
@ -1147,7 +1147,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
|
|||||||
cx: &mut Context,
|
cx: &mut Context,
|
||||||
_: &mut impl PollParameters,
|
_: &mut impl PollParameters,
|
||||||
) -> Poll<
|
) -> Poll<
|
||||||
NBAction<BehaviourEvent<TSpec>, <Behaviour<TSpec> as NetworkBehaviour>::ProtocolsHandler>,
|
NBAction<BehaviourEvent<TSpec>, <Behaviour<TSpec> as NetworkBehaviour>::ConnectionHandler>,
|
||||||
> {
|
> {
|
||||||
if let Some(waker) = &self.waker {
|
if let Some(waker) = &self.waker {
|
||||||
if waker.will_wake(cx.waker()) {
|
if waker.will_wake(cx.waker()) {
|
||||||
|
@ -24,7 +24,7 @@ use futures::stream::FuturesUnordered;
|
|||||||
pub use libp2p::{
|
pub use libp2p::{
|
||||||
core::{connection::ConnectionId, ConnectedPoint, Multiaddr, PeerId},
|
core::{connection::ConnectionId, ConnectedPoint, Multiaddr, PeerId},
|
||||||
swarm::{
|
swarm::{
|
||||||
protocols_handler::ProtocolsHandler, DialError, NetworkBehaviour,
|
handler::ConnectionHandler, DialError, NetworkBehaviour,
|
||||||
NetworkBehaviourAction as NBAction, NotifyHandler, PollParameters, SubstreamProtocol,
|
NetworkBehaviourAction as NBAction, NotifyHandler, PollParameters, SubstreamProtocol,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -908,11 +908,11 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
|||||||
|
|
||||||
impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> {
|
impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> {
|
||||||
// Discovery is not a real NetworkBehaviour...
|
// Discovery is not a real NetworkBehaviour...
|
||||||
type ProtocolsHandler = libp2p::swarm::protocols_handler::DummyProtocolsHandler;
|
type ConnectionHandler = libp2p::swarm::handler::DummyConnectionHandler;
|
||||||
type OutEvent = DiscoveryEvent;
|
type OutEvent = DiscoveryEvent;
|
||||||
|
|
||||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
||||||
libp2p::swarm::protocols_handler::DummyProtocolsHandler::default()
|
libp2p::swarm::handler::DummyConnectionHandler::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles the libp2p request to obtain multiaddrs for peer_id's in order to dial them.
|
// Handles the libp2p request to obtain multiaddrs for peer_id's in order to dial them.
|
||||||
@ -932,14 +932,14 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
_: PeerId,
|
_: PeerId,
|
||||||
_: ConnectionId,
|
_: ConnectionId,
|
||||||
_: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent,
|
_: <Self::ConnectionHandler as ConnectionHandler>::OutEvent,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inject_dial_failure(
|
fn inject_dial_failure(
|
||||||
&mut self,
|
&mut self,
|
||||||
peer_id: Option<PeerId>,
|
peer_id: Option<PeerId>,
|
||||||
_handler: Self::ProtocolsHandler,
|
_handler: Self::ConnectionHandler,
|
||||||
error: &DialError,
|
error: &DialError,
|
||||||
) {
|
) {
|
||||||
if let Some(peer_id) = peer_id {
|
if let Some(peer_id) = peer_id {
|
||||||
@ -967,7 +967,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut Context,
|
cx: &mut Context,
|
||||||
_: &mut impl PollParameters,
|
_: &mut impl PollParameters,
|
||||||
) -> Poll<NBAction<Self::OutEvent, Self::ProtocolsHandler>> {
|
) -> Poll<NBAction<Self::OutEvent, Self::ConnectionHandler>> {
|
||||||
if !self.started {
|
if !self.started {
|
||||||
return Poll::Pending;
|
return Poll::Pending;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ use std::task::{Context, Poll};
|
|||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use libp2p::core::connection::ConnectionId;
|
use libp2p::core::connection::ConnectionId;
|
||||||
use libp2p::core::ConnectedPoint;
|
use libp2p::core::ConnectedPoint;
|
||||||
use libp2p::swarm::protocols_handler::DummyProtocolsHandler;
|
use libp2p::swarm::handler::DummyConnectionHandler;
|
||||||
use libp2p::swarm::{
|
use libp2p::swarm::{
|
||||||
DialError, NetworkBehaviour, NetworkBehaviourAction, PollParameters, ProtocolsHandler,
|
ConnectionHandler, DialError, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
|
||||||
};
|
};
|
||||||
use libp2p::{Multiaddr, PeerId};
|
use libp2p::{Multiaddr, PeerId};
|
||||||
use slog::{debug, error};
|
use slog::{debug, error};
|
||||||
@ -19,21 +19,21 @@ use super::peerdb::BanResult;
|
|||||||
use super::{PeerManager, PeerManagerEvent, ReportSource};
|
use super::{PeerManager, PeerManagerEvent, ReportSource};
|
||||||
|
|
||||||
impl<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
|
impl<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
|
||||||
type ProtocolsHandler = DummyProtocolsHandler;
|
type ConnectionHandler = DummyConnectionHandler;
|
||||||
|
|
||||||
type OutEvent = PeerManagerEvent;
|
type OutEvent = PeerManagerEvent;
|
||||||
|
|
||||||
/* Required trait members */
|
/* Required trait members */
|
||||||
|
|
||||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
||||||
DummyProtocolsHandler::default()
|
DummyConnectionHandler::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inject_event(
|
fn inject_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: PeerId,
|
_: PeerId,
|
||||||
_: ConnectionId,
|
_: ConnectionId,
|
||||||
_: <DummyProtocolsHandler as ProtocolsHandler>::OutEvent,
|
_: <DummyConnectionHandler as ConnectionHandler>::OutEvent,
|
||||||
) {
|
) {
|
||||||
unreachable!("Dummy handler does not emit events")
|
unreachable!("Dummy handler does not emit events")
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
_params: &mut impl PollParameters,
|
_params: &mut impl PollParameters,
|
||||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
|
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
|
||||||
// perform the heartbeat when necessary
|
// perform the heartbeat when necessary
|
||||||
while self.heartbeat.poll_tick(cx).is_ready() {
|
while self.heartbeat.poll_tick(cx).is_ready() {
|
||||||
self.heartbeat();
|
self.heartbeat();
|
||||||
@ -178,7 +178,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
|
|||||||
peer_id: &PeerId,
|
peer_id: &PeerId,
|
||||||
_: &ConnectionId,
|
_: &ConnectionId,
|
||||||
_: &ConnectedPoint,
|
_: &ConnectedPoint,
|
||||||
_: DummyProtocolsHandler,
|
_: DummyConnectionHandler,
|
||||||
remaining_established: usize,
|
remaining_established: usize,
|
||||||
) {
|
) {
|
||||||
if remaining_established > 0 {
|
if remaining_established > 0 {
|
||||||
@ -243,7 +243,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
|
|||||||
fn inject_dial_failure(
|
fn inject_dial_failure(
|
||||||
&mut self,
|
&mut self,
|
||||||
peer_id: Option<PeerId>,
|
peer_id: Option<PeerId>,
|
||||||
_handler: DummyProtocolsHandler,
|
_handler: DummyConnectionHandler,
|
||||||
_error: &DialError,
|
_error: &DialError,
|
||||||
) {
|
) {
|
||||||
if let Some(peer_id) = peer_id {
|
if let Some(peer_id) = peer_id {
|
||||||
|
@ -15,8 +15,9 @@ use futures::{Sink, SinkExt};
|
|||||||
use libp2p::core::upgrade::{
|
use libp2p::core::upgrade::{
|
||||||
InboundUpgrade, NegotiationError, OutboundUpgrade, ProtocolError, UpgradeError,
|
InboundUpgrade, NegotiationError, OutboundUpgrade, ProtocolError, UpgradeError,
|
||||||
};
|
};
|
||||||
use libp2p::swarm::protocols_handler::{
|
use libp2p::swarm::handler::{
|
||||||
KeepAlive, ProtocolsHandler, ProtocolsHandlerEvent, ProtocolsHandlerUpgrErr, SubstreamProtocol,
|
ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive,
|
||||||
|
SubstreamProtocol,
|
||||||
};
|
};
|
||||||
use libp2p::swarm::NegotiatedSubstream;
|
use libp2p::swarm::NegotiatedSubstream;
|
||||||
use slog::{crit, debug, trace, warn};
|
use slog::{crit, debug, trace, warn};
|
||||||
@ -76,7 +77,7 @@ pub enum HandlerErr {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implementation of `ProtocolsHandler` for the RPC protocol.
|
/// Implementation of `ConnectionHandler` for the RPC protocol.
|
||||||
pub struct RPCHandler<TSpec>
|
pub struct RPCHandler<TSpec>
|
||||||
where
|
where
|
||||||
TSpec: EthSpec,
|
TSpec: EthSpec,
|
||||||
@ -309,7 +310,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TSpec> ProtocolsHandler for RPCHandler<TSpec>
|
impl<TSpec> ConnectionHandler for RPCHandler<TSpec>
|
||||||
where
|
where
|
||||||
TSpec: EthSpec,
|
TSpec: EthSpec,
|
||||||
{
|
{
|
||||||
@ -442,12 +443,13 @@ where
|
|||||||
fn inject_dial_upgrade_error(
|
fn inject_dial_upgrade_error(
|
||||||
&mut self,
|
&mut self,
|
||||||
request_info: Self::OutboundOpenInfo,
|
request_info: Self::OutboundOpenInfo,
|
||||||
error: ProtocolsHandlerUpgrErr<
|
error: ConnectionHandlerUpgrErr<
|
||||||
<Self::OutboundProtocol as OutboundUpgrade<NegotiatedSubstream>>::Error,
|
<Self::OutboundProtocol as OutboundUpgrade<NegotiatedSubstream>>::Error,
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
let (id, req) = request_info;
|
let (id, req) = request_info;
|
||||||
if let ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Apply(RPCError::IoError(_))) = error {
|
if let ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(RPCError::IoError(_))) = error
|
||||||
|
{
|
||||||
self.outbound_io_error_retries += 1;
|
self.outbound_io_error_retries += 1;
|
||||||
if self.outbound_io_error_retries < IO_ERROR_RETRIES {
|
if self.outbound_io_error_retries < IO_ERROR_RETRIES {
|
||||||
self.send_request(id, req);
|
self.send_request(id, req);
|
||||||
@ -461,13 +463,13 @@ where
|
|||||||
self.outbound_io_error_retries = 0;
|
self.outbound_io_error_retries = 0;
|
||||||
// map the error
|
// map the error
|
||||||
let error = match error {
|
let error = match error {
|
||||||
ProtocolsHandlerUpgrErr::Timer => RPCError::InternalError("Timer failed"),
|
ConnectionHandlerUpgrErr::Timer => RPCError::InternalError("Timer failed"),
|
||||||
ProtocolsHandlerUpgrErr::Timeout => RPCError::NegotiationTimeout,
|
ConnectionHandlerUpgrErr::Timeout => RPCError::NegotiationTimeout,
|
||||||
ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)) => e,
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Apply(e)) => e,
|
||||||
ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => {
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => {
|
||||||
RPCError::UnsupportedProtocol
|
RPCError::UnsupportedProtocol
|
||||||
}
|
}
|
||||||
ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Select(
|
ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(
|
||||||
NegotiationError::ProtocolError(e),
|
NegotiationError::ProtocolError(e),
|
||||||
)) => match e {
|
)) => match e {
|
||||||
ProtocolError::IoError(io_err) => RPCError::IoError(io_err.to_string()),
|
ProtocolError::IoError(io_err) => RPCError::IoError(io_err.to_string()),
|
||||||
@ -517,7 +519,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
) -> Poll<
|
) -> Poll<
|
||||||
ProtocolsHandlerEvent<
|
ConnectionHandlerEvent<
|
||||||
Self::OutboundProtocol,
|
Self::OutboundProtocol,
|
||||||
Self::OutboundOpenInfo,
|
Self::OutboundOpenInfo,
|
||||||
Self::OutEvent,
|
Self::OutEvent,
|
||||||
@ -533,7 +535,7 @@ where
|
|||||||
}
|
}
|
||||||
// return any events that need to be reported
|
// return any events that need to be reported
|
||||||
if !self.events_out.is_empty() {
|
if !self.events_out.is_empty() {
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Custom(self.events_out.remove(0)));
|
return Poll::Ready(ConnectionHandlerEvent::Custom(self.events_out.remove(0)));
|
||||||
} else {
|
} else {
|
||||||
self.events_out.shrink_to_fit();
|
self.events_out.shrink_to_fit();
|
||||||
}
|
}
|
||||||
@ -543,7 +545,7 @@ where
|
|||||||
if delay.is_elapsed() {
|
if delay.is_elapsed() {
|
||||||
self.state = HandlerState::Deactivated;
|
self.state = HandlerState::Deactivated;
|
||||||
debug!(self.log, "Handler deactivated");
|
debug!(self.log, "Handler deactivated");
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Close(RPCError::InternalError(
|
return Poll::Ready(ConnectionHandlerEvent::Close(RPCError::InternalError(
|
||||||
"Shutdown timeout",
|
"Shutdown timeout",
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -575,7 +577,7 @@ where
|
|||||||
Poll::Ready(Some(Err(e))) => {
|
Poll::Ready(Some(Err(e))) => {
|
||||||
warn!(self.log, "Inbound substream poll failed"; "error" => ?e);
|
warn!(self.log, "Inbound substream poll failed"; "error" => ?e);
|
||||||
// drops the peer if we cannot read the delay queue
|
// drops the peer if we cannot read the delay queue
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Close(RPCError::InternalError(
|
return Poll::Ready(ConnectionHandlerEvent::Close(RPCError::InternalError(
|
||||||
"Could not poll inbound stream timer",
|
"Could not poll inbound stream timer",
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -596,14 +598,14 @@ where
|
|||||||
error: RPCError::StreamTimeout,
|
error: RPCError::StreamTimeout,
|
||||||
};
|
};
|
||||||
// notify the user
|
// notify the user
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Custom(Err(outbound_err)));
|
return Poll::Ready(ConnectionHandlerEvent::Custom(Err(outbound_err)));
|
||||||
} else {
|
} else {
|
||||||
crit!(self.log, "timed out substream not in the books"; "stream_id" => outbound_id.get_ref());
|
crit!(self.log, "timed out substream not in the books"; "stream_id" => outbound_id.get_ref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Poll::Ready(Some(Err(e))) => {
|
Poll::Ready(Some(Err(e))) => {
|
||||||
warn!(self.log, "Outbound substream poll failed"; "error" => ?e);
|
warn!(self.log, "Outbound substream poll failed"; "error" => ?e);
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Close(RPCError::InternalError(
|
return Poll::Ready(ConnectionHandlerEvent::Close(RPCError::InternalError(
|
||||||
"Could not poll outbound stream timer",
|
"Could not poll outbound stream timer",
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -856,7 +858,7 @@ where
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Custom(received));
|
return Poll::Ready(ConnectionHandlerEvent::Custom(received));
|
||||||
}
|
}
|
||||||
Poll::Ready(None) => {
|
Poll::Ready(None) => {
|
||||||
// stream closed
|
// stream closed
|
||||||
@ -871,7 +873,7 @@ where
|
|||||||
// notify the application error
|
// notify the application error
|
||||||
if request.expected_responses() > 1 {
|
if request.expected_responses() > 1 {
|
||||||
// return an end of stream result
|
// return an end of stream result
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Custom(Ok(
|
return Poll::Ready(ConnectionHandlerEvent::Custom(Ok(
|
||||||
RPCReceived::EndOfStream(request_id, request.stream_termination()),
|
RPCReceived::EndOfStream(request_id, request.stream_termination()),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -882,7 +884,7 @@ where
|
|||||||
proto: request.protocol(),
|
proto: request.protocol(),
|
||||||
error: RPCError::IncompleteStream,
|
error: RPCError::IncompleteStream,
|
||||||
};
|
};
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Custom(Err(outbound_err)));
|
return Poll::Ready(ConnectionHandlerEvent::Custom(Err(outbound_err)));
|
||||||
}
|
}
|
||||||
Poll::Pending => {
|
Poll::Pending => {
|
||||||
entry.get_mut().state =
|
entry.get_mut().state =
|
||||||
@ -898,7 +900,7 @@ where
|
|||||||
error: e,
|
error: e,
|
||||||
};
|
};
|
||||||
entry.remove_entry();
|
entry.remove_entry();
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Custom(Err(outbound_err)));
|
return Poll::Ready(ConnectionHandlerEvent::Custom(Err(outbound_err)));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
OutboundSubstreamState::Closing(mut substream) => {
|
OutboundSubstreamState::Closing(mut substream) => {
|
||||||
@ -924,7 +926,7 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(termination) = termination {
|
if let Some(termination) = termination {
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Custom(Ok(
|
return Poll::Ready(ConnectionHandlerEvent::Custom(Ok(
|
||||||
RPCReceived::EndOfStream(request_id, termination),
|
RPCReceived::EndOfStream(request_id, termination),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -946,7 +948,7 @@ where
|
|||||||
self.dial_negotiated += 1;
|
self.dial_negotiated += 1;
|
||||||
let (id, req) = self.dial_queue.remove(0);
|
let (id, req) = self.dial_queue.remove(0);
|
||||||
self.dial_queue.shrink_to_fit();
|
self.dial_queue.shrink_to_fit();
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::OutboundSubstreamRequest {
|
return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest {
|
||||||
protocol: SubstreamProtocol::new(
|
protocol: SubstreamProtocol::new(
|
||||||
OutboundRequestContainer {
|
OutboundRequestContainer {
|
||||||
req: req.clone(),
|
req: req.clone(),
|
||||||
@ -967,7 +969,7 @@ where
|
|||||||
&& self.events_out.is_empty()
|
&& self.events_out.is_empty()
|
||||||
&& self.dial_negotiated == 0
|
&& self.dial_negotiated == 0
|
||||||
{
|
{
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Close(RPCError::Disconnected));
|
return Poll::Ready(ConnectionHandlerEvent::Close(RPCError::Disconnected));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use futures::future::FutureExt;
|
|||||||
use handler::RPCHandler;
|
use handler::RPCHandler;
|
||||||
use libp2p::core::{connection::ConnectionId, ConnectedPoint};
|
use libp2p::core::{connection::ConnectionId, ConnectedPoint};
|
||||||
use libp2p::swarm::{
|
use libp2p::swarm::{
|
||||||
protocols_handler::ProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
|
handler::ConnectionHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler,
|
||||||
PollParameters, SubstreamProtocol,
|
PollParameters, SubstreamProtocol,
|
||||||
};
|
};
|
||||||
use libp2p::{Multiaddr, PeerId};
|
use libp2p::{Multiaddr, PeerId};
|
||||||
@ -92,7 +92,7 @@ pub struct RPCMessage<TSpec: EthSpec> {
|
|||||||
/// Handler managing this message.
|
/// Handler managing this message.
|
||||||
pub conn_id: ConnectionId,
|
pub conn_id: ConnectionId,
|
||||||
/// The message that was sent.
|
/// The message that was sent.
|
||||||
pub event: <RPCHandler<TSpec> as ProtocolsHandler>::OutEvent,
|
pub event: <RPCHandler<TSpec> as ConnectionHandler>::OutEvent,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implements the libp2p `NetworkBehaviour` trait and therefore manages network-level
|
/// Implements the libp2p `NetworkBehaviour` trait and therefore manages network-level
|
||||||
@ -178,10 +178,10 @@ impl<TSpec> NetworkBehaviour for RPC<TSpec>
|
|||||||
where
|
where
|
||||||
TSpec: EthSpec,
|
TSpec: EthSpec,
|
||||||
{
|
{
|
||||||
type ProtocolsHandler = RPCHandler<TSpec>;
|
type ConnectionHandler = RPCHandler<TSpec>;
|
||||||
type OutEvent = RPCMessage<TSpec>;
|
type OutEvent = RPCMessage<TSpec>;
|
||||||
|
|
||||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
||||||
RPCHandler::new(
|
RPCHandler::new(
|
||||||
SubstreamProtocol::new(
|
SubstreamProtocol::new(
|
||||||
RPCProtocol {
|
RPCProtocol {
|
||||||
@ -227,7 +227,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
conn_id: ConnectionId,
|
conn_id: ConnectionId,
|
||||||
event: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent,
|
event: <Self::ConnectionHandler as ConnectionHandler>::OutEvent,
|
||||||
) {
|
) {
|
||||||
if let Ok(RPCReceived::Request(ref id, ref req)) = event {
|
if let Ok(RPCReceived::Request(ref id, ref req)) = event {
|
||||||
// check if the request is conformant to the quota
|
// check if the request is conformant to the quota
|
||||||
@ -289,7 +289,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut Context,
|
cx: &mut Context,
|
||||||
_: &mut impl PollParameters,
|
_: &mut impl PollParameters,
|
||||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
|
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
|
||||||
// let the rate limiter prune
|
// let the rate limiter prune
|
||||||
let _ = self.limiter.poll_unpin(cx);
|
let _ = self.limiter.poll_unpin(cx);
|
||||||
if !self.events.is_empty() {
|
if !self.events.is_empty() {
|
||||||
|
@ -12,13 +12,12 @@ use crate::EnrExt;
|
|||||||
use crate::{NetworkConfig, NetworkGlobals, PeerAction, ReportSource};
|
use crate::{NetworkConfig, NetworkGlobals, PeerAction, ReportSource};
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use libp2p::core::{
|
use libp2p::core::{
|
||||||
connection::ConnectionLimits, identity::Keypair, multiaddr::Multiaddr, muxing::StreamMuxerBox,
|
identity::Keypair, multiaddr::Multiaddr, muxing::StreamMuxerBox, transport::Boxed,
|
||||||
transport::Boxed,
|
|
||||||
};
|
};
|
||||||
use libp2p::{
|
use libp2p::{
|
||||||
bandwidth::{BandwidthLogging, BandwidthSinks},
|
bandwidth::{BandwidthLogging, BandwidthSinks},
|
||||||
core, noise,
|
core, noise,
|
||||||
swarm::{SwarmBuilder, SwarmEvent},
|
swarm::{ConnectionLimits, SwarmBuilder, SwarmEvent},
|
||||||
PeerId, Swarm, Transport,
|
PeerId, Swarm, Transport,
|
||||||
};
|
};
|
||||||
use prometheus_client::registry::Registry;
|
use prometheus_client::registry::Registry;
|
||||||
|
@ -24,9 +24,7 @@ use std::collections::HashMap;
|
|||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use libp2p::core::connection::{ConnectedPoint, ConnectionId, ListenerId};
|
use libp2p::core::connection::{ConnectedPoint, ConnectionId, ListenerId};
|
||||||
use libp2p::swarm::protocols_handler::{
|
use libp2p::swarm::handler::{ConnectionHandler, DummyConnectionHandler, IntoConnectionHandler};
|
||||||
DummyProtocolsHandler, IntoProtocolsHandler, ProtocolsHandler,
|
|
||||||
};
|
|
||||||
use libp2p::swarm::{DialError, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
use libp2p::swarm::{DialError, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
||||||
use libp2p::{Multiaddr, PeerId};
|
use libp2p::{Multiaddr, PeerId};
|
||||||
|
|
||||||
@ -34,10 +32,10 @@ use libp2p::{Multiaddr, PeerId};
|
|||||||
/// the instrumentation of return values, without keeping
|
/// the instrumentation of return values, without keeping
|
||||||
/// any further state.
|
/// any further state.
|
||||||
pub struct MockBehaviour<
|
pub struct MockBehaviour<
|
||||||
THandler = DummyProtocolsHandler,
|
THandler = DummyConnectionHandler,
|
||||||
TOutEvent = <DummyProtocolsHandler as ProtocolsHandler>::OutEvent,
|
TOutEvent = <DummyConnectionHandler as ConnectionHandler>::OutEvent,
|
||||||
> where
|
> where
|
||||||
THandler: ProtocolsHandler,
|
THandler: ConnectionHandler,
|
||||||
{
|
{
|
||||||
/// The prototype protocols handler that is cloned for every
|
/// The prototype protocols handler that is cloned for every
|
||||||
/// invocation of `new_handler`.
|
/// invocation of `new_handler`.
|
||||||
@ -52,7 +50,7 @@ pub struct MockBehaviour<
|
|||||||
|
|
||||||
impl<THandler, TOutEvent> MockBehaviour<THandler, TOutEvent>
|
impl<THandler, TOutEvent> MockBehaviour<THandler, TOutEvent>
|
||||||
where
|
where
|
||||||
THandler: ProtocolsHandler,
|
THandler: ConnectionHandler,
|
||||||
{
|
{
|
||||||
pub fn new(handler_proto: THandler) -> Self {
|
pub fn new(handler_proto: THandler) -> Self {
|
||||||
MockBehaviour {
|
MockBehaviour {
|
||||||
@ -65,14 +63,14 @@ where
|
|||||||
|
|
||||||
impl<THandler, TOutEvent> NetworkBehaviour for MockBehaviour<THandler, TOutEvent>
|
impl<THandler, TOutEvent> NetworkBehaviour for MockBehaviour<THandler, TOutEvent>
|
||||||
where
|
where
|
||||||
THandler: ProtocolsHandler + Clone,
|
THandler: ConnectionHandler + Clone,
|
||||||
THandler::OutEvent: Clone,
|
THandler::OutEvent: Clone,
|
||||||
TOutEvent: Send + 'static,
|
TOutEvent: Send + 'static,
|
||||||
{
|
{
|
||||||
type ProtocolsHandler = THandler;
|
type ConnectionHandler = THandler;
|
||||||
type OutEvent = TOutEvent;
|
type OutEvent = TOutEvent;
|
||||||
|
|
||||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
||||||
self.handler_proto.clone()
|
self.handler_proto.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +84,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
_: &mut Context,
|
_: &mut Context,
|
||||||
_: &mut impl PollParameters,
|
_: &mut impl PollParameters,
|
||||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
|
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
|
||||||
Option::take(&mut self.next_action).map_or(Poll::Pending, Poll::Ready)
|
Option::take(&mut self.next_action).map_or(Poll::Pending, Poll::Ready)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,7 +103,7 @@ where
|
|||||||
pub inject_event: Vec<(
|
pub inject_event: Vec<(
|
||||||
PeerId,
|
PeerId,
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
<<TInner::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent,
|
<<TInner::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
|
||||||
)>,
|
)>,
|
||||||
pub inject_dial_failure: Vec<Option<PeerId>>,
|
pub inject_dial_failure: Vec<Option<PeerId>>,
|
||||||
pub inject_new_listener: Vec<ListenerId>,
|
pub inject_new_listener: Vec<ListenerId>,
|
||||||
@ -212,13 +210,13 @@ where
|
|||||||
impl<TInner> NetworkBehaviour for CallTraceBehaviour<TInner>
|
impl<TInner> NetworkBehaviour for CallTraceBehaviour<TInner>
|
||||||
where
|
where
|
||||||
TInner: NetworkBehaviour,
|
TInner: NetworkBehaviour,
|
||||||
<<TInner::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent:
|
<<TInner::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent:
|
||||||
Clone,
|
Clone,
|
||||||
{
|
{
|
||||||
type ProtocolsHandler = TInner::ProtocolsHandler;
|
type ConnectionHandler = TInner::ConnectionHandler;
|
||||||
type OutEvent = TInner::OutEvent;
|
type OutEvent = TInner::OutEvent;
|
||||||
|
|
||||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
||||||
self.inner.new_handler()
|
self.inner.new_handler()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +271,7 @@ where
|
|||||||
p: &PeerId,
|
p: &PeerId,
|
||||||
c: &ConnectionId,
|
c: &ConnectionId,
|
||||||
e: &ConnectedPoint,
|
e: &ConnectedPoint,
|
||||||
handler: <Self::ProtocolsHandler as IntoProtocolsHandler>::Handler,
|
handler: <Self::ConnectionHandler as IntoConnectionHandler>::Handler,
|
||||||
remaining_established: usize,
|
remaining_established: usize,
|
||||||
) {
|
) {
|
||||||
let mut other_closed_connections = self
|
let mut other_closed_connections = self
|
||||||
@ -320,7 +318,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
p: PeerId,
|
p: PeerId,
|
||||||
c: ConnectionId,
|
c: ConnectionId,
|
||||||
e: <<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent,
|
e: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
|
||||||
) {
|
) {
|
||||||
assert!(
|
assert!(
|
||||||
self.inject_connection_established
|
self.inject_connection_established
|
||||||
@ -343,7 +341,7 @@ where
|
|||||||
fn inject_dial_failure(
|
fn inject_dial_failure(
|
||||||
&mut self,
|
&mut self,
|
||||||
p: Option<PeerId>,
|
p: Option<PeerId>,
|
||||||
handler: Self::ProtocolsHandler,
|
handler: Self::ConnectionHandler,
|
||||||
error: &DialError,
|
error: &DialError,
|
||||||
) {
|
) {
|
||||||
self.inject_dial_failure.push(p);
|
self.inject_dial_failure.push(p);
|
||||||
@ -389,7 +387,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut Context,
|
cx: &mut Context,
|
||||||
args: &mut impl PollParameters,
|
args: &mut impl PollParameters,
|
||||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
|
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
|
||||||
self.poll += 1;
|
self.poll += 1;
|
||||||
self.inner.poll(cx, args)
|
self.inner.poll(cx, args)
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ use super::behaviour::{CallTraceBehaviour, MockBehaviour};
|
|||||||
|
|
||||||
use futures::stream::Stream;
|
use futures::stream::Stream;
|
||||||
use futures::task::{Context, Poll};
|
use futures::task::{Context, Poll};
|
||||||
use libp2p::swarm::protocols_handler::ProtocolsHandler;
|
use libp2p::swarm::handler::ConnectionHandler;
|
||||||
use libp2p::swarm::{IntoProtocolsHandler, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent};
|
use libp2p::swarm::{IntoConnectionHandler, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent};
|
||||||
use libp2p::{PeerId, Transport};
|
use libp2p::{PeerId, Transport};
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
@ -82,10 +82,10 @@ impl<B: NetworkBehaviour> SwarmPool<B> {
|
|||||||
impl<B> Stream for SwarmPool<B>
|
impl<B> Stream for SwarmPool<B>
|
||||||
where
|
where
|
||||||
B: NetworkBehaviour,
|
B: NetworkBehaviour,
|
||||||
<B as NetworkBehaviour>::ProtocolsHandler: ProtocolsHandler,
|
<B as NetworkBehaviour>::ConnectionHandler: ConnectionHandler,
|
||||||
{
|
{
|
||||||
type Item = (PeerId,
|
type Item = (PeerId,
|
||||||
SwarmEvent<<B as NetworkBehaviour>::OutEvent, <<<B as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::Error>);
|
SwarmEvent<<B as NetworkBehaviour>::OutEvent, <<<B as NetworkBehaviour>::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error>);
|
||||||
|
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
let mut polls = self
|
let mut polls = self
|
||||||
|
@ -20,7 +20,7 @@ use futures::StreamExt;
|
|||||||
use libp2p::{
|
use libp2p::{
|
||||||
core::either::EitherError,
|
core::either::EitherError,
|
||||||
swarm::SwarmEvent,
|
swarm::SwarmEvent,
|
||||||
swarm::{protocols_handler::DummyProtocolsHandler, DummyBehaviour, KeepAlive, Swarm},
|
swarm::{handler::DummyConnectionHandler, DummyBehaviour, KeepAlive, Swarm},
|
||||||
NetworkBehaviour,
|
NetworkBehaviour,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ impl Behaviour {
|
|||||||
fn new(pm: PeerManager<E>) -> Self {
|
fn new(pm: PeerManager<E>) -> Self {
|
||||||
Behaviour {
|
Behaviour {
|
||||||
pm_call_trace: CallTraceBehaviour::new(pm),
|
pm_call_trace: CallTraceBehaviour::new(pm),
|
||||||
sibling: MockBehaviour::new(DummyProtocolsHandler {
|
sibling: MockBehaviour::new(DummyConnectionHandler {
|
||||||
// The peer manager votes No, so we make sure the combined handler stays alive this
|
// The peer manager votes No, so we make sure the combined handler stays alive this
|
||||||
// way.
|
// way.
|
||||||
keep_alive: KeepAlive::Yes,
|
keep_alive: KeepAlive::Yes,
|
||||||
|
Loading…
Reference in New Issue
Block a user