This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[WIP] Refactor gossiping system #4125
Closed
Closed
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
431b910
Refactor gossiping system
tomaka c5fdfd5
Work on removing GrandPA Network trait
tomaka 50eacf1
Finish GrandPA Network trait removal
tomaka 64b81b4
More work
tomaka 6a8e7df
Rename AbstractNetwork to Network
tomaka 717a7ee
notif -> notification
tomaka 2fa6a26
Register GrandPa even if disabled
tomaka 500f180
WriteNotif -> WriteNotification
tomaka 3b8b1ca
Implement NetworkService::disconnect_peer
tomaka c8846e4
Fix lots of TODOs
tomaka b30e0a6
Delete consensus_gossip.rs
tomaka d2e6480
handshake -> handshake_msg
tomaka 0c7da32
events_streams -> event_streams
tomaka ff7458f
Fix the TODOs in notif_in
tomaka 83999ca
Log when the wrong function is called
tomaka c8ad54a
Merge remote-tracking branch 'upstream/master' into new-proto-2
tomaka 59a0764
Merge remote-tracking branch 'upstream/master' into new-proto-2
tomaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,9 @@ use crate::generic_proto::{ | |
| handler::notif_out::{NotifsOutHandlerProto, NotifsOutHandler, NotifsOutHandlerIn, NotifsOutHandlerOut}, | ||
| upgrade::{NotificationsIn, NotificationsOut, RegisteredProtocol, SelectUpgrade, UpgradeCollec}, | ||
| }; | ||
| use crate::protocol::message::generic::ConsensusMessage; | ||
| use bytes::BytesMut; | ||
| use codec::Encode as _; | ||
| use futures::prelude::*; | ||
| use libp2p::core::{ConnectedPoint, PeerId}; | ||
| use libp2p::core::either::{EitherError, EitherOutput}; | ||
|
|
@@ -33,6 +35,7 @@ use libp2p::swarm::{ | |
| SubstreamProtocol, | ||
| }; | ||
| use log::error; | ||
| use sr_primitives::ConsensusEngineId; | ||
| use std::{borrow::Cow, error, io}; | ||
| use tokio_io::{AsyncRead, AsyncWrite}; | ||
|
|
||
|
|
@@ -119,13 +122,22 @@ pub enum NotifsHandlerIn { | |
| /// The node should stop using custom protocols. | ||
| Disable, | ||
|
|
||
| /// Sends a message through a custom protocol substream. | ||
| /// Sends a message through the custom protocol substream. | ||
| Send { | ||
| /// Name of the protocol for the message, or `None` to force the legacy protocol. | ||
| /// The message to send. | ||
| message: Vec<u8>, | ||
| }, | ||
|
|
||
| /// Sends a notifications message. | ||
| SendNotif { | ||
|
||
| /// Name of the protocol for the message. | ||
| /// | ||
| /// If `Some`, must match one of the registered protocols. For backwards-compatibility | ||
| /// reasons, if the remote doesn't support this protocol, we use the legacy substream. | ||
| proto_name: Option<Cow<'static, [u8]>>, | ||
| /// Must match one of the registered protocols. For backwards-compatibility reasons, if | ||
| /// the remote doesn't support this protocol, we use the legacy substream. | ||
| proto_name: Cow<'static, [u8]>, | ||
|
|
||
| /// For legacy reasons, the name to use if we send the message on the legacy substream. | ||
| engine_id: ConsensusEngineId, | ||
|
|
||
| /// The message to send. | ||
| message: Vec<u8>, | ||
|
|
@@ -257,17 +269,22 @@ where TSubstream: AsyncRead + AsyncWrite + Send + 'static { | |
| self.in_handlers[num].inject_event(NotifsInHandlerIn::Refuse); | ||
| } | ||
| }, | ||
| NotifsHandlerIn::Send { proto_name, message } => { | ||
| if let Some(proto_name) = proto_name { | ||
| for handler in &mut self.out_handlers { | ||
| if handler.is_open() && handler.protocol_name() == &proto_name[..] { | ||
| handler.inject_event(NotifsOutHandlerIn::Send(message)); | ||
| return; | ||
| } | ||
| NotifsHandlerIn::Send { message } => | ||
| self.legacy.inject_event(LegacyProtoHandlerIn::SendCustomMessage { message }), | ||
| NotifsHandlerIn::SendNotif { message, engine_id, proto_name } => { | ||
| for handler in &mut self.out_handlers { | ||
| if handler.is_open() && handler.protocol_name() == &proto_name[..] { | ||
| handler.inject_event(NotifsOutHandlerIn::Send(message)); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| self.legacy.inject_event(LegacyProtoHandlerIn::SendCustomMessage { message }); | ||
| let message = ConsensusMessage { | ||
| engine_id, | ||
| data: message, | ||
| }; | ||
|
|
||
| self.legacy.inject_event(LegacyProtoHandlerIn::SendCustomMessage { message: message.encode() }); | ||
| }, | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write_notificationplease