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

Commit

Permalink
Remove dependency on the parity repo (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar authored and gavofyork committed Sep 13, 2018
1 parent 5b14573 commit 00e5f23
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 263 deletions.
323 changes: 102 additions & 221 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ substrate-client = { path = "../../core/client" }
substrate-network = { path = "../../core/network" }
substrate-network-libp2p = { path = "../../core/network-libp2p" }
sr-primitives = { path = "../../core/sr-primitives" }
substrate-primitives = { path = "../../core/primitives" }
substrate-service = { path = "../../core/service" }
substrate-telemetry = { path = "../../core/telemetry" }
names = "0.11.0"
Expand Down
7 changes: 5 additions & 2 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern crate substrate_network as network;
extern crate substrate_network_libp2p as network_libp2p;
extern crate sr_primitives as runtime_primitives;
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 @@ -64,13 +65,15 @@ use service::{
FactoryGenesis, PruningMode, ChainSpec,
};
use network::NonReservedPeerMode;
use primitives::H256;

use std::io::{Write, Read, stdin, stdout};
use std::iter;
use std::fs;
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 @@ -311,8 +314,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
6 changes: 1 addition & 5 deletions core/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" }
ethkey = { git = "https://github.com/paritytech/parity.git" }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev = "5980a4538ef6fc8af450893acb01290eaed136de", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] }
ethereum-types = "0.3"
parking_lot = "0.5"
libc = "0.2"
Expand All @@ -30,5 +28,3 @@ unsigned-varint = { version = "0.2.1", features = ["codec"] }
[dev-dependencies]
assert_matches = "1.2"
parity-bytes = "0.1"
ethcore-io = { git = "https://github.com/paritytech/parity.git" }
ethcore-logger = { git = "https://github.com/paritytech/parity.git" }
17 changes: 0 additions & 17 deletions core/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
5 changes: 2 additions & 3 deletions core/network-libp2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extern crate futures;
extern crate tokio;
extern crate tokio_io;
extern crate tokio_timer;
extern crate ethkey;
extern crate libc;
extern crate libp2p;
extern crate rand;
Expand All @@ -38,7 +37,6 @@ extern crate serde_json;
extern crate bytes;
extern crate unsigned_varint;

extern crate ethcore_io as io;
extern crate ethereum_types;

#[macro_use]
Expand All @@ -49,11 +47,12 @@ extern crate log;
extern crate assert_matches;

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;

mod connection_filter;
mod custom_proto;
mod error;
Expand Down
6 changes: 4 additions & 2 deletions core/network-libp2p/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ use std::iter;
use std::net::Ipv4Addr;
use std::str;
use std::time::Duration;
use io::TimerToken;
use TimerToken;
use libp2p::{multiaddr::AddrComponent, Multiaddr};
use error::Error;
use ethkey::Secret;
use ethereum_types::H512;

/// Protocol handler level packet id
Expand All @@ -37,6 +36,9 @@ pub type NodeId = H512;
/// Local (temporary) peer session ID.
pub type NodeIndex = usize;

/// secio secret key;
pub type Secret = [u8; 32];

/// Shared session information
#[derive(Debug, Clone)]
pub struct SessionInfo {
Expand Down
4 changes: 1 addition & 3 deletions core/network-libp2p/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ pub fn build_transport(
mplex_config.max_buffer_len(usize::MAX);

let base = libp2p::CommonTransport::new()
.with_upgrade(secio::SecioConfig {
key: local_private_key,
})
.with_upgrade(secio::SecioConfig::new(local_private_key))
.and_then(move |out, endpoint, client_addr| {
let upgrade = upgrade::or(
upgrade::map(mplex_config, either::EitherOutput::First),
Expand Down
8 changes: 1 addition & 7 deletions core/network-libp2p/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

extern crate parking_lot;
extern crate parity_bytes;
extern crate ethcore_io as io;
extern crate ethcore_logger;
extern crate substrate_network_libp2p;
extern crate ethkey;

use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
use std::sync::Arc;
Expand All @@ -28,8 +25,7 @@ use std::time::*;
use parking_lot::Mutex;
use parity_bytes::Bytes;
use substrate_network_libp2p::*;
use ethkey::{Random, Generator};
use io::TimerToken;
use TimerToken;

pub struct TestProtocol {
drop_session: bool,
Expand Down Expand Up @@ -102,9 +98,7 @@ fn net_service() {
#[test]
#[ignore] // TODO: how is this test even supposed to work?
fn net_disconnect() {
let key1 = Random.generate().unwrap();
let mut config1 = NetworkConfiguration::new_local();
config1.use_secret = Some(key1.secret().clone());
config1.boot_nodes = vec![ ];
let handler1 = Arc::new(TestProtocol::new(false));
let service1 = NetworkService::new(config1, vec![(handler1.clone(), *b"tst", &[(42u8, 1), (43u8, 1)])]).unwrap();
Expand Down
1 change: 0 additions & 1 deletion core/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ bitflags = "1.0"
futures = "0.1.17"
linked-hash-map = "0.5"
rustc-hex = "1.0"
ethcore-io = { git = "https://github.com/paritytech/parity.git" }
substrate-primitives = { path = "../../core/primitives" }
substrate-client = { path = "../../core/client" }
sr-primitives = { path = "../../core/sr-primitives" }
Expand Down
1 change: 0 additions & 1 deletion core/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//! Allows attachment of an optional subprotocol for chain-specific requests.
// end::description[]

extern crate ethcore_io as core_io;
extern crate linked_hash_map;
extern crate parking_lot;
extern crate substrate_primitives as primitives;
Expand Down
3 changes: 2 additions & 1 deletion core/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use futures::sync::{oneshot, mpsc};
use network_libp2p::{NetworkProtocolHandler, NetworkContext, NodeIndex, ProtocolId,
NetworkConfiguration , NonReservedPeerMode, ErrorKind};
use network_libp2p::{NetworkService};
use core_io::{TimerToken};
use io::NetSyncIo;
use protocol::{Protocol, ProtocolContext, Context, ProtocolStatus, PeerInfo as ProtocolPeerInfo};
use config::{ProtocolConfig};
Expand All @@ -39,6 +38,8 @@ pub type FetchFuture = oneshot::Receiver<Vec<u8>>;
/// Type that represents bft messages stream.
pub type BftMessageStream<B> = mpsc::UnboundedReceiver<LocalizedBftMessage<B>>;

type TimerToken = usize;

const TICK_TOKEN: TimerToken = 0;
const TICK_TIMEOUT: Duration = Duration::from_millis(1000);

Expand Down

0 comments on commit 00e5f23

Please sign in to comment.