Update behaviour

This commit is contained in:
Age Manning
2020-05-01 23:05:49 +10:00
parent f3e707c3db
commit a4034e8ae3

View File

@@ -4,19 +4,20 @@ use crate::rpc::*;
use crate::types::{GossipEncoding, GossipKind, GossipTopic}; use crate::types::{GossipEncoding, GossipKind, GossipTopic};
use crate::{error, Enr, NetworkConfig, NetworkGlobals, PubsubMessage, TopicHash}; use crate::{error, Enr, NetworkConfig, NetworkGlobals, PubsubMessage, TopicHash};
use discv5::Discv5Event; use discv5::Discv5Event;
use futures::prelude::*;
use libp2p::{ use libp2p::{
core::{identity::Keypair, ConnectedPoint}, core::{identity::Keypair, ConnectedPoint},
gossipsub::{Gossipsub, GossipsubEvent, MessageId}, gossipsub::{Gossipsub, GossipsubEvent, MessageId},
identify::{Identify, IdentifyEvent}, identify::{Identify, IdentifyEvent},
swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess}, swarm::{NetworkBehaviourAction, NetworkBehaviourEventProcess, PollParameters},
NetworkBehaviour, PeerId, NetworkBehaviour, PeerId,
}; };
use lru::LruCache; use lru::LruCache;
use slog::{crit, debug, o, warn}; use slog::{crit, debug, o, warn};
use std::marker::PhantomData; use std::{
use std::sync::Arc; marker::PhantomData,
use std::task::Poll; sync::Arc,
task::{Context, Poll},
};
use types::{EnrForkId, EthSpec, SubnetId}; use types::{EnrForkId, EthSpec, SubnetId};
const MAX_IDENTIFY_ADDRESSES: usize = 10; const MAX_IDENTIFY_ADDRESSES: usize = 10;
@@ -461,11 +462,13 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
/// Consumes the events list when polled. /// Consumes the events list when polled.
fn poll<TBehaviourIn>( fn poll<TBehaviourIn>(
&mut self, &mut self,
cx: &mut Context,
_: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<TBehaviourIn, BehaviourEvent<TSpec>>> { ) -> Poll<NetworkBehaviourAction<TBehaviourIn, BehaviourEvent<TSpec>>> {
// check the peer manager for events // check the peer manager for events
loop { loop {
match self.peer_manager.poll() { match self.peer_manager.poll_next_unpin(cx) {
Ok(Poll::Ready(Some(event))) => match event { Poll::Ready(Some(event))) => match event {
PeerManagerEvent::Status(peer_id) => { PeerManagerEvent::Status(peer_id) => {
// it's time to status. We don't keep a beacon chain reference here, so we inform // it's time to status. We don't keep a beacon chain reference here, so we inform
// the network to send a status to this peer // the network to send a status to this peer
@@ -488,9 +491,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
} }
}, },
Poll::Pending => break, Poll::Pending => break,
Poll::Ready(None) | Err(_) => { Poll::Ready(None) => break, // peer manager ended
crit!(self.log, "Error polling peer manager");
break;
} }
} }
} }