Removed ethcore-util dependency from ethcore-network (#7180)

* Removed ethcore-util dependency

* Removed snappy
This commit is contained in:
Arkadiy Paronyan 2017-12-02 10:08:04 +01:00 committed by GitHub
parent c544c3e518
commit dde6baedec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 36 additions and 197 deletions

25
Cargo.lock generated
View File

@ -529,7 +529,7 @@ dependencies = [
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"semantic_version 0.1.0",
"snappy 0.1.0",
"snappy 0.1.0 (git+https://github.com/paritytech/rust-snappy)",
"stats 0.1.0",
"table 0.1.0",
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
@ -648,7 +648,6 @@ dependencies = [
"ethcore-devtools 1.9.0",
"ethcore-io 1.9.0",
"ethcore-logger 1.9.0",
"ethcore-util 1.9.0",
"ethcrypto 0.1.0",
"ethkey 0.3.0",
"igd 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -665,7 +664,7 @@ dependencies = [
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"snappy 0.1.0",
"snappy 0.1.0 (git+https://github.com/paritytech/rust-snappy)",
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -746,7 +745,6 @@ dependencies = [
"parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie 0.1.0",
"rlp 0.2.1",
"rocksdb 0.4.5 (git+https://github.com/paritytech/rust-rocksdb)",
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2670,7 +2668,7 @@ dependencies = [
[[package]]
name = "rocksdb"
version = "0.4.5"
source = "git+https://github.com/paritytech/rust-rocksdb#4364caec4dd5da1a1d78c39276774ee65bf55c7d"
source = "git+https://github.com/paritytech/rust-rocksdb#8c4ad5411c141abc63d562d411053f7ebc1aa00c"
dependencies = [
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
"local-encoding 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2680,10 +2678,11 @@ dependencies = [
[[package]]
name = "rocksdb-sys"
version = "0.3.0"
source = "git+https://github.com/paritytech/rust-rocksdb#4364caec4dd5da1a1d78c39276774ee65bf55c7d"
source = "git+https://github.com/paritytech/rust-rocksdb#8c4ad5411c141abc63d562d411053f7ebc1aa00c"
dependencies = [
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
"snappy-sys 0.1.0 (git+https://github.com/paritytech/rust-snappy)",
]
[[package]]
@ -2970,9 +2969,19 @@ dependencies = [
[[package]]
name = "snappy"
version = "0.1.0"
source = "git+https://github.com/paritytech/rust-snappy#858eac97192ea25d18d3f3626a8cc13ca0b175bb"
dependencies = [
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
"rocksdb 0.4.5 (git+https://github.com/paritytech/rust-rocksdb)",
"snappy-sys 0.1.0 (git+https://github.com/paritytech/rust-snappy)",
]
[[package]]
name = "snappy-sys"
version = "0.1.0"
source = "git+https://github.com/paritytech/rust-snappy#858eac97192ea25d18d3f3626a8cc13ca0b175bb"
dependencies = [
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -3763,6 +3772,8 @@ dependencies = [
"checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23"
"checksum smallvec 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c8cbcd6df1e117c2210e13ab5109635ad68a929fcbb8964dc965b76cb5ee013"
"checksum smallvec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8fcd03faf178110ab0334d74ca9631d77f94c8c11cc77fcb59538abf0025695d"
"checksum snappy 0.1.0 (git+https://github.com/paritytech/rust-snappy)" = "<none>"
"checksum snappy-sys 0.1.0 (git+https://github.com/paritytech/rust-snappy)" = "<none>"
"checksum spmc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cd1f11d1fb5fd41834e55ce0b85a186efbf2f2afd9fdb09e2c8d72f9bff1ad1a"
"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b"
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"

View File

@ -54,7 +54,7 @@ kvdb = { path = "../util/kvdb" }
kvdb-rocksdb = { path = "../util/kvdb-rocksdb" }
kvdb-memorydb = { path = "../util/kvdb-memorydb" }
util-error = { path = "../util/error" }
snappy = { path = "../util/snappy" }
snappy = { git = "https://github.com/paritytech/rust-snappy" }
migration = { path = "../util/migration" }
macros = { path = "../util/macros" }
rust-crypto = "0.2.34"

View File

@ -25,7 +25,7 @@ use cli::{Args, ArgsError};
use hash::keccak;
use bigint::prelude::U256;
use bigint::hash::H256;
use util::{version_data, Address};
use util::{version_data, Address, version};
use bytes::Bytes;
use ansi_term::Colour;
use ethsync::{NetworkConfiguration, validate_node_url, self};
@ -751,6 +751,7 @@ impl Configuration {
ret.config_path = Some(net_path.to_str().unwrap().to_owned());
ret.reserved_nodes = self.init_reserved_nodes()?;
ret.allow_non_reserved = !self.args.flag_reserved_only;
ret.client_version = version();
Ok(ret)
}

View File

@ -213,6 +213,7 @@ pub fn default_network_config() -> ::ethsync::NetworkConfiguration {
ip_filter: IpFilter::default(),
reserved_nodes: Vec::new(),
allow_non_reserved: true,
client_version: ::util::version(),
}
}

View File

@ -546,6 +546,8 @@ pub struct NetworkConfiguration {
pub allow_non_reserved: bool,
/// IP Filtering
pub ip_filter: IpFilter,
/// Client version string
pub client_version: String,
}
impl NetworkConfiguration {
@ -578,6 +580,7 @@ impl NetworkConfiguration {
reserved_nodes: self.reserved_nodes,
ip_filter: self.ip_filter,
non_reserved_mode: if self.allow_non_reserved { NonReservedPeerMode::Accept } else { NonReservedPeerMode::Deny },
client_version: self.client_version,
})
}
}
@ -601,6 +604,7 @@ impl From<BasicNetworkConfiguration> for NetworkConfiguration {
reserved_nodes: other.reserved_nodes,
ip_filter: other.ip_filter,
allow_non_reserved: match other.non_reserved_mode { NonReservedPeerMode::Accept => true, _ => false } ,
client_version: other.client_version,
}
}
}

View File

@ -11,7 +11,6 @@ build = "build.rs"
log = "0.3"
env_logger = "0.4"
rustc-hex = "1.0"
rocksdb = { git = "https://github.com/paritytech/rust-rocksdb" }
eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" }
elastic-array = "0.9"
rlp = { path = "rlp" }

View File

@ -22,7 +22,6 @@ parking_lot = "0.4"
ansi_term = "0.9"
rustc-hex = "1.0"
ethcore-io = { path = "../io" }
ethcore-util = { path = ".." }
ethcore-bigint = { path = "../bigint" }
ethcore-bytes = { path = "../bytes" }
ethkey = { path = "../../ethkey" }
@ -32,7 +31,7 @@ path = { path = "../path" }
ethcore-logger = { path ="../../logger" }
ipnetwork = "0.12.6"
keccak-hash = { path = "../hash" }
snappy = { path = "../snappy" }
snappy = { git = "https://github.com/paritytech/rust-snappy" }
serde_json = "1.0"
error-chain = { version = "0.11", default-features = false }

View File

@ -30,7 +30,6 @@ use mio::*;
use mio::deprecated::{EventLoop};
use mio::tcp::*;
use bigint::hash::*;
use util::version;
use rlp::*;
use session::{Session, SessionInfo, SessionData};
use io::*;
@ -108,6 +107,8 @@ pub struct NetworkConfiguration {
pub non_reserved_mode: NonReservedPeerMode,
/// IP filter
pub ip_filter: IpFilter,
/// Client identifier
pub client_version: String,
}
impl Default for NetworkConfiguration {
@ -136,6 +137,7 @@ impl NetworkConfiguration {
ip_filter: IpFilter::default(),
reserved_nodes: Vec::new(),
non_reserved_mode: NonReservedPeerMode::Accept,
client_version: "Parity-network".into(),
}
}
@ -331,8 +333,6 @@ pub struct HostInfo {
nonce: H256,
/// RLPx protocol version
pub protocol_version: u32,
/// Client identifier
pub client_version: String,
/// Registered capabilities (handlers)
pub capabilities: Vec<CapabilityInfo>,
/// Local address + discovery port
@ -357,6 +357,10 @@ impl HostInfo {
self.nonce = keccak(&self.nonce);
self.nonce
}
pub fn client_version(&self) -> &str {
&self.config.client_version
}
}
type SharedSession = Arc<Mutex<Session>>;
@ -423,7 +427,6 @@ impl Host {
config: config,
nonce: H256::random(),
protocol_version: PROTOCOL_VERSION,
client_version: version(),
capabilities: Vec::new(),
public_endpoint: None,
local_endpoint: local_endpoint,
@ -519,10 +522,6 @@ impl Host {
Ok(())
}
pub fn client_version() -> String {
version()
}
pub fn external_url(&self) -> Option<String> {
let info = self.info.read();
info.public_endpoint.as_ref().map(|e| format!("{}", Node::new(info.id().clone(), e.clone())))

View File

@ -59,7 +59,6 @@
#![recursion_limit="128"]
extern crate ethcore_io as io;
extern crate ethcore_util as util;
extern crate ethcore_bigint as bigint;
extern crate ethcore_bytes;
extern crate parking_lot;

View File

@ -59,10 +59,9 @@ impl NetworkService {
let io_service = IoService::<NetworkIoMessage>::start()?;
let stats = Arc::new(NetworkStats::new());
let host_info = Host::client_version();
Ok(NetworkService {
io_service: io_service,
host_info: host_info,
host_info: config.client_version.clone(),
stats: stats,
host: RwLock::new(None),
config: config,

View File

@ -489,7 +489,7 @@ impl Session {
rlp.append_raw(&[PACKET_HELLO as u8], 0);
rlp.begin_list(5)
.append(&host.protocol_version)
.append(&host.client_version)
.append(&host.client_version())
.append_list(&host.capabilities)
.append(&host.local_endpoint.address.port())
.append(host.id());

View File

@ -1,8 +0,0 @@
[package]
name = "snappy"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
libc = "0.2.7"
rocksdb = { git = "https://github.com/paritytech/rust-rocksdb" }

View File

@ -1,164 +0,0 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Snappy compression bindings.
extern crate libc;
use std::fmt;
use libc::{c_char, c_int, size_t};
const SNAPPY_OK: c_int = 0;
const SNAPPY_INVALID_INPUT: c_int = 1;
const SNAPPY_BUFFER_TOO_SMALL: c_int = 2;
#[link(name = "snappy", kind = "static")]
extern {
fn snappy_compress(
input: *const c_char,
input_len: size_t,
compressed: *mut c_char,
compressed_len: *mut size_t
) -> c_int;
fn snappy_max_compressed_length(source_len: size_t) -> size_t;
fn snappy_uncompress(
compressed: *const c_char,
compressed_len: size_t,
uncompressed: *mut c_char,
uncompressed_len: *mut size_t,
) -> c_int;
fn snappy_uncompressed_length(
compressed: *const c_char,
compressed_len: size_t,
result: *mut size_t,
) -> c_int;
fn snappy_validate_compressed_buffer(
compressed: *const c_char,
compressed_len: size_t,
) -> c_int;
}
/// Attempted to decompress an uncompressed buffer.
#[derive(Debug)]
pub struct InvalidInput;
impl std::error::Error for InvalidInput {
fn description(&self) -> &str {
"Attempted snappy decompression with invalid input"
}
}
impl fmt::Display for InvalidInput {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Attempted snappy decompression with invalid input")
}
}
/// The maximum compressed length given a size.
pub fn max_compressed_len(len: usize) -> usize {
unsafe { snappy_max_compressed_length(len as size_t) as usize }
}
/// How large the given data will be when decompressed.
pub fn decompressed_len(compressed: &[u8]) -> Result<usize, InvalidInput> {
let mut size: size_t = 0;
let len = compressed.len() as size_t;
let status = unsafe { snappy_uncompressed_length(compressed.as_ptr() as *const c_char, len, &mut size) };
if status == SNAPPY_INVALID_INPUT {
Err(InvalidInput)
} else {
Ok(size)
}
}
/// Compress a buffer using snappy.
pub fn compress(input: &[u8]) -> Vec<u8> {
let mut buf = Vec::new();
compress_into(input, &mut buf);
buf
}
/// Compress a buffer using snappy, writing the result into
/// the given output buffer, growing it if necessary.
/// Otherwise, returns the length of the compressed data.
pub fn compress_into(input: &[u8], output: &mut Vec<u8>) -> usize {
let mut len = max_compressed_len(input.len());
if output.len() < len {
output.resize(len, 0);
}
let status = unsafe {
snappy_compress(
input.as_ptr() as *const c_char,
input.len() as size_t,
output.as_mut_ptr() as *mut c_char,
&mut len as &mut size_t,
)
};
match status {
SNAPPY_OK => len,
SNAPPY_INVALID_INPUT => panic!("snappy compression has no concept of invalid input"),
SNAPPY_BUFFER_TOO_SMALL => panic!("buffer cannot be too small, the capacity was just ensured."),
_ => panic!("snappy returned unspecified status"),
}
}
/// Decompress a buffer using snappy. Will return an error if the buffer is not snappy-compressed.
pub fn decompress(input: &[u8]) -> Result<Vec<u8>, InvalidInput> {
let mut v = Vec::new();
decompress_into(input, &mut v).map(|_| v)
}
/// Decompress a buffer using snappy, writing the result into
/// the given output buffer, growing it if necessary.
/// Will error if the input buffer is not snappy-compressed.
/// Otherwise, returns the length of the decompressed data.
pub fn decompress_into(input: &[u8], output: &mut Vec<u8>) -> Result<usize, InvalidInput> {
let mut len = decompressed_len(input)?;
if output.len() < len {
output.resize(len, 0);
}
let status = unsafe {
snappy_uncompress(
input.as_ptr() as *const c_char,
input.len() as size_t,
output.as_mut_ptr() as *mut c_char,
&mut len as &mut size_t,
)
};
match status {
SNAPPY_OK => Ok(len as usize),
SNAPPY_INVALID_INPUT => Err(InvalidInput),
SNAPPY_BUFFER_TOO_SMALL => panic!("buffer cannot be too small, size was just set to large enough."),
_ => panic!("snappy returned unspecified status"),
}
}
/// Validate a compressed buffer. True if valid, false if not.
pub fn validate_compressed_buffer(input: &[u8]) -> bool {
let status = unsafe { snappy_validate_compressed_buffer(input.as_ptr() as *const c_char, input.len() as size_t )};
status == SNAPPY_OK
}

View File

@ -88,7 +88,6 @@
//! ```
extern crate rustc_hex;
extern crate rocksdb;
extern crate env_logger;
extern crate secp256k1;
extern crate elastic_array;