From 7c840918f102752f6a9882a36993328a9ed15df8 Mon Sep 17 00:00:00 2001 From: wngr Date: Sun, 24 Oct 2021 20:52:46 +0200 Subject: [PATCH] update libp2p --- Cargo.lock | 219 ++++++++++++++--------------------------------------- Cargo.toml | 5 +- src/lib.rs | 19 ++++- 3 files changed, 77 insertions(+), 166 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 10ab911..6389a86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.44" @@ -35,12 +44,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "base64" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" - [[package]] name = "bitflags" version = "1.3.2" @@ -101,22 +104,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "crypto-mac" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" -dependencies = [ - "generic-array", - "subtle", -] - [[package]] name = "curve25519-dalek" version = "3.2.0" @@ -176,9 +163,9 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "fixedbitset" -version = "0.2.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" +checksum = "398ea4fabe40b9b0d885340a2a991a44c8a645624075ad966d21f88688e2b69e" [[package]] name = "fnv" @@ -353,27 +340,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hmac" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" -dependencies = [ - "crypto-mac", - "digest", -] - -[[package]] -name = "hmac-drbg" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" -dependencies = [ - "digest", - "generic-array", - "hmac", -] - [[package]] name = "idna" version = "0.2.3" @@ -436,13 +402,15 @@ checksum = "7b2f96d100e1cf1929e7719b7edb3b90ab5298072638fccd77be9ce942ecdfce" [[package]] name = "libp2p" -version = "0.39.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9004c06878ef8f3b4b4067e69a140d87ed20bf777287f82223e49713b36ee433" +version = "0.40.0-rc.2" +source = "git+https://github.com/wngr/rust-libp2p?branch=wasm-support#19e475535560fd2993de29daa66dc38dce46c5b9" dependencies = [ "atomic", "bytes", "futures", + "futures-timer", + "getrandom 0.2.3", + "instant", "lazy_static", "libp2p-core", "libp2p-swarm", @@ -450,8 +418,8 @@ dependencies = [ "multiaddr", "parking_lot", "pin-project 1.0.8", + "rand 0.7.3", "smallvec", - "wasm-timer", ] [[package]] @@ -465,9 +433,8 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af9b4abdeaa420593a297c8592f63fad4234f4b88dc9343b8fd8e736c35faa59" +version = "0.30.0-rc.1" +source = "git+https://github.com/wngr/rust-libp2p?branch=wasm-support#19e475535560fd2993de29daa66dc38dce46c5b9" dependencies = [ "asn1_der", "bs58", @@ -476,8 +443,8 @@ dependencies = [ "fnv", "futures", "futures-timer", + "instant", "lazy_static", - "libsecp256k1", "log", "multiaddr", "multihash", @@ -486,7 +453,7 @@ dependencies = [ "pin-project 1.0.8", "prost", "prost-build", - "rand 0.7.3", + "rand 0.8.4", "ring", "rw-stream-sink", "sha2", @@ -499,78 +466,29 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7083861341e1555467863b4cd802bea1e8c4787c0f7b5110097d0f1f3248f9a9" +version = "0.31.0-rc.1" +source = "git+https://github.com/wngr/rust-libp2p?branch=wasm-support#19e475535560fd2993de29daa66dc38dce46c5b9" dependencies = [ "either", "futures", + "futures-timer", + "instant", "libp2p-core", "log", "rand 0.7.3", "smallvec", "void", - "wasm-timer", ] [[package]] name = "libp2p-swarm-derive" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab8cb308d4fc854869f5abb54fdab0833d2cf670d407c745849dc47e6e08d79c" +version = "0.25.0-rc.1" +source = "git+https://github.com/wngr/rust-libp2p?branch=wasm-support#19e475535560fd2993de29daa66dc38dce46c5b9" dependencies = [ "quote", "syn", ] -[[package]] -name = "libsecp256k1" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd1137239ab33b41aa9637a88a28249e5e70c40a42ccc92db7f12cc356c1fcd7" -dependencies = [ - "arrayref", - "base64", - "digest", - "hmac-drbg", - "libsecp256k1-core", - "libsecp256k1-gen-ecmult", - "libsecp256k1-gen-genmult", - "rand 0.7.3", - "serde", - "sha2", - "typenum", -] - -[[package]] -name = "libsecp256k1-core" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0f6ab710cec28cef759c5f18671a27dae2a5f952cdaaee1d8e2908cb2478a80" -dependencies = [ - "crunchy", - "digest", - "subtle", -] - -[[package]] -name = "libsecp256k1-gen-ecmult" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccab96b584d38fac86a83f07e659f0deafd0253dc096dab5a36d53efe653c5c3" -dependencies = [ - "libsecp256k1-core", -] - -[[package]] -name = "libsecp256k1-gen-genmult" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67abfe149395e3aa1c48a2beb32b068e2334402df8181f818d3aee2b304c4f5d" -dependencies = [ - "libsecp256k1-core", -] - [[package]] name = "lock_api" version = "0.4.5" @@ -655,8 +573,7 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "multistream-select" version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56a336acba8bc87c8876f6425407dbbe6c417bf478b22015f8fb0994ef3bc0ab" +source = "git+https://github.com/wngr/rust-libp2p?branch=wasm-support#19e475535560fd2993de29daa66dc38dce46c5b9" dependencies = [ "bytes", "futures", @@ -721,9 +638,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "petgraph" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" +checksum = "4a13a2fa9d0b63e5f22328828741e523766fff0ee9e779316902290dff3f824f" dependencies = [ "fixedbitset", "indexmap", @@ -844,9 +761,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de5e2533f59d08fcf364fd374ebda0692a70bd6d7e66ef97f306f45c6c5d8020" +checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" dependencies = [ "bytes", "prost-derive", @@ -854,27 +771,29 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "355f634b43cdd80724ee7848f95770e7e70eefa6dcf14fea676216573b8fd603" +checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" dependencies = [ "bytes", "heck", "itertools", + "lazy_static", "log", "multimap", "petgraph", "prost", "prost-types", + "regex", "tempfile", "which", ] [[package]] name = "prost-derive" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "600d2f334aa05acb02a755e217ef1ab6dea4d51b58b7846588b747edec04efba" +checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" dependencies = [ "anyhow", "itertools", @@ -885,9 +804,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "603bbd6394701d13f3f25aada59c7de9d35a6a5887cfc156181234a44002771b" +checksum = "534b7a0e836e3c482d2693070f982e39e7611da9695d4d1f5a4b186b51faef0a" dependencies = [ "bytes", "prost", @@ -992,6 +911,23 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + [[package]] name = "remove_dir_all" version = "0.5.3" @@ -1038,20 +974,6 @@ name = "serde" version = "1.0.130" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.130" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] [[package]] name = "sha2" @@ -1289,18 +1211,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" version = "0.2.78" @@ -1330,21 +1240,6 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" -[[package]] -name = "wasm-timer" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" -dependencies = [ - "futures", - "js-sys", - "parking_lot", - "pin-utils", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - [[package]] name = "web-sys" version = "0.3.55" diff --git a/Cargo.toml b/Cargo.toml index ecee840..ab5d7d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,7 @@ repository = "https://github.com/ipfs-rust/libp2p-broadcast" [dependencies] fnv = "1.0.7" futures = "0.3.17" -libp2p = { version = "0.39.1", default-features = false } +libp2p = { version = "0.40.0-rc.2", default-features = false } + +[patch.crates-io] +libp2p = { git = "https://github.com/wngr/rust-libp2p", branch = "wasm-support" } diff --git a/src/lib.rs b/src/lib.rs index d9d6c40..c4b785a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ use libp2p::swarm::{ }; use libp2p::{Multiaddr, PeerId}; use std::collections::VecDeque; +use std::fmt; use std::sync::Arc; use std::task::{Context, Poll}; @@ -19,14 +20,26 @@ pub enum BroadcastEvent { Unsubscribed(PeerId, Topic), Received(PeerId, Topic, Arc<[u8]>), } +type Handler = OneShotHandler; -#[derive(Debug, Default)] +#[derive(Default)] pub struct Broadcast { config: BroadcastConfig, subscriptions: FnvHashSet, peers: FnvHashMap>, topics: FnvHashMap>, - events: VecDeque>, + events: VecDeque>, +} + +impl fmt::Debug for Broadcast { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Broadcast") + .field("config", &self.config) + .field("subscriptions", &self.subscriptions) + .field("peers", &self.peers) + .field("topics", &self.topics) + .finish() + } } impl Broadcast { @@ -156,7 +169,7 @@ impl NetworkBehaviour for Broadcast { &mut self, _: &mut Context, _: &mut impl PollParameters, - ) -> Poll> { + ) -> Poll> { if let Some(event) = self.events.pop_front() { Poll::Ready(event) } else {