mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 11:41:51 +00:00
Update libp2p (#3039)
Update libp2p. This corrects some gossipsub metrics.
This commit is contained in:
@@ -24,9 +24,7 @@ use std::collections::HashMap;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use libp2p::core::connection::{ConnectedPoint, ConnectionId, ListenerId};
|
||||
use libp2p::swarm::protocols_handler::{
|
||||
DummyProtocolsHandler, IntoProtocolsHandler, ProtocolsHandler,
|
||||
};
|
||||
use libp2p::swarm::handler::{ConnectionHandler, DummyConnectionHandler, IntoConnectionHandler};
|
||||
use libp2p::swarm::{DialError, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
||||
use libp2p::{Multiaddr, PeerId};
|
||||
|
||||
@@ -34,10 +32,10 @@ use libp2p::{Multiaddr, PeerId};
|
||||
/// the instrumentation of return values, without keeping
|
||||
/// any further state.
|
||||
pub struct MockBehaviour<
|
||||
THandler = DummyProtocolsHandler,
|
||||
TOutEvent = <DummyProtocolsHandler as ProtocolsHandler>::OutEvent,
|
||||
THandler = DummyConnectionHandler,
|
||||
TOutEvent = <DummyConnectionHandler as ConnectionHandler>::OutEvent,
|
||||
> where
|
||||
THandler: ProtocolsHandler,
|
||||
THandler: ConnectionHandler,
|
||||
{
|
||||
/// The prototype protocols handler that is cloned for every
|
||||
/// invocation of `new_handler`.
|
||||
@@ -52,7 +50,7 @@ pub struct MockBehaviour<
|
||||
|
||||
impl<THandler, TOutEvent> MockBehaviour<THandler, TOutEvent>
|
||||
where
|
||||
THandler: ProtocolsHandler,
|
||||
THandler: ConnectionHandler,
|
||||
{
|
||||
pub fn new(handler_proto: THandler) -> Self {
|
||||
MockBehaviour {
|
||||
@@ -65,14 +63,14 @@ where
|
||||
|
||||
impl<THandler, TOutEvent> NetworkBehaviour for MockBehaviour<THandler, TOutEvent>
|
||||
where
|
||||
THandler: ProtocolsHandler + Clone,
|
||||
THandler: ConnectionHandler + Clone,
|
||||
THandler::OutEvent: Clone,
|
||||
TOutEvent: Send + 'static,
|
||||
{
|
||||
type ProtocolsHandler = THandler;
|
||||
type ConnectionHandler = THandler;
|
||||
type OutEvent = TOutEvent;
|
||||
|
||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
||||
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
||||
self.handler_proto.clone()
|
||||
}
|
||||
|
||||
@@ -86,7 +84,7 @@ where
|
||||
&mut self,
|
||||
_: &mut Context,
|
||||
_: &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)
|
||||
}
|
||||
}
|
||||
@@ -105,7 +103,7 @@ where
|
||||
pub inject_event: Vec<(
|
||||
PeerId,
|
||||
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_new_listener: Vec<ListenerId>,
|
||||
@@ -212,13 +210,13 @@ where
|
||||
impl<TInner> NetworkBehaviour for CallTraceBehaviour<TInner>
|
||||
where
|
||||
TInner: NetworkBehaviour,
|
||||
<<TInner::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent:
|
||||
<<TInner::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent:
|
||||
Clone,
|
||||
{
|
||||
type ProtocolsHandler = TInner::ProtocolsHandler;
|
||||
type ConnectionHandler = TInner::ConnectionHandler;
|
||||
type OutEvent = TInner::OutEvent;
|
||||
|
||||
fn new_handler(&mut self) -> Self::ProtocolsHandler {
|
||||
fn new_handler(&mut self) -> Self::ConnectionHandler {
|
||||
self.inner.new_handler()
|
||||
}
|
||||
|
||||
@@ -273,7 +271,7 @@ where
|
||||
p: &PeerId,
|
||||
c: &ConnectionId,
|
||||
e: &ConnectedPoint,
|
||||
handler: <Self::ProtocolsHandler as IntoProtocolsHandler>::Handler,
|
||||
handler: <Self::ConnectionHandler as IntoConnectionHandler>::Handler,
|
||||
remaining_established: usize,
|
||||
) {
|
||||
let mut other_closed_connections = self
|
||||
@@ -320,7 +318,7 @@ where
|
||||
&mut self,
|
||||
p: PeerId,
|
||||
c: ConnectionId,
|
||||
e: <<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent,
|
||||
e: <<Self::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent,
|
||||
) {
|
||||
assert!(
|
||||
self.inject_connection_established
|
||||
@@ -343,7 +341,7 @@ where
|
||||
fn inject_dial_failure(
|
||||
&mut self,
|
||||
p: Option<PeerId>,
|
||||
handler: Self::ProtocolsHandler,
|
||||
handler: Self::ConnectionHandler,
|
||||
error: &DialError,
|
||||
) {
|
||||
self.inject_dial_failure.push(p);
|
||||
@@ -389,7 +387,7 @@ where
|
||||
&mut self,
|
||||
cx: &mut Context,
|
||||
args: &mut impl PollParameters,
|
||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>> {
|
||||
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
|
||||
self.poll += 1;
|
||||
self.inner.poll(cx, args)
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ use super::behaviour::{CallTraceBehaviour, MockBehaviour};
|
||||
|
||||
use futures::stream::Stream;
|
||||
use futures::task::{Context, Poll};
|
||||
use libp2p::swarm::protocols_handler::ProtocolsHandler;
|
||||
use libp2p::swarm::{IntoProtocolsHandler, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent};
|
||||
use libp2p::swarm::handler::ConnectionHandler;
|
||||
use libp2p::swarm::{IntoConnectionHandler, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent};
|
||||
use libp2p::{PeerId, Transport};
|
||||
|
||||
use futures::StreamExt;
|
||||
@@ -82,10 +82,10 @@ impl<B: NetworkBehaviour> SwarmPool<B> {
|
||||
impl<B> Stream for SwarmPool<B>
|
||||
where
|
||||
B: NetworkBehaviour,
|
||||
<B as NetworkBehaviour>::ProtocolsHandler: ProtocolsHandler,
|
||||
<B as NetworkBehaviour>::ConnectionHandler: ConnectionHandler,
|
||||
{
|
||||
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>> {
|
||||
let mut polls = self
|
||||
|
||||
@@ -20,7 +20,7 @@ use futures::StreamExt;
|
||||
use libp2p::{
|
||||
core::either::EitherError,
|
||||
swarm::SwarmEvent,
|
||||
swarm::{protocols_handler::DummyProtocolsHandler, DummyBehaviour, KeepAlive, Swarm},
|
||||
swarm::{handler::DummyConnectionHandler, DummyBehaviour, KeepAlive, Swarm},
|
||||
NetworkBehaviour,
|
||||
};
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Behaviour {
|
||||
fn new(pm: PeerManager<E>) -> Self {
|
||||
Behaviour {
|
||||
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
|
||||
// way.
|
||||
keep_alive: KeepAlive::Yes,
|
||||
|
||||
Reference in New Issue
Block a user