Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 0ae8373

Browse files
committed
Backport #742 and #734
1 parent 204d059 commit 0ae8373

File tree

17 files changed

+3567
-2415
lines changed

17 files changed

+3567
-2415
lines changed

Cargo.lock

Lines changed: 135 additions & 185 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ substrate-extrinsic-pool = { path = "../../substrate/extrinsic-pool" }
2727
substrate-network = { path = "../../substrate/network" }
2828
substrate-network-libp2p = { path = "../../substrate/network-libp2p" }
2929
substrate-runtime-primitives = { path = "../../substrate/runtime/primitives" }
30+
substrate-primitives = { path = "../../substrate/primitives" }
3031
substrate-service = { path = "../../substrate/service" }
3132
substrate-telemetry = { path = "../../substrate/telemetry" }
3233
names = "0.11.0"

substrate/cli/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern crate substrate_network_libp2p as network_libp2p;
3737
extern crate substrate_runtime_primitives as runtime_primitives;
3838
extern crate substrate_extrinsic_pool;
3939
extern crate substrate_service as service;
40+
extern crate substrate_primitives as primitives;
4041
#[macro_use]
4142
extern crate slog; // needed until we can reexport `slog_info` from `substrate_telemetry`
4243
#[macro_use]
@@ -62,12 +63,14 @@ use service::{
6263
FactoryGenesis, PruningMode, ChainSpec,
6364
};
6465
use network::NonReservedPeerMode;
66+
use primitives::H256;
6567

6668
use std::io::{Write, Read, stdin, stdout};
6769
use std::iter;
6870
use std::fs::File;
6971
use std::net::{Ipv4Addr, SocketAddr};
7072
use std::path::{Path, PathBuf};
73+
use std::str::FromStr;
7174
use names::{Generator, Name};
7275
use regex::Regex;
7376

@@ -301,8 +304,8 @@ where
301304
];
302305
config.network.public_addresses = Vec::new();
303306
config.network.client_version = config.client_id();
304-
config.network.use_secret = match matches.value_of("node-key").map(|s| s.parse()) {
305-
Some(Ok(secret)) => Some(secret),
307+
config.network.use_secret = match matches.value_of("node-key").map(H256::from_str) {
308+
Some(Ok(secret)) => Some(secret.into()),
306309
Some(Err(err)) => return Err(format!("Error parsing node key: {}", err).into()),
307310
None => None,
308311
};

substrate/network-libp2p/Cargo.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ bytes = "0.4"
1111
error-chain = { version = "0.12", default-features = false }
1212
fnv = "1.0"
1313
futures = "0.1"
14-
libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev = "304e9c72c88bc97824f2734dc19d1b5f4556d346", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] }
15-
ethcore-io = { git = "https://github.com/paritytech/parity.git", rev = "202c54d42398fc4b49d67ffbf9070522e38f9360" }
16-
ethkey = { git = "https://github.com/paritytech/parity.git", rev = "202c54d42398fc4b49d67ffbf9070522e38f9360" }
14+
libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev = "2a7a48b4962cd01095ed634f7d0fb4dd2bddb7e4", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] }
1715
ethereum-types = "0.3"
1816
parking_lot = "0.5"
1917
libc = "0.2"
@@ -22,13 +20,13 @@ rand = "0.5.0"
2220
serde = "1.0.70"
2321
serde_derive = "1.0.70"
2422
serde_json = "1.0.24"
23+
smallvec = "0.6.5"
2524
tokio = "0.1"
25+
tokio-executor = "0.1"
2626
tokio-io = "0.1"
2727
tokio-timer = "0.2"
2828
unsigned-varint = { version = "0.2.1", features = ["codec"] }
2929

3030
[dev-dependencies]
3131
assert_matches = "1.2"
32-
parity-bytes = { git = "https://github.com/paritytech/parity-common.git" }
33-
ethcore-io = { git = "https://github.com/paritytech/parity.git", rev = "202c54d42398fc4b49d67ffbf9070522e38f9360" }
34-
ethcore-logger = { git = "https://github.com/paritytech/parity.git", rev = "202c54d42398fc4b49d67ffbf9070522e38f9360" }
32+
parity-bytes = "0.1"

substrate/network-libp2p/src/custom_proto.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ where C: AsyncRead + AsyncWrite + Send + 'static, // TODO: 'static :-/
233233
pub struct RegisteredProtocols<T>(pub Vec<RegisteredProtocol<T>>);
234234

235235
impl<T> RegisteredProtocols<T> {
236+
/// Returns the number of protocols.
237+
#[inline]
238+
pub fn len(&self) -> usize {
239+
self.0.len()
240+
}
241+
236242
/// Finds a protocol in the list by its id.
237243
pub fn find_protocol(&self, protocol: ProtocolId)
238244
-> Option<&RegisteredProtocol<T>> {

substrate/network-libp2p/src/error.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
use std::{io, net, fmt};
1818
use libc::{ENFILE, EMFILE};
19-
use io::IoError;
20-
use ethkey;
2119

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

8482
error_chain! {
85-
foreign_links {
86-
SocketIo(IoError) #[doc = "Socket IO error."];
87-
}
88-
8983
errors {
9084
#[doc = "Error concerning the network address parsing subsystem."]
9185
AddressParse {
@@ -171,17 +165,6 @@ impl From<io::Error> for Error {
171165
}
172166
}
173167

174-
impl From<ethkey::Error> for Error {
175-
fn from(_err: ethkey::Error) -> Self {
176-
ErrorKind::Auth.into()
177-
}
178-
}
179-
180-
impl From<ethkey::crypto::Error> for Error {
181-
fn from(_err: ethkey::crypto::Error) -> Self {
182-
ErrorKind::Auth.into()
183-
}
184-
}
185168

186169
impl From<net::AddrParseError> for Error {
187170
fn from(_err: net::AddrParseError) -> Self { ErrorKind::AddressParse.into() }

substrate/network-libp2p/src/lib.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,32 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
1616

17+
// tag::description[]
18+
//! TODO: Missing doc
19+
// end::description[]
20+
1721
#![recursion_limit="128"]
1822
#![type_length_limit = "268435456"]
1923

2024
extern crate parking_lot;
2125
extern crate fnv;
2226
extern crate futures;
2327
extern crate tokio;
28+
extern crate tokio_executor;
2429
extern crate tokio_io;
2530
extern crate tokio_timer;
26-
extern crate ethkey;
2731
extern crate libc;
32+
#[macro_use]
2833
extern crate libp2p;
2934
extern crate rand;
3035
extern crate serde;
3136
#[macro_use]
3237
extern crate serde_derive;
3338
extern crate serde_json;
39+
extern crate smallvec;
3440
extern crate bytes;
3541
extern crate unsigned_varint;
3642

37-
extern crate ethcore_io as io;
3843
extern crate ethereum_types;
3944

4045
#[macro_use]
@@ -44,17 +49,25 @@ extern crate log;
4449
#[cfg(test)] #[macro_use]
4550
extern crate assert_matches;
4651

52+
use libp2p::PeerId;
53+
4754
pub use connection_filter::{ConnectionFilter, ConnectionDirection};
48-
pub use io::TimerToken;
4955
pub use error::{Error, ErrorKind, DisconnectReason};
5056
pub use libp2p::{Multiaddr, multiaddr::AddrComponent};
5157
pub use traits::*;
5258

59+
pub type TimerToken = usize;
60+
61+
// TODO: remove as it is unused ; however modifying `network` causes a clusterfuck of dependencies
62+
// resolve errors at the moment
5363
mod connection_filter;
5464
mod custom_proto;
5565
mod error;
56-
mod network_state;
66+
mod node_handler;
67+
mod secret;
5768
mod service;
69+
mod service_task;
70+
mod swarm;
5871
mod timeouts;
5972
mod topology;
6073
mod traits;
@@ -64,8 +77,19 @@ pub use service::NetworkService;
6477

6578
/// Check if node url is valid
6679
pub fn validate_node_url(url: &str) -> Result<(), Error> {
67-
match url.parse::<libp2p::multiaddr::Multiaddr>() {
80+
match url.parse::<Multiaddr>() {
6881
Ok(_) => Ok(()),
6982
Err(_) => Err(ErrorKind::InvalidNodeId.into()),
7083
}
7184
}
85+
86+
/// Parses a string address and returns the component, if valid.
87+
pub(crate) fn parse_str_addr(addr_str: &str) -> Result<(PeerId, Multiaddr), Error> {
88+
let mut addr: Multiaddr = addr_str.parse().map_err(|_| ErrorKind::AddressParse)?;
89+
let who = match addr.pop() {
90+
Some(AddrComponent::P2P(key)) =>
91+
PeerId::from_multihash(key).map_err(|_| ErrorKind::AddressParse)?,
92+
_ => return Err(ErrorKind::AddressParse.into()),
93+
};
94+
Ok((who, addr))
95+
}

0 commit comments

Comments
 (0)