Merge branch 'master' into db

This commit is contained in:
Nikolay Volf
2016-02-21 15:05:36 +03:00
27 changed files with 184 additions and 109 deletions

View File

@@ -30,6 +30,7 @@ clippy = { version = "0.0.42", optional = true }
json-tests = { path = "json-tests" }
target_info = "0.1.0"
igd = "0.4.2"
ethcore-devtools = { path = "../devtools" }
libc = "0.2.7"
[features]

View File

@@ -635,7 +635,7 @@ mod tests {
use std::str::FromStr;
#[test]
#[allow(eq_op)]
#[cfg_attr(feature="dev", allow(eq_op))]
fn hash() {
let h = H64([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]);
assert_eq!(H64::from_str("0123456789abcdef").unwrap(), h);

View File

@@ -1030,7 +1030,7 @@ mod file_tests {
mod directory_tests {
use super::{KeyDirectory, new_uuid, uuid_to_string, KeyFileContent, KeyFileCrypto, MAX_CACHE_USAGE_TRACK};
use common::*;
use tests::helpers::*;
use devtools::*;
#[test]
fn key_directory_locates_keys() {
@@ -1110,7 +1110,7 @@ mod directory_tests {
mod specs {
use super::*;
use common::*;
use tests::helpers::*;
use devtools::*;
#[test]
fn can_initiate_key_directory() {

View File

@@ -70,7 +70,7 @@ impl SecretStore {
}
#[cfg(test)]
fn new_test(path: &::tests::helpers::RandomTempPath) -> SecretStore {
fn new_test(path: &::devtools::RandomTempPath) -> SecretStore {
SecretStore {
directory: KeyDirectory::new(path.as_path())
}
@@ -203,7 +203,7 @@ mod vector_tests {
#[cfg(test)]
mod tests {
use super::*;
use tests::helpers::*;
use devtools::*;
use common::*;
#[test]

View File

@@ -106,6 +106,7 @@ extern crate serde;
#[macro_use]
extern crate log as rlog;
extern crate igd;
extern crate ethcore_devtools as devtools;
extern crate libc;
pub mod standard;
@@ -163,5 +164,3 @@ pub use io::*;
pub use log::*;
pub use kvdb::*;
#[cfg(test)]
mod tests;

View File

@@ -174,8 +174,8 @@ pub struct NetworkContext<'s, Message> where Message: Send + Sync + Clone + 'sta
impl<'s, Message> NetworkContext<'s, Message> where Message: Send + Sync + Clone + 'static, {
/// Create a new network IO access point. Takes references to all the data that can be updated within the IO handler.
fn new(io: &'s IoContext<NetworkIoMessage<Message>>,
protocol: ProtocolId,
fn new(io: &'s IoContext<NetworkIoMessage<Message>>,
protocol: ProtocolId,
session: Option<StreamToken>, sessions: Arc<RwLock<Slab<SharedSession>>>) -> NetworkContext<'s, Message> {
NetworkContext {
io: io,
@@ -337,9 +337,9 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
// Setup the server socket
let tcp_listener = TcpListener::bind(&listen_address).unwrap();
let keys = if let Some(ref secret) = config.use_secret {
KeyPair::from_secret(secret.clone()).unwrap()
} else {
let keys = if let Some(ref secret) = config.use_secret {
KeyPair::from_secret(secret.clone()).unwrap()
} else {
config.config_path.clone().and_then(|ref p| load_key(&Path::new(&p)))
.map_or_else(|| {
let key = KeyPair::create().unwrap();
@@ -351,7 +351,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
|s| KeyPair::from_secret(s).expect("Error creating node secret key"))
};
let discovery = if config.discovery_enabled && !config.pin {
Some(Discovery::new(&keys, listen_address.clone(), public_endpoint.clone(), DISCOVERY))
Some(Discovery::new(&keys, listen_address.clone(), public_endpoint.clone(), DISCOVERY))
} else { None };
let path = config.config_path.clone();
let mut host = Host::<Message> {
@@ -546,7 +546,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
if let Err(e) = h.writable(io, &self.info.read().unwrap()) {
debug!(target: "net", "Handshake write error: {}:{:?}", token, e);
}
}
}
}
fn session_writable(&self, token: StreamToken, io: &IoContext<NetworkIoMessage<Message>>) {
@@ -557,7 +557,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
debug!(target: "net", "Session write error: {}:{:?}", token, e);
}
io.update_registration(token).unwrap_or_else(|e| debug!(target: "net", "Session registration error: {:?}", e));
}
}
}
fn connection_closed(&self, token: TimerToken, io: &IoContext<NetworkIoMessage<Message>>) {
@@ -619,7 +619,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
},
Ok(SessionData::None) => {},
}
}
}
if kill {
self.kill_connection(token, io, true); //TODO: mark connection as dead an check in kill_connection
}
@@ -639,7 +639,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
if handshakes.get(token).is_none() {
return;
}
// turn a handshake into a session
let mut sessions = self.sessions.write().unwrap();
let mut h = handshakes.remove(token).unwrap();
@@ -782,7 +782,7 @@ impl<Message> IoHandler<NetworkIoMessage<Message>> for Host<Message> where Messa
}
io.update_registration(DISCOVERY).expect("Error updating discovery registration");
},
TCP_ACCEPT => self.accept(io),
TCP_ACCEPT => self.accept(io),
_ => panic!("Received unknown readable token"),
}
}
@@ -858,7 +858,7 @@ impl<Message> IoHandler<NetworkIoMessage<Message>> for Host<Message> where Messa
let session = { self.sessions.read().unwrap().get(*peer).cloned() };
if let Some(session) = session {
session.lock().unwrap().disconnect(DisconnectReason::DisconnectRequested);
}
}
self.kill_connection(*peer, io, false);
},
NetworkIoMessage::User(ref message) => {
@@ -961,14 +961,14 @@ fn load_key(path: &Path) -> Option<Secret> {
let mut buf = String::new();
match file.read_to_string(&mut buf) {
Ok(_) => {},
Err(e) => {
Err(e) => {
warn!("Error reading key file: {:?}", e);
return None;
}
}
match Secret::from_str(&buf) {
Ok(key) => Some(key),
Err(e) => {
Err(e) => {
warn!("Error parsing key file: {:?}", e);
None
}
@@ -977,7 +977,7 @@ fn load_key(path: &Path) -> Option<Secret> {
#[test]
fn key_save_load() {
use tests::helpers::RandomTempPath;
use ::devtools::RandomTempPath;
let temp_path = RandomTempPath::create_dir();
let key = H256::random();
save_key(temp_path.as_path(), &key);

View File

@@ -159,7 +159,7 @@ impl Display for Node {
Ok(())
}
}
impl FromStr for Node {
type Err = UtilError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -265,7 +265,7 @@ impl NodeTable {
let node_ids = self.nodes();
for i in 0 .. node_ids.len() {
let node = self.nodes.get(&node_ids[i]).unwrap();
json.push_str(&format!("\t{{ \"url\": \"{}\", \"failures\": {} }}{}\n", node, node.failures, if i == node_ids.len() - 1 {""} else {","}))
json.push_str(&format!("\t{{ \"url\": \"{}\", \"failures\": {} }}{}\n", node, node.failures, if i == node_ids.len() - 1 {""} else {","}))
}
json.push_str("]\n");
json.push_str("}");
@@ -297,14 +297,14 @@ impl NodeTable {
let mut buf = String::new();
match file.read_to_string(&mut buf) {
Ok(_) => {},
Err(e) => {
Err(e) => {
warn!("Error reading node table file: {:?}", e);
return nodes;
}
}
let json = match Json::from_str(&buf) {
Ok(json) => json,
Err(e) => {
Err(e) => {
warn!("Error parsing node table file: {:?}", e);
return nodes;
}
@@ -344,7 +344,7 @@ mod tests {
use std::str::FromStr;
use std::net::*;
use hash::*;
use tests::helpers::*;
use devtools::*;
#[test]
fn endpoint_parse() {

View File

@@ -18,7 +18,6 @@
use std::thread;
use std::ops::DerefMut;
use std::any::Any;
use std::sync::{Arc, Mutex};
/// Thread-safe closure for handling possible panics
@@ -73,9 +72,8 @@ impl PanicHandler {
/// Invoke closure and catch any possible panics.
/// In case of panic notifies all listeners about it.
#[cfg_attr(feature="dev", allow(deprecated))]
// TODO [todr] catch_panic is deprecated but panic::recover has different bounds (not allowing mutex)
pub fn catch_panic<G, R>(&self, g: G) -> thread::Result<R> where G: FnOnce() -> R + Send + 'static {
let guard = PanicGuard { handler: self };
let _guard = PanicGuard { handler: self };
let result = g();
Ok(result)
}
@@ -108,13 +106,6 @@ impl<F> OnPanicListener for F
}
}
fn convert_to_string(t: &Box<Any + Send>) -> Option<String> {
let as_str = t.downcast_ref::<&'static str>().cloned().map(|t| t.to_owned());
let as_string = t.downcast_ref::<String>().cloned();
as_str.or(as_string)
}
#[test]
#[ignore] // panic forwarding doesnt work on the same thread in beta
fn should_notify_listeners_about_panic () {

View File

@@ -1,31 +0,0 @@
use common::*;
use std::path::PathBuf;
use std::fs::{remove_dir_all};
use std::env;
pub struct RandomTempPath {
path: PathBuf
}
impl RandomTempPath {
pub fn create_dir() -> RandomTempPath {
let mut dir = env::temp_dir();
dir.push(H32::random().hex());
fs::create_dir_all(dir.as_path()).unwrap();
RandomTempPath {
path: dir.clone()
}
}
pub fn as_path(&self) -> &PathBuf {
&self.path
}
}
impl Drop for RandomTempPath {
fn drop(&mut self) {
if let Err(e) = remove_dir_all(self.as_path()) {
panic!("failed to remove temp directory, probably something failed to destroyed ({})", e);
}
}
}

View File

@@ -1 +0,0 @@
pub mod helpers;

View File

@@ -991,7 +991,7 @@ mod tests {
}
#[test]
#[allow(eq_op)]
#[cfg_attr(feature="dev", allow(eq_op))]
pub fn uint256_comp_test() {
let small = U256([10u64, 0, 0, 0]);
let big = U256([0x8C8C3EE70C644118u64, 0x0209E7378231E632, 0, 0]);