Split IO and network crates (#1828)
* Abort on panic * Split IO and network crates * Restore panic handler * Fixed doc tests
This commit is contained in:
parent
08f30fc1a8
commit
05bfdc508e
104
Cargo.lock
generated
104
Cargo.lock
generated
@ -11,6 +11,7 @@ dependencies = [
|
|||||||
"ethcore 1.3.0",
|
"ethcore 1.3.0",
|
||||||
"ethcore-dapps 1.3.0",
|
"ethcore-dapps 1.3.0",
|
||||||
"ethcore-devtools 1.3.0",
|
"ethcore-devtools 1.3.0",
|
||||||
|
"ethcore-io 1.3.0",
|
||||||
"ethcore-ipc 1.3.0",
|
"ethcore-ipc 1.3.0",
|
||||||
"ethcore-ipc-codegen 1.3.0",
|
"ethcore-ipc-codegen 1.3.0",
|
||||||
"ethcore-ipc-hypervisor 1.2.0",
|
"ethcore-ipc-hypervisor 1.2.0",
|
||||||
@ -91,11 +92,6 @@ name = "bit-vec"
|
|||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "0.3.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@ -106,11 +102,6 @@ name = "bitflags"
|
|||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blastfig"
|
name = "blastfig"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
@ -136,15 +127,6 @@ name = "cfg-if"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "chrono"
|
|
||||||
version = "0.2.22"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clippy"
|
name = "clippy"
|
||||||
version = "0.0.80"
|
version = "0.0.80"
|
||||||
@ -264,6 +246,7 @@ dependencies = [
|
|||||||
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ethash 1.3.0",
|
"ethash 1.3.0",
|
||||||
"ethcore-devtools 1.3.0",
|
"ethcore-devtools 1.3.0",
|
||||||
|
"ethcore-io 1.3.0",
|
||||||
"ethcore-ipc 1.3.0",
|
"ethcore-ipc 1.3.0",
|
||||||
"ethcore-ipc-codegen 1.3.0",
|
"ethcore-ipc-codegen 1.3.0",
|
||||||
"ethcore-ipc-nano 1.3.0",
|
"ethcore-ipc-nano 1.3.0",
|
||||||
@ -314,6 +297,17 @@ dependencies = [
|
|||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ethcore-io"
|
||||||
|
version = "1.3.0"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"mio 0.5.1 (git+https://github.com/ethcore/mio?branch=v0.5.x)",
|
||||||
|
"parking_lot 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"slab 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ethcore-ipc"
|
name = "ethcore-ipc"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
@ -384,6 +378,27 @@ dependencies = [
|
|||||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ethcore-network"
|
||||||
|
version = "1.3.0"
|
||||||
|
dependencies = [
|
||||||
|
"ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"ethcore-devtools 1.3.0",
|
||||||
|
"ethcore-io 1.3.0",
|
||||||
|
"ethcore-util 1.3.0",
|
||||||
|
"igd 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"mio 0.5.1 (git+https://github.com/ethcore/mio?branch=v0.5.x)",
|
||||||
|
"parking_lot 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"slab 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"tiny-keccak 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ethcore-rpc"
|
name = "ethcore-rpc"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
@ -392,6 +407,7 @@ dependencies = [
|
|||||||
"ethash 1.3.0",
|
"ethash 1.3.0",
|
||||||
"ethcore 1.3.0",
|
"ethcore 1.3.0",
|
||||||
"ethcore-devtools 1.3.0",
|
"ethcore-devtools 1.3.0",
|
||||||
|
"ethcore-io 1.3.0",
|
||||||
"ethcore-ipc 1.3.0",
|
"ethcore-ipc 1.3.0",
|
||||||
"ethcore-util 1.3.0",
|
"ethcore-util 1.3.0",
|
||||||
"ethjson 0.1.0",
|
"ethjson 0.1.0",
|
||||||
@ -414,6 +430,7 @@ version = "1.3.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"clippy 0.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clippy 0.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"ethcore-io 1.3.0",
|
||||||
"ethcore-rpc 1.3.0",
|
"ethcore-rpc 1.3.0",
|
||||||
"ethcore-util 1.3.0",
|
"ethcore-util 1.3.0",
|
||||||
"jsonrpc-core 2.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jsonrpc-core 2.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -431,21 +448,16 @@ dependencies = [
|
|||||||
"ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ansi_term 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"arrayvec 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"bigint 0.1.0",
|
"bigint 0.1.0",
|
||||||
"chrono 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"clippy 0.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clippy 0.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"crossbeam 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"elastic-array 0.4.0 (git+https://github.com/ethcore/elastic-array)",
|
"elastic-array 0.4.0 (git+https://github.com/ethcore/elastic-array)",
|
||||||
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"eth-secp256k1 0.5.4 (git+https://github.com/ethcore/rust-secp256k1)",
|
"eth-secp256k1 0.5.4 (git+https://github.com/ethcore/rust-secp256k1)",
|
||||||
"ethcore-devtools 1.3.0",
|
"ethcore-devtools 1.3.0",
|
||||||
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"igd 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"mio 0.5.1 (git+https://github.com/ethcore/mio?branch=v0.5.x)",
|
|
||||||
"nix 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"parking_lot 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parking_lot 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rocksdb 0.4.5 (git+https://github.com/ethcore/rust-rocksdb)",
|
"rocksdb 0.4.5 (git+https://github.com/ethcore/rust-rocksdb)",
|
||||||
@ -453,11 +465,9 @@ dependencies = [
|
|||||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"sha3 0.1.0",
|
"sha3 0.1.0",
|
||||||
"slab 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"table 0.1.0",
|
"table 0.1.0",
|
||||||
"target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"tiny-keccak 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"using_queue 0.1.0",
|
"using_queue 0.1.0",
|
||||||
"vergen 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"vergen 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
@ -509,9 +519,11 @@ dependencies = [
|
|||||||
"clippy 0.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clippy 0.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ethcore 1.3.0",
|
"ethcore 1.3.0",
|
||||||
|
"ethcore-io 1.3.0",
|
||||||
"ethcore-ipc 1.3.0",
|
"ethcore-ipc 1.3.0",
|
||||||
"ethcore-ipc-codegen 1.3.0",
|
"ethcore-ipc-codegen 1.3.0",
|
||||||
"ethcore-ipc-nano 1.3.0",
|
"ethcore-ipc-nano 1.3.0",
|
||||||
|
"ethcore-network 1.3.0",
|
||||||
"ethcore-util 1.3.0",
|
"ethcore-util 1.3.0",
|
||||||
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -605,6 +617,26 @@ dependencies = [
|
|||||||
"vecio 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"vecio 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hyper"
|
||||||
|
version = "0.9.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "idna"
|
name = "idna"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -617,13 +649,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "igd"
|
name = "igd"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hyper 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 0.1.68 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 0.1.68 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"xml-rs 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
"xml-rs 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"xmltree 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"xmltree 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1495,18 +1527,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xml-rs"
|
name = "xml-rs"
|
||||||
version = "0.1.26"
|
version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "xml-rs"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1514,7 +1538,7 @@ name = "xmltree"
|
|||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"xml-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"xml-rs 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
|
@ -31,6 +31,7 @@ fdlimit = { path = "util/fdlimit" }
|
|||||||
ethcore = { path = "ethcore" }
|
ethcore = { path = "ethcore" }
|
||||||
ethcore-util = { path = "util" }
|
ethcore-util = { path = "util" }
|
||||||
ethsync = { path = "sync" }
|
ethsync = { path = "sync" }
|
||||||
|
ethcore-io = { path = "util/io" }
|
||||||
ethcore-devtools = { path = "devtools" }
|
ethcore-devtools = { path = "devtools" }
|
||||||
ethcore-rpc = { path = "rpc" }
|
ethcore-rpc = { path = "rpc" }
|
||||||
ethcore-signer = { path = "signer" }
|
ethcore-signer = { path = "signer" }
|
||||||
@ -68,3 +69,4 @@ name = "parity"
|
|||||||
[profile.release]
|
[profile.release]
|
||||||
debug = true
|
debug = true
|
||||||
lto = false
|
lto = false
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ evmjit = { path = "../evmjit", optional = true }
|
|||||||
clippy = { version = "0.0.80", optional = true}
|
clippy = { version = "0.0.80", optional = true}
|
||||||
ethash = { path = "../ethash" }
|
ethash = { path = "../ethash" }
|
||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
|
ethcore-io = { path = "../util/io" }
|
||||||
ethcore-devtools = { path = "../devtools" }
|
ethcore-devtools = { path = "../devtools" }
|
||||||
ethjson = { path = "../json" }
|
ethjson = { path = "../json" }
|
||||||
ethcore-ipc = { path = "../ipc/rpc" }
|
ethcore-ipc = { path = "../ipc/rpc" }
|
||||||
|
@ -20,6 +20,7 @@ use std::thread::{JoinHandle, self};
|
|||||||
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
|
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
|
||||||
use std::sync::{Condvar as SCondvar, Mutex as SMutex};
|
use std::sync::{Condvar as SCondvar, Mutex as SMutex};
|
||||||
use util::*;
|
use util::*;
|
||||||
|
use io::*;
|
||||||
use verification::*;
|
use verification::*;
|
||||||
use error::*;
|
use error::*;
|
||||||
use engines::Engine;
|
use engines::Engine;
|
||||||
@ -27,7 +28,6 @@ use views::*;
|
|||||||
use header::*;
|
use header::*;
|
||||||
use service::*;
|
use service::*;
|
||||||
use client::BlockStatus;
|
use client::BlockStatus;
|
||||||
use util::panics::*;
|
|
||||||
|
|
||||||
pub use types::block_queue_info::BlockQueueInfo;
|
pub use types::block_queue_info::BlockQueueInfo;
|
||||||
|
|
||||||
@ -450,6 +450,7 @@ impl Drop for BlockQueue {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use util::*;
|
use util::*;
|
||||||
|
use io::*;
|
||||||
use spec::*;
|
use spec::*;
|
||||||
use block_queue::*;
|
use block_queue::*;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
|
@ -27,12 +27,11 @@ use util::{journaldb, rlp, Bytes, View, PerfTimer, Itertools, Mutex, RwLock};
|
|||||||
use util::journaldb::JournalDB;
|
use util::journaldb::JournalDB;
|
||||||
use util::rlp::{UntrustedRlp};
|
use util::rlp::{UntrustedRlp};
|
||||||
use util::numbers::*;
|
use util::numbers::*;
|
||||||
use util::panics::*;
|
|
||||||
use util::io::*;
|
|
||||||
use util::sha3::*;
|
use util::sha3::*;
|
||||||
use util::kvdb::*;
|
use util::kvdb::*;
|
||||||
|
|
||||||
// other
|
// other
|
||||||
|
use io::*;
|
||||||
use views::{BlockView, HeaderView, BodyView};
|
use views::{BlockView, HeaderView, BodyView};
|
||||||
use error::{ImportError, ExecutionError, CallError, BlockError, ImportResult};
|
use error::{ImportError, ExecutionError, CallError, BlockError, ImportResult};
|
||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
//! General error types for use in ethcore.
|
//! General error types for use in ethcore.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
use io::*;
|
||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
use basic_types::LogBloom;
|
use basic_types::LogBloom;
|
||||||
use client::Error as ClientError;
|
use client::Error as ClientError;
|
||||||
@ -227,8 +228,10 @@ pub enum Error {
|
|||||||
PowInvalid,
|
PowInvalid,
|
||||||
/// Error concerning TrieDBs
|
/// Error concerning TrieDBs
|
||||||
Trie(TrieError),
|
Trie(TrieError),
|
||||||
/// Io error.
|
/// Io crate error.
|
||||||
Io(::std::io::Error),
|
Io(IoError),
|
||||||
|
/// Standard io error.
|
||||||
|
StdIo(::std::io::Error),
|
||||||
/// Snappy error.
|
/// Snappy error.
|
||||||
Snappy(::util::snappy::InvalidInput),
|
Snappy(::util::snappy::InvalidInput),
|
||||||
}
|
}
|
||||||
@ -238,6 +241,7 @@ impl fmt::Display for Error {
|
|||||||
match *self {
|
match *self {
|
||||||
Error::Client(ref err) => f.write_fmt(format_args!("{}", err)),
|
Error::Client(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
Error::Util(ref err) => f.write_fmt(format_args!("{}", err)),
|
Error::Util(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
|
Error::Io(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
Error::Block(ref err) => f.write_fmt(format_args!("{}", err)),
|
Error::Block(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
Error::Execution(ref err) => f.write_fmt(format_args!("{}", err)),
|
Error::Execution(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
Error::Transaction(ref err) => f.write_fmt(format_args!("{}", err)),
|
Error::Transaction(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
@ -247,7 +251,7 @@ impl fmt::Display for Error {
|
|||||||
Error::PowHashInvalid => f.write_str("Invalid or out of date PoW hash."),
|
Error::PowHashInvalid => f.write_str("Invalid or out of date PoW hash."),
|
||||||
Error::PowInvalid => f.write_str("Invalid nonce or mishash"),
|
Error::PowInvalid => f.write_str("Invalid nonce or mishash"),
|
||||||
Error::Trie(ref err) => f.write_fmt(format_args!("{}", err)),
|
Error::Trie(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
Error::Io(ref err) => f.write_fmt(format_args!("{}", err)),
|
Error::StdIo(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
Error::Snappy(ref err) => f.write_fmt(format_args!("{}", err)),
|
Error::Snappy(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,7 +313,7 @@ impl From<UtilError> for Error {
|
|||||||
|
|
||||||
impl From<IoError> for Error {
|
impl From<IoError> for Error {
|
||||||
fn from(err: IoError) -> Error {
|
fn from(err: IoError) -> Error {
|
||||||
Error::Util(From::from(err))
|
Error::Io(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,7 +325,7 @@ impl From<TrieError> for Error {
|
|||||||
|
|
||||||
impl From<::std::io::Error> for Error {
|
impl From<::std::io::Error> for Error {
|
||||||
fn from(err: ::std::io::Error) -> Error {
|
fn from(err: ::std::io::Error) -> Error {
|
||||||
Error::Io(err)
|
Error::StdIo(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ use spec::Genesis;
|
|||||||
use ethjson;
|
use ethjson;
|
||||||
use ethjson::blockchain::BlockChain;
|
use ethjson::blockchain::BlockChain;
|
||||||
use miner::Miner;
|
use miner::Miner;
|
||||||
|
use io::IoChannel;
|
||||||
|
|
||||||
pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
||||||
init_log();
|
init_log();
|
||||||
|
@ -77,6 +77,7 @@
|
|||||||
|
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
#[macro_use] extern crate ethcore_util as util;
|
#[macro_use] extern crate ethcore_util as util;
|
||||||
|
extern crate ethcore_io as io;
|
||||||
#[macro_use] extern crate lazy_static;
|
#[macro_use] extern crate lazy_static;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
#[macro_use] extern crate heapsize;
|
#[macro_use] extern crate heapsize;
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
//! extern crate ethcore_util as util;
|
//! extern crate ethcore_util as util;
|
||||||
//! extern crate ethcore;
|
//! extern crate ethcore;
|
||||||
//! use std::env;
|
//! use std::env;
|
||||||
//! use util::network::{NetworkService, NetworkConfiguration};
|
|
||||||
//! use ethcore::ethereum;
|
//! use ethcore::ethereum;
|
||||||
//! use ethcore::client::{Client, ClientConfig};
|
//! use ethcore::client::{Client, ClientConfig};
|
||||||
//! use ethcore::miner::{Miner, MinerService};
|
//! use ethcore::miner::{Miner, MinerService};
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
//! Creates and registers client and network services.
|
//! Creates and registers client and network services.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use util::panics::*;
|
use io::*;
|
||||||
use spec::Spec;
|
use spec::Spec;
|
||||||
use error::*;
|
use error::*;
|
||||||
use client::{Client, ClientConfig, ChainNotify};
|
use client::{Client, ClientConfig, ChainNotify};
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use io::IoChannel;
|
||||||
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockID};
|
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockID};
|
||||||
use block::IsBlock;
|
use block::IsBlock;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use io::*;
|
||||||
use client::{self, BlockChainClient, Client, ClientConfig};
|
use client::{self, BlockChainClient, Client, ClientConfig};
|
||||||
use common::*;
|
use common::*;
|
||||||
use spec::*;
|
use spec::*;
|
||||||
|
@ -24,7 +24,7 @@ use tests::helpers::*;
|
|||||||
use devtools::*;
|
use devtools::*;
|
||||||
use miner::Miner;
|
use miner::Miner;
|
||||||
use crossbeam;
|
use crossbeam;
|
||||||
use common::IoChannel;
|
use io::IoChannel;
|
||||||
|
|
||||||
pub fn run_test_worker(scope: &crossbeam::Scope, stop: Arc<AtomicBool>, socket_path: &str) {
|
pub fn run_test_worker(scope: &crossbeam::Scope, stop: Arc<AtomicBool>, socket_path: &str) {
|
||||||
let socket_path = socket_path.to_owned();
|
let socket_path = socket_path.to_owned();
|
||||||
|
@ -23,7 +23,7 @@ use std::path::Path;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use rustc_serialize::hex::FromHex;
|
use rustc_serialize::hex::FromHex;
|
||||||
use ethcore_logger::{setup_log, Config as LogConfig};
|
use ethcore_logger::{setup_log, Config as LogConfig};
|
||||||
use util::panics::{PanicHandler, ForwardPanic};
|
use io::{PanicHandler, ForwardPanic};
|
||||||
use util::{PayloadInfo, ToPretty};
|
use util::{PayloadInfo, ToPretty};
|
||||||
use ethcore::service::ClientService;
|
use ethcore::service::ClientService;
|
||||||
use ethcore::client::{Mode, DatabaseCompactionProfile, Switch, VMType, BlockImportError, BlockChainClient, BlockID};
|
use ethcore::client::{Mode, DatabaseCompactionProfile, Switch, VMType, BlockImportError, BlockChainClient, BlockID};
|
||||||
|
@ -21,13 +21,14 @@ use std::path::PathBuf;
|
|||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use cli::{USAGE, Args};
|
use cli::{USAGE, Args};
|
||||||
use docopt::{Docopt, Error as DocoptError};
|
use docopt::{Docopt, Error as DocoptError};
|
||||||
use util::{Hashable, NetworkConfiguration, U256, Uint, is_valid_node_url, Bytes, version_data, Secret, Address};
|
use util::{Hashable, U256, Uint, Bytes, version_data, Secret, Address};
|
||||||
use util::network_settings::NetworkSettings;
|
|
||||||
use util::log::Colour;
|
use util::log::Colour;
|
||||||
|
use ethsync::{NetworkConfiguration, is_valid_node_url};
|
||||||
use ethcore::client::{VMType, Mode};
|
use ethcore::client::{VMType, Mode};
|
||||||
use ethcore::miner::MinerOptions;
|
use ethcore::miner::MinerOptions;
|
||||||
|
|
||||||
use rpc::{IpcConfiguration, HttpConfiguration};
|
use rpc::{IpcConfiguration, HttpConfiguration};
|
||||||
|
use ethcore_rpc::NetworkSettings;
|
||||||
use cache::CacheConfig;
|
use cache::CacheConfig;
|
||||||
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home,
|
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home,
|
||||||
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address};
|
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address};
|
||||||
@ -397,8 +398,8 @@ impl Configuration {
|
|||||||
ret.nat_enabled = self.args.flag_nat == "any" || self.args.flag_nat == "upnp";
|
ret.nat_enabled = self.args.flag_nat == "any" || self.args.flag_nat == "upnp";
|
||||||
ret.boot_nodes = try!(to_bootnodes(&self.args.flag_bootnodes));
|
ret.boot_nodes = try!(to_bootnodes(&self.args.flag_bootnodes));
|
||||||
let (listen, public) = try!(self.net_addresses());
|
let (listen, public) = try!(self.net_addresses());
|
||||||
ret.listen_address = listen;
|
ret.listen_address = listen.map(|l| format!("{}", l));
|
||||||
ret.public_address = public;
|
ret.public_address = public.map(|p| format!("{}", p));
|
||||||
ret.use_secret = self.args.flag_node_key.as_ref().map(|s| s.parse::<Secret>().unwrap_or_else(|_| s.sha3()));
|
ret.use_secret = self.args.flag_node_key.as_ref().map(|s| s.parse::<Secret>().unwrap_or_else(|_| s.sha3()));
|
||||||
ret.discovery_enabled = !self.args.flag_no_discovery && !self.args.flag_nodiscover;
|
ret.discovery_enabled = !self.args.flag_no_discovery && !self.args.flag_nodiscover;
|
||||||
ret.max_peers = self.max_peers();
|
ret.max_peers = self.max_peers();
|
||||||
@ -408,9 +409,7 @@ impl Configuration {
|
|||||||
ret.config_path = Some(net_path.to_str().unwrap().to_owned());
|
ret.config_path = Some(net_path.to_str().unwrap().to_owned());
|
||||||
ret.reserved_nodes = try!(self.init_reserved_nodes());
|
ret.reserved_nodes = try!(self.init_reserved_nodes());
|
||||||
|
|
||||||
if self.args.flag_reserved_only {
|
ret.allow_non_reserved = !self.args.flag_reserved_only;
|
||||||
ret.non_reserved_mode = ::util::network::NonReservedPeerMode::Deny;
|
|
||||||
}
|
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,7 +551,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use cli::USAGE;
|
use cli::USAGE;
|
||||||
use docopt::Docopt;
|
use docopt::Docopt;
|
||||||
use util::network_settings::NetworkSettings;
|
use ethcore_rpc::NetworkSettings;
|
||||||
use ethcore::client::{VMType, BlockID};
|
use ethcore::client::{VMType, BlockID};
|
||||||
use helpers::{replace_home, default_network_config};
|
use helpers::{replace_home, default_network_config};
|
||||||
use run::RunCmd;
|
use run::RunCmd;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use util::panics::PanicHandler;
|
use io::PanicHandler;
|
||||||
use rpc_apis;
|
use rpc_apis;
|
||||||
use helpers::replace_home;
|
use helpers::replace_home;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ use std::io::{Write, Read, BufReader, BufRead};
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use util::{clean_0x, U256, Uint, Address, path, is_valid_node_url, H256, CompactionProfile};
|
use util::{clean_0x, U256, Uint, Address, path, H256, CompactionProfile};
|
||||||
use util::journaldb::Algorithm;
|
use util::journaldb::Algorithm;
|
||||||
use ethcore::client::{Mode, BlockID, Switch, VMType, DatabaseCompactionProfile, ClientConfig};
|
use ethcore::client::{Mode, BlockID, Switch, VMType, DatabaseCompactionProfile, ClientConfig};
|
||||||
use ethcore::miner::PendingSet;
|
use ethcore::miner::PendingSet;
|
||||||
@ -28,6 +28,7 @@ use dir::Directories;
|
|||||||
use params::Pruning;
|
use params::Pruning;
|
||||||
use upgrade::upgrade;
|
use upgrade::upgrade;
|
||||||
use migration::migrate;
|
use migration::migrate;
|
||||||
|
use ethsync::is_valid_node_url;
|
||||||
|
|
||||||
pub fn to_duration(s: &str) -> Result<Duration, String> {
|
pub fn to_duration(s: &str) -> Result<Duration, String> {
|
||||||
to_seconds(s).map(Duration::from_secs)
|
to_seconds(s).map(Duration::from_secs)
|
||||||
@ -167,11 +168,11 @@ pub fn to_bootnodes(bootnodes: &Option<String>) -> Result<Vec<String>, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn default_network_config() -> ::util::NetworkConfiguration {
|
pub fn default_network_config() -> ::ethsync::NetworkConfiguration {
|
||||||
use util::{NetworkConfiguration, NonReservedPeerMode};
|
use ethsync::NetworkConfiguration;
|
||||||
NetworkConfiguration {
|
NetworkConfiguration {
|
||||||
config_path: Some(replace_home("$HOME/.parity/network")),
|
config_path: Some(replace_home("$HOME/.parity/network")),
|
||||||
listen_address: Some("0.0.0.0:30303".parse().unwrap()),
|
listen_address: Some("0.0.0.0:30303".into()),
|
||||||
public_address: None,
|
public_address: None,
|
||||||
udp_port: None,
|
udp_port: None,
|
||||||
nat_enabled: true,
|
nat_enabled: true,
|
||||||
@ -181,7 +182,7 @@ pub fn default_network_config() -> ::util::NetworkConfiguration {
|
|||||||
max_peers: 50,
|
max_peers: 50,
|
||||||
min_peers: 25,
|
min_peers: 25,
|
||||||
reserved_nodes: Vec::new(),
|
reserved_nodes: Vec::new(),
|
||||||
non_reserved_mode: NonReservedPeerMode::Accept,
|
allow_non_reserved: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ use ethcore::client::Client;
|
|||||||
use ethcore::service::ClientIoMessage;
|
use ethcore::service::ClientIoMessage;
|
||||||
use ethsync::{SyncProvider, ManageNetwork};
|
use ethsync::{SyncProvider, ManageNetwork};
|
||||||
use ethcore::account_provider::AccountProvider;
|
use ethcore::account_provider::AccountProvider;
|
||||||
use util::{TimerToken, IoHandler, IoContext};
|
use io::{TimerToken, IoHandler, IoContext};
|
||||||
|
|
||||||
use informant::Informant;
|
use informant::Informant;
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ extern crate time;
|
|||||||
extern crate number_prefix;
|
extern crate number_prefix;
|
||||||
extern crate rpassword;
|
extern crate rpassword;
|
||||||
extern crate semver;
|
extern crate semver;
|
||||||
|
extern crate ethcore_io as io;
|
||||||
extern crate ethcore_ipc as ipc;
|
extern crate ethcore_ipc as ipc;
|
||||||
extern crate ethcore_ipc_nano as nanoipc;
|
extern crate ethcore_ipc_nano as nanoipc;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use ethcore::client::BlockChainClient;
|
use ethcore::client::BlockChainClient;
|
||||||
use ethcore;
|
|
||||||
use hypervisor::Hypervisor;
|
use hypervisor::Hypervisor;
|
||||||
use ethsync::{SyncConfig, NetworkConfiguration};
|
use ethsync::{SyncConfig, NetworkConfiguration, NetworkError};
|
||||||
#[cfg(not(feature="ipc"))]
|
#[cfg(not(feature="ipc"))]
|
||||||
use self::no_ipc_deps::*;
|
use self::no_ipc_deps::*;
|
||||||
#[cfg(feature="ipc")]
|
#[cfg(feature="ipc")]
|
||||||
@ -103,7 +102,7 @@ pub fn sync
|
|||||||
_client: Arc<BlockChainClient>,
|
_client: Arc<BlockChainClient>,
|
||||||
log_settings: &LogConfig,
|
log_settings: &LogConfig,
|
||||||
)
|
)
|
||||||
-> Result<SyncModules, ethcore::error::Error>
|
-> Result<SyncModules, NetworkError>
|
||||||
{
|
{
|
||||||
let mut hypervisor = hypervisor_ref.take().expect("There should be hypervisor for ipc configuration");
|
let mut hypervisor = hypervisor_ref.take().expect("There should be hypervisor for ipc configuration");
|
||||||
hypervisor = hypervisor.module(SYNC_MODULE_ID, "parity", sync_arguments(sync_cfg, net_cfg, log_settings));
|
hypervisor = hypervisor.module(SYNC_MODULE_ID, "parity", sync_arguments(sync_cfg, net_cfg, log_settings));
|
||||||
@ -128,8 +127,8 @@ pub fn sync
|
|||||||
client: Arc<BlockChainClient>,
|
client: Arc<BlockChainClient>,
|
||||||
_log_settings: &LogConfig,
|
_log_settings: &LogConfig,
|
||||||
)
|
)
|
||||||
-> Result<SyncModules, ethcore::error::Error>
|
-> Result<SyncModules, NetworkError>
|
||||||
{
|
{
|
||||||
let eth_sync = try!(EthSync::new(sync_cfg, client, net_cfg).map_err(ethcore::error::Error::Util));
|
let eth_sync = try!(EthSync::new(sync_cfg, client, net_cfg));
|
||||||
Ok((eth_sync.clone() as Arc<SyncProvider>, eth_sync.clone() as Arc<ManageNetwork>, eth_sync.clone() as Arc<ChainNotify>))
|
Ok((eth_sync.clone() as Arc<SyncProvider>, eth_sync.clone() as Arc<ManageNetwork>, eth_sync.clone() as Arc<ChainNotify>))
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use util::panics::PanicHandler;
|
use io::PanicHandler;
|
||||||
use ethcore_rpc::{RpcServerError, RpcServer as Server};
|
use ethcore_rpc::{RpcServerError, RpcServer as Server};
|
||||||
use jsonipc;
|
use jsonipc;
|
||||||
use rpc_apis;
|
use rpc_apis;
|
||||||
|
@ -20,12 +20,11 @@ use std::cmp::PartialEq;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use util::RotatingLogger;
|
use util::RotatingLogger;
|
||||||
use util::network_settings::NetworkSettings;
|
|
||||||
use ethcore::miner::{Miner, ExternalMiner};
|
use ethcore::miner::{Miner, ExternalMiner};
|
||||||
use ethcore::client::Client;
|
use ethcore::client::Client;
|
||||||
use ethcore::account_provider::AccountProvider;
|
use ethcore::account_provider::AccountProvider;
|
||||||
use ethsync::{ManageNetwork, SyncProvider};
|
use ethsync::{ManageNetwork, SyncProvider};
|
||||||
use ethcore_rpc::Extendable;
|
use ethcore_rpc::{Extendable, NetworkSettings};
|
||||||
pub use ethcore_rpc::ConfirmationsQueue;
|
pub use ethcore_rpc::ConfirmationsQueue;
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,9 +20,10 @@ use std::io::ErrorKind;
|
|||||||
use ctrlc::CtrlC;
|
use ctrlc::CtrlC;
|
||||||
use fdlimit::raise_fd_limit;
|
use fdlimit::raise_fd_limit;
|
||||||
use ethcore_logger::{Config as LogConfig, setup_log};
|
use ethcore_logger::{Config as LogConfig, setup_log};
|
||||||
use util::network_settings::NetworkSettings;
|
use ethcore_rpc::NetworkSettings;
|
||||||
use util::{Colour, version, NetworkConfiguration, U256};
|
use ethsync::NetworkConfiguration;
|
||||||
use util::panics::{MayPanic, ForwardPanic, PanicHandler};
|
use util::{Colour, version, U256};
|
||||||
|
use io::{MayPanic, ForwardPanic, PanicHandler};
|
||||||
use ethcore::client::{Mode, Switch, DatabaseCompactionProfile, VMType, ChainNotify};
|
use ethcore::client::{Mode, Switch, DatabaseCompactionProfile, VMType, ChainNotify};
|
||||||
use ethcore::service::ClientService;
|
use ethcore::service::ClientService;
|
||||||
use ethcore::account_provider::AccountProvider;
|
use ethcore::account_provider::AccountProvider;
|
||||||
|
@ -18,7 +18,7 @@ use std::io;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use ansi_term::Colour;
|
use ansi_term::Colour;
|
||||||
use util::panics::{ForwardPanic, PanicHandler};
|
use io::{ForwardPanic, PanicHandler};
|
||||||
use util::path::restrict_permissions_owner;
|
use util::path::restrict_permissions_owner;
|
||||||
use rpc_apis;
|
use rpc_apis;
|
||||||
use ethcore_signer as signer;
|
use ethcore_signer as signer;
|
||||||
|
@ -14,6 +14,7 @@ serde = "0.7.0"
|
|||||||
serde_json = "0.7.0"
|
serde_json = "0.7.0"
|
||||||
jsonrpc-core = "2.0"
|
jsonrpc-core = "2.0"
|
||||||
jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git" }
|
jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git" }
|
||||||
|
ethcore-io = { path = "../util/io" }
|
||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
ethcore = { path = "../ethcore" }
|
ethcore = { path = "../ethcore" }
|
||||||
ethash = { path = "../ethash" }
|
ethash = { path = "../ethash" }
|
||||||
|
@ -28,6 +28,7 @@ extern crate jsonrpc_core;
|
|||||||
extern crate jsonrpc_http_server;
|
extern crate jsonrpc_http_server;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
|
extern crate ethcore_io as io;
|
||||||
extern crate ethcore;
|
extern crate ethcore;
|
||||||
extern crate ethsync;
|
extern crate ethsync;
|
||||||
extern crate transient_hashmap;
|
extern crate transient_hashmap;
|
||||||
@ -41,12 +42,12 @@ extern crate ethcore_devtools as devtools;
|
|||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use util::panics::PanicHandler;
|
use io::PanicHandler;
|
||||||
use self::jsonrpc_core::{IoHandler, IoDelegate};
|
use self::jsonrpc_core::{IoHandler, IoDelegate};
|
||||||
|
|
||||||
pub use jsonrpc_http_server::{ServerBuilder, Server, RpcServerError};
|
pub use jsonrpc_http_server::{ServerBuilder, Server, RpcServerError};
|
||||||
pub mod v1;
|
pub mod v1;
|
||||||
pub use v1::{SigningQueue, ConfirmationsQueue};
|
pub use v1::{SigningQueue, ConfirmationsQueue, NetworkSettings};
|
||||||
|
|
||||||
/// An object that can be extended with `IoDelegates`
|
/// An object that can be extended with `IoDelegates`
|
||||||
pub trait Extendable {
|
pub trait Extendable {
|
||||||
|
@ -18,8 +18,10 @@ mod poll_manager;
|
|||||||
mod poll_filter;
|
mod poll_filter;
|
||||||
mod requests;
|
mod requests;
|
||||||
mod signing_queue;
|
mod signing_queue;
|
||||||
|
mod network_settings;
|
||||||
|
|
||||||
pub use self::poll_manager::PollManager;
|
pub use self::poll_manager::PollManager;
|
||||||
pub use self::poll_filter::PollFilter;
|
pub use self::poll_filter::PollFilter;
|
||||||
pub use self::requests::{TransactionRequest, FilledTransactionRequest, ConfirmationRequest, ConfirmationPayload, CallRequest};
|
pub use self::requests::{TransactionRequest, FilledTransactionRequest, ConfirmationRequest, ConfirmationPayload, CallRequest};
|
||||||
pub use self::signing_queue::{ConfirmationsQueue, ConfirmationPromise, ConfirmationResult, SigningQueue, QueueEvent};
|
pub use self::signing_queue::{ConfirmationsQueue, ConfirmationPromise, ConfirmationResult, SigningQueue, QueueEvent};
|
||||||
|
pub use self::network_settings::NetworkSettings;
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
//! Ethcore-specific rpc implementation.
|
//! Ethcore-specific rpc implementation.
|
||||||
use util::{RotatingLogger};
|
use util::{RotatingLogger};
|
||||||
use util::network_settings::NetworkSettings;
|
|
||||||
use util::misc::version_data;
|
use util::misc::version_data;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
@ -26,7 +25,7 @@ use jsonrpc_core::*;
|
|||||||
use ethcore::miner::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
use v1::traits::Ethcore;
|
use v1::traits::Ethcore;
|
||||||
use v1::types::{Bytes, U256};
|
use v1::types::{Bytes, U256};
|
||||||
use v1::helpers::{SigningQueue, ConfirmationsQueue};
|
use v1::helpers::{SigningQueue, ConfirmationsQueue, NetworkSettings};
|
||||||
use v1::impls::signer_disabled_error;
|
use v1::impls::signer_disabled_error;
|
||||||
|
|
||||||
/// Ethcore implementation.
|
/// Ethcore implementation.
|
||||||
|
@ -27,4 +27,4 @@ pub mod types;
|
|||||||
|
|
||||||
pub use self::traits::{Web3, Eth, EthFilter, EthSigning, Personal, PersonalSigner, Net, Ethcore, EthcoreSet, Traces, Rpc};
|
pub use self::traits::{Web3, Eth, EthFilter, EthSigning, Personal, PersonalSigner, Net, Ethcore, EthcoreSet, Traces, Rpc};
|
||||||
pub use self::impls::*;
|
pub use self::impls::*;
|
||||||
pub use self::helpers::{SigningQueue, ConfirmationsQueue};
|
pub use self::helpers::{SigningQueue, ConfirmationsQueue, NetworkSettings};
|
||||||
|
@ -29,7 +29,7 @@ use ethcore::miner::{MinerOptions, GasPricer, MinerService, ExternalMiner, Miner
|
|||||||
use ethcore::account_provider::AccountProvider;
|
use ethcore::account_provider::AccountProvider;
|
||||||
use devtools::RandomTempPath;
|
use devtools::RandomTempPath;
|
||||||
use util::Hashable;
|
use util::Hashable;
|
||||||
use util::io::IoChannel;
|
use io::IoChannel;
|
||||||
use util::{U256, H256, Uint};
|
use util::{U256, H256, Uint};
|
||||||
use jsonrpc_core::IoHandler;
|
use jsonrpc_core::IoHandler;
|
||||||
use ethjson::blockchain::BlockChain;
|
use ethjson::blockchain::BlockChain;
|
||||||
|
@ -21,7 +21,7 @@ use v1::tests::helpers::TestMinerService;
|
|||||||
use v1::helpers::ConfirmationsQueue;
|
use v1::helpers::ConfirmationsQueue;
|
||||||
use ethcore::client::{TestBlockChainClient};
|
use ethcore::client::{TestBlockChainClient};
|
||||||
use util::log::RotatingLogger;
|
use util::log::RotatingLogger;
|
||||||
use util::network_settings::NetworkSettings;
|
use v1::helpers::NetworkSettings;
|
||||||
|
|
||||||
fn miner_service() -> Arc<TestMinerService> {
|
fn miner_service() -> Arc<TestMinerService> {
|
||||||
Arc::new(TestMinerService::default())
|
Arc::new(TestMinerService::default())
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use ethsync::{ManageNetwork, NetworkConfiguration};
|
use ethsync::{ManageNetwork, NetworkConfiguration};
|
||||||
use util;
|
|
||||||
|
|
||||||
pub struct TestManageNetwork;
|
pub struct TestManageNetwork;
|
||||||
|
|
||||||
@ -27,5 +26,5 @@ impl ManageNetwork for TestManageNetwork {
|
|||||||
fn add_reserved_peer(&self, _peer: String) -> Result<(), String> { Ok(()) }
|
fn add_reserved_peer(&self, _peer: String) -> Result<(), String> { Ok(()) }
|
||||||
fn start_network(&self) {}
|
fn start_network(&self) {}
|
||||||
fn stop_network(&self) {}
|
fn stop_network(&self) {}
|
||||||
fn network_config(&self) -> NetworkConfiguration { NetworkConfiguration::from(util::NetworkConfiguration::new_local()) }
|
fn network_config(&self) -> NetworkConfiguration { NetworkConfiguration::new_local() }
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ export TARGETS="
|
|||||||
-p ethcore-rpc \
|
-p ethcore-rpc \
|
||||||
-p ethcore-signer \
|
-p ethcore-signer \
|
||||||
-p ethcore-util \
|
-p ethcore-util \
|
||||||
|
-p ethcore-network \
|
||||||
|
-p ethcore-io \
|
||||||
-p ethkey \
|
-p ethkey \
|
||||||
-p ethstore \
|
-p ethstore \
|
||||||
-p ethsync \
|
-p ethsync \
|
||||||
|
@ -17,6 +17,7 @@ log = "0.3"
|
|||||||
env_logger = "0.3"
|
env_logger = "0.3"
|
||||||
ws = { git = "https://github.com/ethcore/ws-rs.git", branch = "stable" }
|
ws = { git = "https://github.com/ethcore/ws-rs.git", branch = "stable" }
|
||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
|
ethcore-io = { path = "../util/io" }
|
||||||
ethcore-rpc = { path = "../rpc" }
|
ethcore-rpc = { path = "../rpc" }
|
||||||
parity-dapps-signer = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6", optional = true}
|
parity-dapps-signer = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6", optional = true}
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ extern crate env_logger;
|
|||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
|
extern crate ethcore_io as io;
|
||||||
extern crate ethcore_rpc as rpc;
|
extern crate ethcore_rpc as rpc;
|
||||||
extern crate jsonrpc_core;
|
extern crate jsonrpc_core;
|
||||||
extern crate ws;
|
extern crate ws;
|
||||||
|
@ -24,7 +24,7 @@ use std::default::Default;
|
|||||||
use std::ops::Drop;
|
use std::ops::Drop;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use util::panics::{PanicHandler, OnPanicListener, MayPanic};
|
use io::{PanicHandler, OnPanicListener, MayPanic};
|
||||||
use jsonrpc_core::{IoHandler, IoDelegate};
|
use jsonrpc_core::{IoHandler, IoDelegate};
|
||||||
use rpc::{Extendable, ConfirmationsQueue};
|
use rpc::{Extendable, ConfirmationsQueue};
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ ethcore-ipc-codegen = { path = "../ipc/codegen" }
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
|
ethcore-network = { path = "../util/network" }
|
||||||
|
ethcore-io = { path = "../util/io" }
|
||||||
ethcore = { path = "../ethcore" }
|
ethcore = { path = "../ethcore" }
|
||||||
clippy = { version = "0.0.80", optional = true}
|
clippy = { version = "0.0.80", optional = true}
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
|
@ -16,17 +16,19 @@
|
|||||||
|
|
||||||
use std::ops::*;
|
use std::ops::*;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use util::network::{NetworkProtocolHandler, NetworkService, NetworkContext, PeerId,
|
use network::{NetworkProtocolHandler, NetworkService, NetworkContext, PeerId,
|
||||||
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode};
|
NetworkConfiguration as BasicNetworkConfiguration, NonReservedPeerMode, NetworkError};
|
||||||
use util::{TimerToken, U256, H256, UtilError, Secret, Populatable};
|
use util::{U256, H256, Secret, Populatable};
|
||||||
|
use io::{TimerToken};
|
||||||
use ethcore::client::{BlockChainClient, ChainNotify};
|
use ethcore::client::{BlockChainClient, ChainNotify};
|
||||||
use ethcore::header::BlockNumber;
|
use ethcore::header::BlockNumber;
|
||||||
use io::NetSyncIo;
|
use sync_io::NetSyncIo;
|
||||||
use chain::{ChainSync, SyncStatus};
|
use chain::{ChainSync, SyncStatus};
|
||||||
use std::net::{SocketAddr, AddrParseError};
|
use std::net::{SocketAddr, AddrParseError};
|
||||||
use ipc::{BinaryConvertable, BinaryConvertError, IpcConfig};
|
use ipc::{BinaryConvertable, BinaryConvertError, IpcConfig};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
use std::str::FromStr;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
|
|
||||||
/// Ethereum sync protocol
|
/// Ethereum sync protocol
|
||||||
@ -72,7 +74,7 @@ pub struct EthSync {
|
|||||||
|
|
||||||
impl EthSync {
|
impl EthSync {
|
||||||
/// Creates and register protocol with the network service
|
/// Creates and register protocol with the network service
|
||||||
pub fn new(config: SyncConfig, chain: Arc<BlockChainClient>, network_config: NetworkConfiguration) -> Result<Arc<EthSync>, UtilError> {
|
pub fn new(config: SyncConfig, chain: Arc<BlockChainClient>, network_config: NetworkConfiguration) -> Result<Arc<EthSync>, NetworkError> {
|
||||||
let chain_sync = ChainSync::new(config, chain.deref());
|
let chain_sync = ChainSync::new(config, chain.deref());
|
||||||
let service = try!(NetworkService::new(try!(network_config.into_basic())));
|
let service = try!(NetworkService::new(try!(network_config.into_basic())));
|
||||||
let sync = Arc::new(EthSync{
|
let sync = Arc::new(EthSync{
|
||||||
@ -213,7 +215,7 @@ impl ManageNetwork for EthSync {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Binary, Debug, Clone)]
|
#[derive(Binary, Debug, Clone, PartialEq, Eq)]
|
||||||
/// Network service configuration
|
/// Network service configuration
|
||||||
pub struct NetworkConfiguration {
|
pub struct NetworkConfiguration {
|
||||||
/// Directory path to store network configuration. None means nothing will be saved
|
/// Directory path to store network configuration. None means nothing will be saved
|
||||||
@ -243,8 +245,25 @@ pub struct NetworkConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NetworkConfiguration {
|
impl NetworkConfiguration {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
From::from(BasicNetworkConfiguration::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_local() -> Self {
|
||||||
|
From::from(BasicNetworkConfiguration::new_local())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate(&self) -> Result<(), AddrParseError> {
|
||||||
|
if let Some(ref addr) = self.listen_address {
|
||||||
|
try!(SocketAddr::from_str(&addr));
|
||||||
|
}
|
||||||
|
if let Some(ref addr) = self.public_address {
|
||||||
|
try!(SocketAddr::from_str(&addr));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn into_basic(self) -> Result<BasicNetworkConfiguration, AddrParseError> {
|
pub fn into_basic(self) -> Result<BasicNetworkConfiguration, AddrParseError> {
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
Ok(BasicNetworkConfiguration {
|
Ok(BasicNetworkConfiguration {
|
||||||
config_path: self.config_path,
|
config_path: self.config_path,
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
use network::NetworkError;
|
||||||
use ethcore::header::{ Header as BlockHeader};
|
use ethcore::header::{ Header as BlockHeader};
|
||||||
|
|
||||||
known_heap_size!(0, HeaderId, SyncBlock);
|
known_heap_size!(0, HeaderId, SyncBlock);
|
||||||
@ -228,7 +229,7 @@ impl BlockCollection {
|
|||||||
self.downloading_headers.contains(hash) || self.downloading_bodies.contains(hash)
|
self.downloading_headers.contains(hash) || self.downloading_bodies.contains(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_body(&mut self, b: Bytes) -> Result<(), UtilError> {
|
fn insert_body(&mut self, b: Bytes) -> Result<(), NetworkError> {
|
||||||
let body = UntrustedRlp::new(&b);
|
let body = UntrustedRlp::new(&b);
|
||||||
let tx = try!(body.at(0));
|
let tx = try!(body.at(0));
|
||||||
let tx_root = ordered_trie_root(tx.iter().map(|r| r.as_raw().to_vec()).collect()); //TODO: get rid of vectors here
|
let tx_root = ordered_trie_root(tx.iter().map(|r| r.as_raw().to_vec()).collect()); //TODO: get rid of vectors here
|
||||||
@ -249,13 +250,13 @@ impl BlockCollection {
|
|||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
warn!("Got body with no header {}", h);
|
warn!("Got body with no header {}", h);
|
||||||
Err(UtilError::Network(NetworkError::BadProtocol))
|
Err(NetworkError::BadProtocol)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
trace!(target: "sync", "Ignored unknown/stale block body");
|
trace!(target: "sync", "Ignored unknown/stale block body");
|
||||||
Err(UtilError::Network(NetworkError::BadProtocol))
|
Err(NetworkError::BadProtocol)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,13 +88,14 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
use network::*;
|
||||||
use std::mem::{replace};
|
use std::mem::{replace};
|
||||||
use ethcore::views::{HeaderView, BlockView};
|
use ethcore::views::{HeaderView, BlockView};
|
||||||
use ethcore::header::{BlockNumber, Header as BlockHeader};
|
use ethcore::header::{BlockNumber, Header as BlockHeader};
|
||||||
use ethcore::client::{BlockChainClient, BlockStatus, BlockID, BlockChainInfo, BlockImportError};
|
use ethcore::client::{BlockChainClient, BlockStatus, BlockID, BlockChainInfo, BlockImportError};
|
||||||
use ethcore::error::*;
|
use ethcore::error::*;
|
||||||
use ethcore::block::Block;
|
use ethcore::block::Block;
|
||||||
use io::SyncIo;
|
use sync_io::SyncIo;
|
||||||
use time;
|
use time;
|
||||||
use super::SyncConfig;
|
use super::SyncConfig;
|
||||||
use blocks::BlockCollection;
|
use blocks::BlockCollection;
|
||||||
@ -1045,7 +1046,7 @@ impl ChainSync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Send Status message
|
/// Send Status message
|
||||||
fn send_status(&mut self, io: &mut SyncIo) -> Result<(), UtilError> {
|
fn send_status(&mut self, io: &mut SyncIo) -> Result<(), NetworkError> {
|
||||||
let mut packet = RlpStream::new_list(5);
|
let mut packet = RlpStream::new_list(5);
|
||||||
let chain = io.chain().chain_info();
|
let chain = io.chain().chain_info();
|
||||||
packet.append(&(PROTOCOL_VERSION as u32));
|
packet.append(&(PROTOCOL_VERSION as u32));
|
||||||
@ -1191,7 +1192,7 @@ impl ChainSync {
|
|||||||
|
|
||||||
fn return_rlp<FRlp, FError>(io: &mut SyncIo, rlp: &UntrustedRlp, peer: PeerId, rlp_func: FRlp, error_func: FError) -> Result<(), PacketDecodeError>
|
fn return_rlp<FRlp, FError>(io: &mut SyncIo, rlp: &UntrustedRlp, peer: PeerId, rlp_func: FRlp, error_func: FError) -> Result<(), PacketDecodeError>
|
||||||
where FRlp : Fn(&SyncIo, &UntrustedRlp, PeerId) -> RlpResponseResult,
|
where FRlp : Fn(&SyncIo, &UntrustedRlp, PeerId) -> RlpResponseResult,
|
||||||
FError : FnOnce(UtilError) -> String
|
FError : FnOnce(NetworkError) -> String
|
||||||
{
|
{
|
||||||
let response = rlp_func(io, rlp, peer);
|
let response = rlp_func(io, rlp, peer);
|
||||||
match response {
|
match response {
|
||||||
|
@ -30,11 +30,12 @@
|
|||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! extern crate ethcore_util as util;
|
//! extern crate ethcore_util as util;
|
||||||
|
//! extern crate ethcore_io as io;
|
||||||
//! extern crate ethcore;
|
//! extern crate ethcore;
|
||||||
//! extern crate ethsync;
|
//! extern crate ethsync;
|
||||||
//! use std::env;
|
//! use std::env;
|
||||||
//! use std::sync::Arc;
|
//! use std::sync::Arc;
|
||||||
//! use util::io::IoChannel;
|
//! use io::IoChannel;
|
||||||
//! use ethcore::client::{Client, ClientConfig};
|
//! use ethcore::client::{Client, ClientConfig};
|
||||||
//! use ethsync::{EthSync, SyncConfig, ManageNetwork, NetworkConfiguration};
|
//! use ethsync::{EthSync, SyncConfig, ManageNetwork, NetworkConfiguration};
|
||||||
//! use ethcore::ethereum;
|
//! use ethcore::ethereum;
|
||||||
@ -55,7 +56,7 @@
|
|||||||
//! miner,
|
//! miner,
|
||||||
//! IoChannel::disconnected()
|
//! IoChannel::disconnected()
|
||||||
//! ).unwrap();
|
//! ).unwrap();
|
||||||
//! let sync = EthSync::new(SyncConfig::default(), client, NetworkConfiguration::from(util::NetworkConfiguration::new())).unwrap();
|
//! let sync = EthSync::new(SyncConfig::default(), client, NetworkConfiguration::from(NetworkConfiguration::new())).unwrap();
|
||||||
//! sync.start_network();
|
//! sync.start_network();
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
@ -64,6 +65,8 @@
|
|||||||
extern crate log;
|
extern crate log;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate ethcore_util as util;
|
extern crate ethcore_util as util;
|
||||||
|
extern crate ethcore_network as network;
|
||||||
|
extern crate ethcore_io as io;
|
||||||
extern crate ethcore;
|
extern crate ethcore;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
@ -77,7 +80,7 @@ extern crate parking_lot;
|
|||||||
|
|
||||||
mod chain;
|
mod chain;
|
||||||
mod blocks;
|
mod blocks;
|
||||||
mod io;
|
mod sync_io;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
@ -88,6 +91,7 @@ mod api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub use api::{EthSync, SyncProvider, SyncClient, NetworkManagerClient, ManageNetwork, SyncConfig,
|
pub use api::{EthSync, SyncProvider, SyncClient, NetworkManagerClient, ManageNetwork, SyncConfig,
|
||||||
NetworkConfiguration, ServiceConfiguration};
|
ServiceConfiguration, NetworkConfiguration};
|
||||||
pub use chain::{SyncStatus, SyncState};
|
pub use chain::{SyncStatus, SyncState};
|
||||||
|
pub use network::{is_valid_node_url, NonReservedPeerMode, NetworkError};
|
||||||
|
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::{NetworkContext, PeerId, PacketId,};
|
use network::{NetworkContext, PeerId, PacketId, NetworkError};
|
||||||
use util::error::UtilError;
|
|
||||||
use ethcore::client::BlockChainClient;
|
use ethcore::client::BlockChainClient;
|
||||||
|
|
||||||
/// IO interface for the syning handler.
|
/// IO interface for the syning handler.
|
||||||
@ -27,9 +26,9 @@ pub trait SyncIo {
|
|||||||
/// Disconnect peer
|
/// Disconnect peer
|
||||||
fn disconnect_peer(&mut self, peer_id: PeerId);
|
fn disconnect_peer(&mut self, peer_id: PeerId);
|
||||||
/// Respond to current request with a packet. Can be called from an IO handler for incoming packet.
|
/// Respond to current request with a packet. Can be called from an IO handler for incoming packet.
|
||||||
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError>;
|
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError>;
|
||||||
/// Send a packet to a peer.
|
/// Send a packet to a peer.
|
||||||
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError>;
|
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError>;
|
||||||
/// Get the blockchain
|
/// Get the blockchain
|
||||||
fn chain(&self) -> &BlockChainClient;
|
fn chain(&self) -> &BlockChainClient;
|
||||||
/// Returns peer client identifier string
|
/// Returns peer client identifier string
|
||||||
@ -69,11 +68,11 @@ impl<'s, 'h> SyncIo for NetSyncIo<'s, 'h> {
|
|||||||
self.network.disconnect_peer(peer_id);
|
self.network.disconnect_peer(peer_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError>{
|
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError>{
|
||||||
self.network.respond(packet_id, data)
|
self.network.respond(packet_id, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError>{
|
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError>{
|
||||||
self.network.send(peer_id, packet_id, data)
|
self.network.send(peer_id, packet_id, data)
|
||||||
}
|
}
|
||||||
|
|
@ -15,9 +15,10 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
use network::*;
|
||||||
use ethcore::client::{TestBlockChainClient, BlockChainClient};
|
use ethcore::client::{TestBlockChainClient, BlockChainClient};
|
||||||
use ethcore::header::BlockNumber;
|
use ethcore::header::BlockNumber;
|
||||||
use io::SyncIo;
|
use sync_io::SyncIo;
|
||||||
use chain::ChainSync;
|
use chain::ChainSync;
|
||||||
use ::SyncConfig;
|
use ::SyncConfig;
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ impl<'p> SyncIo for TestIo<'p> {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError> {
|
fn respond(&mut self, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
|
||||||
self.queue.push_back(TestPacket {
|
self.queue.push_back(TestPacket {
|
||||||
data: data,
|
data: data,
|
||||||
packet_id: packet_id,
|
packet_id: packet_id,
|
||||||
@ -57,7 +58,7 @@ impl<'p> SyncIo for TestIo<'p> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError> {
|
fn send(&mut self, peer_id: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
|
||||||
self.queue.push_back(TestPacket {
|
self.queue.push_back(TestPacket {
|
||||||
data: data,
|
data: data,
|
||||||
packet_id: packet_id,
|
packet_id: packet_id,
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use super::super::NetworkConfiguration;
|
use super::super::NetworkConfiguration;
|
||||||
use util::NetworkConfiguration as BasicNetworkConfiguration;
|
use network::NetworkConfiguration as BasicNetworkConfiguration;
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use ipc::binary::{serialize, deserialize};
|
use ipc::binary::{serialize, deserialize};
|
||||||
|
|
||||||
|
@ -12,11 +12,8 @@ log = "0.3"
|
|||||||
env_logger = "0.3"
|
env_logger = "0.3"
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
arrayvec = "0.3"
|
arrayvec = "0.3"
|
||||||
mio = { git = "https://github.com/ethcore/mio", branch = "v0.5.x" }
|
|
||||||
nix ="0.5.0"
|
|
||||||
rand = "0.3.12"
|
rand = "0.3.12"
|
||||||
time = "0.1.34"
|
time = "0.1.34"
|
||||||
tiny-keccak = "1.0"
|
|
||||||
rocksdb = { git = "https://github.com/ethcore/rust-rocksdb" }
|
rocksdb = { git = "https://github.com/ethcore/rust-rocksdb" }
|
||||||
lazy_static = "0.2"
|
lazy_static = "0.2"
|
||||||
eth-secp256k1 = { git = "https://github.com/ethcore/rust-secp256k1" }
|
eth-secp256k1 = { git = "https://github.com/ethcore/rust-secp256k1" }
|
||||||
@ -24,17 +21,13 @@ rust-crypto = "0.2.34"
|
|||||||
elastic-array = { git = "https://github.com/ethcore/elastic-array" }
|
elastic-array = { git = "https://github.com/ethcore/elastic-array" }
|
||||||
heapsize = { version = "0.3", features = ["unstable"] }
|
heapsize = { version = "0.3", features = ["unstable"] }
|
||||||
itertools = "0.4"
|
itertools = "0.4"
|
||||||
crossbeam = "0.2"
|
|
||||||
slab = "0.2"
|
|
||||||
sha3 = { path = "sha3" }
|
sha3 = { path = "sha3" }
|
||||||
clippy = { version = "0.0.80", optional = true}
|
clippy = { version = "0.0.80", optional = true}
|
||||||
igd = "0.5.0"
|
|
||||||
ethcore-devtools = { path = "../devtools" }
|
ethcore-devtools = { path = "../devtools" }
|
||||||
libc = "0.2.7"
|
libc = "0.2.7"
|
||||||
vergen = "0.1"
|
vergen = "0.1"
|
||||||
target_info = "0.1"
|
target_info = "0.1"
|
||||||
bigint = { path = "bigint" }
|
bigint = { path = "bigint" }
|
||||||
chrono = "0.2"
|
|
||||||
parking_lot = "0.2.6"
|
parking_lot = "0.2.6"
|
||||||
using_queue = { path = "using_queue" }
|
using_queue = { path = "using_queue" }
|
||||||
table = { path = "table" }
|
table = { path = "table" }
|
||||||
|
15
util/io/Cargo.toml
Normal file
15
util/io/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
description = "Ethcore IO library"
|
||||||
|
homepage = "http://ethcore.io"
|
||||||
|
license = "GPL-3.0"
|
||||||
|
name = "ethcore-io"
|
||||||
|
version = "1.3.0"
|
||||||
|
authors = ["Ethcore <admin@ethcore.io>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
mio = { git = "https://github.com/ethcore/mio", branch = "v0.5.x" }
|
||||||
|
crossbeam = "0.2"
|
||||||
|
parking_lot = "0.2.6"
|
||||||
|
log = "0.3"
|
||||||
|
slab = "0.2"
|
||||||
|
|
@ -19,8 +19,9 @@
|
|||||||
//! Example usage for creating a network service and adding an IO handler:
|
//! Example usage for creating a network service and adding an IO handler:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! extern crate ethcore_util;
|
//! extern crate ethcore_io;
|
||||||
//! use ethcore_util::*;
|
//! use ethcore_io::*;
|
||||||
|
//! use std::sync::Arc;
|
||||||
//!
|
//!
|
||||||
//! struct MyHandler;
|
//! struct MyHandler;
|
||||||
//!
|
//!
|
||||||
@ -52,8 +53,17 @@
|
|||||||
//! // Drop the service
|
//! // Drop the service
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
extern crate mio;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log as rlog;
|
||||||
|
extern crate slab;
|
||||||
|
extern crate crossbeam;
|
||||||
|
extern crate parking_lot;
|
||||||
|
|
||||||
mod service;
|
mod service;
|
||||||
mod worker;
|
mod worker;
|
||||||
|
mod panics;
|
||||||
|
|
||||||
use mio::{EventLoop, Token};
|
use mio::{EventLoop, Token};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@ -63,6 +73,8 @@ use std::fmt;
|
|||||||
pub enum IoError {
|
pub enum IoError {
|
||||||
/// Low level error from mio crate
|
/// Low level error from mio crate
|
||||||
Mio(::std::io::Error),
|
Mio(::std::io::Error),
|
||||||
|
/// Error concerning the Rust standard library's IO subsystem.
|
||||||
|
StdIo(::std::io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for IoError {
|
impl fmt::Display for IoError {
|
||||||
@ -70,11 +82,18 @@ impl fmt::Display for IoError {
|
|||||||
// just defer to the std implementation for now.
|
// just defer to the std implementation for now.
|
||||||
// we can refine the formatting when more variants are added.
|
// we can refine the formatting when more variants are added.
|
||||||
match *self {
|
match *self {
|
||||||
IoError::Mio(ref std_err) => std_err.fmt(f)
|
IoError::Mio(ref std_err) => std_err.fmt(f),
|
||||||
|
IoError::StdIo(ref std_err) => std_err.fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<::std::io::Error> for IoError {
|
||||||
|
fn from(err: ::std::io::Error) -> IoError {
|
||||||
|
IoError::StdIo(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<Message> From<::mio::NotifyError<service::IoMessage<Message>>> for IoError where Message: Send + Clone {
|
impl<Message> From<::mio::NotifyError<service::IoMessage<Message>>> for IoError where Message: Send + Clone {
|
||||||
fn from(_err: ::mio::NotifyError<service::IoMessage<Message>>) -> IoError {
|
fn from(_err: ::mio::NotifyError<service::IoMessage<Message>>) -> IoError {
|
||||||
IoError::Mio(::std::io::Error::new(::std::io::ErrorKind::ConnectionAborted, "Network IO notification error"))
|
IoError::Mio(::std::io::Error::new(::std::io::ErrorKind::ConnectionAborted, "Network IO notification error"))
|
||||||
@ -105,19 +124,20 @@ pub trait IoHandler<Message>: Send + Sync where Message: Send + Sync + Clone + '
|
|||||||
fn deregister_stream(&self, _stream: StreamToken, _event_loop: &mut EventLoop<IoManager<Message>>) {}
|
fn deregister_stream(&self, _stream: StreamToken, _event_loop: &mut EventLoop<IoManager<Message>>) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use io::service::TimerToken;
|
pub use service::TimerToken;
|
||||||
pub use io::service::StreamToken;
|
pub use service::StreamToken;
|
||||||
pub use io::service::IoContext;
|
pub use service::IoContext;
|
||||||
pub use io::service::IoService;
|
pub use service::IoService;
|
||||||
pub use io::service::IoChannel;
|
pub use service::IoChannel;
|
||||||
pub use io::service::IoManager;
|
pub use service::IoManager;
|
||||||
pub use io::service::TOKENS_PER_HANDLER;
|
pub use service::TOKENS_PER_HANDLER;
|
||||||
|
pub use panics::{PanicHandler, MayPanic, OnPanicListener, ForwardPanic};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use io::*;
|
use super::*;
|
||||||
|
|
||||||
struct MyHandler;
|
struct MyHandler;
|
||||||
|
|
@ -20,11 +20,9 @@ use std::collections::HashMap;
|
|||||||
use mio::*;
|
use mio::*;
|
||||||
use crossbeam::sync::chase_lev;
|
use crossbeam::sync::chase_lev;
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
use error::*;
|
use {IoError, IoHandler};
|
||||||
use io::{IoError, IoHandler};
|
use worker::{Worker, Work, WorkType};
|
||||||
use io::worker::{Worker, Work, WorkType};
|
|
||||||
use panics::*;
|
use panics::*;
|
||||||
|
|
||||||
use parking_lot::{RwLock};
|
use parking_lot::{RwLock};
|
||||||
use std::sync::{Condvar as SCondvar, Mutex as SMutex};
|
use std::sync::{Condvar as SCondvar, Mutex as SMutex};
|
||||||
|
|
||||||
@ -92,7 +90,7 @@ impl<Message> IoContext<Message> where Message: Send + Clone + 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Register a new IO timer. 'IoHandler::timeout' will be called with the token.
|
/// Register a new IO timer. 'IoHandler::timeout' will be called with the token.
|
||||||
pub fn register_timer(&self, token: TimerToken, ms: u64) -> Result<(), UtilError> {
|
pub fn register_timer(&self, token: TimerToken, ms: u64) -> Result<(), IoError> {
|
||||||
try!(self.channel.send_io(IoMessage::AddTimer {
|
try!(self.channel.send_io(IoMessage::AddTimer {
|
||||||
token: token,
|
token: token,
|
||||||
delay: ms,
|
delay: ms,
|
||||||
@ -102,7 +100,7 @@ impl<Message> IoContext<Message> where Message: Send + Clone + 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Delete a timer.
|
/// Delete a timer.
|
||||||
pub fn clear_timer(&self, token: TimerToken) -> Result<(), UtilError> {
|
pub fn clear_timer(&self, token: TimerToken) -> Result<(), IoError> {
|
||||||
try!(self.channel.send_io(IoMessage::RemoveTimer {
|
try!(self.channel.send_io(IoMessage::RemoveTimer {
|
||||||
token: token,
|
token: token,
|
||||||
handler_id: self.handler,
|
handler_id: self.handler,
|
||||||
@ -111,7 +109,7 @@ impl<Message> IoContext<Message> where Message: Send + Clone + 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Register a new IO stream.
|
/// Register a new IO stream.
|
||||||
pub fn register_stream(&self, token: StreamToken) -> Result<(), UtilError> {
|
pub fn register_stream(&self, token: StreamToken) -> Result<(), IoError> {
|
||||||
try!(self.channel.send_io(IoMessage::RegisterStream {
|
try!(self.channel.send_io(IoMessage::RegisterStream {
|
||||||
token: token,
|
token: token,
|
||||||
handler_id: self.handler,
|
handler_id: self.handler,
|
||||||
@ -120,7 +118,7 @@ impl<Message> IoContext<Message> where Message: Send + Clone + 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deregister an IO stream.
|
/// Deregister an IO stream.
|
||||||
pub fn deregister_stream(&self, token: StreamToken) -> Result<(), UtilError> {
|
pub fn deregister_stream(&self, token: StreamToken) -> Result<(), IoError> {
|
||||||
try!(self.channel.send_io(IoMessage::DeregisterStream {
|
try!(self.channel.send_io(IoMessage::DeregisterStream {
|
||||||
token: token,
|
token: token,
|
||||||
handler_id: self.handler,
|
handler_id: self.handler,
|
||||||
@ -129,7 +127,7 @@ impl<Message> IoContext<Message> where Message: Send + Clone + 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reregister an IO stream.
|
/// Reregister an IO stream.
|
||||||
pub fn update_registration(&self, token: StreamToken) -> Result<(), UtilError> {
|
pub fn update_registration(&self, token: StreamToken) -> Result<(), IoError> {
|
||||||
try!(self.channel.send_io(IoMessage::UpdateStreamRegistration {
|
try!(self.channel.send_io(IoMessage::UpdateStreamRegistration {
|
||||||
token: token,
|
token: token,
|
||||||
handler_id: self.handler,
|
handler_id: self.handler,
|
||||||
@ -138,7 +136,7 @@ impl<Message> IoContext<Message> where Message: Send + Clone + 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Broadcast a message to other IO clients
|
/// Broadcast a message to other IO clients
|
||||||
pub fn message(&self, message: Message) -> Result<(), UtilError> {
|
pub fn message(&self, message: Message) -> Result<(), IoError> {
|
||||||
try!(self.channel.send(message));
|
try!(self.channel.send(message));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -175,7 +173,7 @@ pub struct IoManager<Message> where Message: Send + Sync {
|
|||||||
|
|
||||||
impl<Message> IoManager<Message> where Message: Send + Sync + Clone + 'static {
|
impl<Message> IoManager<Message> where Message: Send + Sync + Clone + 'static {
|
||||||
/// Creates a new instance and registers it with the event loop.
|
/// Creates a new instance and registers it with the event loop.
|
||||||
pub fn start(panic_handler: Arc<PanicHandler>, event_loop: &mut EventLoop<IoManager<Message>>) -> Result<(), UtilError> {
|
pub fn start(panic_handler: Arc<PanicHandler>, event_loop: &mut EventLoop<IoManager<Message>>) -> Result<(), IoError> {
|
||||||
let (worker, stealer) = chase_lev::deque();
|
let (worker, stealer) = chase_lev::deque();
|
||||||
let num_workers = 4;
|
let num_workers = 4;
|
||||||
let work_ready_mutex = Arc::new(SMutex::new(()));
|
let work_ready_mutex = Arc::new(SMutex::new(()));
|
||||||
@ -187,7 +185,7 @@ impl<Message> IoManager<Message> where Message: Send + Sync + Clone + 'static {
|
|||||||
IoChannel::new(event_loop.channel()),
|
IoChannel::new(event_loop.channel()),
|
||||||
work_ready.clone(),
|
work_ready.clone(),
|
||||||
work_ready_mutex.clone(),
|
work_ready_mutex.clone(),
|
||||||
panic_handler.clone()
|
panic_handler.clone(),
|
||||||
)
|
)
|
||||||
).collect();
|
).collect();
|
||||||
|
|
||||||
@ -360,7 +358,7 @@ impl<Message> MayPanic for IoService<Message> where Message: Send + Sync + Clone
|
|||||||
|
|
||||||
impl<Message> IoService<Message> where Message: Send + Sync + Clone + 'static {
|
impl<Message> IoService<Message> where Message: Send + Sync + Clone + 'static {
|
||||||
/// Starts IO event loop
|
/// Starts IO event loop
|
||||||
pub fn start() -> Result<IoService<Message>, UtilError> {
|
pub fn start() -> Result<IoService<Message>, IoError> {
|
||||||
let panic_handler = PanicHandler::new_in_arc();
|
let panic_handler = PanicHandler::new_in_arc();
|
||||||
let mut config = EventLoopConfig::new();
|
let mut config = EventLoopConfig::new();
|
||||||
config.messages_per_tick(1024);
|
config.messages_per_tick(1024);
|
@ -19,8 +19,8 @@ use std::mem;
|
|||||||
use std::thread::{JoinHandle, self};
|
use std::thread::{JoinHandle, self};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
|
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
|
||||||
use crossbeam::sync::chase_lev;
|
use crossbeam::sync::chase_lev;
|
||||||
use io::service::{HandlerId, IoChannel, IoContext};
|
use service::{HandlerId, IoChannel, IoContext};
|
||||||
use io::{IoHandler};
|
use IoHandler;
|
||||||
use panics::*;
|
use panics::*;
|
||||||
|
|
||||||
use std::sync::{Condvar as SCondvar, Mutex as SMutex};
|
use std::sync::{Condvar as SCondvar, Mutex as SMutex};
|
29
util/network/Cargo.toml
Normal file
29
util/network/Cargo.toml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
[package]
|
||||||
|
description = "Ethcore network library"
|
||||||
|
homepage = "http://ethcore.io"
|
||||||
|
license = "GPL-3.0"
|
||||||
|
name = "ethcore-network"
|
||||||
|
version = "1.3.0"
|
||||||
|
authors = ["Ethcore <admin@ethcore.io>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
log = "0.3"
|
||||||
|
mio = { git = "https://github.com/ethcore/mio", branch = "v0.5.x" }
|
||||||
|
rand = "0.3.12"
|
||||||
|
time = "0.1.34"
|
||||||
|
tiny-keccak = "1.0"
|
||||||
|
rust-crypto = "0.2.34"
|
||||||
|
slab = "0.2"
|
||||||
|
clippy = { version = "0.0.79", optional = true}
|
||||||
|
igd = "0.5.0"
|
||||||
|
libc = "0.2.7"
|
||||||
|
parking_lot = "0.2.6"
|
||||||
|
ansi_term = "0.7"
|
||||||
|
rustc-serialize = "0.3"
|
||||||
|
ethcore-io = { path = "../io" }
|
||||||
|
ethcore-util = { path = ".." }
|
||||||
|
ethcore-devtools = { path = "../../devtools" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
dev = ["clippy"]
|
@ -20,17 +20,16 @@ use std::net::SocketAddr;
|
|||||||
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
|
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
|
||||||
use mio::{Handler, Token, EventSet, EventLoop, PollOpt, TryRead, TryWrite};
|
use mio::{Handler, Token, EventSet, EventLoop, PollOpt, TryRead, TryWrite};
|
||||||
use mio::tcp::*;
|
use mio::tcp::*;
|
||||||
use hash::*;
|
use util::hash::*;
|
||||||
use sha3::*;
|
use util::sha3::*;
|
||||||
use bytes::*;
|
use util::bytes::*;
|
||||||
use rlp::*;
|
use util::rlp::*;
|
||||||
use std::io::{self, Cursor, Read, Write};
|
use std::io::{self, Cursor, Read, Write};
|
||||||
use error::*;
|
use error::*;
|
||||||
use io::{IoContext, StreamToken};
|
use io::{IoContext, StreamToken};
|
||||||
use network::error::NetworkError;
|
use handshake::Handshake;
|
||||||
use network::handshake::Handshake;
|
use stats::NetworkStats;
|
||||||
use network::stats::NetworkStats;
|
use util::crypto;
|
||||||
use crypto;
|
|
||||||
use rcrypto::blockmodes::*;
|
use rcrypto::blockmodes::*;
|
||||||
use rcrypto::aessafe::*;
|
use rcrypto::aessafe::*;
|
||||||
use rcrypto::symmetriccipher::*;
|
use rcrypto::symmetriccipher::*;
|
||||||
@ -121,7 +120,7 @@ impl<Socket: GenericSocket> GenericConnection<Socket> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Writable IO handler. Called when the socket is ready to send.
|
/// Writable IO handler. Called when the socket is ready to send.
|
||||||
pub fn writable<Message>(&mut self, io: &IoContext<Message>) -> Result<WriteStatus, UtilError> where Message: Send + Clone {
|
pub fn writable<Message>(&mut self, io: &IoContext<Message>) -> Result<WriteStatus, NetworkError> where Message: Send + Clone {
|
||||||
if self.send_queue.is_empty() {
|
if self.send_queue.is_empty() {
|
||||||
return Ok(WriteStatus::Complete)
|
return Ok(WriteStatus::Complete)
|
||||||
}
|
}
|
||||||
@ -288,7 +287,7 @@ pub struct EncryptedConnection {
|
|||||||
|
|
||||||
impl EncryptedConnection {
|
impl EncryptedConnection {
|
||||||
/// Create an encrypted connection out of the handshake.
|
/// Create an encrypted connection out of the handshake.
|
||||||
pub fn new(handshake: &mut Handshake) -> Result<EncryptedConnection, UtilError> {
|
pub fn new(handshake: &mut Handshake) -> Result<EncryptedConnection, NetworkError> {
|
||||||
let shared = try!(crypto::ecdh::agree(handshake.ecdhe.secret(), &handshake.remote_ephemeral));
|
let shared = try!(crypto::ecdh::agree(handshake.ecdhe.secret(), &handshake.remote_ephemeral));
|
||||||
let mut nonce_material = H512::new();
|
let mut nonce_material = H512::new();
|
||||||
if handshake.originated {
|
if handshake.originated {
|
||||||
@ -341,7 +340,7 @@ impl EncryptedConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Send a packet
|
/// Send a packet
|
||||||
pub fn send_packet<Message>(&mut self, io: &IoContext<Message>, payload: &[u8]) -> Result<(), UtilError> where Message: Send + Clone {
|
pub fn send_packet<Message>(&mut self, io: &IoContext<Message>, payload: &[u8]) -> Result<(), NetworkError> where Message: Send + Clone {
|
||||||
let mut header = RlpStream::new();
|
let mut header = RlpStream::new();
|
||||||
let len = payload.len() as usize;
|
let len = payload.len() as usize;
|
||||||
header.append_raw(&[(len >> 16) as u8, (len >> 8) as u8, len as u8], 1);
|
header.append_raw(&[(len >> 16) as u8, (len >> 8) as u8, len as u8], 1);
|
||||||
@ -368,7 +367,7 @@ impl EncryptedConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Decrypt and authenticate an incoming packet header. Prepare for receiving payload.
|
/// Decrypt and authenticate an incoming packet header. Prepare for receiving payload.
|
||||||
fn read_header(&mut self, header: &[u8]) -> Result<(), UtilError> {
|
fn read_header(&mut self, header: &[u8]) -> Result<(), NetworkError> {
|
||||||
if header.len() != ENCRYPTED_HEADER_LEN {
|
if header.len() != ENCRYPTED_HEADER_LEN {
|
||||||
return Err(From::from(NetworkError::Auth));
|
return Err(From::from(NetworkError::Auth));
|
||||||
}
|
}
|
||||||
@ -398,7 +397,7 @@ impl EncryptedConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Decrypt and authenticate packet payload.
|
/// Decrypt and authenticate packet payload.
|
||||||
fn read_payload(&mut self, payload: &[u8]) -> Result<Packet, UtilError> {
|
fn read_payload(&mut self, payload: &[u8]) -> Result<Packet, NetworkError> {
|
||||||
let padding = (16 - (self.payload_len % 16)) % 16;
|
let padding = (16 - (self.payload_len % 16)) % 16;
|
||||||
let full_length = self.payload_len + padding + 16;
|
let full_length = self.payload_len + padding + 16;
|
||||||
if payload.len() != full_length {
|
if payload.len() != full_length {
|
||||||
@ -436,7 +435,7 @@ impl EncryptedConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Readable IO handler. Tracker receive status and returns decoded packet if avaialable.
|
/// Readable IO handler. Tracker receive status and returns decoded packet if avaialable.
|
||||||
pub fn readable<Message>(&mut self, io: &IoContext<Message>) -> Result<Option<Packet>, UtilError> where Message: Send + Clone{
|
pub fn readable<Message>(&mut self, io: &IoContext<Message>) -> Result<Option<Packet>, NetworkError> where Message: Send + Clone{
|
||||||
try!(io.clear_timer(self.connection.token));
|
try!(io.clear_timer(self.connection.token));
|
||||||
if let EncryptedConnectionState::Header = self.read_state {
|
if let EncryptedConnectionState::Header = self.read_state {
|
||||||
if let Some(data) = try!(self.connection.readable()) {
|
if let Some(data) = try!(self.connection.readable()) {
|
||||||
@ -459,7 +458,7 @@ impl EncryptedConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Writable IO handler. Processes send queeue.
|
/// Writable IO handler. Processes send queeue.
|
||||||
pub fn writable<Message>(&mut self, io: &IoContext<Message>) -> Result<(), UtilError> where Message: Send + Clone {
|
pub fn writable<Message>(&mut self, io: &IoContext<Message>) -> Result<(), NetworkError> where Message: Send + Clone {
|
||||||
try!(self.connection.writable(io));
|
try!(self.connection.writable(io));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -467,7 +466,7 @@ impl EncryptedConnection {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_encryption() {
|
pub fn test_encryption() {
|
||||||
use hash::*;
|
use util::hash::*;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
let key = H256::from_str("2212767d793a7a3d66f869ae324dd11bd17044b82c9f463b8a541a4d089efec5").unwrap();
|
let key = H256::from_str("2212767d793a7a3d66f869ae324dd11bd17044b82c9f463b8a541a4d089efec5").unwrap();
|
||||||
let before = H128::from_str("12532abaec065082a3cf1da7d0136f15").unwrap();
|
let before = H128::from_str("12532abaec065082a3cf1da7d0136f15").unwrap();
|
||||||
@ -496,7 +495,7 @@ mod tests {
|
|||||||
use std::io::{Read, Write, Error, Cursor, ErrorKind};
|
use std::io::{Read, Write, Error, Cursor, ErrorKind};
|
||||||
use mio::{EventSet};
|
use mio::{EventSet};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use bytes::*;
|
use util::bytes::*;
|
||||||
use devtools::*;
|
use devtools::*;
|
||||||
use io::*;
|
use io::*;
|
||||||
|
|
@ -14,23 +14,23 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use bytes::Bytes;
|
use util::bytes::Bytes;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::collections::{HashSet, HashMap, BTreeMap, VecDeque};
|
use std::collections::{HashSet, HashMap, BTreeMap, VecDeque};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use mio::*;
|
use mio::*;
|
||||||
use mio::udp::*;
|
use mio::udp::*;
|
||||||
use sha3::*;
|
use util::sha3::*;
|
||||||
use time;
|
use time;
|
||||||
use hash::*;
|
use util::hash::*;
|
||||||
use crypto::*;
|
use util::crypto::*;
|
||||||
use rlp::*;
|
use util::rlp::*;
|
||||||
use network::node_table::*;
|
use node_table::*;
|
||||||
use network::error::NetworkError;
|
use error::NetworkError;
|
||||||
use io::{StreamToken, IoContext};
|
use io::{StreamToken, IoContext};
|
||||||
|
|
||||||
use network::PROTOCOL_VERSION;
|
use PROTOCOL_VERSION;
|
||||||
|
|
||||||
const ADDRESS_BYTES_SIZE: u32 = 32; // Size of address type in bytes.
|
const ADDRESS_BYTES_SIZE: u32 = 32; // Size of address type in bytes.
|
||||||
const ADDRESS_BITS: u32 = 8 * ADDRESS_BYTES_SIZE; // Denoted by n in [Kademlia].
|
const ADDRESS_BITS: u32 = 8 * ADDRESS_BYTES_SIZE; // Denoted by n in [Kademlia].
|
||||||
@ -533,10 +533,10 @@ impl Discovery {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use hash::*;
|
use util::hash::*;
|
||||||
use std::net::*;
|
use std::net::*;
|
||||||
use network::node_table::*;
|
use node_table::*;
|
||||||
use crypto::KeyPair;
|
use util::crypto::KeyPair;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use rustc_serialize::hex::FromHex;
|
use rustc_serialize::hex::FromHex;
|
||||||
|
|
@ -15,8 +15,9 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use io::IoError;
|
use io::IoError;
|
||||||
use crypto::CryptoError;
|
use util::crypto::CryptoError;
|
||||||
use rlp::*;
|
use util::rlp::*;
|
||||||
|
use util::UtilError;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
@ -94,8 +95,16 @@ pub enum NetworkError {
|
|||||||
PeerNotFound,
|
PeerNotFound,
|
||||||
/// Peer is diconnected.
|
/// Peer is diconnected.
|
||||||
Disconnect(DisconnectReason),
|
Disconnect(DisconnectReason),
|
||||||
|
/// Util error.
|
||||||
|
Util(UtilError),
|
||||||
/// Socket IO error.
|
/// Socket IO error.
|
||||||
Io(IoError),
|
Io(IoError),
|
||||||
|
/// Error concerning the network address parsing subsystem.
|
||||||
|
AddressParse(::std::net::AddrParseError),
|
||||||
|
/// Error concerning the network address resolution subsystem.
|
||||||
|
AddressResolve(Option<::std::io::Error>),
|
||||||
|
/// Error concerning the Rust standard library's IO subsystem.
|
||||||
|
StdIo(::std::io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for NetworkError {
|
impl fmt::Display for NetworkError {
|
||||||
@ -109,6 +118,11 @@ impl fmt::Display for NetworkError {
|
|||||||
PeerNotFound => "Peer not found".into(),
|
PeerNotFound => "Peer not found".into(),
|
||||||
Disconnect(ref reason) => format!("Peer disconnected: {}", reason),
|
Disconnect(ref reason) => format!("Peer disconnected: {}", reason),
|
||||||
Io(ref err) => format!("Socket I/O error: {}", err),
|
Io(ref err) => format!("Socket I/O error: {}", err),
|
||||||
|
AddressParse(ref err) => format!("{}", err),
|
||||||
|
AddressResolve(Some(ref err)) => format!("{}", err),
|
||||||
|
AddressResolve(_) => "Failed to resolve network address.".into(),
|
||||||
|
StdIo(ref err) => format!("{}", err),
|
||||||
|
Util(ref err) => format!("{}", err),
|
||||||
};
|
};
|
||||||
|
|
||||||
f.write_fmt(format_args!("Network error ({})", msg))
|
f.write_fmt(format_args!("Network error ({})", msg))
|
||||||
@ -121,18 +135,36 @@ impl From<DecoderError> for NetworkError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<::std::io::Error> for NetworkError {
|
||||||
|
fn from(err: ::std::io::Error) -> NetworkError {
|
||||||
|
NetworkError::StdIo(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<IoError> for NetworkError {
|
impl From<IoError> for NetworkError {
|
||||||
fn from(err: IoError) -> NetworkError {
|
fn from(err: IoError) -> NetworkError {
|
||||||
NetworkError::Io(err)
|
NetworkError::Io(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<UtilError> for NetworkError {
|
||||||
|
fn from(err: UtilError) -> NetworkError {
|
||||||
|
NetworkError::Util(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<CryptoError> for NetworkError {
|
impl From<CryptoError> for NetworkError {
|
||||||
fn from(_err: CryptoError) -> NetworkError {
|
fn from(_err: CryptoError) -> NetworkError {
|
||||||
NetworkError::Auth
|
NetworkError::Auth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<::std::net::AddrParseError> for NetworkError {
|
||||||
|
fn from(err: ::std::net::AddrParseError) -> NetworkError {
|
||||||
|
NetworkError::AddressParse(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_errors() {
|
fn test_errors() {
|
||||||
assert_eq!(DisconnectReason::ClientQuit, DisconnectReason::from_u8(8));
|
assert_eq!(DisconnectReason::ClientQuit, DisconnectReason::from_u8(8));
|
@ -17,18 +17,17 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use rand::random;
|
use rand::random;
|
||||||
use mio::tcp::*;
|
use mio::tcp::*;
|
||||||
use hash::*;
|
use util::hash::*;
|
||||||
use rlp::*;
|
use util::rlp::*;
|
||||||
use sha3::Hashable;
|
use util::sha3::Hashable;
|
||||||
use bytes::Bytes;
|
use util::bytes::Bytes;
|
||||||
use crypto::*;
|
use util::crypto::*;
|
||||||
use crypto;
|
use util::crypto;
|
||||||
use network::connection::{Connection};
|
use connection::{Connection};
|
||||||
use network::host::{HostInfo};
|
use host::{HostInfo};
|
||||||
use network::node_table::NodeId;
|
use node_table::NodeId;
|
||||||
use error::*;
|
use error::*;
|
||||||
use network::error::NetworkError;
|
use stats::NetworkStats;
|
||||||
use network::stats::NetworkStats;
|
|
||||||
use io::{IoContext, StreamToken};
|
use io::{IoContext, StreamToken};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
@ -84,7 +83,7 @@ const ECIES_OVERHEAD: usize = 113;
|
|||||||
|
|
||||||
impl Handshake {
|
impl Handshake {
|
||||||
/// Create a new handshake object
|
/// Create a new handshake object
|
||||||
pub fn new(token: StreamToken, id: Option<&NodeId>, socket: TcpStream, nonce: &H256, stats: Arc<NetworkStats>) -> Result<Handshake, UtilError> {
|
pub fn new(token: StreamToken, id: Option<&NodeId>, socket: TcpStream, nonce: &H256, stats: Arc<NetworkStats>) -> Result<Handshake, NetworkError> {
|
||||||
Ok(Handshake {
|
Ok(Handshake {
|
||||||
id: if let Some(id) = id { id.clone()} else { NodeId::new() },
|
id: if let Some(id) = id { id.clone()} else { NodeId::new() },
|
||||||
connection: Connection::new(token, socket, stats),
|
connection: Connection::new(token, socket, stats),
|
||||||
@ -107,7 +106,7 @@ impl Handshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Start a handhsake
|
/// Start a handhsake
|
||||||
pub fn start<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo, originated: bool) -> Result<(), UtilError> where Message: Send + Clone{
|
pub fn start<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo, originated: bool) -> Result<(), NetworkError> where Message: Send + Clone{
|
||||||
self.originated = originated;
|
self.originated = originated;
|
||||||
io.register_timer(self.connection.token, HANDSHAKE_TIMEOUT).ok();
|
io.register_timer(self.connection.token, HANDSHAKE_TIMEOUT).ok();
|
||||||
if originated {
|
if originated {
|
||||||
@ -126,7 +125,7 @@ impl Handshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Readable IO handler. Drives the state change.
|
/// Readable IO handler. Drives the state change.
|
||||||
pub fn readable<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo) -> Result<(), UtilError> where Message: Send + Clone {
|
pub fn readable<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo) -> Result<(), NetworkError> where Message: Send + Clone {
|
||||||
if !self.expired() {
|
if !self.expired() {
|
||||||
while let Some(data) = try!(self.connection.readable()) {
|
while let Some(data) = try!(self.connection.readable()) {
|
||||||
match self.state {
|
match self.state {
|
||||||
@ -155,14 +154,14 @@ impl Handshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Writabe IO handler.
|
/// Writabe IO handler.
|
||||||
pub fn writable<Message>(&mut self, io: &IoContext<Message>) -> Result<(), UtilError> where Message: Send + Clone {
|
pub fn writable<Message>(&mut self, io: &IoContext<Message>) -> Result<(), NetworkError> where Message: Send + Clone {
|
||||||
if !self.expired() {
|
if !self.expired() {
|
||||||
try!(self.connection.writable(io));
|
try!(self.connection.writable(io));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_auth(&mut self, host_secret: &Secret, sig: &[u8], remote_public: &[u8], remote_nonce: &[u8], remote_version: u64) -> Result<(), UtilError> {
|
fn set_auth(&mut self, host_secret: &Secret, sig: &[u8], remote_public: &[u8], remote_nonce: &[u8], remote_version: u64) -> Result<(), NetworkError> {
|
||||||
self.id.clone_from_slice(remote_public);
|
self.id.clone_from_slice(remote_public);
|
||||||
self.remote_nonce.clone_from_slice(remote_nonce);
|
self.remote_nonce.clone_from_slice(remote_nonce);
|
||||||
self.remote_version = remote_version;
|
self.remote_version = remote_version;
|
||||||
@ -173,7 +172,7 @@ impl Handshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parse, validate and confirm auth message
|
/// Parse, validate and confirm auth message
|
||||||
fn read_auth<Message>(&mut self, io: &IoContext<Message>, secret: &Secret, data: &[u8]) -> Result<(), UtilError> where Message: Send + Clone {
|
fn read_auth<Message>(&mut self, io: &IoContext<Message>, secret: &Secret, data: &[u8]) -> Result<(), NetworkError> where Message: Send + Clone {
|
||||||
trace!(target: "network", "Received handshake auth from {:?}", self.connection.remote_addr_str());
|
trace!(target: "network", "Received handshake auth from {:?}", self.connection.remote_addr_str());
|
||||||
if data.len() != V4_AUTH_PACKET_SIZE {
|
if data.len() != V4_AUTH_PACKET_SIZE {
|
||||||
debug!(target: "network", "Wrong auth packet size");
|
debug!(target: "network", "Wrong auth packet size");
|
||||||
@ -204,7 +203,7 @@ impl Handshake {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_auth_eip8<Message>(&mut self, io: &IoContext<Message>, secret: &Secret, data: &[u8]) -> Result<(), UtilError> where Message: Send + Clone {
|
fn read_auth_eip8<Message>(&mut self, io: &IoContext<Message>, secret: &Secret, data: &[u8]) -> Result<(), NetworkError> where Message: Send + Clone {
|
||||||
trace!(target: "network", "Received EIP8 handshake auth from {:?}", self.connection.remote_addr_str());
|
trace!(target: "network", "Received EIP8 handshake auth from {:?}", self.connection.remote_addr_str());
|
||||||
self.auth_cipher.extend_from_slice(data);
|
self.auth_cipher.extend_from_slice(data);
|
||||||
let auth = try!(ecies::decrypt(secret, &self.auth_cipher[0..2], &self.auth_cipher[2..]));
|
let auth = try!(ecies::decrypt(secret, &self.auth_cipher[0..2], &self.auth_cipher[2..]));
|
||||||
@ -219,7 +218,7 @@ impl Handshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parse and validate ack message
|
/// Parse and validate ack message
|
||||||
fn read_ack(&mut self, secret: &Secret, data: &[u8]) -> Result<(), UtilError> {
|
fn read_ack(&mut self, secret: &Secret, data: &[u8]) -> Result<(), NetworkError> {
|
||||||
trace!(target: "network", "Received handshake ack from {:?}", self.connection.remote_addr_str());
|
trace!(target: "network", "Received handshake ack from {:?}", self.connection.remote_addr_str());
|
||||||
if data.len() != V4_ACK_PACKET_SIZE {
|
if data.len() != V4_ACK_PACKET_SIZE {
|
||||||
debug!(target: "network", "Wrong ack packet size");
|
debug!(target: "network", "Wrong ack packet size");
|
||||||
@ -247,7 +246,7 @@ impl Handshake {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_ack_eip8(&mut self, secret: &Secret, data: &[u8]) -> Result<(), UtilError> {
|
fn read_ack_eip8(&mut self, secret: &Secret, data: &[u8]) -> Result<(), NetworkError> {
|
||||||
trace!(target: "network", "Received EIP8 handshake auth from {:?}", self.connection.remote_addr_str());
|
trace!(target: "network", "Received EIP8 handshake auth from {:?}", self.connection.remote_addr_str());
|
||||||
self.ack_cipher.extend_from_slice(data);
|
self.ack_cipher.extend_from_slice(data);
|
||||||
let ack = try!(ecies::decrypt(secret, &self.ack_cipher[0..2], &self.ack_cipher[2..]));
|
let ack = try!(ecies::decrypt(secret, &self.ack_cipher[0..2], &self.ack_cipher[2..]));
|
||||||
@ -260,7 +259,7 @@ impl Handshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sends auth message
|
/// Sends auth message
|
||||||
fn write_auth<Message>(&mut self, io: &IoContext<Message>, secret: &Secret, public: &Public) -> Result<(), UtilError> where Message: Send + Clone {
|
fn write_auth<Message>(&mut self, io: &IoContext<Message>, secret: &Secret, public: &Public) -> Result<(), NetworkError> where Message: Send + Clone {
|
||||||
trace!(target: "network", "Sending handshake auth to {:?}", self.connection.remote_addr_str());
|
trace!(target: "network", "Sending handshake auth to {:?}", self.connection.remote_addr_str());
|
||||||
let mut data = [0u8; /*Signature::SIZE*/ 65 + /*H256::SIZE*/ 32 + /*Public::SIZE*/ 64 + /*H256::SIZE*/ 32 + 1]; //TODO: use associated constants
|
let mut data = [0u8; /*Signature::SIZE*/ 65 + /*H256::SIZE*/ 32 + /*Public::SIZE*/ 64 + /*H256::SIZE*/ 32 + 1]; //TODO: use associated constants
|
||||||
let len = data.len();
|
let len = data.len();
|
||||||
@ -287,7 +286,7 @@ impl Handshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sends ack message
|
/// Sends ack message
|
||||||
fn write_ack<Message>(&mut self, io: &IoContext<Message>) -> Result<(), UtilError> where Message: Send + Clone {
|
fn write_ack<Message>(&mut self, io: &IoContext<Message>) -> Result<(), NetworkError> where Message: Send + Clone {
|
||||||
trace!(target: "network", "Sending handshake ack to {:?}", self.connection.remote_addr_str());
|
trace!(target: "network", "Sending handshake ack to {:?}", self.connection.remote_addr_str());
|
||||||
let mut data = [0u8; 1 + /*Public::SIZE*/ 64 + /*H256::SIZE*/ 32]; //TODO: use associated constants
|
let mut data = [0u8; 1 + /*Public::SIZE*/ 64 + /*H256::SIZE*/ 32]; //TODO: use associated constants
|
||||||
let len = data.len();
|
let len = data.len();
|
||||||
@ -306,7 +305,7 @@ impl Handshake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sends EIP8 ack message
|
/// Sends EIP8 ack message
|
||||||
fn write_ack_eip8<Message>(&mut self, io: &IoContext<Message>) -> Result<(), UtilError> where Message: Send + Clone {
|
fn write_ack_eip8<Message>(&mut self, io: &IoContext<Message>) -> Result<(), NetworkError> where Message: Send + Clone {
|
||||||
trace!(target: "network", "Sending EIP8 handshake ack to {:?}", self.connection.remote_addr_str());
|
trace!(target: "network", "Sending EIP8 handshake ack to {:?}", self.connection.remote_addr_str());
|
||||||
let mut rlp = RlpStream::new_list(3);
|
let mut rlp = RlpStream::new_list(3);
|
||||||
rlp.append(self.ecdhe.public());
|
rlp.append(self.ecdhe.public());
|
||||||
@ -335,12 +334,12 @@ mod test {
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use rustc_serialize::hex::FromHex;
|
use rustc_serialize::hex::FromHex;
|
||||||
use super::*;
|
use super::*;
|
||||||
use crypto::*;
|
use util::crypto::*;
|
||||||
use hash::*;
|
use util::hash::*;
|
||||||
use io::*;
|
use io::*;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use mio::tcp::TcpStream;
|
use mio::tcp::TcpStream;
|
||||||
use network::stats::NetworkStats;
|
use stats::NetworkStats;
|
||||||
|
|
||||||
fn check_auth(h: &Handshake, version: u64) {
|
fn check_auth(h: &Handshake, version: u64) {
|
||||||
assert_eq!(h.id, Public::from_str("fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877").unwrap());
|
assert_eq!(h.id, Public::from_str("fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877").unwrap());
|
@ -27,21 +27,20 @@ use std::default::Default;
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use mio::*;
|
use mio::*;
|
||||||
use mio::tcp::*;
|
use mio::tcp::*;
|
||||||
use hash::*;
|
use util::hash::*;
|
||||||
use misc::*;
|
use util::crypto::*;
|
||||||
use crypto::*;
|
use util::Hashable;
|
||||||
use sha3::Hashable;
|
use util::rlp::*;
|
||||||
use rlp::*;
|
use util::version;
|
||||||
use network::session::{Session, SessionData};
|
use session::{Session, SessionData};
|
||||||
use error::*;
|
use error::*;
|
||||||
use io::*;
|
use io::*;
|
||||||
use network::{NetworkProtocolHandler, NonReservedPeerMode, PROTOCOL_VERSION};
|
use {NetworkProtocolHandler, NonReservedPeerMode, PROTOCOL_VERSION};
|
||||||
use network::node_table::*;
|
use node_table::*;
|
||||||
use network::stats::NetworkStats;
|
use stats::NetworkStats;
|
||||||
use network::error::{NetworkError, DisconnectReason};
|
use discovery::{Discovery, TableUpdates, NodeEntry};
|
||||||
use network::discovery::{Discovery, TableUpdates, NodeEntry};
|
use ip_utils::{map_external_address, select_public_address};
|
||||||
use network::ip_utils::{map_external_address, select_public_address};
|
use util::path::restrict_permissions_owner;
|
||||||
use path::restrict_permissions_owner;
|
|
||||||
use parking_lot::{Mutex, RwLock};
|
use parking_lot::{Mutex, RwLock};
|
||||||
|
|
||||||
type Slab<T> = ::slab::Slab<T, usize>;
|
type Slab<T> = ::slab::Slab<T, usize>;
|
||||||
@ -224,7 +223,7 @@ impl<'s> NetworkContext<'s> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Send a packet over the network to another peer.
|
/// Send a packet over the network to another peer.
|
||||||
pub fn send(&self, peer: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError> {
|
pub fn send(&self, peer: PeerId, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
|
||||||
let session = self.resolve_session(peer);
|
let session = self.resolve_session(peer);
|
||||||
if let Some(session) = session {
|
if let Some(session) = session {
|
||||||
try!(session.lock().send_packet(self.io, self.protocol, packet_id as u8, &data));
|
try!(session.lock().send_packet(self.io, self.protocol, packet_id as u8, &data));
|
||||||
@ -235,7 +234,7 @@ impl<'s> NetworkContext<'s> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Respond to a current network message. Panics if no there is no packet in the context. If the session is expired returns nothing.
|
/// Respond to a current network message. Panics if no there is no packet in the context. If the session is expired returns nothing.
|
||||||
pub fn respond(&self, packet_id: PacketId, data: Vec<u8>) -> Result<(), UtilError> {
|
pub fn respond(&self, packet_id: PacketId, data: Vec<u8>) -> Result<(), NetworkError> {
|
||||||
assert!(self.session.is_some(), "Respond called without network context");
|
assert!(self.session.is_some(), "Respond called without network context");
|
||||||
self.send(self.session_id.unwrap(), packet_id, data)
|
self.send(self.session_id.unwrap(), packet_id, data)
|
||||||
}
|
}
|
||||||
@ -264,7 +263,7 @@ impl<'s> NetworkContext<'s> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Register a new IO timer. 'IoHandler::timeout' will be called with the token.
|
/// Register a new IO timer. 'IoHandler::timeout' will be called with the token.
|
||||||
pub fn register_timer(&self, token: TimerToken, ms: u64) -> Result<(), UtilError> {
|
pub fn register_timer(&self, token: TimerToken, ms: u64) -> Result<(), NetworkError> {
|
||||||
self.io.message(NetworkIoMessage::AddTimer {
|
self.io.message(NetworkIoMessage::AddTimer {
|
||||||
token: token,
|
token: token,
|
||||||
delay: ms,
|
delay: ms,
|
||||||
@ -347,7 +346,7 @@ pub struct Host {
|
|||||||
|
|
||||||
impl Host {
|
impl Host {
|
||||||
/// Create a new instance
|
/// Create a new instance
|
||||||
pub fn new(config: NetworkConfiguration, stats: Arc<NetworkStats>) -> Result<Host, UtilError> {
|
pub fn new(config: NetworkConfiguration, stats: Arc<NetworkStats>) -> Result<Host, NetworkError> {
|
||||||
trace!(target: "host", "Creating new Host object");
|
trace!(target: "host", "Creating new Host object");
|
||||||
|
|
||||||
let mut listen_address = match config.listen_address {
|
let mut listen_address = match config.listen_address {
|
||||||
@ -428,7 +427,7 @@ impl Host {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_reserved_node(&self, id: &str) -> Result<(), UtilError> {
|
pub fn add_reserved_node(&self, id: &str) -> Result<(), NetworkError> {
|
||||||
let n = try!(Node::from_str(id));
|
let n = try!(Node::from_str(id));
|
||||||
|
|
||||||
let entry = NodeEntry { endpoint: n.endpoint.clone(), id: n.id.clone() };
|
let entry = NodeEntry { endpoint: n.endpoint.clone(), id: n.id.clone() };
|
||||||
@ -472,7 +471,7 @@ impl Host {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_reserved_node(&self, id: &str) -> Result<(), UtilError> {
|
pub fn remove_reserved_node(&self, id: &str) -> Result<(), NetworkError> {
|
||||||
let n = try!(Node::from_str(id));
|
let n = try!(Node::from_str(id));
|
||||||
self.reserved_nodes.write().remove(&n.id);
|
self.reserved_nodes.write().remove(&n.id);
|
||||||
|
|
||||||
@ -493,7 +492,7 @@ impl Host {
|
|||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(&self, io: &IoContext<NetworkIoMessage>) -> Result<(), UtilError> {
|
pub fn stop(&self, io: &IoContext<NetworkIoMessage>) -> Result<(), NetworkError> {
|
||||||
self.stopping.store(true, AtomicOrdering::Release);
|
self.stopping.store(true, AtomicOrdering::Release);
|
||||||
let mut to_kill = Vec::new();
|
let mut to_kill = Vec::new();
|
||||||
for e in self.sessions.write().iter_mut() {
|
for e in self.sessions.write().iter_mut() {
|
||||||
@ -509,7 +508,7 @@ impl Host {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_public_interface(&self, io: &IoContext<NetworkIoMessage>) -> Result<(), UtilError> {
|
fn init_public_interface(&self, io: &IoContext<NetworkIoMessage>) -> Result<(), NetworkError> {
|
||||||
if self.info.read().public_endpoint.is_some() {
|
if self.info.read().public_endpoint.is_some() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -684,7 +683,7 @@ impl Host {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature="dev", allow(block_in_if_condition_stmt))]
|
#[cfg_attr(feature="dev", allow(block_in_if_condition_stmt))]
|
||||||
fn create_connection(&self, socket: TcpStream, id: Option<&NodeId>, io: &IoContext<NetworkIoMessage>) -> Result<(), UtilError> {
|
fn create_connection(&self, socket: TcpStream, id: Option<&NodeId>, io: &IoContext<NetworkIoMessage>) -> Result<(), NetworkError> {
|
||||||
let nonce = self.info.write().next_nonce();
|
let nonce = self.info.write().next_nonce();
|
||||||
let mut sessions = self.sessions.write();
|
let mut sessions = self.sessions.write();
|
||||||
|
|
||||||
@ -699,7 +698,7 @@ impl Host {
|
|||||||
});
|
});
|
||||||
|
|
||||||
match token {
|
match token {
|
||||||
Some(t) => io.register_stream(t),
|
Some(t) => Ok(try!(From::from(io.register_stream(t)))),
|
||||||
None => {
|
None => {
|
||||||
debug!(target: "network", "Max sessions reached");
|
debug!(target: "network", "Max sessions reached");
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -756,7 +755,7 @@ impl Host {
|
|||||||
match session_result {
|
match session_result {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace!(target: "network", "Session read error: {}:{:?} ({:?}) {:?}", token, s.id(), s.remote_addr(), e);
|
trace!(target: "network", "Session read error: {}:{:?} ({:?}) {:?}", token, s.id(), s.remote_addr(), e);
|
||||||
if let UtilError::Network(NetworkError::Disconnect(DisconnectReason::IncompatibleProtocol)) = e {
|
if let NetworkError::Disconnect(DisconnectReason::IncompatibleProtocol) = e {
|
||||||
if let Some(id) = s.id() {
|
if let Some(id) = s.id() {
|
||||||
if !self.reserved_nodes.read().contains(id) {
|
if !self.reserved_nodes.read().contains(id) {
|
||||||
self.nodes.write().mark_as_useless(id);
|
self.nodes.write().mark_as_useless(id);
|
@ -20,7 +20,7 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV
|
|||||||
use std::io;
|
use std::io;
|
||||||
use igd::{PortMappingProtocol, search_gateway_from_timeout};
|
use igd::{PortMappingProtocol, search_gateway_from_timeout};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use network::node_table::{NodeEndpoint};
|
use node_table::{NodeEndpoint};
|
||||||
|
|
||||||
/// Socket address extension for rustc beta. To be replaces with now unstable API
|
/// Socket address extension for rustc beta. To be replaces with now unstable API
|
||||||
pub trait SocketAddrExt {
|
pub trait SocketAddrExt {
|
@ -19,8 +19,9 @@
|
|||||||
//! Example usage for craeting a network service and adding an IO handler:
|
//! Example usage for craeting a network service and adding an IO handler:
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! extern crate ethcore_util as util;
|
//! extern crate ethcore_network as net;
|
||||||
//! use util::*;
|
//! use net::*;
|
||||||
|
//! use std::sync::Arc;
|
||||||
//!
|
//!
|
||||||
//! struct MyHandler;
|
//! struct MyHandler;
|
||||||
//!
|
//!
|
||||||
@ -40,10 +41,6 @@
|
|||||||
//! fn disconnected(&self, io: &NetworkContext, peer: &PeerId) {
|
//! fn disconnected(&self, io: &NetworkContext, peer: &PeerId) {
|
||||||
//! println!("Disconnected {}", peer);
|
//! println!("Disconnected {}", peer);
|
||||||
//! }
|
//! }
|
||||||
//!
|
|
||||||
//! fn timeout(&self, io: &NetworkContext, timer: TimerToken) {
|
|
||||||
//! println!("Timeout {}", timer);
|
|
||||||
//! }
|
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! fn main () {
|
//! fn main () {
|
||||||
@ -56,6 +53,26 @@
|
|||||||
//! // Drop the service
|
//! // Drop the service
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
extern crate ethcore_io as io;
|
||||||
|
extern crate ethcore_util as util;
|
||||||
|
extern crate parking_lot;
|
||||||
|
extern crate mio;
|
||||||
|
extern crate tiny_keccak;
|
||||||
|
extern crate crypto as rcrypto;
|
||||||
|
extern crate rand;
|
||||||
|
extern crate time;
|
||||||
|
extern crate ansi_term; //TODO: remove this
|
||||||
|
extern crate rustc_serialize;
|
||||||
|
extern crate igd;
|
||||||
|
extern crate libc;
|
||||||
|
extern crate slab;
|
||||||
|
#[cfg(test)]
|
||||||
|
extern crate ethcore_devtools as devtools;
|
||||||
|
|
||||||
mod host;
|
mod host;
|
||||||
mod connection;
|
mod connection;
|
||||||
mod handshake;
|
mod handshake;
|
||||||
@ -70,17 +87,17 @@ mod ip_utils;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
pub use network::host::PeerId;
|
pub use host::PeerId;
|
||||||
pub use network::host::PacketId;
|
pub use host::PacketId;
|
||||||
pub use network::host::NetworkContext;
|
pub use host::NetworkContext;
|
||||||
pub use network::service::NetworkService;
|
pub use service::NetworkService;
|
||||||
pub use network::host::NetworkIoMessage;
|
pub use host::NetworkIoMessage;
|
||||||
pub use network::error::NetworkError;
|
pub use error::NetworkError;
|
||||||
pub use network::host::NetworkConfiguration;
|
pub use host::NetworkConfiguration;
|
||||||
pub use network::stats::NetworkStats;
|
pub use stats::NetworkStats;
|
||||||
|
|
||||||
use io::TimerToken;
|
use io::TimerToken;
|
||||||
pub use network::node_table::is_valid_node_url;
|
pub use node_table::is_valid_node_url;
|
||||||
|
|
||||||
const PROTOCOL_VERSION: u32 = 4;
|
const PROTOCOL_VERSION: u32 = 4;
|
||||||
|
|
@ -25,12 +25,12 @@ use std::path::{PathBuf};
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use hash::*;
|
use util::hash::*;
|
||||||
use rlp::*;
|
use util::rlp::*;
|
||||||
use time::Tm;
|
use time::Tm;
|
||||||
use error::*;
|
use error::NetworkError;
|
||||||
use network::discovery::{TableUpdates, NodeEntry};
|
use discovery::{TableUpdates, NodeEntry};
|
||||||
use network::ip_utils::*;
|
use ip_utils::*;
|
||||||
pub use rustc_serialize::json::Json;
|
pub use rustc_serialize::json::Json;
|
||||||
|
|
||||||
/// Node public key
|
/// Node public key
|
||||||
@ -107,18 +107,18 @@ impl NodeEndpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for NodeEndpoint {
|
impl FromStr for NodeEndpoint {
|
||||||
type Err = UtilError;
|
type Err = NetworkError;
|
||||||
|
|
||||||
/// Create endpoint from string. Performs name resolution if given a host name.
|
/// Create endpoint from string. Performs name resolution if given a host name.
|
||||||
fn from_str(s: &str) -> Result<NodeEndpoint, UtilError> {
|
fn from_str(s: &str) -> Result<NodeEndpoint, NetworkError> {
|
||||||
let address = s.to_socket_addrs().map(|mut i| i.next());
|
let address = s.to_socket_addrs().map(|mut i| i.next());
|
||||||
match address {
|
match address {
|
||||||
Ok(Some(a)) => Ok(NodeEndpoint {
|
Ok(Some(a)) => Ok(NodeEndpoint {
|
||||||
address: a,
|
address: a,
|
||||||
udp_port: a.port()
|
udp_port: a.port()
|
||||||
}),
|
}),
|
||||||
Ok(_) => Err(UtilError::AddressResolve(None)),
|
Ok(_) => Err(NetworkError::AddressResolve(None)),
|
||||||
Err(e) => Err(UtilError::AddressResolve(Some(e)))
|
Err(e) => Err(NetworkError::AddressResolve(Some(e)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ impl Display for Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Node {
|
impl FromStr for Node {
|
||||||
type Err = UtilError;
|
type Err = NetworkError;
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let (id, endpoint) = if s.len() > 136 && &s[0..8] == "enode://" && &s[136..137] == "@" {
|
let (id, endpoint) = if s.len() > 136 && &s[0..8] == "enode://" && &s[136..137] == "@" {
|
||||||
(try!(NodeId::from_str(&s[8..136])), try!(NodeEndpoint::from_str(&s[137..])))
|
(try!(NodeId::from_str(&s[8..136])), try!(NodeEndpoint::from_str(&s[137..])))
|
||||||
@ -357,7 +357,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::net::*;
|
use std::net::*;
|
||||||
use hash::*;
|
use util::hash::*;
|
||||||
use devtools::*;
|
use devtools::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
@ -14,12 +14,10 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use error::*;
|
use {NetworkProtocolHandler, NetworkConfiguration, NonReservedPeerMode};
|
||||||
use panics::*;
|
use error::NetworkError;
|
||||||
use network::{NetworkProtocolHandler, NetworkConfiguration};
|
use host::{Host, NetworkContext, NetworkIoMessage, ProtocolId};
|
||||||
use network::error::NetworkError;
|
use stats::NetworkStats;
|
||||||
use network::host::{Host, NetworkContext, NetworkIoMessage, ProtocolId};
|
|
||||||
use network::stats::NetworkStats;
|
|
||||||
use io::*;
|
use io::*;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -55,7 +53,7 @@ pub struct NetworkService {
|
|||||||
|
|
||||||
impl NetworkService {
|
impl NetworkService {
|
||||||
/// Starts IO event loop
|
/// Starts IO event loop
|
||||||
pub fn new(config: NetworkConfiguration) -> Result<NetworkService, UtilError> {
|
pub fn new(config: NetworkConfiguration) -> Result<NetworkService, NetworkError> {
|
||||||
let host_handler = Arc::new(HostHandler { public_url: RwLock::new(None) });
|
let host_handler = Arc::new(HostHandler { public_url: RwLock::new(None) });
|
||||||
let panic_handler = PanicHandler::new_in_arc();
|
let panic_handler = PanicHandler::new_in_arc();
|
||||||
let io_service = try!(IoService::<NetworkIoMessage>::start());
|
let io_service = try!(IoService::<NetworkIoMessage>::start());
|
||||||
@ -117,7 +115,7 @@ impl NetworkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Start network IO
|
/// Start network IO
|
||||||
pub fn start(&self) -> Result<(), UtilError> {
|
pub fn start(&self) -> Result<(), NetworkError> {
|
||||||
let mut host = self.host.write();
|
let mut host = self.host.write();
|
||||||
if host.is_none() {
|
if host.is_none() {
|
||||||
let h = Arc::new(try!(Host::new(self.config.clone(), self.stats.clone())));
|
let h = Arc::new(try!(Host::new(self.config.clone(), self.stats.clone())));
|
||||||
@ -133,7 +131,7 @@ impl NetworkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Stop network IO
|
/// Stop network IO
|
||||||
pub fn stop(&self) -> Result<(), UtilError> {
|
pub fn stop(&self) -> Result<(), NetworkError> {
|
||||||
let mut host = self.host.write();
|
let mut host = self.host.write();
|
||||||
if let Some(ref host) = *host {
|
if let Some(ref host) = *host {
|
||||||
let io = IoContext::new(self.io_service.channel(), 0); //TODO: take token id from host
|
let io = IoContext::new(self.io_service.channel(), 0); //TODO: take token id from host
|
||||||
@ -144,7 +142,7 @@ impl NetworkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Try to add a reserved peer.
|
/// Try to add a reserved peer.
|
||||||
pub fn add_reserved_peer(&self, peer: &str) -> Result<(), UtilError> {
|
pub fn add_reserved_peer(&self, peer: &str) -> Result<(), NetworkError> {
|
||||||
let host = self.host.read();
|
let host = self.host.read();
|
||||||
if let Some(ref host) = *host {
|
if let Some(ref host) = *host {
|
||||||
host.add_reserved_node(peer)
|
host.add_reserved_node(peer)
|
||||||
@ -154,7 +152,7 @@ impl NetworkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Try to remove a reserved peer.
|
/// Try to remove a reserved peer.
|
||||||
pub fn remove_reserved_peer(&self, peer: &str) -> Result<(), UtilError> {
|
pub fn remove_reserved_peer(&self, peer: &str) -> Result<(), NetworkError> {
|
||||||
let host = self.host.read();
|
let host = self.host.read();
|
||||||
if let Some(ref host) = *host {
|
if let Some(ref host) = *host {
|
||||||
host.remove_reserved_node(peer)
|
host.remove_reserved_node(peer)
|
||||||
@ -164,7 +162,7 @@ impl NetworkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the non-reserved peer mode.
|
/// Set the non-reserved peer mode.
|
||||||
pub fn set_non_reserved_mode(&self, mode: ::network::NonReservedPeerMode) {
|
pub fn set_non_reserved_mode(&self, mode: NonReservedPeerMode) {
|
||||||
let host = self.host.read();
|
let host = self.host.read();
|
||||||
if let Some(ref host) = *host {
|
if let Some(ref host) = *host {
|
||||||
let io_ctxt = IoContext::new(self.io_service.channel(), 0);
|
let io_ctxt = IoContext::new(self.io_service.channel(), 0);
|
@ -19,16 +19,15 @@ use std::io;
|
|||||||
use std::sync::*;
|
use std::sync::*;
|
||||||
use mio::*;
|
use mio::*;
|
||||||
use mio::tcp::*;
|
use mio::tcp::*;
|
||||||
use rlp::*;
|
use util::rlp::*;
|
||||||
use hash::*;
|
use util::hash::*;
|
||||||
use network::connection::{EncryptedConnection, Packet, Connection};
|
use connection::{EncryptedConnection, Packet, Connection};
|
||||||
use network::handshake::Handshake;
|
use handshake::Handshake;
|
||||||
use error::*;
|
|
||||||
use io::{IoContext, StreamToken};
|
use io::{IoContext, StreamToken};
|
||||||
use network::error::{NetworkError, DisconnectReason};
|
use error::{NetworkError, DisconnectReason};
|
||||||
use network::host::*;
|
use host::*;
|
||||||
use network::node_table::NodeId;
|
use node_table::NodeId;
|
||||||
use network::stats::NetworkStats;
|
use stats::NetworkStats;
|
||||||
use time;
|
use time;
|
||||||
|
|
||||||
const PING_TIMEOUT_SEC: u64 = 30;
|
const PING_TIMEOUT_SEC: u64 = 30;
|
||||||
@ -125,7 +124,7 @@ impl Session {
|
|||||||
/// Create a new session out of comepleted handshake. This clones the handshake connection object
|
/// Create a new session out of comepleted handshake. This clones the handshake connection object
|
||||||
/// and leaves the handhsake in limbo to be deregistered from the event loop.
|
/// and leaves the handhsake in limbo to be deregistered from the event loop.
|
||||||
pub fn new<Message>(io: &IoContext<Message>, socket: TcpStream, token: StreamToken, id: Option<&NodeId>,
|
pub fn new<Message>(io: &IoContext<Message>, socket: TcpStream, token: StreamToken, id: Option<&NodeId>,
|
||||||
nonce: &H256, stats: Arc<NetworkStats>, host: &HostInfo) -> Result<Session, UtilError>
|
nonce: &H256, stats: Arc<NetworkStats>, host: &HostInfo) -> Result<Session, NetworkError>
|
||||||
where Message: Send + Clone {
|
where Message: Send + Clone {
|
||||||
let originated = id.is_some();
|
let originated = id.is_some();
|
||||||
let mut handshake = Handshake::new(token, id, socket, nonce, stats).expect("Can't create handshake");
|
let mut handshake = Handshake::new(token, id, socket, nonce, stats).expect("Can't create handshake");
|
||||||
@ -147,7 +146,7 @@ impl Session {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_handshake<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo) -> Result<(), UtilError> where Message: Send + Sync + Clone {
|
fn complete_handshake<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo) -> Result<(), NetworkError> where Message: Send + Sync + Clone {
|
||||||
let connection = if let State::Handshake(ref mut h) = self.state {
|
let connection = if let State::Handshake(ref mut h) = self.state {
|
||||||
self.info.id = Some(h.id.clone());
|
self.info.id = Some(h.id.clone());
|
||||||
try!(EncryptedConnection::new(h))
|
try!(EncryptedConnection::new(h))
|
||||||
@ -201,7 +200,7 @@ impl Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Readable IO handler. Returns packet data if available.
|
/// Readable IO handler. Returns packet data if available.
|
||||||
pub fn readable<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo) -> Result<SessionData, UtilError> where Message: Send + Sync + Clone {
|
pub fn readable<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo) -> Result<SessionData, NetworkError> where Message: Send + Sync + Clone {
|
||||||
if self.expired() {
|
if self.expired() {
|
||||||
return Ok(SessionData::None)
|
return Ok(SessionData::None)
|
||||||
}
|
}
|
||||||
@ -232,7 +231,7 @@ impl Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Writable IO handler. Sends pending packets.
|
/// Writable IO handler. Sends pending packets.
|
||||||
pub fn writable<Message>(&mut self, io: &IoContext<Message>, _host: &HostInfo) -> Result<(), UtilError> where Message: Send + Sync + Clone {
|
pub fn writable<Message>(&mut self, io: &IoContext<Message>, _host: &HostInfo) -> Result<(), NetworkError> where Message: Send + Sync + Clone {
|
||||||
match self.state {
|
match self.state {
|
||||||
State::Handshake(ref mut h) => h.writable(io),
|
State::Handshake(ref mut h) => h.writable(io),
|
||||||
State::Session(ref mut s) => s.writable(io),
|
State::Session(ref mut s) => s.writable(io),
|
||||||
@ -245,7 +244,7 @@ impl Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Register the session socket with the event loop
|
/// Register the session socket with the event loop
|
||||||
pub fn register_socket<Host:Handler<Timeout = Token>>(&self, reg: Token, event_loop: &mut EventLoop<Host>) -> Result<(), UtilError> {
|
pub fn register_socket<Host:Handler<Timeout = Token>>(&self, reg: Token, event_loop: &mut EventLoop<Host>) -> Result<(), NetworkError> {
|
||||||
if self.expired() {
|
if self.expired() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -254,19 +253,19 @@ impl Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Update registration with the event loop. Should be called at the end of the IO handler.
|
/// Update registration with the event loop. Should be called at the end of the IO handler.
|
||||||
pub fn update_socket<Host:Handler>(&self, reg:Token, event_loop: &mut EventLoop<Host>) -> Result<(), UtilError> {
|
pub fn update_socket<Host:Handler>(&self, reg:Token, event_loop: &mut EventLoop<Host>) -> Result<(), NetworkError> {
|
||||||
try!(self.connection().update_socket(reg, event_loop));
|
try!(self.connection().update_socket(reg, event_loop));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Delete registration
|
/// Delete registration
|
||||||
pub fn deregister_socket<Host:Handler>(&self, event_loop: &mut EventLoop<Host>) -> Result<(), UtilError> {
|
pub fn deregister_socket<Host:Handler>(&self, event_loop: &mut EventLoop<Host>) -> Result<(), NetworkError> {
|
||||||
try!(self.connection().deregister_socket(event_loop));
|
try!(self.connection().deregister_socket(event_loop));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a protocol packet to peer.
|
/// Send a protocol packet to peer.
|
||||||
pub fn send_packet<Message>(&mut self, io: &IoContext<Message>, protocol: &str, packet_id: u8, data: &[u8]) -> Result<(), UtilError>
|
pub fn send_packet<Message>(&mut self, io: &IoContext<Message>, protocol: &str, packet_id: u8, data: &[u8]) -> Result<(), NetworkError>
|
||||||
where Message: Send + Sync + Clone {
|
where Message: Send + Sync + Clone {
|
||||||
if self.info.capabilities.is_empty() || !self.had_hello {
|
if self.info.capabilities.is_empty() || !self.had_hello {
|
||||||
debug!(target: "network", "Sending to unconfirmed session {}, protocol: {}, packet: {}", self.token(), protocol, packet_id);
|
debug!(target: "network", "Sending to unconfirmed session {}, protocol: {}, packet: {}", self.token(), protocol, packet_id);
|
||||||
@ -313,7 +312,7 @@ impl Session {
|
|||||||
self.connection().token()
|
self.connection().token()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_packet<Message>(&mut self, io: &IoContext<Message>, packet: Packet, host: &HostInfo) -> Result<SessionData, UtilError>
|
fn read_packet<Message>(&mut self, io: &IoContext<Message>, packet: Packet, host: &HostInfo) -> Result<SessionData, NetworkError>
|
||||||
where Message: Send + Sync + Clone {
|
where Message: Send + Sync + Clone {
|
||||||
if packet.data.len() < 2 {
|
if packet.data.len() < 2 {
|
||||||
return Err(From::from(NetworkError::BadProtocol));
|
return Err(From::from(NetworkError::BadProtocol));
|
||||||
@ -369,7 +368,7 @@ impl Session {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_hello<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo) -> Result<(), UtilError> where Message: Send + Sync + Clone {
|
fn write_hello<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo) -> Result<(), NetworkError> where Message: Send + Sync + Clone {
|
||||||
let mut rlp = RlpStream::new();
|
let mut rlp = RlpStream::new();
|
||||||
rlp.append_raw(&[PACKET_HELLO as u8], 0);
|
rlp.append_raw(&[PACKET_HELLO as u8], 0);
|
||||||
rlp.begin_list(5)
|
rlp.begin_list(5)
|
||||||
@ -381,7 +380,7 @@ impl Session {
|
|||||||
self.send(io, rlp)
|
self.send(io, rlp)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_hello<Message>(&mut self, io: &IoContext<Message>, rlp: &UntrustedRlp, host: &HostInfo) -> Result<(), UtilError>
|
fn read_hello<Message>(&mut self, io: &IoContext<Message>, rlp: &UntrustedRlp, host: &HostInfo) -> Result<(), NetworkError>
|
||||||
where Message: Send + Sync + Clone {
|
where Message: Send + Sync + Clone {
|
||||||
let protocol = try!(rlp.val_at::<u32>(0));
|
let protocol = try!(rlp.val_at::<u32>(0));
|
||||||
let client_version = try!(rlp.val_at::<String>(1));
|
let client_version = try!(rlp.val_at::<String>(1));
|
||||||
@ -436,14 +435,14 @@ impl Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Senf ping packet
|
/// Senf ping packet
|
||||||
pub fn send_ping<Message>(&mut self, io: &IoContext<Message>) -> Result<(), UtilError> where Message: Send + Sync + Clone {
|
pub fn send_ping<Message>(&mut self, io: &IoContext<Message>) -> Result<(), NetworkError> where Message: Send + Sync + Clone {
|
||||||
try!(self.send(io, try!(Session::prepare(PACKET_PING))));
|
try!(self.send(io, try!(Session::prepare(PACKET_PING))));
|
||||||
self.ping_time_ns = time::precise_time_ns();
|
self.ping_time_ns = time::precise_time_ns();
|
||||||
self.pong_time_ns = None;
|
self.pong_time_ns = None;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_pong<Message>(&mut self, io: &IoContext<Message>) -> Result<(), UtilError> where Message: Send + Sync + Clone {
|
fn send_pong<Message>(&mut self, io: &IoContext<Message>) -> Result<(), NetworkError> where Message: Send + Sync + Clone {
|
||||||
self.send(io, try!(Session::prepare(PACKET_PONG)))
|
self.send(io, try!(Session::prepare(PACKET_PONG)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,14 +458,14 @@ impl Session {
|
|||||||
NetworkError::Disconnect(reason)
|
NetworkError::Disconnect(reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare(packet_id: u8) -> Result<RlpStream, UtilError> {
|
fn prepare(packet_id: u8) -> Result<RlpStream, NetworkError> {
|
||||||
let mut rlp = RlpStream::new();
|
let mut rlp = RlpStream::new();
|
||||||
rlp.append(&(packet_id as u32));
|
rlp.append(&(packet_id as u32));
|
||||||
rlp.begin_list(0);
|
rlp.begin_list(0);
|
||||||
Ok(rlp)
|
Ok(rlp)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send<Message>(&mut self, io: &IoContext<Message>, rlp: RlpStream) -> Result<(), UtilError> where Message: Send + Sync + Clone {
|
fn send<Message>(&mut self, io: &IoContext<Message>, rlp: RlpStream) -> Result<(), NetworkError> where Message: Send + Sync + Clone {
|
||||||
match self.state {
|
match self.state {
|
||||||
State::Handshake(_) => {
|
State::Handshake(_) => {
|
||||||
warn!(target:"network", "Unexpected send request");
|
warn!(target:"network", "Unexpected send request");
|
@ -14,13 +14,13 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
use super::*;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
|
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::*;
|
use std::time::*;
|
||||||
use common::*;
|
use util::common::*;
|
||||||
use network::*;
|
|
||||||
use io::TimerToken;
|
use io::TimerToken;
|
||||||
use crypto::KeyPair;
|
use util::crypto::KeyPair;
|
||||||
|
|
||||||
pub struct TestProtocol {
|
pub struct TestProtocol {
|
||||||
drop_session: bool,
|
drop_session: bool,
|
||||||
@ -98,7 +98,7 @@ fn net_service() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn net_connect() {
|
fn net_connect() {
|
||||||
::log::init_log();
|
::util::log::init_log();
|
||||||
let key1 = KeyPair::create().unwrap();
|
let key1 = KeyPair::create().unwrap();
|
||||||
let mut config1 = NetworkConfiguration::new_local();
|
let mut config1 = NetworkConfiguration::new_local();
|
||||||
config1.use_secret = Some(key1.secret().clone());
|
config1.use_secret = Some(key1.secret().clone());
|
@ -17,9 +17,7 @@
|
|||||||
//! General error types for use in ethcore.
|
//! General error types for use in ethcore.
|
||||||
|
|
||||||
use rustc_serialize::hex::FromHexError;
|
use rustc_serialize::hex::FromHexError;
|
||||||
use network::NetworkError;
|
|
||||||
use rlp::DecoderError;
|
use rlp::DecoderError;
|
||||||
use io;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use hash::H256;
|
use hash::H256;
|
||||||
|
|
||||||
@ -50,18 +48,10 @@ pub enum UtilError {
|
|||||||
Crypto(::crypto::CryptoError),
|
Crypto(::crypto::CryptoError),
|
||||||
/// Error concerning the Rust standard library's IO subsystem.
|
/// Error concerning the Rust standard library's IO subsystem.
|
||||||
StdIo(::std::io::Error),
|
StdIo(::std::io::Error),
|
||||||
/// Error concerning our IO utility subsystem.
|
|
||||||
Io(io::IoError),
|
|
||||||
/// Error concerning the network address parsing subsystem.
|
|
||||||
AddressParse(::std::net::AddrParseError),
|
|
||||||
/// Error concerning the network address resolution subsystem.
|
|
||||||
AddressResolve(Option<::std::io::Error>),
|
|
||||||
/// Error concerning the hex conversion logic.
|
/// Error concerning the hex conversion logic.
|
||||||
FromHex(FromHexError),
|
FromHex(FromHexError),
|
||||||
/// Error concerning the database abstraction logic.
|
/// Error concerning the database abstraction logic.
|
||||||
BaseData(BaseDataError),
|
BaseData(BaseDataError),
|
||||||
/// Error concerning the network subsystem.
|
|
||||||
Network(NetworkError),
|
|
||||||
/// Error concerning the RLP decoder.
|
/// Error concerning the RLP decoder.
|
||||||
Decoder(DecoderError),
|
Decoder(DecoderError),
|
||||||
/// Miscellaneous error described by a string.
|
/// Miscellaneous error described by a string.
|
||||||
@ -77,13 +67,8 @@ impl fmt::Display for UtilError {
|
|||||||
match *self {
|
match *self {
|
||||||
UtilError::Crypto(ref err) => f.write_fmt(format_args!("{}", err)),
|
UtilError::Crypto(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
UtilError::StdIo(ref err) => f.write_fmt(format_args!("{}", err)),
|
UtilError::StdIo(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
UtilError::Io(ref err) => f.write_fmt(format_args!("{}", err)),
|
|
||||||
UtilError::AddressParse(ref err) => f.write_fmt(format_args!("{}", err)),
|
|
||||||
UtilError::AddressResolve(Some(ref err)) => f.write_fmt(format_args!("{}", err)),
|
|
||||||
UtilError::AddressResolve(_) => f.write_str("Failed to resolve network address."),
|
|
||||||
UtilError::FromHex(ref err) => f.write_fmt(format_args!("{}", err)),
|
UtilError::FromHex(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
UtilError::BaseData(ref err) => f.write_fmt(format_args!("{}", err)),
|
UtilError::BaseData(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
UtilError::Network(ref err) => f.write_fmt(format_args!("{}", err)),
|
|
||||||
UtilError::Decoder(ref err) => f.write_fmt(format_args!("{}", err)),
|
UtilError::Decoder(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||||
UtilError::SimpleString(ref msg) => f.write_str(msg),
|
UtilError::SimpleString(ref msg) => f.write_str(msg),
|
||||||
UtilError::BadSize => f.write_str("Bad input size."),
|
UtilError::BadSize => f.write_str("Bad input size."),
|
||||||
@ -143,36 +128,18 @@ impl From<BaseDataError> for UtilError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<NetworkError> for UtilError {
|
|
||||||
fn from(err: NetworkError) -> UtilError {
|
|
||||||
UtilError::Network(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<::std::io::Error> for UtilError {
|
impl From<::std::io::Error> for UtilError {
|
||||||
fn from(err: ::std::io::Error) -> UtilError {
|
fn from(err: ::std::io::Error) -> UtilError {
|
||||||
UtilError::StdIo(err)
|
UtilError::StdIo(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<io::IoError> for UtilError {
|
|
||||||
fn from(err: io::IoError) -> UtilError {
|
|
||||||
UtilError::Io(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<::crypto::CryptoError> for UtilError {
|
impl From<::crypto::CryptoError> for UtilError {
|
||||||
fn from(err: ::crypto::CryptoError) -> UtilError {
|
fn from(err: ::crypto::CryptoError) -> UtilError {
|
||||||
UtilError::Crypto(err)
|
UtilError::Crypto(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::std::net::AddrParseError> for UtilError {
|
|
||||||
fn from(err: ::std::net::AddrParseError) -> UtilError {
|
|
||||||
UtilError::AddressParse(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<::rlp::DecoderError> for UtilError {
|
impl From<::rlp::DecoderError> for UtilError {
|
||||||
fn from(err: ::rlp::DecoderError) -> UtilError {
|
fn from(err: ::rlp::DecoderError) -> UtilError {
|
||||||
UtilError::Decoder(err)
|
UtilError::Decoder(err)
|
||||||
|
@ -85,12 +85,9 @@
|
|||||||
//! cargo build --release
|
//! cargo build --release
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
extern crate slab;
|
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
extern crate mio;
|
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate rocksdb;
|
extern crate rocksdb;
|
||||||
extern crate tiny_keccak;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate heapsize;
|
extern crate heapsize;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -98,20 +95,17 @@ extern crate lazy_static;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
extern crate time;
|
|
||||||
extern crate crypto as rcrypto;
|
extern crate crypto as rcrypto;
|
||||||
extern crate secp256k1;
|
extern crate secp256k1;
|
||||||
extern crate arrayvec;
|
extern crate arrayvec;
|
||||||
extern crate elastic_array;
|
extern crate elastic_array;
|
||||||
extern crate crossbeam;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log as rlog;
|
extern crate log as rlog;
|
||||||
extern crate igd;
|
extern crate time;
|
||||||
extern crate ethcore_devtools as devtools;
|
extern crate ethcore_devtools as devtools;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate target_info;
|
extern crate target_info;
|
||||||
extern crate bigint;
|
extern crate bigint;
|
||||||
extern crate chrono;
|
|
||||||
extern crate parking_lot;
|
extern crate parking_lot;
|
||||||
pub extern crate using_queue;
|
pub extern crate using_queue;
|
||||||
pub extern crate table;
|
pub extern crate table;
|
||||||
@ -144,11 +138,7 @@ pub mod nibbleslice;
|
|||||||
pub mod nibblevec;
|
pub mod nibblevec;
|
||||||
mod heapsizeof;
|
mod heapsizeof;
|
||||||
pub mod semantic_version;
|
pub mod semantic_version;
|
||||||
pub mod io;
|
|
||||||
pub mod network;
|
|
||||||
pub mod log;
|
pub mod log;
|
||||||
pub mod panics;
|
|
||||||
pub mod network_settings;
|
|
||||||
pub mod path;
|
pub mod path;
|
||||||
pub mod snappy;
|
pub mod snappy;
|
||||||
mod timer;
|
mod timer;
|
||||||
@ -166,8 +156,6 @@ pub use triehash::*;
|
|||||||
pub use trie::{Trie, TrieMut, TrieDB, TrieDBMut, TrieFactory, TrieError, SecTrieDB, SecTrieDBMut};
|
pub use trie::{Trie, TrieMut, TrieDB, TrieDBMut, TrieFactory, TrieError, SecTrieDB, SecTrieDBMut};
|
||||||
pub use nibbleslice::*;
|
pub use nibbleslice::*;
|
||||||
pub use semantic_version::*;
|
pub use semantic_version::*;
|
||||||
pub use network::*;
|
|
||||||
pub use io::*;
|
|
||||||
pub use log::*;
|
pub use log::*;
|
||||||
pub use kvdb::*;
|
pub use kvdb::*;
|
||||||
pub use timer::*;
|
pub use timer::*;
|
||||||
|
Loading…
Reference in New Issue
Block a user