Add DC/Shutdown capabilities to the behaviour handler (#1233)

* Remove ban event from the PM

* Fix dispatching of responses to peer's requests

* Disconnection logic
This commit is contained in:
divma
2020-06-17 20:53:08 -05:00
committed by GitHub
parent 9db0c28051
commit 065251b701
12 changed files with 544 additions and 358 deletions

View File

@@ -22,8 +22,8 @@ mod delegate;
pub struct BehaviourHandler<TSpec: EthSpec> {
/// Handler combining all sub behaviour's handlers.
delegate: DelegatingHandler<TSpec>,
/// Keep alive for this handler.
keep_alive: KeepAlive,
/// Flag indicating if the handler is shutting down.
shutting_down: bool,
}
impl<TSpec: EthSpec> BehaviourHandler<TSpec> {
@@ -35,7 +35,7 @@ impl<TSpec: EthSpec> BehaviourHandler<TSpec> {
) -> Self {
BehaviourHandler {
delegate: DelegatingHandler::new(gossipsub, rpc, identify, discovery),
keep_alive: KeepAlive::Yes,
shutting_down: false,
}
}
}
@@ -43,8 +43,8 @@ impl<TSpec: EthSpec> BehaviourHandler<TSpec> {
#[derive(Clone)]
pub enum BehaviourHandlerIn<TSpec: EthSpec> {
Delegate(DelegateIn<TSpec>),
// TODO: replace custom with incoming events
Custom,
/// Start the shutdown process.
Shutdown(Option<(RequestId, RPCRequest<TSpec>)>),
}
pub enum BehaviourHandlerOut<TSpec: EthSpec> {
@@ -84,8 +84,9 @@ impl<TSpec: EthSpec> ProtocolsHandler for BehaviourHandler<TSpec> {
match event {
BehaviourHandlerIn::Delegate(delegated_ev) => self.delegate.inject_event(delegated_ev),
/* Events comming from the behaviour */
BehaviourHandlerIn::Custom => {
// TODO: implement
BehaviourHandlerIn::Shutdown(last_message) => {
self.shutting_down = true;
self.delegate.rpc_mut().shutdown(last_message);
}
}
}
@@ -101,8 +102,13 @@ impl<TSpec: EthSpec> ProtocolsHandler for BehaviourHandler<TSpec> {
}
fn connection_keep_alive(&self) -> KeepAlive {
// TODO: refine this logic
self.keep_alive.min(self.delegate.connection_keep_alive())
if self.shutting_down {
let rpc_keep_alive = self.delegate.rpc().connection_keep_alive();
let identify_keep_alive = self.delegate.identify().connection_keep_alive();
rpc_keep_alive.max(identify_keep_alive)
} else {
KeepAlive::Yes
}
}
fn poll(
@@ -135,7 +141,5 @@ impl<TSpec: EthSpec> ProtocolsHandler for BehaviourHandler<TSpec> {
}
Poll::Pending
// TODO: speak to our behaviour here
}
}