Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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
320 changes: 135 additions & 185 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions substrate/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ substrate-extrinsic-pool = { path = "../../substrate/extrinsic-pool" }
substrate-network = { path = "../../substrate/network" }
substrate-network-libp2p = { path = "../../substrate/network-libp2p" }
substrate-runtime-primitives = { path = "../../substrate/runtime/primitives" }
substrate-primitives = { path = "../../substrate/primitives" }
substrate-service = { path = "../../substrate/service" }
substrate-telemetry = { path = "../../substrate/telemetry" }
names = "0.11.0"
Expand Down
7 changes: 5 additions & 2 deletions substrate/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern crate substrate_network_libp2p as network_libp2p;
extern crate substrate_runtime_primitives as runtime_primitives;
extern crate substrate_extrinsic_pool;
extern crate substrate_service as service;
extern crate substrate_primitives as primitives;
#[macro_use]
extern crate slog; // needed until we can reexport `slog_info` from `substrate_telemetry`
#[macro_use]
Expand All @@ -62,12 +63,14 @@ use service::{
FactoryGenesis, PruningMode, ChainSpec,
};
use network::NonReservedPeerMode;
use primitives::H256;

use std::io::{Write, Read, stdin, stdout};
use std::iter;
use std::fs::File;
use std::net::{Ipv4Addr, SocketAddr};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use names::{Generator, Name};
use regex::Regex;

Expand Down Expand Up @@ -301,8 +304,8 @@ where
];
config.network.public_addresses = Vec::new();
config.network.client_version = config.client_id();
config.network.use_secret = match matches.value_of("node-key").map(|s| s.parse()) {
Some(Ok(secret)) => Some(secret),
config.network.use_secret = match matches.value_of("node-key").map(H256::from_str) {
Some(Ok(secret)) => Some(secret.into()),
Some(Err(err)) => return Err(format!("Error parsing node key: {}", err).into()),
None => None,
};
Expand Down
10 changes: 4 additions & 6 deletions substrate/network-libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ bytes = "0.4"
error-chain = { version = "0.12", default-features = false }
fnv = "1.0"
futures = "0.1"
libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev = "304e9c72c88bc97824f2734dc19d1b5f4556d346", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] }
ethcore-io = { git = "https://github.com/paritytech/parity.git", rev = "202c54d42398fc4b49d67ffbf9070522e38f9360" }
ethkey = { git = "https://github.com/paritytech/parity.git", rev = "202c54d42398fc4b49d67ffbf9070522e38f9360" }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev = "2a7a48b4962cd01095ed634f7d0fb4dd2bddb7e4", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] }
ethereum-types = "0.3"
parking_lot = "0.5"
libc = "0.2"
Expand All @@ -22,13 +20,13 @@ rand = "0.5.0"
serde = "1.0.70"
serde_derive = "1.0.70"
serde_json = "1.0.24"
smallvec = "0.6.5"
tokio = "0.1"
tokio-executor = "0.1"
tokio-io = "0.1"
tokio-timer = "0.2"
unsigned-varint = { version = "0.2.1", features = ["codec"] }

[dev-dependencies]
assert_matches = "1.2"
parity-bytes = { git = "https://github.com/paritytech/parity-common.git" }
ethcore-io = { git = "https://github.com/paritytech/parity.git", rev = "202c54d42398fc4b49d67ffbf9070522e38f9360" }
ethcore-logger = { git = "https://github.com/paritytech/parity.git", rev = "202c54d42398fc4b49d67ffbf9070522e38f9360" }
parity-bytes = "0.1"
6 changes: 6 additions & 0 deletions substrate/network-libp2p/src/custom_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ where C: AsyncRead + AsyncWrite + Send + 'static, // TODO: 'static :-/
pub struct RegisteredProtocols<T>(pub Vec<RegisteredProtocol<T>>);

impl<T> RegisteredProtocols<T> {
/// Returns the number of protocols.
#[inline]
pub fn len(&self) -> usize {
self.0.len()
}

/// Finds a protocol in the list by its id.
pub fn find_protocol(&self, protocol: ProtocolId)
-> Option<&RegisteredProtocol<T>> {
Expand Down
17 changes: 0 additions & 17 deletions substrate/network-libp2p/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

use std::{io, net, fmt};
use libc::{ENFILE, EMFILE};
use io::IoError;
use ethkey;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum DisconnectReason
Expand Down Expand Up @@ -82,10 +80,6 @@ impl fmt::Display for DisconnectReason {
}

error_chain! {
foreign_links {
SocketIo(IoError) #[doc = "Socket IO error."];
}

errors {
#[doc = "Error concerning the network address parsing subsystem."]
AddressParse {
Expand Down Expand Up @@ -171,17 +165,6 @@ impl From<io::Error> for Error {
}
}

impl From<ethkey::Error> for Error {
fn from(_err: ethkey::Error) -> Self {
ErrorKind::Auth.into()
}
}

impl From<ethkey::crypto::Error> for Error {
fn from(_err: ethkey::crypto::Error) -> Self {
ErrorKind::Auth.into()
}
}

impl From<net::AddrParseError> for Error {
fn from(_err: net::AddrParseError) -> Self { ErrorKind::AddressParse.into() }
Expand Down
34 changes: 29 additions & 5 deletions substrate/network-libp2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,32 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

// tag::description[]
//! TODO: Missing doc
// end::description[]

#![recursion_limit="128"]
#![type_length_limit = "268435456"]

extern crate parking_lot;
extern crate fnv;
extern crate futures;
extern crate tokio;
extern crate tokio_executor;
extern crate tokio_io;
extern crate tokio_timer;
extern crate ethkey;
extern crate libc;
#[macro_use]
extern crate libp2p;
extern crate rand;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate smallvec;
extern crate bytes;
extern crate unsigned_varint;

extern crate ethcore_io as io;
extern crate ethereum_types;

#[macro_use]
Expand All @@ -44,17 +49,25 @@ extern crate log;
#[cfg(test)] #[macro_use]
extern crate assert_matches;

use libp2p::PeerId;

pub use connection_filter::{ConnectionFilter, ConnectionDirection};
pub use io::TimerToken;
pub use error::{Error, ErrorKind, DisconnectReason};
pub use libp2p::{Multiaddr, multiaddr::AddrComponent};
pub use traits::*;

pub type TimerToken = usize;

// TODO: remove as it is unused ; however modifying `network` causes a clusterfuck of dependencies
// resolve errors at the moment
mod connection_filter;
mod custom_proto;
mod error;
mod network_state;
mod node_handler;
mod secret;
mod service;
mod service_task;
mod swarm;
mod timeouts;
mod topology;
mod traits;
Expand All @@ -64,8 +77,19 @@ pub use service::NetworkService;

/// Check if node url is valid
pub fn validate_node_url(url: &str) -> Result<(), Error> {
match url.parse::<libp2p::multiaddr::Multiaddr>() {
match url.parse::<Multiaddr>() {
Ok(_) => Ok(()),
Err(_) => Err(ErrorKind::InvalidNodeId.into()),
}
}

/// Parses a string address and returns the component, if valid.
pub(crate) fn parse_str_addr(addr_str: &str) -> Result<(PeerId, Multiaddr), Error> {
let mut addr: Multiaddr = addr_str.parse().map_err(|_| ErrorKind::AddressParse)?;
let who = match addr.pop() {
Some(AddrComponent::P2P(key)) =>
PeerId::from_multihash(key).map_err(|_| ErrorKind::AddressParse)?,
_ => return Err(ErrorKind::AddressParse.into()),
};
Ok((who, addr))
}
Loading