diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock
index 5974505b2f..7f4c6186de 100644
--- a/substrate/Cargo.lock
+++ b/substrate/Cargo.lock
@@ -3520,15 +3520,12 @@ dependencies = [
name = "substrate-network-libp2p"
version = "0.1.0"
dependencies = [
- "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
"libp2p 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/substrate/core/network-libp2p/Cargo.toml b/substrate/core/network-libp2p/Cargo.toml
index 4fee117b4e..882dec068d 100644
--- a/substrate/core/network-libp2p/Cargo.toml
+++ b/substrate/core/network-libp2p/Cargo.toml
@@ -1,5 +1,6 @@
[package]
description = "libp2p implementation of the ethcore network library"
+edition = "2018"
homepage = "http://parity.io"
license = "GPL-3.0"
name = "substrate-network-libp2p"
@@ -13,7 +14,6 @@ fnv = "1.0"
futures = "0.1"
libp2p = { version = "0.2", default-features = false, features = ["secio-rsa", "secio-secp256k1"] }
parking_lot = "0.7.1"
-libc = "0.2"
log = "0.4"
rand = "0.5.0"
serde = "1.0.70"
@@ -25,7 +25,3 @@ tokio-io = "0.1"
tokio-timer = "0.2"
unsigned-varint = { version = "0.2.1", features = ["codec"] }
void = "1.0"
-
-[dev-dependencies]
-assert_matches = "1.2"
-parity-bytes = { git = "https://github.com/paritytech/parity-common", rev = "b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
diff --git a/substrate/core/network-libp2p/src/behaviour.rs b/substrate/core/network-libp2p/src/behaviour.rs
index e4e90b2c68..f4318dfcaa 100644
--- a/substrate/core/network-libp2p/src/behaviour.rs
+++ b/substrate/core/network-libp2p/src/behaviour.rs
@@ -18,12 +18,14 @@ use crate::custom_proto::{CustomProtos, CustomProtosOut, RegisteredProtocols};
use crate::{NetworkConfiguration, ProtocolId};
use bytes::Bytes;
use futures::prelude::*;
+use libp2p::NetworkBehaviour;
use libp2p::core::{PeerId, ProtocolsHandler};
use libp2p::core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction};
use libp2p::core::swarm::{NetworkBehaviourEventProcess, PollParameters};
use libp2p::identify::{Identify, IdentifyEvent};
use libp2p::kad::{Kademlia, KademliaOut, KademliaTopology};
use libp2p::ping::{Ping, PingEvent};
+use log::{debug, trace, warn};
use std::{cmp, time::Duration, time::Instant};
use tokio_io::{AsyncRead, AsyncWrite};
use tokio_timer::Delay;
diff --git a/substrate/core/network-libp2p/src/custom_proto/behaviour.rs b/substrate/core/network-libp2p/src/custom_proto/behaviour.rs
index 521c204ff2..679f44853a 100644
--- a/substrate/core/network-libp2p/src/custom_proto/behaviour.rs
+++ b/substrate/core/network-libp2p/src/custom_proto/behaviour.rs
@@ -22,6 +22,7 @@ use fnv::{FnvHashMap, FnvHashSet};
use futures::prelude::*;
use libp2p::core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use libp2p::core::{protocols_handler::ProtocolsHandler, PeerId};
+use log::{debug, trace, warn};
use smallvec::SmallVec;
use std::{io, marker::PhantomData, time::Duration, time::Instant};
use tokio_io::{AsyncRead, AsyncWrite};
diff --git a/substrate/core/network-libp2p/src/custom_proto/handler.rs b/substrate/core/network-libp2p/src/custom_proto/handler.rs
index d03f3f093d..45a9a6f273 100644
--- a/substrate/core/network-libp2p/src/custom_proto/handler.rs
+++ b/substrate/core/network-libp2p/src/custom_proto/handler.rs
@@ -23,6 +23,7 @@ use libp2p::core::{
protocols_handler::ProtocolsHandlerUpgrErr,
upgrade::{InboundUpgrade, OutboundUpgrade}
};
+use log::{trace, warn};
use smallvec::SmallVec;
use std::{fmt, io};
use tokio_io::{AsyncRead, AsyncWrite};
diff --git a/substrate/core/network-libp2p/src/custom_proto/upgrade.rs b/substrate/core/network-libp2p/src/custom_proto/upgrade.rs
index 992989b3f3..70eb517023 100644
--- a/substrate/core/network-libp2p/src/custom_proto/upgrade.rs
+++ b/substrate/core/network-libp2p/src/custom_proto/upgrade.rs
@@ -14,14 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see .
+use crate::ProtocolId;
use bytes::Bytes;
use libp2p::core::{UpgradeInfo, InboundUpgrade, OutboundUpgrade, upgrade::ProtocolName};
use libp2p::tokio_codec::Framed;
+use log::debug;
use std::{collections::VecDeque, io, vec::IntoIter as VecIntoIter};
use futures::{prelude::*, future, stream};
use tokio_io::{AsyncRead, AsyncWrite};
use unsigned_varint::codec::UviBytes;
-use ProtocolId;
/// Connection upgrade for a single protocol.
///
diff --git a/substrate/core/network-libp2p/src/error.rs b/substrate/core/network-libp2p/src/error.rs
index 9de1b9d43f..5466ce2a26 100644
--- a/substrate/core/network-libp2p/src/error.rs
+++ b/substrate/core/network-libp2p/src/error.rs
@@ -14,12 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see .
+use error_chain::*;
use std::{io, net, fmt};
-use libc::{ENFILE, EMFILE};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
-pub enum DisconnectReason
-{
+pub enum DisconnectReason {
DisconnectRequested,
TCPError,
BadProtocol,
@@ -135,18 +134,6 @@ error_chain! {
display("Packet is too large"),
}
- #[doc = "Reached system resource limits for this process"]
- ProcessTooManyFiles {
- description("Too many open files in process."),
- display("Too many open files in this process. Check your resource limits and restart parity"),
- }
-
- #[doc = "Reached system wide resource limits"]
- SystemTooManyFiles {
- description("Too many open files on system."),
- display("Too many open files on system. Consider closing some processes/release some file handlers or increas the system-wide resource limits and restart parity."),
- }
-
#[doc = "An unknown IO error occurred."]
Io(err: io::Error) {
description("IO Error"),
@@ -157,15 +144,10 @@ error_chain! {
impl From for Error {
fn from(err: io::Error) -> Self {
- match err.raw_os_error() {
- Some(ENFILE) => ErrorKind::ProcessTooManyFiles.into(),
- Some(EMFILE) => ErrorKind::SystemTooManyFiles.into(),
- _ => Error::from_kind(ErrorKind::Io(err))
- }
+ Error::from_kind(ErrorKind::Io(err))
}
}
-
impl From for Error {
fn from(_err: net::AddrParseError) -> Self { ErrorKind::AddressParse.into() }
}
@@ -179,26 +161,3 @@ fn test_errors() {
}
assert_eq!(DisconnectReason::Unknown, r);
}
-
-#[test]
-fn test_io_errors() {
- use libc::{EMFILE, ENFILE};
-
- assert_matches!(
- >::from(
- io::Error::from_raw_os_error(ENFILE)
- ).kind(),
- ErrorKind::ProcessTooManyFiles);
-
- assert_matches!(
- >::from(
- io::Error::from_raw_os_error(EMFILE)
- ).kind(),
- ErrorKind::SystemTooManyFiles);
-
- assert_matches!(
- >::from(
- io::Error::from_raw_os_error(0)
- ).kind(),
- ErrorKind::Io(_));
-}
diff --git a/substrate/core/network-libp2p/src/lib.rs b/substrate/core/network-libp2p/src/lib.rs
index 9fb1bb8a13..5204e38949 100644
--- a/substrate/core/network-libp2p/src/lib.rs
+++ b/substrate/core/network-libp2p/src/lib.rs
@@ -16,33 +16,6 @@
//! Networking layer of Substrate.
-#![recursion_limit = "128"]
-
-extern crate parking_lot;
-extern crate fnv;
-extern crate futures;
-extern crate tokio;
-extern crate tokio_io;
-extern crate tokio_timer;
-extern crate libc;
-#[macro_use]
-extern crate libp2p;
-extern crate rand;
-#[macro_use]
-extern crate serde_derive;
-extern crate serde_json;
-extern crate smallvec;
-extern crate void;
-extern crate bytes;
-extern crate unsigned_varint;
-
-#[macro_use]
-extern crate error_chain;
-#[macro_use]
-extern crate log;
-#[cfg(test)] #[macro_use]
-extern crate assert_matches;
-
mod behaviour;
mod custom_proto;
mod error;
@@ -52,13 +25,13 @@ mod topology;
mod traits;
mod transport;
-pub use custom_proto::RegisteredProtocol;
-pub use error::{Error, ErrorKind, DisconnectReason};
+pub use crate::custom_proto::RegisteredProtocol;
+pub use crate::error::{Error, ErrorKind, DisconnectReason};
+pub use crate::secret::obtain_private_key;
+pub use crate::service_task::{start_service, Service, ServiceEvent};
+pub use crate::traits::{NetworkConfiguration, NodeIndex, NodeId, NonReservedPeerMode};
+pub use crate::traits::{ProtocolId, Secret, Severity};
pub use libp2p::{Multiaddr, multiaddr::{Protocol}, multiaddr, PeerId, core::PublicKey};
-pub use secret::obtain_private_key;
-pub use service_task::{start_service, Service, ServiceEvent};
-pub use traits::{NetworkConfiguration, NodeIndex, NodeId, NonReservedPeerMode};
-pub use traits::{ProtocolId, Secret, Severity};
/// Check if node url is valid
pub fn validate_node_url(url: &str) -> Result<(), Error> {
diff --git a/substrate/core/network-libp2p/src/secret.rs b/substrate/core/network-libp2p/src/secret.rs
index 093d67f3d9..e185dc1a78 100644
--- a/substrate/core/network-libp2p/src/secret.rs
+++ b/substrate/core/network-libp2p/src/secret.rs
@@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see .
+use crate::NetworkConfiguration;
use libp2p::secio;
-use rand::{self, Rng};
-use std::fs;
+use log::{trace, warn};
+use rand::Rng;
use std::io::{Error as IoError, ErrorKind as IoErrorKind, Read, Write};
-use std::path::Path;
-use NetworkConfiguration;
+use std::{fs, path::Path};
// File where the private key is stored.
const SECRET_FILE: &str = "secret";
diff --git a/substrate/core/network-libp2p/src/service_task.rs b/substrate/core/network-libp2p/src/service_task.rs
index 0a6b094408..98206333f9 100644
--- a/substrate/core/network-libp2p/src/service_task.rs
+++ b/substrate/core/network-libp2p/src/service_task.rs
@@ -15,22 +15,23 @@
// along with Substrate. If not, see .
use crate::{behaviour::Behaviour, custom_proto::CustomProtosOut, secret::obtain_private_key, transport};
+use crate::custom_proto::{RegisteredProtocol, RegisteredProtocols};
+use crate::topology::NetTopology;
+use crate::{Error, NetworkConfiguration, NodeIndex, ProtocolId, parse_str_addr};
use bytes::Bytes;
-use custom_proto::{RegisteredProtocol, RegisteredProtocols};
use fnv::FnvHashMap;
use futures::{prelude::*, Stream};
-use libp2p::{Multiaddr, PeerId};
+use libp2p::{Multiaddr, PeerId, multiaddr};
use libp2p::core::{Swarm, nodes::Substream, transport::boxed::Boxed, muxing::StreamMuxerBox};
use libp2p::core::nodes::ConnectedPoint;
+use log::{debug, info, warn};
use std::collections::hash_map::Entry;
use std::fs;
use std::io::{Error as IoError, ErrorKind as IoErrorKind};
use std::net::SocketAddr;
use std::path::Path;
use std::time::Duration;
-use topology::NetTopology;
use tokio_timer::Interval;
-use {Error, NetworkConfiguration, NodeIndex, ProtocolId, parse_str_addr};
// File where the network topology is stored.
const NODES_FILE: &str = "nodes.json";
diff --git a/substrate/core/network-libp2p/src/topology.rs b/substrate/core/network-libp2p/src/topology.rs
index 0bd3067076..6689caf4b0 100644
--- a/substrate/core/network-libp2p/src/topology.rs
+++ b/substrate/core/network-libp2p/src/topology.rs
@@ -18,7 +18,8 @@ use fnv::FnvHashMap;
use libp2p::{Multiaddr, PeerId, identify::IdentifyTopology, multihash::Multihash};
use libp2p::core::{PublicKey, swarm::ConnectedPoint, topology::DisconnectReason, topology::Topology};
use libp2p::kad::{KBucketsPeerId, KadConnectionType, KademliaTopology};
-use serde_json;
+use log::{debug, info, trace, warn};
+use serde_derive::{Serialize, Deserialize};
use std::{cmp, fs, iter, vec};
use std::io::{Read, Cursor, Error as IoError, ErrorKind as IoErrorKind, Write, BufReader, BufWriter};
use std::path::{Path, PathBuf};
diff --git a/substrate/core/network-libp2p/tests/test.rs b/substrate/core/network-libp2p/tests/test.rs
index 985a7c436e..8120e15c3a 100644
--- a/substrate/core/network-libp2p/tests/test.rs
+++ b/substrate/core/network-libp2p/tests/test.rs
@@ -14,15 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see .
-#[macro_use]
-extern crate futures;
-#[macro_use]
-extern crate substrate_network_libp2p;
-extern crate tokio;
-
-use futures::{future, prelude::*};
+use futures::{future, prelude::*, try_ready};
use std::{io, iter};
-use substrate_network_libp2p::ServiceEvent;
+use substrate_network_libp2p::{ServiceEvent, multiaddr};
/// Builds two services. The second one has the first one as its bootstrap node.
/// This is to be used only for testing, and a panic will happen if something goes wrong.