diff --git a/Cargo.lock b/Cargo.lock index 1bf7ce434008f3f266662023ecb34cd6e0219b39..04d2f85ed42dc7300fdb0a8d2e3ff628807c7367 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,11 +1,3 @@ -[[package]] -name = "aho-corasick" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ansi_term" version = "0.11.0" @@ -223,6 +215,7 @@ dependencies = [ "duniter-message 0.1.0-a0.1", "duniter-module 0.1.0-a0.1", "duniter-network 0.1.0-a0.1", + "durs-network-documents 0.1.0-a0.1", "durs-wot 0.8.0-a0.9", "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -296,7 +289,6 @@ dependencies = [ "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "rustbreak 2.0.0-rc2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", @@ -351,16 +343,11 @@ dependencies = [ name = "duniter-network" version = "0.1.0-a0.1" dependencies = [ - "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "duniter-crypto 0.2.0-a0.1", "duniter-documents 0.8.0-a0.1", "duniter-module 0.1.0-a0.1", - "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "durs-network-documents 0.1.0-a0.1", "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", @@ -377,6 +364,7 @@ dependencies = [ "duniter-message 0.1.0-a0.1", "duniter-module 0.1.0-a0.1", "duniter-network 0.1.0-a0.1", + "durs-network-documents 0.1.0-a0.1", "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", @@ -396,6 +384,22 @@ dependencies = [ "structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "durs-network-documents" +version = "0.1.0-a0.1" +dependencies = [ + "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "duniter-crypto 0.2.0-a0.1", + "duniter-documents 0.8.0-a0.1", + "pest 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pest_derive 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "durs-wot" version = "0.8.0-a0.9" @@ -416,6 +420,7 @@ dependencies = [ "duniter-message 0.1.0-a0.1", "duniter-module 0.1.0-a0.1", "duniter-network 0.1.0-a0.1", + "durs-network-documents 0.1.0-a0.1", "durs-ws2p-messages 0.1.0-a0.1", "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", @@ -431,10 +436,9 @@ dependencies = [ "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "duniter-crypto 0.2.0-a0.1", "duniter-documents 0.8.0-a0.1", - "duniter-network 0.1.0-a0.1", + "durs-network-documents 0.1.0-a0.1", "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", @@ -453,11 +457,10 @@ dependencies = [ "duniter-message 0.1.0-a0.1", "duniter-module 0.1.0-a0.1", "duniter-network 0.1.0-a0.1", + "durs-network-documents 0.1.0-a0.1", "durs-wot 0.8.0-a0.9", - "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.78 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", @@ -631,14 +634,6 @@ name = "matches" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "memchr" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "memoffset" version = "0.2.1" @@ -877,46 +872,6 @@ dependencies = [ "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rust-crypto" version = "0.2.36" @@ -1136,15 +1091,6 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "thread_local" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "threadpool" version = "1.7.1" @@ -1173,11 +1119,6 @@ name = "ucd-trie" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "ucd-util" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "unicode-bidi" version = "0.3.4" @@ -1206,14 +1147,6 @@ name = "unicode-xid" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "unreachable" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "url" version = "1.7.0" @@ -1224,11 +1157,6 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "utf8-ranges" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "vcpkg" version = "0.2.4" @@ -1239,11 +1167,6 @@ name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "winapi" version = "0.2.8" @@ -1302,7 +1225,6 @@ dependencies = [ ] [metadata] -"checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" @@ -1353,7 +1275,6 @@ dependencies = [ "checksum log-panics 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae0136257df209261daa18d6c16394757c63e032e27aafd8b07788b051082bef" "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" -"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mio 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)" = "6d771e3ef92d58a8da8df7d6976bfca9371ed1de6619d9d5a5ce5b1f29b85bfe" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" @@ -1381,10 +1302,6 @@ dependencies = [ "checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" -"checksum regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13c93d55961981ba9226a213b385216f83ab43bd6ac53ab16b2eeb47e337cf4e" -"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" -"checksum regex-syntax 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05b06a75f5217880fc5e905952a42750bf44787e56a6c6d6852ed0992f5e1d54" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" "checksum rustbreak 2.0.0-rc2 (registry+https://github.com/rust-lang/crates.io-index)" = "676cb04876f4391d5d2f2c9029d10cfe5fe28ad625ad8460531bed1191477083" "checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649" @@ -1412,23 +1329,18 @@ dependencies = [ "checksum term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6b677dd1e8214ea1ef4297f85dbcbed8e8cdddb561040cc998ca2551c37561" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693" -"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963" "checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-trie 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "71a9c5b1fe77426cf144cc30e49e955270f5086e31a6441dfa8b32efc09b9d77" -"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7" -"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum vcpkg 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cbe533e138811704c0e3cbde65a818b35d3240409b4346256c5ede403e082474" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/Cargo.toml b/Cargo.toml index 53541ce5706cbc7923ee807b52718bdb6097ff9b..6730082ae8164f6d04d93c83da89e248e6e4c779 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ members = [ "message", "module", "network", + "network-documents", "tui", "wot", "ws2p", diff --git a/blockchain/Cargo.toml b/blockchain/Cargo.toml index a4be6dacb8599541eb09e6d766118795af1b6a42..ebe5daa816d100ea69997fc12967734e85c09d0a 100644 --- a/blockchain/Cargo.toml +++ b/blockchain/Cargo.toml @@ -14,6 +14,7 @@ duniter-conf = { path = "../conf" } duniter-crypto = { path = "../crypto" } duniter-dal = { path = "../dal" } duniter-documents = { path = "../documents" } +durs-network-documents = { path = "../network-documents" } duniter-message = { path = "../message" } duniter-module = { path = "../module" } duniter-network = { path = "../network" } diff --git a/blockchain/lib.rs b/blockchain/lib.rs index 02e0a4ff21752e222bcc32fe6154eb1583a348ac..75ca3e4fffa0a4a205ebac2bf766b50dddd653ca 100644 --- a/blockchain/lib.rs +++ b/blockchain/lib.rs @@ -40,6 +40,7 @@ extern crate duniter_documents; extern crate duniter_message; extern crate duniter_module; extern crate duniter_network; +extern crate durs_network_documents; extern crate durs_wot; extern crate serde; extern crate serde_json; @@ -76,8 +77,9 @@ use duniter_documents::{BlockchainProtocol, Document}; use duniter_message::*; use duniter_module::*; use duniter_network::{ - NetworkBlock, NetworkDocument, NetworkEvent, NetworkResponse, NodeFullId, OldNetworkRequest, + BlockchainDocument, NetworkBlock, NetworkEvent, NetworkResponse, OldNetworkRequest, }; +use durs_network_documents::NodeFullId; use durs_wot::data::rusty::RustyWebOfTrust; use durs_wot::operations::distance::RustyDistanceCalculator; use durs_wot::{NodeId, WebOfTrust}; @@ -302,7 +304,7 @@ impl BlockchainModule { } fn receive_network_documents<W: WebOfTrust>( &mut self, - network_documents: &[NetworkDocument], + network_documents: &[BlockchainDocument], current_blockstamp: &Blockstamp, wot_index: &mut HashMap<PubKey, NodeId>, wot_db: &BinDB<W>, @@ -314,7 +316,7 @@ impl BlockchainModule { let mut save_currency_dbs = false; for network_document in network_documents { match *network_document { - NetworkDocument::Block(ref network_block) => { + BlockchainDocument::Block(ref network_block) => { match check_and_apply_block::<W>( &self.blocks_databases, &self.wot_databases.certs_db, @@ -385,23 +387,23 @@ impl BlockchainModule { } } } - NetworkDocument::Identity(ref doc) => blockchain_documents.push( + BlockchainDocument::Identity(ref doc) => blockchain_documents.push( BlockchainProtocol::V10(Box::new(V10Document::Identity(doc.deref().clone()))), ), - NetworkDocument::Membership(ref doc) => blockchain_documents.push( + BlockchainDocument::Membership(ref doc) => blockchain_documents.push( BlockchainProtocol::V10(Box::new(V10Document::Membership(doc.deref().clone()))), ), - NetworkDocument::Certification(ref doc) => { + BlockchainDocument::Certification(ref doc) => { blockchain_documents.push(BlockchainProtocol::V10(Box::new( V10Document::Certification(Box::new(doc.deref().clone())), ))) } - NetworkDocument::Revocation(ref doc) => { + BlockchainDocument::Revocation(ref doc) => { blockchain_documents.push(BlockchainProtocol::V10(Box::new( V10Document::Revocation(Box::new(doc.deref().clone())), ))) } - NetworkDocument::Transaction(ref doc) => { + BlockchainDocument::Transaction(ref doc) => { blockchain_documents.push(BlockchainProtocol::V10(Box::new( V10Document::Transaction(Box::new(doc.deref().clone())), ))) diff --git a/dal/Cargo.toml b/dal/Cargo.toml index 535bf8557687ae2731684883124426809d997f91..24ec294350d8780b1104bd75e68bf473511734a1 100644 --- a/dal/Cargo.toml +++ b/dal/Cargo.toml @@ -19,7 +19,6 @@ log = "0.4.*" rand = "0.4.*" rustbreak = {version = "2.0.0-rc2", features = ["bin_enc"]} rust-crypto = "0.2.*" -regex = "1.0.*" serde = "1.0.*" serde_derive = "1.0.*" serde_json = "1.0.*" diff --git a/network-documents/Cargo.toml b/network-documents/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..49ee5a6c2b693b6195327f7f781299c2ccd3c57a --- /dev/null +++ b/network-documents/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "durs-network-documents" +version = "0.1.0-a0.1" +authors = ["librelois <elois@duniter.org>"] +description = "Network documents for DUNP (DUniter Network Protocol)" +license = "AGPL-3.0" + +[lib] +path = "src/lib.rs" + +[dependencies] +base58 = "0.1.*" +duniter-crypto = { path = "../crypto" } +duniter-documents = { path = "../documents" } +pest = "2.0" +pest_derive = "2.0" +serde = "1.0.*" +serde_derive = "1.0.*" +serde_json = "1.0.*" + +[dev-dependencies] +pretty_assertions = "0.5.1" +bincode = "1.0.1" + +[features] +# Treat warnings as a build error. +strict = [] \ No newline at end of file diff --git a/network-documents/src/lib.rs b/network-documents/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..99f1e744fb509fb23ad9f2e9672d56458cc05976 --- /dev/null +++ b/network-documents/src/lib.rs @@ -0,0 +1,179 @@ +// Copyright (C) 2018 The Duniter Project Developers. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Implements the Documents of DUNP (DUniter Network Protocol). + +#![cfg_attr(feature = "strict", deny(warnings))] +#![deny( + missing_debug_implementations, + missing_copy_implementations, + trivial_casts, + trivial_numeric_casts, + unsafe_code, + unstable_features, + unused_import_braces +)] + +extern crate base58; +extern crate duniter_crypto; +extern crate duniter_documents; +extern crate pest; +#[macro_use] +extern crate pest_derive; +#[cfg(test)] +#[macro_use] +extern crate pretty_assertions; +extern crate serde; +extern crate serde_json; +#[macro_use] +extern crate serde_derive; + +pub mod network_endpoint; +pub mod network_head; +pub mod network_head_v2; +pub mod network_head_v3; +pub mod network_peer; + +use duniter_crypto::hashs::*; +use duniter_crypto::keys::*; +use std::fmt::{Display, Error, Formatter}; + +#[derive(Parser)] +#[grammar = "network_documents.pest"] +/// Parser for network documents +struct NetworkDocsParser; + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] +/// Random identifier with which several Duniter nodes with the same network keypair can be differentiated +pub struct NodeId(pub u32); + +impl Default for NodeId { + fn default() -> NodeId { + NodeId(0) + } +} + +impl Display for NodeId { + fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { + write!(f, "{:x}", self.0) + } +} + +impl<'a> From<&'a str> for NodeId { + fn from(source: &'a str) -> NodeId { + NodeId(u32::from_str_radix(source, 16).expect("Fail to parse NodeId")) + } +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +/// Complete identifier of a duniter node. +pub struct NodeFullId(pub NodeId, pub PubKey); + +impl Default for NodeFullId { + fn default() -> NodeFullId { + NodeFullId( + NodeId::default(), + PubKey::Ed25519( + ed25519::PublicKey::from_base58("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + .unwrap(), + ), + ) + } +} + +impl Display for NodeFullId { + fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { + write!(f, "{}-{}", self.0, self.1) + } +} + +impl NodeFullId { + /// Compute sha256 hash + pub fn sha256(&self) -> Hash { + Hash::compute(format!("{}", self).as_bytes()) + } + /// To human string + pub fn to_human_string(&self) -> String { + let mut pubkey_string = self.1.to_string(); + pubkey_string.truncate(8); + format!("{:8x}-{:8}", (self.0).0, pubkey_string) + } +} + +#[cfg(test)] +mod tests { + pub extern crate bincode; + use super::network_endpoint::*; + use super::*; + + pub fn keypair1() -> ed25519::KeyPair { + ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters().generate( + "JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV".as_bytes(), + "JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV_".as_bytes(), + ) + } + + #[test] + fn parse_endpoint() { + let issuer = PubKey::Ed25519( + ed25519::PublicKey::from_base58("D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx") + .unwrap(), + ); + let node_id = NodeId(u32::from_str_radix("c1c39a0a", 16).unwrap()); + let full_id = NodeFullId(node_id, issuer); + assert_eq!( + EndpointEnum::parse_from_raw("WS2P c1c39a0a i3.ifee.fr 80 /ws2p", issuer, 0, 0, 1), + Ok(EndpointEnum::V1(EndpointEnumV1 { + version: 1, + issuer, + api: NetworkEndpointApi(String::from("WS2P")), + node_id: Some(node_id), + hash_full_id: Some(full_id.sha256()), + host: String::from("i3.ifee.fr"), + port: 80, + path: Some(String::from("ws2p")), + raw_endpoint: String::from("WS2P c1c39a0a i3.ifee.fr 80 /ws2p"), + last_check: 0, + status: 0, + },)) + ); + } + + #[test] + fn parse_endpoint2() { + let issuer = PubKey::Ed25519( + ed25519::PublicKey::from_base58("5gJYnQp8v7bWwk7EWRoL8vCLof1r3y9c6VDdnGSM1GLv") + .unwrap(), + ); + let node_id = NodeId(u32::from_str_radix("cb06a19b", 16).unwrap()); + let full_id = NodeFullId(node_id, issuer); + assert_eq!( + EndpointEnum::parse_from_raw("WS2P cb06a19b g1.imirhil.fr 53012 /", issuer, 0, 0, 1), + Ok(EndpointEnum::V1(EndpointEnumV1 { + version: 1, + issuer, + api: NetworkEndpointApi(String::from("WS2P")), + node_id: Some(node_id), + hash_full_id: Some(full_id.sha256()), + host: String::from("g1.imirhil.fr"), + port: 53012, + path: None, + raw_endpoint: String::from("WS2P cb06a19b g1.imirhil.fr 53012 /"), + last_check: 0, + status: 0, + },)) + ); + } +} diff --git a/network-documents/src/network_documents.pest b/network-documents/src/network_documents.pest new file mode 100644 index 0000000000000000000000000000000000000000..44b3b35d42af28a4b4cb46c1d7f10e7cf77994d2 --- /dev/null +++ b/network-documents/src/network_documents.pest @@ -0,0 +1,16 @@ +//r"^(?P<api>[A-Z0-9_]+) (?P<version>[1-9][0-9]*)? ?(?P<uuid>[a-f0-9]{6,8})? ?(?P<host>[a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) (?P<port>[0-9]+)(?: /?(?P<path>.+)?)? *$" + +no_zero_u_int = @{ '1'..'9' ~ ASCII_DIGIT* } +u_int = @{ "0" | no_zero_u_int } + +api_name = @{ (ASCII_ALPHA_UPPER | ASCII_DIGIT)+ } +version = @{ u_int } +node_id = @{ ASCII_HEX_DIGIT{6,8} } +host = @{ ASCII_ALPHA_LOWER ~ (ASCII_ALPHA_LOWER | ASCII_DIGIT | "-" | "_" | ".")* } +port = @{ u_int } +path_inner = @{ (ASCII_ALPHANUMERIC | "-" | "_" | ".")+ } +path = _{ "/"? ~ path_inner } + +endpoint_v1 = { api_name ~ version? ~ node_id? ~ host ~ port ~ path? } + +WHITESPACE = _{ " " } \ No newline at end of file diff --git a/network/network_endpoint.rs b/network-documents/src/network_endpoint.rs similarity index 92% rename from network/network_endpoint.rs rename to network-documents/src/network_endpoint.rs index e33a864b42789ba07c7eee8e74a460f04db8a042..2a240ba7cd572e99b3b2afe8f8af4c750b082ab2 100644 --- a/network/network_endpoint.rs +++ b/network-documents/src/network_endpoint.rs @@ -15,20 +15,17 @@ //! Module defining the format of network endpoints and how to handle them. -extern crate crypto; extern crate duniter_crypto; extern crate duniter_documents; -extern crate duniter_module; -extern crate regex; extern crate serde; -use self::regex::Regex; use duniter_crypto::hashs::Hash; use duniter_crypto::keys::PubKey; +use pest::Parser; use std::net::{AddrParseError, Ipv4Addr, Ipv6Addr}; use std::num::ParseIntError; use std::str::FromStr; -use {NodeFullId, NodeId}; +use *; /// Total size of all fixed size fields of an EndpointV2 pub static ENDPOINTV2_FIXED_SIZE: &'static usize = &9; @@ -71,21 +68,13 @@ impl ApiFeatures { } } -lazy_static! { - #[derive(Debug)] - /// Regex match all endpoint in V1 format (works for all api) - pub static ref ENDPOINT_V1_REGEX: Regex = Regex::new( - r"^(?P<api>[A-Z0-9_]+) (?P<version>[1-9][0-9]*)? ?(?P<uuid>[a-f0-9]{6,8})? ?(?P<host>[a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) (?P<port>[0-9]+)(?: /?(?P<path>.+)?)? *$" - ).unwrap(); -} - #[derive(Debug, Clone, PartialEq, Eq)] /// ParseEndpointError pub enum ParseEndpointError { /// VersionNotSupported VersionNotSupported(), /// WrongV1Format - WrongV1Format(), + WrongV1Format(String), /// WrongV2Format (human-readable explanation) WrongV2Format(&'static str), /// ApiNameTooLong @@ -735,7 +724,57 @@ impl EndpointEnum { endpoint_version: u16, ) -> Result<EndpointEnum, ParseEndpointError> { match endpoint_version { - 1 => match ENDPOINT_V1_REGEX.captures(raw_endpoint) { + 1 => match NetworkDocsParser::parse(Rule::endpoint_v1, raw_endpoint) { + Ok(mut ep_ast) => { + let ep_pairs = ep_ast.next().unwrap().into_inner(); // get and unwrap the `envpoint_v1` rule; never fails + + let mut api_name = ""; + let mut node_id = None; + let mut hash_full_id = None; + let mut host_str = ""; + let mut port = 0; + let mut path = None; + + for ep_pair in ep_pairs { + match ep_pair.as_rule() { + Rule::api_name => api_name = ep_pair.as_str(), + Rule::node_id => { + node_id = match u32::from_str_radix(ep_pair.as_str(), 16) { + Ok(node_id) => Some(NodeId(node_id)), + Err(_) => { + return Err(ParseEndpointError::WrongV1Format( + "NodeId must be an hexadecimal string !".to_owned(), + )) + } + }; + hash_full_id = match node_id { + Some(node_id_) => Some(NodeFullId(node_id_, issuer).sha256()), + None => None, + }; + } + Rule::host => host_str = ep_pair.as_str(), + Rule::port => port = ep_pair.as_str().parse().unwrap(), + Rule::path_inner => path = Some(String::from(ep_pair.as_str())), + _ => panic!("unexpected rule: {:?}", ep_pair.as_rule()), // Grammar ensures that we never reach this line + } + } + Ok(EndpointEnum::V1(EndpointEnumV1 { + version: 1, + issuer, + api: NetworkEndpointApi(String::from(api_name)), + node_id, + hash_full_id, + host: String::from(host_str), + port, + path, + raw_endpoint: String::from(raw_endpoint), + status, + last_check, + })) + } + Err(e) => Err(ParseEndpointError::WrongV1Format(format!("{}", e))), + }, + /*match ENDPOINT_V1_REGEX.captures(raw_endpoint) { Some(caps) => { let node_id = match caps.name("uuid") { Some(caps_node_id) => { @@ -768,7 +807,7 @@ impl EndpointEnum { })) } None => Err(ParseEndpointError::WrongV1Format()), - }, + },*/ 2 => EndpointV2::parse_from_raw(raw_endpoint, status, last_check), _ => Err(ParseEndpointError::VersionNotSupported()), } diff --git a/network/network_head.rs b/network-documents/src/network_head.rs similarity index 100% rename from network/network_head.rs rename to network-documents/src/network_head.rs diff --git a/network/network_head_v2.rs b/network-documents/src/network_head_v2.rs similarity index 100% rename from network/network_head_v2.rs rename to network-documents/src/network_head_v2.rs diff --git a/network/network_head_v3.rs b/network-documents/src/network_head_v3.rs similarity index 100% rename from network/network_head_v3.rs rename to network-documents/src/network_head_v3.rs diff --git a/network/network_peer.rs b/network-documents/src/network_peer.rs similarity index 99% rename from network/network_peer.rs rename to network-documents/src/network_peer.rs index caacd3390e0074170d42127c39a2117757deaf94..556dfe7a2b976fc063854f1caa4012948024daaf 100644 --- a/network/network_peer.rs +++ b/network-documents/src/network_peer.rs @@ -15,10 +15,8 @@ //! Module defining the format of network peer cards and how to handle them. -extern crate crypto; extern crate duniter_crypto; extern crate duniter_documents; -extern crate duniter_module; extern crate serde; use base58::ToBase58; diff --git a/network/Cargo.toml b/network/Cargo.toml index f31e48bf03b8a9e25119fd3fcd8b90a29a7ad19a..5aed7a4258467ec832a29405f32a616de67e54f4 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -2,28 +2,23 @@ name = "duniter-network" version = "0.1.0-a0.1" authors = ["librelois <elois@duniter.org>"] -description = "network model for the Duniter project." +description = "Network model for the Durs project." license = "AGPL-3.0" [lib] path = "lib.rs" [dependencies] -base58 = "0.1.*" -byteorder = "1.2.3" duniter-crypto = { path = "../crypto" } duniter-documents = { path = "../documents" } duniter-module = { path = "../module" } -lazy_static = "1.0.*" -regex = "1.0.*" -rust-crypto = "0.2.*" +durs-network-documents = { path = "../network-documents" } serde = "1.0.*" serde_derive = "1.0.*" serde_json = "1.0.*" [dev-dependencies] pretty_assertions = "0.5.1" -bincode = "1.0.1" [features] # Treat warnings as a build error. diff --git a/network/lib.rs b/network/lib.rs index b8de326f9daf90f67ae44a41fcafeca65b330bc4..ebbda957271ea4c5c6a561f29c36cf067d2d4590 100644 --- a/network/lib.rs +++ b/network/lib.rs @@ -28,33 +28,16 @@ unused_qualifications )] -#[macro_use] -extern crate lazy_static; -#[cfg(test)] -#[macro_use] -extern crate pretty_assertions; -#[macro_use] -extern crate serde_derive; - -extern crate base58; -extern crate byteorder; -extern crate crypto; extern crate duniter_crypto; extern crate duniter_documents; extern crate duniter_module; +extern crate durs_network_documents; +#[cfg(test)] +#[macro_use] +extern crate pretty_assertions; extern crate serde; extern crate serde_json; -pub mod network_endpoint; -pub mod network_head; -pub mod network_head_v2; -pub mod network_head_v3; -pub mod network_peer; - -use crypto::digest::Digest; -use crypto::sha2::Sha256; -use duniter_crypto::hashs::*; -use duniter_crypto::keys::*; use duniter_documents::v10::block::BlockDocument; use duniter_documents::v10::certification::CertificationDocument; use duniter_documents::v10::identity::IdentityDocument; @@ -64,10 +47,11 @@ use duniter_documents::v10::transaction::TransactionDocument; use duniter_documents::Document; use duniter_documents::{blockstamp::Blockstamp, BlockHash, BlockId}; use duniter_module::*; -use network_endpoint::ApiFeatures; -use network_head::NetworkHead; -use network_peer::PeerCard; -use std::fmt::{Debug, Display, Error, Formatter}; +use durs_network_documents::network_endpoint::ApiFeatures; +use durs_network_documents::network_head::NetworkHead; +use durs_network_documents::network_peer::PeerCard; +use durs_network_documents::*; +use std::fmt::Debug; use std::ops::Deref; use std::sync::mpsc; @@ -115,65 +99,6 @@ pub struct SyncEndpoint { pub tls: bool, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] -/// Random identifier with which several Duniter nodes with the same network keypair can be differentiated -pub struct NodeId(pub u32); - -impl Default for NodeId { - fn default() -> NodeId { - NodeId(0) - } -} - -impl Display for NodeId { - fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - write!(f, "{:x}", self.0) - } -} - -impl<'a> From<&'a str> for NodeId { - fn from(source: &'a str) -> NodeId { - NodeId(u32::from_str_radix(source, 16).expect("Fail to parse NodeId")) - } -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -/// Complete identifier of a duniter node. -pub struct NodeFullId(pub NodeId, pub PubKey); - -impl Default for NodeFullId { - fn default() -> NodeFullId { - NodeFullId( - NodeId::default(), - PubKey::Ed25519( - ed25519::PublicKey::from_base58("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") - .unwrap(), - ), - ) - } -} - -impl Display for NodeFullId { - fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - write!(f, "{}-{}", self.0, self.1) - } -} - -impl NodeFullId { - /// Compute sha256 hash - pub fn sha256(&self) -> Hash { - let mut sha256 = Sha256::new(); - sha256.input_str(&format!("{}", self)); - Hash::from_hex(&sha256.result_str()).unwrap() - } - /// To human string - pub fn to_human_string(&self) -> String { - let mut pubkey_string = self.1.to_string(); - pubkey_string.truncate(8); - format!("{:8x}-{:8}", (self.0).0, pubkey_string) - } -} - /// Trait to be implemented by the configuration object of the module managing the inter-node network. pub trait NetworkConf: Debug + Copy + Clone + PartialEq {} @@ -235,7 +160,7 @@ impl NetworkBlock { #[derive(Debug, Clone)] /// Network Document -pub enum NetworkDocument { +pub enum BlockchainDocument { /// Network Block Block(NetworkBlock), /// Identity Document @@ -318,7 +243,7 @@ pub enum NetworkResponse { /// Chunk Chunk(ModuleReqFullId, NodeFullId, Vec<Box<NetworkBlock>>), /// PendingDocuments - PendingDocuments(ModuleReqFullId, Vec<NetworkDocument>), + PendingDocuments(ModuleReqFullId, Vec<BlockchainDocument>), /// Consensus Consensus(ModuleReqFullId, Result<Blockstamp, NetworkConsensusError>), /// HeadsCache @@ -349,75 +274,9 @@ pub enum NetworkEvent { /// A connection has changed state(`u32` is the new state, `Option<String>` est l'uid du noeud) ConnectionStateChange(NodeFullId, u32, Option<String>, String), /// Receiving Pending Documents - ReceiveDocuments(Vec<NetworkDocument>), + ReceiveDocuments(Vec<BlockchainDocument>), /// Receipt of peer cards ReceivePeers(Vec<PeerCard>), /// Receiving heads ReceiveHeads(Vec<NetworkHead>), } - -#[cfg(test)] -mod tests { - pub extern crate bincode; - use super::network_endpoint::*; - use super::*; - - pub fn keypair1() -> ed25519::KeyPair { - ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters().generate( - "JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV".as_bytes(), - "JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV_".as_bytes(), - ) - } - - #[test] - fn parse_endpoint() { - let issuer = PubKey::Ed25519( - ed25519::PublicKey::from_base58("D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx") - .unwrap(), - ); - let node_id = NodeId(u32::from_str_radix("c1c39a0a", 16).unwrap()); - let full_id = NodeFullId(node_id, issuer); - assert_eq!( - EndpointEnum::parse_from_raw("WS2P c1c39a0a i3.ifee.fr 80 /ws2p", issuer, 0, 0, 1), - Ok(EndpointEnum::V1(EndpointEnumV1 { - version: 1, - issuer, - api: NetworkEndpointApi(String::from("WS2P")), - node_id: Some(node_id), - hash_full_id: Some(full_id.sha256()), - host: String::from("i3.ifee.fr"), - port: 80, - path: Some(String::from("ws2p")), - raw_endpoint: String::from("WS2P c1c39a0a i3.ifee.fr 80 /ws2p"), - last_check: 0, - status: 0, - },)) - ); - } - - #[test] - fn parse_endpoint2() { - let issuer = PubKey::Ed25519( - ed25519::PublicKey::from_base58("5gJYnQp8v7bWwk7EWRoL8vCLof1r3y9c6VDdnGSM1GLv") - .unwrap(), - ); - let node_id = NodeId(u32::from_str_radix("cb06a19b", 16).unwrap()); - let full_id = NodeFullId(node_id, issuer); - assert_eq!( - EndpointEnum::parse_from_raw("WS2P cb06a19b g1.imirhil.fr 53012 /", issuer, 0, 0, 1), - Ok(EndpointEnum::V1(EndpointEnumV1 { - version: 1, - issuer, - api: NetworkEndpointApi(String::from("WS2P")), - node_id: Some(node_id), - hash_full_id: Some(full_id.sha256()), - host: String::from("g1.imirhil.fr"), - port: 53012, - path: None, - raw_endpoint: String::from("WS2P cb06a19b g1.imirhil.fr 53012 /"), - last_check: 0, - status: 0, - },)) - ); - } -} diff --git a/tui/Cargo.toml b/tui/Cargo.toml index 044e90e971096e286a320ecc45cd311b4df6e86a..326a033a93c2d597888c1c66337ccb98f9e7be40 100644 --- a/tui/Cargo.toml +++ b/tui/Cargo.toml @@ -16,6 +16,7 @@ duniter-documents = { path = "../documents" } duniter-message = { path = "../message" } duniter-module = { path = "../module" } duniter-network = { path = "../network" } +durs-network-documents = { path = "../network-documents" } log = "0.4.*" serde = "1.0.*" serde_derive = "1.0.*" diff --git a/tui/lib.rs b/tui/lib.rs index b9d3f1f14fc0beb3dfec88609b7bd56a2b9b4838..3c07534453db042d72032e025ac2f16bbd4eaa70 100644 --- a/tui/lib.rs +++ b/tui/lib.rs @@ -43,6 +43,7 @@ extern crate duniter_documents; extern crate duniter_message; extern crate duniter_module; extern crate duniter_network; +extern crate durs_network_documents; extern crate serde; extern crate serde_json; extern crate termion; @@ -51,8 +52,9 @@ use duniter_conf::DuRsConf; use duniter_dal::dal_event::DALEvent; use duniter_message::*; use duniter_module::*; -use duniter_network::network_head::NetworkHead; -use duniter_network::{NetworkEvent, NodeFullId}; +use duniter_network::NetworkEvent; +use durs_network_documents::network_head::NetworkHead; +use durs_network_documents::NodeFullId; use std::collections::HashMap; use std::io::{stdout, Write}; use std::ops::Deref; diff --git a/ws2p-messages/Cargo.toml b/ws2p-messages/Cargo.toml index aa6532d06cbcf4373f87bcf91b7665f5225a6bbf..0aad533057253d78cb215d56b081d2b3cf634b23 100644 --- a/ws2p-messages/Cargo.toml +++ b/ws2p-messages/Cargo.toml @@ -13,9 +13,8 @@ bincode = "1.0.*" byteorder = "1.2.3" duniter-crypto = { path = "../crypto" } duniter-documents = { path = "../documents" } -duniter-network = { path = "../network" } +durs-network-documents = { path = "../network-documents" } log = "0.4.*" -regex = "0.2.*" rust-crypto = "0.2.*" serde = "1.0.*" serde_derive = "1.0.*" diff --git a/ws2p-messages/lib.rs b/ws2p-messages/lib.rs index f3f2e9b7ecd7d9e11fa2a17abf6fd0bf70c820bd..940da6ced6b20e86115465bacf5aec2821f07302 100644 --- a/ws2p-messages/lib.rs +++ b/ws2p-messages/lib.rs @@ -38,7 +38,7 @@ extern crate bincode; extern crate byteorder; extern crate duniter_crypto; extern crate duniter_documents; -extern crate duniter_network; +extern crate durs_network_documents; /// WS2Pv2 Messages pub mod v2; @@ -60,9 +60,9 @@ mod tests { use duniter_crypto::keys::*; use duniter_documents::v10::certification::*; use duniter_documents::{Blockstamp, CurrencyName}; - use duniter_network::network_endpoint::*; - use duniter_network::network_peer::*; - use duniter_network::*; + use durs_network_documents::network_endpoint::*; + use durs_network_documents::network_peer::*; + use durs_network_documents::*; use std::net::Ipv4Addr; use std::str::FromStr; use v2::payload_container::WS2Pv0MessagePayload; diff --git a/ws2p-messages/v2/connect.rs b/ws2p-messages/v2/connect.rs index f1ad97ae6b54c8ba0dd310dc63f7c6e75df6e385..949ec0c1bce29f1f16baa795e98b4548ae5a8403 100644 --- a/ws2p-messages/v2/connect.rs +++ b/ws2p-messages/v2/connect.rs @@ -17,7 +17,7 @@ use super::api_features::WS2PFeatures; use duniter_crypto::hashs::Hash; use duniter_documents::Blockstamp; -use duniter_network::network_peer::PeerCardV11; +use durs_network_documents::network_peer::PeerCardV11; /// WS2P v2 connect message min size pub static CONNECT_MSG_MIN_SIZE: &'static usize = &36; diff --git a/ws2p-messages/v2/mod.rs b/ws2p-messages/v2/mod.rs index 8562ef37c5896781f3458f90dd3a716de1315408..002d7dd2a3c7479bc686cf06c638f830a677afc3 100644 --- a/ws2p-messages/v2/mod.rs +++ b/ws2p-messages/v2/mod.rs @@ -32,7 +32,7 @@ use duniter_crypto::hashs::Hash; use duniter_crypto::keys::bin_signable::BinSignable; use duniter_crypto::keys::*; use duniter_documents::CurrencyName; -use duniter_network::NodeId; +use durs_network_documents::NodeId; use v2::payload_container::*; /// WS2P v2 message metadata size diff --git a/ws2p-messages/v2/payload_container.rs b/ws2p-messages/v2/payload_container.rs index 473502878493826dbc59b6c4b61a26378b9014f2..eb545044edaef843515fd89172e8eade720c20b7 100644 --- a/ws2p-messages/v2/payload_container.rs +++ b/ws2p-messages/v2/payload_container.rs @@ -25,9 +25,9 @@ use duniter_documents::v10::identity::IdentityDocument; use duniter_documents::v10::membership::MembershipDocument; use duniter_documents::v10::revocation::RevocationDocument; use duniter_documents::v10::transaction::TransactionDocument; -use duniter_network::network_head_v2::NetworkHeadV2; -use duniter_network::network_head_v3::NetworkHeadV3Container; -use duniter_network::network_peer::PeerCardV11; +use durs_network_documents::network_head_v2::NetworkHeadV2; +use durs_network_documents::network_head_v3::NetworkHeadV3Container; +use durs_network_documents::network_peer::PeerCardV11; /// WS2P v2 message payload metadata size pub static WS2P_V2_MESSAGE_PAYLOAD_METADATA_SIZE: &'static usize = &8; diff --git a/ws2p-v1-legacy/Cargo.toml b/ws2p-v1-legacy/Cargo.toml index 63e77f2cbfb42055b5a4e3d2fe57c5d5d041c172..8e41ff446c2798fab0b30bdc45c472a464d3f3e6 100644 --- a/ws2p-v1-legacy/Cargo.toml +++ b/ws2p-v1-legacy/Cargo.toml @@ -14,14 +14,13 @@ duniter-conf = { path = "../conf" } duniter-crypto = { path = "../crypto" } duniter-dal = { path = "../dal" } duniter-documents = { path = "../documents" } +durs-network-documents = { path = "../network-documents" } duniter-message = { path = "../message" } duniter-module = { path = "../module" } duniter-network = { path = "../network" } durs-wot = { path = "../wot" } -lazy_static = "1.0.*" log = "0.4.*" rand = "0.4.*" -regex = "0.2.*" rust-crypto = "0.2.*" sqlite = "0.23.*" serde = "1.0.*" diff --git a/ws2p-v1-legacy/constants.rs b/ws2p-v1-legacy/constants.rs index bc8844462cb4e4e94db783f0ce47d604b17d3c69..aaada76d3146c71a060bf8edea98979815bcad7d 100644 --- a/ws2p-v1-legacy/constants.rs +++ b/ws2p-v1-legacy/constants.rs @@ -1,13 +1,3 @@ -extern crate regex; - -use self::regex::Regex; - -lazy_static! { - #[derive(Debug)] - pub static ref WS2P_V1_ENDPOINT_REGEX: Regex = Regex::new( - "^WS2P (?P<version>[1-9][0-9]* )?(?P<uuid>[a-f0-9]{6,8}) (?P<host>[a-z_][a-z0-9-_.]*|[0-9.]+|[0-9a-f:]+) (?P<port>[0-9]+)(?: /?(?P<path>.+)?)? *$" - ).unwrap(); -} pub static WS2P_OUTCOMING_INTERVAL_AT_STARTUP: &'static u64 = &75; pub static WS2P_OUTCOMING_INTERVAL: &'static u64 = &300; pub static WS2P_DEFAULT_OUTCOMING_QUOTA: &'static usize = &10; diff --git a/ws2p-v1-legacy/datas.rs b/ws2p-v1-legacy/datas.rs index 48f0c125320cbde3f7e9ed9a9b1b5fd60164f616..65952ca35e0b1987f2da7a5013cd13ff352ca3d4 100644 --- a/ws2p-v1-legacy/datas.rs +++ b/ws2p-v1-legacy/datas.rs @@ -18,9 +18,10 @@ use duniter_crypto::keys::*; use duniter_dal::dal_requests::DALRequest; use duniter_documents::Blockstamp; use duniter_message::*; -use duniter_network::network_endpoint::*; -use duniter_network::network_head::*; use duniter_network::*; +use durs_network_documents::network_endpoint::*; +use durs_network_documents::network_head::*; +use durs_network_documents::*; use std::collections::HashSet; use std::sync::mpsc; use *; @@ -96,8 +97,8 @@ impl WS2PModuleDatas { NetworkEvent::ReceiveDocuments(network_docs) => { if !network_docs.is_empty() { match network_docs[0] { - NetworkDocument::Block(_) => ModuleEvent::NewBlockFromNetwork, - NetworkDocument::Transaction(_) => ModuleEvent::NewTxFromNetwork, + BlockchainDocument::Block(_) => ModuleEvent::NewBlockFromNetwork, + BlockchainDocument::Transaction(_) => ModuleEvent::NewTxFromNetwork, _ => ModuleEvent::NewWotDocFromNetwork, } } else { diff --git a/ws2p-v1-legacy/heads.rs b/ws2p-v1-legacy/heads.rs index f57ad2c40441be2918c201ee7515f142368fb57e..bdcb8f6417b33238b12555f5d7bed0c8f7f9813e 100644 --- a/ws2p-v1-legacy/heads.rs +++ b/ws2p-v1-legacy/heads.rs @@ -14,7 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use duniter_documents::Blockstamp; -use duniter_network::network_head_v2::*; +use durs_network_documents::network_head_v2::*; use *; pub fn generate_my_head( diff --git a/ws2p-v1-legacy/lib.rs b/ws2p-v1-legacy/lib.rs index 1406c811f9433ad90eb490fd6b3a2312e5b96657..03afbabd1ecb92f9b11573f1850fd349c7fc0092 100644 --- a/ws2p-v1-legacy/lib.rs +++ b/ws2p-v1-legacy/lib.rs @@ -27,8 +27,6 @@ )] #![recursion_limit = "256"] -#[macro_use] -extern crate lazy_static; #[macro_use] extern crate log; #[macro_use] @@ -46,6 +44,7 @@ extern crate duniter_documents; extern crate duniter_message; extern crate duniter_module; extern crate duniter_network; +extern crate durs_network_documents; extern crate rand; extern crate sqlite; extern crate ws; @@ -73,9 +72,10 @@ use duniter_dal::dal_requests::{DALReqBlockchain, DALRequest, DALResBlockchain, use duniter_documents::Blockstamp; use duniter_message::*; use duniter_module::*; -use duniter_network::network_endpoint::*; -use duniter_network::network_head::*; use duniter_network::*; +use durs_network_documents::network_endpoint::*; +use durs_network_documents::network_head::*; +use durs_network_documents::*; use ok_message::WS2POkMessageV1; use parsers::blocks::parse_json_block; use std::collections::HashMap; @@ -145,7 +145,7 @@ pub enum WS2PSignal { DalRequest(NodeFullId, ModuleReqId, serde_json::Value), PeerCard(NodeFullId, serde_json::Value, Vec<EndpointEnum>), Heads(NodeFullId, Vec<NetworkHead>), - Document(NodeFullId, NetworkDocument), + Document(NodeFullId, BlockchainDocument), ReqResponse( ModuleReqId, OldNetworkRequest, @@ -746,7 +746,7 @@ impl DuniterModule<DuRsConf, DursMsg> for WS2PModule { let mut chunk = Vec::new(); for json_block in response.as_array().unwrap() { if let Some(block) = parse_json_block(json_block) { - chunk.push(NetworkDocument::Block(block)); + chunk.push(BlockchainDocument::Block(block)); } else { warn!("WS2PModule: Error : fail to parse one json block !"); } @@ -931,7 +931,6 @@ mod tests { use duniter_crypto::keys::PublicKey; use duniter_documents::v10::BlockDocument; use duniter_module::DuniterModule; - use duniter_network::network_endpoint::{EndpointEnum, NetworkEndpointApi}; use duniter_network::NetworkBlock; use std::fs; use std::path::PathBuf; diff --git a/ws2p-v1-legacy/serializer.rs b/ws2p-v1-legacy/serializer.rs index f780006811a746eb6e6c93426abd9ed65d7a0f1f..52c6c0682c61db96dc7a6e9b99af9ef88958ef71 100644 --- a/ws2p-v1-legacy/serializer.rs +++ b/ws2p-v1-legacy/serializer.rs @@ -1,6 +1,6 @@ extern crate serde_json; -use duniter_network::network_head::*; +use durs_network_documents::network_head::*; use std::ops::Deref; diff --git a/ws2p-v1-legacy/ws2p_connection.rs b/ws2p-v1-legacy/ws2p_connection.rs index 11969541bf44553b647af4e5210b996361b651eb..a5ff269c408f16614e810c62022c9f69170fadc6 100644 --- a/ws2p-v1-legacy/ws2p_connection.rs +++ b/ws2p-v1-legacy/ws2p_connection.rs @@ -1,8 +1,9 @@ use constants::*; use duniter_crypto::keys::*; use duniter_module::ModuleReqId; -use duniter_network::network_endpoint::{EndpointEnum, NetworkEndpointApi}; -use duniter_network::{NetworkDocument, NodeId}; +use duniter_network::BlockchainDocument; +use durs_network_documents::network_endpoint::{EndpointEnum, NetworkEndpointApi}; +use durs_network_documents::NodeId; use parsers::blocks::parse_json_block; use rand::Rng; use std::sync::mpsc; @@ -272,7 +273,7 @@ pub enum WS2PConnectionMessagePayload { DalRequest(ModuleReqId, serde_json::Value), PeerCard(serde_json::Value, Vec<EndpointEnum>), Heads(Vec<serde_json::Value>), - Document(NetworkDocument), + Document(BlockchainDocument), ReqResponse(ModuleReqId, serde_json::Value), InvalidMessage, WrongFormatMessage, @@ -486,7 +487,7 @@ impl WS2PConnectionMetaDatas { Some(block) => { if let Some(network_block) = parse_json_block(&block) { return WS2PConnectionMessagePayload::Document( - NetworkDocument::Block(network_block), + BlockchainDocument::Block(network_block), ); } else { info!("WS2PSignal: receive invalid block (wrong format)."); @@ -512,7 +513,7 @@ impl WS2PConnectionMetaDatas { self.node_full_id() ); /*return WS2PConnectionMessagePayload::Document( - NetworkDocument::Certification(_) + BlockchainDocument::Certification(_) );*/ } _ => { diff --git a/ws2p-v1-legacy/ws2p_db.rs b/ws2p-v1-legacy/ws2p_db.rs index 88f165a7d7f76f2a2f68eeb017add0e1d841e558..68386757f74bf70abc81dd87ecf222cc37c8213c 100644 --- a/ws2p-v1-legacy/ws2p_db.rs +++ b/ws2p-v1-legacy/ws2p_db.rs @@ -1,13 +1,6 @@ -extern crate duniter_crypto; -extern crate duniter_documents; -extern crate duniter_message; -extern crate duniter_module; -extern crate duniter_network; -extern crate serde_json; -extern crate sqlite; - use duniter_crypto::keys::*; -use duniter_network::network_endpoint::{EndpointEnum, NetworkEndpointApi}; +use durs_network_documents::network_endpoint::{EndpointEnum, NetworkEndpointApi}; +use sqlite::*; #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum EndpointApi { @@ -51,17 +44,14 @@ pub fn api_to_integer(api: &NetworkEndpointApi) -> i64 { } } -pub fn get_endpoints_for_api( - db: &sqlite::Connection, - api: &NetworkEndpointApi, -) -> Vec<EndpointEnum> { - let mut cursor:sqlite::Cursor = db +pub fn get_endpoints_for_api(db: &Connection, api: &NetworkEndpointApi) -> Vec<EndpointEnum> { + let mut cursor: Cursor = db .prepare("SELECT hash_full_id, status, node_id, pubkey, api, version, endpoint, last_check FROM endpoints WHERE api=? ORDER BY status DESC;") .expect("get_endpoints_for_api() : Error in SQL request !") .cursor(); cursor - .bind(&[sqlite::Value::Integer(api_to_integer(&api))]) + .bind(&[Value::Integer(api_to_integer(&api))]) .expect("get_endpoints_for_api() : Error in cursor binding !"); let mut endpoints = Vec::new(); while let Some(row) = cursor @@ -93,7 +83,7 @@ pub fn get_endpoints_for_api( } pub fn write_endpoint( - db: &sqlite::Connection, + db: &Connection, endpoint: &EndpointEnum, new_status: u32, new_last_check: u64, @@ -103,12 +93,12 @@ pub fn write_endpoint( .expect("Fail to write endpoint : node_full_id() return None !") .sha256(); // Check if endpoint it's already written - let mut cursor: sqlite::Cursor = db + let mut cursor: Cursor = db .prepare("SELECT status FROM endpoints WHERE hash_full_id=? ORDER BY status DESC;") .expect("write_endpoint() : Error in SQL request !") .cursor(); cursor - .bind(&[sqlite::Value::String(hash_full_id.to_string())]) + .bind(&[Value::String(hash_full_id.to_string())]) .expect("write_endpoint() : Error in cursor binding !"); // If endpoint it's already written, update status diff --git a/ws2p/Cargo.toml b/ws2p/Cargo.toml index 9180eefb609fd93b2c9ed855006124170d7d4a3b..27a970e291ace8032096003a4a17ef593cf047ac 100644 --- a/ws2p/Cargo.toml +++ b/ws2p/Cargo.toml @@ -11,10 +11,11 @@ path = "lib.rs" [dependencies] duniter-conf = { path = "../conf" } duniter-crypto = { path = "../crypto" } +durs-network-documents = { path = "../network-documents" } +durs-ws2p-messages = { path = "../ws2p-messages" } duniter-message= { path = "../message" } duniter-module = { path = "../module" } duniter-network = { path = "../network" } -durs-ws2p-messages = { path = "../ws2p-messages" } log = "0.4.*" serde = "1.0.*" serde_derive = "1.0.*" diff --git a/ws2p/lib.rs b/ws2p/lib.rs index 773de02fb52906286db1a86e586b8edf43a40eee..bb35611d41bdf96ccd3eafa6f94397f5005dc398 100644 --- a/ws2p/lib.rs +++ b/ws2p/lib.rs @@ -39,6 +39,7 @@ extern crate duniter_crypto; extern crate duniter_message; extern crate duniter_module; extern crate duniter_network; +extern crate durs_network_documents; extern crate durs_ws2p_messages; mod constants; @@ -48,8 +49,8 @@ use duniter_conf::DuRsConf; use duniter_crypto::keys::*; use duniter_message::DursMsg; use duniter_module::*; -use duniter_network::network_endpoint::*; use duniter_network::*; +use durs_network_documents::network_endpoint::*; use std::sync::mpsc; #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]