Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Simplify network protocols #1968

Merged
merged 3 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ members = [
"benches",
"error",
"notify",
"protocols/ping",
"protocols/identify",
"protocols/discovery",
]

[profile.release]
Expand Down
5 changes: 1 addition & 4 deletions network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ serde = { version = "1.0", features = ["derive"] }
ckb-util = { path = "../util" }
ckb-stop-handler = { path = "../util/stop-handler" }
ckb-logger = { path = "../util/logger" }
tokio = { version = "0.2.11", features = ["time", "io-util", "tcp", "dns", "rt-threaded", "blocking"] }
tokio = { version = "0.2.11", features = ["time", "io-util", "tcp", "dns", "rt-threaded", "blocking", "stream"] }
tokio-util = { version = "0.2.0", features = ["codec"] }
futures = "0.3"
crossbeam-channel = "0.3"
p2p = { version="0.3.0-alpha.2", package="tentacle", features = ["molc"] }
p2p-ping = { package="ckb-ping", path = "../protocols/ping" }
p2p-discovery = { package="ckb-discovery", path = "../protocols/discovery" }
p2p-identify = { package="ckb-identify", path = "../protocols/identify" }
faketime = "0.2.0"
lazy_static = "1.3.0"
bs58 = "0.3.0"
Expand Down
29 changes: 9 additions & 20 deletions network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::peer_store::{
};
use crate::protocols::{
disconnect_message::DisconnectMessageProtocol,
discovery::{DiscoveryProtocol, DiscoveryService},
discovery::DiscoveryProtocol,
feeler::Feeler,
identify::IdentifyCallback,
ping::PingService,
identify::{IdentifyCallback, IdentifyProtocol},
ping::{PingHandler, PingService},
};
use crate::services::{
dns_seeding::DnsSeedingService, dump_peer_store::DumpPeerStoreService,
Expand All @@ -25,10 +25,7 @@ use ckb_logger::{debug, error, info, trace, warn};
use ckb_stop_handler::{SignalSender, StopHandler};
use ckb_util::{Condvar, Mutex, RwLock};
use futures::{
channel::{
mpsc::{self, channel},
oneshot,
},
channel::{mpsc::channel, oneshot},
Future, StreamExt,
};
use ipnetwork::IpNetwork;
Expand All @@ -47,8 +44,6 @@ use p2p::{
utils::extract_peer_id,
SessionId,
};
use p2p_identify::IdentifyProtocol;
use p2p_ping::PingHandler;
use std::{
cmp::max,
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -881,7 +876,7 @@ impl NetworkService {
.build();

// Discovery protocol
let (disc_sender, disc_receiver) = mpsc::unbounded();
let disc_network_state = Arc::clone(&network_state);
let disc_meta = MetaBuilder::default()
.id(DISCOVERY_PROTOCOL_ID.into())
.name(move |_| "/ckb/discovery".to_string())
Expand All @@ -893,10 +888,10 @@ impl NetworkService {
)
})
.service_handle(move || {
ProtocolHandle::Both(Box::new(
DiscoveryProtocol::new(disc_sender.clone())
.global_ip_only(!config.discovery_local_address),
))
ProtocolHandle::Both(Box::new(DiscoveryProtocol::new(
disc_network_state,
config.discovery_local_address,
)))
})
.build();

Expand Down Expand Up @@ -977,11 +972,6 @@ impl NetworkService {
.build(event_handler);

// == Build background service tasks
let disc_service = DiscoveryService::new(
Arc::clone(&network_state),
disc_receiver,
config.discovery_local_address,
);
let mut ping_service = PingService::new(
Arc::clone(&network_state),
p2p_service.control().to_owned(),
Expand All @@ -1001,7 +991,6 @@ impl NetworkService {
}
}
}) as Pin<Box<_>>,
Box::pin(disc_service) as Pin<Box<_>>,
Box::pin(dump_peer_store_service) as Pin<Box<_>>,
Box::pin(protocol_type_checker_service) as Pin<Box<_>>,
];
Expand Down
Loading