From 7345a7b01b0cb99105f445a32f9af05e7cdbd915 Mon Sep 17 00:00:00 2001 From: Alessandro Date: Thu, 14 Dec 2023 18:41:22 +0100 Subject: [PATCH] now compiles --- .cargo/config.toml | 2 + Cargo.lock | 400 +++++++++++++++++++++++------------------- Cargo.toml | 5 +- src/lib.rs | 62 ++++--- src/p2p/behaviour.rs | 13 +- src/p2p/client.rs | 24 +-- src/p2p/event_loop.rs | 10 -- 7 files changed, 281 insertions(+), 235 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..f4e8c00 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "wasm32-unknown-unknown" diff --git a/Cargo.lock b/Cargo.lock index cb15e51..54c5dda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1226,9 +1226,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ "cfg-if", "js-sys", @@ -1616,9 +1616,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "js-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" dependencies = [ "wasm-bindgen", ] @@ -1663,12 +1663,12 @@ dependencies = [ "either", "futures", "futures-timer", - "getrandom 0.2.10", + "getrandom 0.2.11", "instant", "libp2p-allow-block-list", "libp2p-autonat", "libp2p-connection-limits", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-dcutr", "libp2p-dns", "libp2p-floodsub", @@ -1679,7 +1679,7 @@ dependencies = [ "libp2p-mdns", "libp2p-memory-connection-limits", "libp2p-metrics", - "libp2p-noise 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-noise", "libp2p-ping", "libp2p-plaintext", "libp2p-pnet", @@ -1698,7 +1698,7 @@ dependencies = [ "libp2p-yamux", "multiaddr", "pin-project", - "rw-stream-sink 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink", "thiserror", ] @@ -1708,7 +1708,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "107b238b794cb83ab53b74ad5dcf7cca3200899b72fe662840cfb52f5b0a32e6" dependencies = [ - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "void", @@ -1725,12 +1725,12 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-request-response", "libp2p-swarm", "quick-protobuf", - "quick-protobuf-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-protobuf-codec 0.2.0", "rand 0.8.5", "tracing", ] @@ -1741,7 +1741,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2af4b1e1a1d6c5005a59b42287c0a526bcce94d8d688e2e9233b18eb843ceb4" dependencies = [ - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "void", @@ -1749,9 +1749,9 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.41.0" +version = "0.41.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b8b63f1df89173dc6c582c07abfc072acf2792ce1787363ab266e0a18882fac" +checksum = "8130a8269e65a2554d55131c770bdf4bcd94d2b8d4efb24ca23699be65066c05" dependencies = [ "either", "fnv", @@ -1761,45 +1761,18 @@ dependencies = [ "libp2p-identity", "multiaddr", "multihash", - "multistream-select 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "multistream-select", "once_cell", "parking_lot", "pin-project", "quick-protobuf", "rand 0.8.5", - "rw-stream-sink 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink", "serde", "smallvec", "thiserror", "tracing", - "unsigned-varint", - "void", -] - -[[package]] -name = "libp2p-core" -version = "0.41.1" -source = "git+https://github.com/libp2p/rust-libp2p.git#dbfda10e3f0f649c6f8556d0afc71bf525968104" -dependencies = [ - "either", - "fnv", - "futures", - "futures-timer", - "instant", - "libp2p-identity", - "multiaddr", - "multihash", - "multistream-select 0.13.0 (git+https://github.com/libp2p/rust-libp2p.git)", - "once_cell", - "parking_lot", - "pin-project", - "quick-protobuf", - "rand 0.8.5", - "rw-stream-sink 0.4.0 (git+https://github.com/libp2p/rust-libp2p.git)", - "smallvec", - "thiserror", - "tracing", - "unsigned-varint", + "unsigned-varint 0.8.0", "void", ] @@ -1815,12 +1788,12 @@ dependencies = [ "futures-bounded", "futures-timer", "instant", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "lru 0.11.1", "quick-protobuf", - "quick-protobuf-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-protobuf-codec 0.2.0", "thiserror", "tracing", "void", @@ -1836,7 +1809,7 @@ dependencies = [ "async-trait", "futures", "hickory-resolver", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "parking_lot", "smallvec", @@ -1854,11 +1827,11 @@ dependencies = [ "cuckoofilter", "fnv", "futures", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "quick-protobuf", - "quick-protobuf-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-protobuf-codec 0.2.0", "rand 0.8.5", "smallvec", "thiserror", @@ -1879,22 +1852,22 @@ dependencies = [ "fnv", "futures", "futures-ticker", - "getrandom 0.2.10", + "getrandom 0.2.11", "hex_fmt", "instant", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "prometheus-client", "quick-protobuf", - "quick-protobuf-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-protobuf-codec 0.2.0", "rand 0.8.5", "regex", "serde", "sha2 0.10.8", "smallvec", "tracing", - "unsigned-varint", + "unsigned-varint 0.7.2", "void", ] @@ -1909,12 +1882,12 @@ dependencies = [ "futures", "futures-bounded", "futures-timer", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "lru 0.12.0", "quick-protobuf", - "quick-protobuf-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-protobuf-codec 0.2.0", "smallvec", "thiserror", "tracing", @@ -1923,25 +1896,25 @@ dependencies = [ [[package]] name = "libp2p-identity" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdd6317441f361babc74c2989c6484eb0726045399b6648de039e1805ea96972" +checksum = "999ec70441b2fb35355076726a6bc466c932e9bdc66f6a11c6c0aa17c7ab9be0" dependencies = [ "asn1_der", "bs58", "ed25519-dalek", "hkdf", "libsecp256k1", - "log", "multihash", "p256", "quick-protobuf", "rand 0.8.5", - "ring 0.16.20", + "ring 0.17.5", "sec1", "serde", "sha2 0.10.8", "thiserror", + "tracing", "void", "zeroize", ] @@ -1960,11 +1933,11 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "quick-protobuf", - "quick-protobuf-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-protobuf-codec 0.2.0", "rand 0.8.5", "serde", "sha2 0.10.8", @@ -1972,7 +1945,7 @@ dependencies = [ "thiserror", "tracing", "uint", - "unsigned-varint", + "unsigned-varint 0.7.2", "void", ] @@ -1988,7 +1961,7 @@ dependencies = [ "futures", "hickory-proto", "if-watch", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "rand 0.8.5", @@ -2005,7 +1978,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f63ec429a224821a9915f31613743566846c6d20078af9736975a60bea4a9293" dependencies = [ - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "memory-stats", @@ -2021,7 +1994,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ac3c92d46c061d3564b660c143356de966a9ab17eb6bfa8d6819daa2ae49b28" dependencies = [ "instant", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", @@ -2043,32 +2016,7 @@ dependencies = [ "bytes", "curve25519-dalek", "futures", - "libp2p-core 0.41.0", - "libp2p-identity", - "multiaddr", - "multihash", - "once_cell", - "quick-protobuf", - "rand 0.8.5", - "sha2 0.10.8", - "snow", - "static_assertions", - "thiserror", - "tracing", - "x25519-dalek", - "zeroize", -] - -[[package]] -name = "libp2p-noise" -version = "0.44.0" -source = "git+https://github.com/libp2p/rust-libp2p.git#dbfda10e3f0f649c6f8556d0afc71bf525968104" -dependencies = [ - "asynchronous-codec 0.7.0", - "bytes", - "curve25519-dalek", - "futures", - "libp2p-core 0.41.1", + "libp2p-core", "libp2p-identity", "multiaddr", "multihash", @@ -2094,7 +2042,7 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "rand 0.8.5", @@ -2111,10 +2059,10 @@ dependencies = [ "asynchronous-codec 0.6.2", "bytes", "futures", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "quick-protobuf", - "quick-protobuf-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-protobuf-codec 0.2.0", "tracing", ] @@ -2143,7 +2091,7 @@ dependencies = [ "futures", "futures-timer", "if-watch", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-tls", "parking_lot", @@ -2170,11 +2118,11 @@ dependencies = [ "futures-bounded", "futures-timer", "instant", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "quick-protobuf", - "quick-protobuf-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-protobuf-codec 0.2.0", "rand 0.8.5", "static_assertions", "thiserror", @@ -2194,12 +2142,12 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-request-response", "libp2p-swarm", "quick-protobuf", - "quick-protobuf-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-protobuf-codec 0.2.0", "rand 0.8.5", "thiserror", "tracing", @@ -2218,7 +2166,7 @@ dependencies = [ "futures-bounded", "futures-timer", "instant", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm", "rand 0.8.5", @@ -2240,12 +2188,12 @@ dependencies = [ "fnv", "futures", "futures-timer", - "getrandom 0.2.10", + "getrandom 0.2.11", "instant", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "libp2p-swarm-derive", - "multistream-select 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "multistream-select", "once_cell", "rand 0.8.5", "smallvec", @@ -2278,7 +2226,7 @@ dependencies = [ "futures-timer", "if-watch", "libc", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "socket2 0.5.5", "tokio", @@ -2293,7 +2241,7 @@ checksum = "93ce7e3c2e7569d685d08ec795157981722ff96e9e9f9eae75df3c29d02b07a5" dependencies = [ "futures", "futures-rustls", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "rcgen", "ring 0.16.20", @@ -2311,7 +2259,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee6531e4844f618678c70ce52fe5cc6971442edc343fc5c774333a28f039d83f" dependencies = [ "futures", - "libp2p-core 0.41.0", + "libp2p-core", "tracing", ] @@ -2324,7 +2272,7 @@ dependencies = [ "futures", "futures-timer", "igd-next", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-swarm", "tokio", "tracing", @@ -2333,18 +2281,19 @@ dependencies = [ [[package]] name = "libp2p-webrtc-utils" -version = "0.1.0" -source = "git+https://github.com/libp2p/rust-libp2p.git#dbfda10e3f0f649c6f8556d0afc71bf525968104" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91f11471ca53e34254033c0ecb94c06ab8b4c856de396706b6a7d273be1bf687" dependencies = [ - "asynchronous-codec 0.6.2", + "asynchronous-codec 0.7.0", "bytes", "futures", "hex", - "libp2p-core 0.41.1", + "libp2p-core", "libp2p-identity", - "libp2p-noise 0.44.0 (git+https://github.com/libp2p/rust-libp2p.git)", + "libp2p-noise", "quick-protobuf", - "quick-protobuf-codec 0.2.0 (git+https://github.com/libp2p/rust-libp2p.git)", + "quick-protobuf-codec 0.3.1", "rand 0.8.5", "serde", "sha2 0.10.8", @@ -2355,21 +2304,19 @@ dependencies = [ [[package]] name = "libp2p-webrtc-websys" -version = "0.2.0-alpha" -source = "git+https://github.com/libp2p/rust-libp2p.git#dbfda10e3f0f649c6f8556d0afc71bf525968104" +version = "0.3.0-alpha" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0831af98b9a29453c72e5f0973d8af8abc94ec8937cafae848a9bd7c97b6747" dependencies = [ "bytes", "futures", - "futures-timer", - "getrandom 0.2.10", + "getrandom 0.2.11", "hex", "js-sys", - "libp2p-core 0.41.1", + "libp2p-core", "libp2p-identity", - "libp2p-noise 0.44.0 (git+https://github.com/libp2p/rust-libp2p.git)", "libp2p-webrtc-utils", "send_wrapper 0.6.0", - "serde", "thiserror", "tracing", "wasm-bindgen", @@ -2386,11 +2333,11 @@ dependencies = [ "either", "futures", "futures-rustls", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", "parking_lot", "pin-project-lite", - "rw-stream-sink 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink", "soketto", "tracing", "url", @@ -2406,7 +2353,7 @@ dependencies = [ "bytes", "futures", "js-sys", - "libp2p-core 0.41.0", + "libp2p-core", "parking_lot", "send_wrapper 0.6.0", "thiserror", @@ -2423,9 +2370,9 @@ checksum = "840b63681e3bedbdb3df3e4f2dd48e9a20d2c6714264829ab90c6fce8549d627" dependencies = [ "futures", "js-sys", - "libp2p-core 0.41.0", + "libp2p-core", "libp2p-identity", - "libp2p-noise 0.44.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-noise", "multiaddr", "multihash", "send_wrapper 0.6.0", @@ -2443,7 +2390,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "751f4778f71bc3db1ccf2451e7f4484463fec7f00c1ac2680e39c8368c23aae8" dependencies = [ "futures", - "libp2p-core 0.41.0", + "libp2p-core", "thiserror", "tracing", "yamux", @@ -2577,6 +2524,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "memchr" version = "2.6.4" @@ -2630,9 +2586,9 @@ dependencies = [ [[package]] name = "multiaddr" -version = "0.18.0" +version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92a651988b3ed3ad1bc8c87d016bb92f6f395b84ed1db9b926b32b1fc5a2c8b5" +checksum = "8b852bc02a2da5feed68cd14fa50d0774b92790a5bdbfa932a813926c8472070" dependencies = [ "arrayref", "byteorder", @@ -2643,7 +2599,7 @@ dependencies = [ "percent-encoding", "serde", "static_assertions", - "unsigned-varint", + "unsigned-varint 0.7.2", "url", ] @@ -2666,7 +2622,7 @@ checksum = "076d548d76a0e2a0d4ab471d0b1c36c577786dfc4471242035d97a12a735c492" dependencies = [ "core2", "serde", - "unsigned-varint", + "unsigned-varint 0.7.2", ] [[package]] @@ -2680,20 +2636,7 @@ dependencies = [ "log", "pin-project", "smallvec", - "unsigned-varint", -] - -[[package]] -name = "multistream-select" -version = "0.13.0" -source = "git+https://github.com/libp2p/rust-libp2p.git#dbfda10e3f0f649c6f8556d0afc71bf525968104" -dependencies = [ - "bytes", - "futures", - "pin-project", - "smallvec", - "tracing", - "unsigned-varint", + "unsigned-varint 0.7.2", ] [[package]] @@ -2799,6 +2742,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-bigint" version = "0.4.4" @@ -2869,6 +2822,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "p256" version = "0.13.2" @@ -3131,19 +3090,20 @@ dependencies = [ "bytes", "quick-protobuf", "thiserror", - "unsigned-varint", + "unsigned-varint 0.7.2", ] [[package]] name = "quick-protobuf-codec" -version = "0.2.0" -source = "git+https://github.com/libp2p/rust-libp2p.git#dbfda10e3f0f649c6f8556d0afc71bf525968104" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a0580ab32b169745d7a39db2ba969226ca16738931be152a3209b409de2474" dependencies = [ - "asynchronous-codec 0.6.2", + "asynchronous-codec 0.7.0", "bytes", "quick-protobuf", "thiserror", - "unsigned-varint", + "unsigned-varint 0.8.0", ] [[package]] @@ -3264,7 +3224,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.10", + "getrandom 0.2.11", ] [[package]] @@ -3325,8 +3285,17 @@ checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -3337,9 +3306,15 @@ checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.2", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.2" @@ -3388,7 +3363,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b" dependencies = [ "cc", - "getrandom 0.2.10", + "getrandom 0.2.11", "libc", "spin 0.9.8", "untrusted 0.9.0", @@ -3523,16 +3498,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "rw-stream-sink" -version = "0.4.0" -source = "git+https://github.com/libp2p/rust-libp2p.git#dbfda10e3f0f649c6f8556d0afc71bf525968104" -dependencies = [ - "futures", - "pin-project", - "static_assertions", -] - [[package]] name = "ryu" version = "1.0.15" @@ -3677,6 +3642,15 @@ dependencies = [ "keccak", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -3707,9 +3681,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.1" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "smol" @@ -3904,6 +3878,16 @@ dependencies = [ "syn 2.0.39", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "time" version = "0.3.30" @@ -4023,6 +4007,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "tracing-wasm" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4575c663a174420fa2d78f4108ff68f65bf2fbb7dd89f33749b6e826b3626e07" +dependencies = [ + "tracing", + "tracing-subscriber", + "wasm-bindgen", ] [[package]] @@ -4096,6 +4121,12 @@ dependencies = [ "bytes", ] +[[package]] +name = "unsigned-varint" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" + [[package]] name = "untrusted" version = "0.7.1" @@ -4119,6 +4150,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "value-bag" version = "1.4.2" @@ -4177,6 +4214,9 @@ dependencies = [ "m3u8-rs", "rmp-serde", "serde", + "tracing", + "tracing-subscriber", + "tracing-wasm", "wasm-bindgen", "wasm-bindgen-futures", "wasm-logger", @@ -4185,9 +4225,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -4195,9 +4235,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" dependencies = [ "bumpalo", "log", @@ -4210,9 +4250,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" +checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" dependencies = [ "cfg-if", "js-sys", @@ -4222,9 +4262,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4232,9 +4272,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", @@ -4245,9 +4285,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "wasm-logger" @@ -4262,9 +4302,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.65" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" +checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 47e6aab..ea8c104 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] async-trait = "^0.1" libp2p = { version = "^0.53", features = ["full"] } -libp2p-webrtc-websys = { git = "https://github.com/libp2p/rust-libp2p.git" } +libp2p-webrtc-websys = "0.3.0-alpha" wasm-bindgen = "^0.2" wasm-bindgen-futures = "^0.4" wasm-logger = "^0.2" @@ -19,6 +19,9 @@ serde = { version = "^1.0", features = ["derive"] } rmp-serde = "^1.1" m3u8-rs = "^5.0" lru = "^0.12" +tracing = "0.1.37" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } +tracing-wasm = "0.2.1" [dependencies.web-sys] version = "^0.3" diff --git a/src/lib.rs b/src/lib.rs index fc67ef1..ebc9718 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,8 @@ -use futures::{StreamExt, future::select_ok}; +use futures::{future::select_ok, StreamExt}; use libp2p::Multiaddr; use p2p::client; use storage::memory_storage::MemoryStorage; use wasm_bindgen::prelude::*; -use wasm_logger; use crate::{p2p::event_loop::LoopEvent, storage::SegmentStorage}; @@ -14,7 +13,7 @@ mod storage; #[wasm_bindgen(start)] pub async fn start() -> Result<(), JsValue> { - wasm_logger::init(wasm_logger::Config::default()); + tracing_wasm::set_as_global_default(); let mut local_storage = MemoryStorage::new(); @@ -24,36 +23,55 @@ pub async fn start() -> Result<(), JsValue> { let server_addr = "/ip4/0.0.0.0".parse::().unwrap(); client.start_listening().await.unwrap(); - client.dial(server_peer_id, server_addr); + client.dial(server_peer_id, server_addr).await; // Player request segment let segment_id = "segment_1"; let segment = match local_storage.get(segment_id) { - Some(segment) => Some(segment.to_vec()), + Some(segment) => Some(segment.to_owned()), None => { let providers = client.get_providers(segment_id.to_string()).await; + if providers.is_empty() { - http::downloader::download_segment(segment_id).await.ok(); + match http::downloader::download_segment(segment_id).await { + Ok(segment) => { + local_storage.set(segment_id, segment.to_vec()); + client.start_providing(segment_id.to_string()).await; + return Ok(()); + } + Err(_) => return Ok(()), + } } - let segment_request = providers - .iter() - .map(|p| Box::pin(client.request_segment(p.to_owned(), segment_id.to_string()))); - let segment_response = select_ok(segment_request).await; - let segment = match segment_response { - Ok((segment, _)) => match segment { - Some(segment) => Some(segment), - None => http::downloader::download_segment(segment_id).await.ok(), - }, - Err(a) => http::downloader::download_segment(segment_id).await.ok(), - }; - - if let Some(seg) = segment.clone() { - local_storage.set(segment_id, seg); - client.start_providing(segment_id.to_string()).await; + let mut segments = Vec::new(); + for provider in providers { + let r = client + .request_segment(provider.to_owned(), segment_id.to_string()) + .await + .ok() + .flatten(); + segments.push(r); } - segment + let segment = segments.into_iter().find(|s| s.is_some()).flatten(); + match segment { + Some(seg) => { + local_storage.set(segment_id, seg.to_vec()); + client.start_providing(segment_id.to_string()).await; + Some(seg) + } + None => { + match http::downloader::download_segment(segment_id) + .await { + Ok(segment) => { + local_storage.set(segment_id, segment.to_vec()); + client.start_providing(segment_id.to_string()).await; + Some(segment) + } + Err(_) => None, + } + }, + } } }; wasm_bindgen_futures::spawn_local(async move { diff --git a/src/p2p/behaviour.rs b/src/p2p/behaviour.rs index 0c8e070..0e1b01f 100644 --- a/src/p2p/behaviour.rs +++ b/src/p2p/behaviour.rs @@ -6,7 +6,7 @@ use libp2p::{ ping, request_response::{self, ProtocolSupport}, swarm::NetworkBehaviour, - PeerId, StreamProtocol, + PeerId, StreamProtocol, identity::Keypair, }; use serde::{Serialize, Deserialize}; @@ -18,8 +18,8 @@ pub struct ComposedSwarmBehaviour { pub kademlia: Behaviour, } -impl ComposedSwarmBehaviour { - pub fn default(peer_id: PeerId) -> Self { +impl From for ComposedSwarmBehaviour { + fn from(peer_id: PeerId) -> Self { // Define the various behaviours of the swarm. let ping_config = ping::Config::new() .with_timeout(Duration::from_secs(10)) @@ -54,6 +54,13 @@ impl ComposedSwarmBehaviour { } } +impl From<&Keypair> for ComposedSwarmBehaviour { + fn from(keypair: &Keypair) -> Self { + let peer_id = keypair.public().to_peer_id(); + Self::from(peer_id) + } +} + #[derive(Debug)] pub enum ComposedSwarmEvent { Ping(ping::Event), diff --git a/src/p2p/client.rs b/src/p2p/client.rs index 8053463..466a392 100644 --- a/src/p2p/client.rs +++ b/src/p2p/client.rs @@ -1,6 +1,5 @@ -use std::{collections::HashSet, error::Error}; use futures::Stream; -//use libp2p::webrtc_websys; +use std::{collections::HashSet, error::Error}; use libp2p::{ futures::{ channel::{mpsc, oneshot}, @@ -15,7 +14,7 @@ use libp2p_webrtc_websys as webrtc_websys; use super::{ behaviour::{ComposedSwarmBehaviour, SegmentResponse}, - event_loop::{EventLoop, LoopCommand, LoopEvent} + event_loop::{EventLoop, LoopCommand, LoopEvent}, }; pub async fn new( @@ -37,8 +36,6 @@ pub async fn new( // Build the Swarm, connecting the lower layer transport logic with the // higher layer network behaviour logic. let swarm = { - let behaviour = ComposedSwarmBehaviour::default(peer_id); - let swarm_config = swarm::Config::with_wasm_executor() .with_max_negotiating_inbound_streams(32) .with_dial_concurrency_factor(5.try_into().unwrap()); @@ -48,8 +45,9 @@ pub async fn new( .with_other_transport(|key| { webrtc_websys::Transport::new(webrtc_websys::Config::new(&key)) })? - .with_behaviour(|_| behaviour)? - .with_swarm_config(swarm_config) + .with_behaviour(|key| ComposedSwarmBehaviour::from(key))? + .build() + //.max_negotiating_inbound_streams(32) }; @@ -70,18 +68,6 @@ pub async fn new( pub struct Client(mpsc::Sender); impl Client { - /// Listen for incoming connections on the given address. - pub async fn start_listening(&mut self) -> Result<(), Box> { - let addr = "/ip4/0.0.0.0".parse::().unwrap(); - - let (sender, receiver) = oneshot::channel(); - self.0 - .send(LoopCommand::StartListening { addr, sender }) - .await - .expect("Command receiver not to be dropped."); - receiver.await.expect("Sender not to be dropped.") - } - /// Dial the given peer at the given address. pub async fn dial( &mut self, diff --git a/src/p2p/event_loop.rs b/src/p2p/event_loop.rs index 1fd95fe..b08210e 100644 --- a/src/p2p/event_loop.rs +++ b/src/p2p/event_loop.rs @@ -241,12 +241,6 @@ impl EventLoop { async fn handle_command(&mut self, command: LoopCommand) { match command { - LoopCommand::StartListening { addr, sender } => { - let _ = match self.swarm.listen_on(addr) { - Ok(_) => sender.send(Ok(())), - Err(e) => sender.send(Err(Box::new(e))), - }; - } LoopCommand::Dial { peer_id, peer_addr, @@ -321,10 +315,6 @@ impl EventLoop { #[derive(Debug)] pub enum LoopCommand { - StartListening { - addr: Multiaddr, - sender: oneshot::Sender>>, - }, Dial { peer_id: PeerId, peer_addr: Multiaddr,