parent
c4bd9c86e6
commit
e3c7b58657
@ -41,15 +41,9 @@ pub enum BehaviourHandlerIn<TSpec: EthSpec> {
|
|||||||
Shutdown(Option<(RequestId, RPCRequest<TSpec>)>),
|
Shutdown(Option<(RequestId, RPCRequest<TSpec>)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum BehaviourHandlerOut<TSpec: EthSpec> {
|
|
||||||
Delegate(Box<DelegateOut<TSpec>>),
|
|
||||||
// TODO: replace custom with events to send
|
|
||||||
Custom,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<TSpec: EthSpec> ProtocolsHandler for BehaviourHandler<TSpec> {
|
impl<TSpec: EthSpec> ProtocolsHandler for BehaviourHandler<TSpec> {
|
||||||
type InEvent = BehaviourHandlerIn<TSpec>;
|
type InEvent = BehaviourHandlerIn<TSpec>;
|
||||||
type OutEvent = BehaviourHandlerOut<TSpec>;
|
type OutEvent = DelegateOut<TSpec>;
|
||||||
type Error = DelegateError<TSpec>;
|
type Error = DelegateError<TSpec>;
|
||||||
type InboundProtocol = DelegateInProto<TSpec>;
|
type InboundProtocol = DelegateInProto<TSpec>;
|
||||||
type OutboundProtocol = DelegateOutProto<TSpec>;
|
type OutboundProtocol = DelegateOutProto<TSpec>;
|
||||||
@ -122,9 +116,7 @@ impl<TSpec: EthSpec> ProtocolsHandler for BehaviourHandler<TSpec> {
|
|||||||
|
|
||||||
match self.delegate.poll(cx) {
|
match self.delegate.poll(cx) {
|
||||||
Poll::Ready(ProtocolsHandlerEvent::Custom(event)) => {
|
Poll::Ready(ProtocolsHandlerEvent::Custom(event)) => {
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Custom(
|
return Poll::Ready(ProtocolsHandlerEvent::Custom(event))
|
||||||
BehaviourHandlerOut::Delegate(Box::new(event)),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
Poll::Ready(ProtocolsHandlerEvent::Close(err)) => {
|
Poll::Ready(ProtocolsHandlerEvent::Close(err)) => {
|
||||||
return Poll::Ready(ProtocolsHandlerEvent::Close(err))
|
return Poll::Ready(ProtocolsHandlerEvent::Close(err))
|
||||||
|
@ -5,7 +5,7 @@ use crate::types::{GossipEncoding, GossipKind, GossipTopic, SubnetDiscovery};
|
|||||||
use crate::Eth2Enr;
|
use crate::Eth2Enr;
|
||||||
use crate::{error, metrics, Enr, NetworkConfig, NetworkGlobals, PubsubMessage, TopicHash};
|
use crate::{error, metrics, Enr, NetworkConfig, NetworkGlobals, PubsubMessage, TopicHash};
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
use handler::{BehaviourHandler, BehaviourHandlerIn, BehaviourHandlerOut, DelegateIn, DelegateOut};
|
use handler::{BehaviourHandler, BehaviourHandlerIn, DelegateIn, DelegateOut};
|
||||||
use libp2p::{
|
use libp2p::{
|
||||||
core::{
|
core::{
|
||||||
connection::{ConnectedPoint, ConnectionId, ListenerId},
|
connection::{ConnectedPoint, ConnectionId, ListenerId},
|
||||||
@ -591,7 +591,6 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
|
|||||||
} => {
|
} => {
|
||||||
if matches!(error, RPCError::HandlerRejected) {
|
if matches!(error, RPCError::HandlerRejected) {
|
||||||
// this peer's request got canceled
|
// this peer's request got canceled
|
||||||
// TODO: cancel processing for this request
|
|
||||||
}
|
}
|
||||||
// Inform the peer manager of the error.
|
// Inform the peer manager of the error.
|
||||||
// An inbound error here means we sent an error to the peer, or the stream
|
// An inbound error here means we sent an error to the peer, or the stream
|
||||||
@ -624,8 +623,6 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
|
|||||||
// TODO: inform the peer manager?
|
// TODO: inform the peer manager?
|
||||||
}
|
}
|
||||||
RPCRequest::Goodbye(reason) => {
|
RPCRequest::Goodbye(reason) => {
|
||||||
// let the peer manager know this peer is in the process of disconnecting
|
|
||||||
self.peer_manager._disconnecting_peer(&peer_id);
|
|
||||||
// queue for disconnection without a goodbye message
|
// queue for disconnection without a goodbye message
|
||||||
debug!(
|
debug!(
|
||||||
self.log, "Peer sent Goodbye";
|
self.log, "Peer sent Goodbye";
|
||||||
@ -975,17 +972,11 @@ impl<TSpec: EthSpec> NetworkBehaviour for Behaviour<TSpec> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Events comming from the handler, redirected to each behaviour
|
||||||
match event {
|
match event {
|
||||||
// Events comming from the handler, redirected to each behaviour
|
DelegateOut::Gossipsub(ev) => self.gossipsub.inject_event(peer_id, conn_id, ev),
|
||||||
BehaviourHandlerOut::Delegate(delegate) => match *delegate {
|
DelegateOut::RPC(ev) => self.eth2_rpc.inject_event(peer_id, conn_id, ev),
|
||||||
DelegateOut::Gossipsub(ev) => self.gossipsub.inject_event(peer_id, conn_id, ev),
|
DelegateOut::Identify(ev) => self.identify.inject_event(peer_id, conn_id, *ev),
|
||||||
DelegateOut::RPC(ev) => self.eth2_rpc.inject_event(peer_id, conn_id, ev),
|
|
||||||
DelegateOut::Identify(ev) => self.identify.inject_event(peer_id, conn_id, *ev),
|
|
||||||
},
|
|
||||||
/* Custom events sent BY the handler */
|
|
||||||
BehaviourHandlerOut::Custom => {
|
|
||||||
// TODO: implement
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1003,7 +994,6 @@ impl<TSpec: EthSpec> NetworkBehaviour for Behaviour<TSpec> {
|
|||||||
self.waker = Some(cx.waker().clone());
|
self.waker = Some(cx.waker().clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move where it's less distracting
|
|
||||||
macro_rules! poll_behaviour {
|
macro_rules! poll_behaviour {
|
||||||
/* $behaviour: The sub-behaviour being polled.
|
/* $behaviour: The sub-behaviour being polled.
|
||||||
* $on_event_fn: Function to call if we get an event from the sub-behaviour.
|
* $on_event_fn: Function to call if we get an event from the sub-behaviour.
|
||||||
|
@ -322,15 +322,6 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
|
|||||||
self.connect_peer(peer_id, ConnectingType::OutgoingConnected { multiaddr })
|
self.connect_peer(peer_id, ConnectingType::OutgoingConnected { multiaddr })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the database informing that a peer is being disconnected.
|
|
||||||
pub fn _disconnecting_peer(&mut self, _peer_id: &PeerId) -> bool {
|
|
||||||
// TODO: implement
|
|
||||||
// This informs the database that we are in the process of disconnecting the
|
|
||||||
// peer. Currently this state only exists for a short period of time before we force the
|
|
||||||
// disconnection.
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reports if a peer is banned or not.
|
/// Reports if a peer is banned or not.
|
||||||
///
|
///
|
||||||
/// This is used to determine if we should accept incoming connections.
|
/// This is used to determine if we should accept incoming connections.
|
||||||
|
Loading…
Reference in New Issue
Block a user