Skip to content

Commit

Permalink
chore(network): move in protocols (#3)
Browse files Browse the repository at this point in the history
* feat(network): move in discovery protocol from forked

* feat(network): move in ping protocol

* feat(network): move in identify protocol

* chore(network): use tentacle from crate

* refactor(network): change allow_global_ip feature to global_ip_only

* change(network): remove secio_enabled in identify protocol

secio should be always enabled in muta network

* refactor(network): identify protocol

* refactor(network): discovery global_ip_only feature

* chore(network): remove garbage files

* fix(network): clippy on auto generated code

* fix(network): clippy warnings

* refactor(nework): ping message use protobuf instead

* refactor(network): use protobuf to define discovery message

* chore(network): turn off global_ip_only feature by default

* refactor(network): define identify message using protobuf

* fix(network): clippy warnings

* chore(network): remove unused molecule
  • Loading branch information
zeroqn committed Jul 27, 2020
1 parent c54dd01 commit 46a3088
Show file tree
Hide file tree
Showing 21 changed files with 2,194 additions and 409 deletions.
10 changes: 4 additions & 6 deletions core/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ rand = "0.7"
serde = "1.0"
serde_derive = "1.0"
snap = "0.2"
tentacle = { git = "https://github.com/zeroqn/p2p", branch = "v0.3.0.alpha5-muta", features = [ "molc" ]}
tentacle-ping = { git = "https://github.com/zeroqn/p2p", branch = "v0.3.0.alpha5-muta", features = [ "molc" ]}
tentacle-discovery = { git = "https://github.com/zeroqn/p2p", branch = "v0.3.0.alpha5-muta", features = [ "molc" ]}
tentacle-identify = { git = "https://github.com/zeroqn/p2p", branch = "v0.3.0.alpha5-muta", features = [ "molc" ]}
tentacle = { version = "0.3.0-alpha.5", features = ["molc"]}
tokio = { version = "0.2", features = ["macros", "rt-core"]}
tokio-util = { version = "0.2", features = ["codec"] }
hostname = "0.3"
lazy_static = "1.4"

Expand All @@ -40,10 +38,10 @@ quickcheck_macros = "0.8"
tokio = { version = "0.2", features = ["macros", "rt-core"]}

[features]
allow_global_ip = []
default = []
global_ip_only = []
diagnostic = []

[[test]]
name = "broadcast"
path = "tests/gossip_test.rs"
required-features = [ "allow_global_ip" ]
87 changes: 0 additions & 87 deletions core/network/src/peer_manager/disc.rs

This file was deleted.

123 changes: 0 additions & 123 deletions core/network/src/peer_manager/ident.rs

This file was deleted.

4 changes: 0 additions & 4 deletions core/network/src/peer_manager/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![allow(clippy::mutable_key_type)]

mod addr_set;
mod disc;
mod ident;
mod peer;
mod retry;
mod save_restore;
Expand All @@ -18,8 +16,6 @@ use peer::Peer;
use retry::Retry;
use save_restore::{NoPeerDatFile, PeerDatFile, SaveRestore};

pub use disc::DiscoveryAddrManager;
pub use ident::IdentifyCallback;
pub use peer::{ArcPeer, Connectedness};
pub use shared::{SharedSessions, SharedSessionsConfig};
pub use trust_metric::{TrustMetric, TrustMetricConfig};
Expand Down
52 changes: 26 additions & 26 deletions core/network/src/protocols/core.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
use std::time::Duration;
use crate::{
event::PeerManagerEvent,
message::RawSessionMessage,
peer_manager::PeerManagerHandle,
protocols::{discovery::Discovery, identify::Identify, ping::Ping, transmitter::Transmitter},
traits::NetworkProtocol,
};

use futures::channel::mpsc::UnboundedSender;
use tentacle::{
service::{ProtocolMeta, TargetProtocol},
ProtocolId,
};
use tentacle_discovery::AddressManager;
use tentacle_identify::Callback;

use crate::{
event::PeerManagerEvent,
message::RawSessionMessage,
protocols::{discovery::Discovery, identify::Identify, ping::Ping, transmitter::Transmitter},
traits::NetworkProtocol,
};
use std::time::Duration;

pub const PING_PROTOCOL_ID: usize = 1;
pub const IDENTIFY_PROTOCOL_ID: usize = 2;
pub const DISCOVERY_PROTOCOL_ID: usize = 3;
pub const TRANSMITTER_PROTOCOL_ID: usize = 4;

#[derive(Default)]
pub struct CoreProtocolBuilder<M, C> {
pub struct CoreProtocolBuilder {
ping: Option<Ping>,
identify: Option<Identify<C>>,
discovery: Option<Discovery<M>>,
identify: Option<Identify>,
discovery: Option<Discovery>,
transmitter: Option<Transmitter>,
}

Expand All @@ -33,11 +32,7 @@ pub struct CoreProtocol {
}

impl CoreProtocol {
pub fn build<M, C>() -> CoreProtocolBuilder<M, C>
where
M: AddressManager + Send + 'static + Unpin,
C: Callback + Send + 'static + Unpin,
{
pub fn build() -> CoreProtocolBuilder {
CoreProtocolBuilder::new()
}
}
Expand All @@ -61,11 +56,7 @@ impl NetworkProtocol for CoreProtocol {
}
}

impl<M, C> CoreProtocolBuilder<M, C>
where
M: AddressManager + Send + 'static + Unpin,
C: Callback + Send + 'static + Unpin,
{
impl CoreProtocolBuilder {
pub fn new() -> Self {
CoreProtocolBuilder {
ping: None,
Expand All @@ -87,15 +78,24 @@ where
self
}

pub fn identify(mut self, callback: C) -> Self {
let identify = Identify::new(callback);
pub fn identify(
mut self,
peer_mgr: PeerManagerHandle,
event_tx: UnboundedSender<PeerManagerEvent>,
) -> Self {
let identify = Identify::new(peer_mgr, event_tx);

self.identify = Some(identify);
self
}

pub fn discovery(mut self, addr_mgr: M, sync_interval: Duration) -> Self {
let discovery = Discovery::new(addr_mgr, sync_interval);
pub fn discovery(
mut self,
peer_mgr: PeerManagerHandle,
event_tx: UnboundedSender<PeerManagerEvent>,
sync_interval: Duration,
) -> Self {
let discovery = Discovery::new(peer_mgr, event_tx, sync_interval);

self.discovery = Some(discovery);
self
Expand Down
Loading

0 comments on commit 46a3088

Please sign in to comment.