Skip to content

Commit

Permalink
chore: upgrade p2p dependence
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Apr 12, 2019
1 parent 9485f1a commit db84513
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 70 deletions.
55 changes: 30 additions & 25 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions network/Cargo.toml
Expand Up @@ -23,11 +23,11 @@ tokio = "0.1.18"
futures = "0.1"
snap = "0.2"
crossbeam-channel = "0.3"
p2p = { git = "https://github.com/nervosnetwork/p2p", rev="53cb765b94041543a9c8582aa4d0d34fb2ac6d95", package="tentacle" }
secio = { git = "https://github.com/nervosnetwork/p2p", rev="53cb765b94041543a9c8582aa4d0d34fb2ac6d95", package="tentacle-secio" }
p2p-ping = { git = "https://github.com/nervosnetwork/p2p", rev="53cb765b94041543a9c8582aa4d0d34fb2ac6d95", package="tentacle-ping" }
p2p-discovery = { git = "https://github.com/nervosnetwork/p2p", rev="53cb765b94041543a9c8582aa4d0d34fb2ac6d95", package="tentacle-discovery" }
p2p-identify = { git = "https://github.com/nervosnetwork/p2p", rev="53cb765b94041543a9c8582aa4d0d34fb2ac6d95", package="tentacle-identify" }
p2p = { git = "https://github.com/nervosnetwork/p2p", rev="1ce924dec380d65444a14dbbf285f2d6f411145d", package="tentacle" }
secio = { git = "https://github.com/nervosnetwork/p2p", rev="1ce924dec380d65444a14dbbf285f2d6f411145d", package="tentacle-secio" }
p2p-ping = { git = "https://github.com/nervosnetwork/p2p", rev="1ce924dec380d65444a14dbbf285f2d6f411145d", package="tentacle-ping" }
p2p-discovery = { git = "https://github.com/nervosnetwork/p2p", rev="1ce924dec380d65444a14dbbf285f2d6f411145d", package="tentacle-discovery" }
p2p-identify = { git = "https://github.com/nervosnetwork/p2p", rev="1ce924dec380d65444a14dbbf285f2d6f411145d", package="tentacle-identify" }
faketime = "0.2.0"
rusqlite = {version = "0.16.0", features = ["bundled"]}
lazy_static = "1.3.0"
Expand Down
16 changes: 9 additions & 7 deletions network/src/network.rs
Expand Up @@ -463,14 +463,16 @@ impl NetworkService {
// TODO: how to deny banned node to open those protocols?
// Ping protocol
let (ping_sender, ping_receiver) = channel(std::u8::MAX as usize);
let ping_interval = Duration::from_secs(config.ping_interval_secs);
let ping_timeout = Duration::from_secs(config.ping_timeout_secs);

let ping_meta = MetaBuilder::default()
.id(PING_PROTOCOL_ID)
.service_handle(move || {
ProtocolHandle::Both(Box::new(PingHandler::new(
PING_PROTOCOL_ID,
Duration::from_secs(config.ping_interval_secs),
Duration::from_secs(config.ping_timeout_secs),
ping_sender,
ping_interval,
ping_timeout,
ping_sender.clone(),
)))
})
.build();
Expand All @@ -480,7 +482,7 @@ impl NetworkService {
let disc_meta = MetaBuilder::default()
.id(DISCOVERY_PROTOCOL_ID)
.service_handle(move || {
ProtocolHandle::Both(Box::new(DiscoveryProtocol::new(disc_sender)))
ProtocolHandle::Both(Box::new(DiscoveryProtocol::new(disc_sender.clone())))
})
.build();

Expand All @@ -489,7 +491,7 @@ impl NetworkService {
let identify_meta = MetaBuilder::default()
.id(IDENTIFY_PROTOCOL_ID)
.service_handle(move || {
ProtocolHandle::Both(Box::new(IdentifyProtocol::new(identify_callback)))
ProtocolHandle::Both(Box::new(IdentifyProtocol::new(identify_callback.clone())))
})
.build();

Expand All @@ -498,7 +500,7 @@ impl NetworkService {
"flr".to_string(),
FEELER_PROTOCOL_ID,
&[1][..],
Box::new(Feeler {}),
|| Box::new(Feeler {}),
Arc::clone(&network_state),
);

Expand Down
16 changes: 4 additions & 12 deletions network/src/protocols/discovery.rs
Expand Up @@ -3,7 +3,7 @@ use crate::NetworkState;
use fnv::FnvHashMap;
use futures::{sync::mpsc, sync::oneshot, try_ready, Async, Future, Stream};
use log::{debug, trace, warn};
use std::sync::Arc;
use std::{sync::Arc, time::Duration};

use p2p::{
context::{ProtocolContext, ProtocolContextMutRef},
Expand All @@ -29,7 +29,7 @@ impl DiscoveryProtocol {
let addr_mgr = DiscoveryAddressManager {
event_sender: event_sender.clone(),
};
let discovery = Discovery::new(addr_mgr);
let discovery = Discovery::new(addr_mgr, Some(Duration::from_secs(7)));
let discovery_handle = discovery.handle();
DiscoveryProtocol {
discovery: Some(discovery),
Expand Down Expand Up @@ -63,7 +63,7 @@ impl ServiceProtocol for DiscoveryProtocol {
context.future_task(discovery_task);
}

fn connected(&mut self, mut context: ProtocolContextMutRef, _: &str) {
fn connected(&mut self, context: ProtocolContextMutRef, _: &str) {
let session = context.session;
debug!(
target: "network",
Expand All @@ -81,15 +81,7 @@ impl ServiceProtocol for DiscoveryProtocol {

let (sender, receiver) = mpsc::channel(8);
self.discovery_senders.insert(session.id, sender);
let substream = Substream::new(
session.address.clone(),
session.ty,
context.proto_id,
session.id,
receiver,
context.control().clone(),
context.listens(),
);
let substream = Substream::new(context, receiver);
match self.discovery_handle.substream_sender.try_send(substream) {
Ok(_) => {
debug!(target: "network", "Send substream success");
Expand Down

0 comments on commit db84513

Please sign in to comment.