Pass an encoded Roles as the notifications protocols handshakes (#5665)

This commit is contained in:
Pierre Krieger
2020-04-21 10:47:37 +02:00
committed by GitHub
parent 5db336c743
commit f2578bdc3b
5 changed files with 71 additions and 38 deletions
+2 -1
View File
@@ -1043,12 +1043,13 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
&'a mut self,
engine_id: ConsensusEngineId,
protocol_name: impl Into<Cow<'static, [u8]>>,
handshake_message: Vec<u8>,
) -> impl ExactSizeIterator<Item = (&'a PeerId, Roles)> + 'a {
let protocol_name = protocol_name.into();
if self.protocol_name_by_engine.insert(engine_id, protocol_name.clone()).is_some() {
error!(target: "sub-libp2p", "Notifications protocol already registered: {:?}", protocol_name);
} else {
self.behaviour.register_notif_protocol(protocol_name.clone(), Vec::new());
self.behaviour.register_notif_protocol(protocol_name.clone(), handshake_message);
self.legacy_equiv_by_name.insert(protocol_name, Fallback::Consensus(engine_id));
}