From a70a51f88e9fa56e6930045cbad23882037a93c4 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 3 Nov 2022 18:27:58 +0100 Subject: [PATCH 01/48] impl a basic NetworkBehaviour and config objects --- Cargo.lock | 1639 ++++++++++++++++++++++++++++++---------------- Cargo.toml | 2 +- lib/Cargo.toml | 2 +- src/behaviour.rs | 104 +++ src/lib.rs | 1 + 5 files changed, 1174 insertions(+), 574 deletions(-) create mode 100644 src/behaviour.rs diff --git a/Cargo.lock b/Cargo.lock index 38ef3f5e..f53c908f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,20 +71,6 @@ dependencies = [ "cpufeatures", ] -[[package]] -name = "aes-gcm" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da" -dependencies = [ - "aead 0.3.2", - "aes 0.6.0", - "cipher 0.2.5", - "ctr 0.6.0", - "ghash 0.3.1", - "subtle", -] - [[package]] name = "aes-gcm" version = "0.9.4" @@ -133,11 +119,33 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.8", + "once_cell", + "version_check 0.9.4", +] + +[[package]] +name = "ahash" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +dependencies = [ + "cfg-if", + "once_cell", + "version_check 0.9.4", +] + [[package]] name = "aho-corasick" -version = "0.7.20" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] @@ -194,14 +202,14 @@ dependencies = [ "num-traits", "rusticata-macros", "thiserror", - "time 0.3.17", + "time 0.3.16", ] [[package]] name = "asn1-rs" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf6690c370453db30743b373a60ba498fc0d6d83b11f4abfd87a84a075db5dd4" +checksum = "7f6fd5ddaf0351dff5b8da21b2fb4ff8e08ddd02857f0bf69c47639106c0fff0" dependencies = [ "asn1-rs-derive 0.4.0", "asn1-rs-impl", @@ -210,7 +218,7 @@ dependencies = [ "num-traits", "rusticata-macros", "thiserror", - "time 0.3.17", + "time 0.3.16", ] [[package]] @@ -248,12 +256,6 @@ dependencies = [ "syn", ] -[[package]] -name = "asn1_der" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" - [[package]] name = "async-attributes" version = "1.1.2" @@ -266,9 +268,9 @@ dependencies = [ [[package]] name = "async-channel" -version = "1.8.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" +checksum = "e14485364214912d3b19cc3435dde4df66065127f05fa0d75c712f36f12c2f28" dependencies = [ "concurrent-queue", "event-listener", @@ -277,15 +279,15 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.5.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b" +checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" dependencies = [ - "async-lock", "async-task", "concurrent-queue", "fastrand", "futures-lite", + "once_cell", "slab", ] @@ -306,9 +308,9 @@ dependencies = [ [[package]] name = "async-io" -version = "1.12.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794" +checksum = "e8121296a9f05be7f34aa4196b1747243b3b62e048bb7906f644f3fbfc490cf7" dependencies = [ "async-lock", "autocfg", @@ -321,7 +323,7 @@ dependencies = [ "slab", "socket2", "waker-fn", - "windows-sys", + "winapi", ] [[package]] @@ -401,9 +403,9 @@ checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" [[package]] name = "async-trait" -version = "0.1.61" +version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "705339e0e4a9690e2908d2b3d049d85682cf19fbd5782494498fbf7003a6a282" +checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c" dependencies = [ "proc-macro2", "quote", @@ -440,9 +442,9 @@ dependencies = [ [[package]] name = "atomic-waker" -version = "1.1.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" [[package]] name = "atty" @@ -450,7 +452,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi", "libc", "winapi", ] @@ -482,7 +484,7 @@ dependencies = [ "http", "hyper", "ring", - "time 0.3.17", + "time 0.3.16", "tokio", "tower", "tracing", @@ -646,7 +648,7 @@ dependencies = [ "percent-encoding", "regex", "ring", - "time 0.3.17", + "time 0.3.16", "tracing", ] @@ -782,7 +784,7 @@ dependencies = [ "itoa", "num-integer", "ryu", - "time 0.3.17", + "time 0.3.16", ] [[package]] @@ -834,12 +836,6 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "base64" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" - [[package]] name = "base64" version = "0.21.0" @@ -899,11 +895,11 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.6" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388" dependencies = [ - "digest 0.10.6", + "digest 0.10.5", ] [[package]] @@ -914,7 +910,7 @@ checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" dependencies = [ "arrayref", "arrayvec 0.5.2", - "constant_time_eq 0.1.5", + "constant_time_eq", ] [[package]] @@ -925,7 +921,7 @@ checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" dependencies = [ "arrayref", "arrayvec 0.7.2", - "constant_time_eq 0.1.5", + "constant_time_eq", ] [[package]] @@ -936,20 +932,20 @@ checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" dependencies = [ "arrayref", "arrayvec 0.7.2", - "constant_time_eq 0.1.5", + "constant_time_eq", ] [[package]] name = "blake3" -version = "1.3.3" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ae2468a89544a466886840aa467a25b766499f4f04bf7d9fcd10ecee9fccef" +checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f" dependencies = [ "arrayref", "arrayvec 0.7.2", "cc", "cfg-if", - "constant_time_eq 0.2.4", + "constant_time_eq", ] [[package]] @@ -1020,16 +1016,16 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "blocking" -version = "1.3.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c67b173a56acffd6d2326fb7ab938ba0b00a71480e14902b2591c87bc5741e8" +checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" dependencies = [ "async-channel", - "async-lock", "async-task", "atomic-waker", "fastrand", "futures-lite", + "once_cell", ] [[package]] @@ -1064,9 +1060,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.12.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "byte-tools" @@ -1082,9 +1078,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "bytes-utils" @@ -1108,13 +1104,19 @@ dependencies = [ "iri-string 0.6.0", "libipld", "serde", - "serde_with 2.2.0", + "serde_with 2.0.1", "siwe", "thiserror", - "time 0.3.17", + "time 0.3.16", "url", ] +[[package]] +name = "cache-padded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" + [[package]] name = "cached" version = "0.30.0" @@ -1189,9 +1191,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.78" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" [[package]] name = "ccm" @@ -1246,16 +1248,16 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.23" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" dependencies = [ "iana-time-zone", "js-sys", "num-integer", "num-traits", "serde", - "time 0.1.45", + "time 0.1.44", "wasm-bindgen", "winapi", ] @@ -1335,11 +1337,11 @@ checksum = "337cdbf3f1a0e643b4a7d1a2ffa39d22342fb6ee25739b5cfb997c28b3586422" [[package]] name = "concurrent-queue" -version = "2.1.0" +version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e" +checksum = "af4780a44ab5696ea9e28294517f1fffb421a83a25af521333c838635509db9c" dependencies = [ - "crossbeam-utils", + "cache-padded", ] [[package]] @@ -1360,9 +1362,9 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "const-oid" -version = "0.9.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cec318a675afcb6a1ea1d4340e2d377e56e47c266f28043ceccbf4412ddfdd3b" +checksum = "722e23542a15cea1f65d4a1419c4cfd7a26706c70871a13a04238ca3f40f1661" [[package]] name = "constant_time_eq" @@ -1371,26 +1373,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] -name = "constant_time_eq" -version = "0.2.4" +name = "contextual" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3ad85c1f65dc7b37604eb0e89748faf0b9653065f2a8ef69f96a687ec1e9279" +checksum = "4e916dad4a946c830c9f199481a03be3e8d45792d5fd228c6bde51195a34d6c7" [[package]] name = "cookie" -version = "0.16.2" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" +checksum = "344adc371239ef32293cb1c4fe519592fcf21206c79c02854320afcdf3ab4917" dependencies = [ "aes-gcm 0.10.1", - "base64 0.20.0", + "base64 0.13.1", "hkdf", "hmac 0.12.1", "percent-encoding", "rand 0.8.5", "sha2 0.10.6", "subtle", - "time 0.3.17", + "time 0.3.16", "version_check 0.9.4", ] @@ -1428,12 +1430,6 @@ dependencies = [ "libc", ] -[[package]] -name = "cpuid-bool" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" - [[package]] name = "crc" version = "3.0.1" @@ -1485,22 +1481,22 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.13" +version = "0.9.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" +checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "memoffset 0.7.1", + "memoffset", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.14" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if", ] @@ -1544,16 +1540,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "crypto-mac" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff07008ec701e8028e2ceb8f83f0e4274ee62bd2dbdc4fefff2e9a91824081a" -dependencies = [ - "generic-array 0.14.6", - "subtle", -] - [[package]] name = "crypto-mac" version = "0.11.1" @@ -1583,15 +1569,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ctr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f" -dependencies = [ - "cipher 0.2.5", -] - [[package]] name = "ctr" version = "0.8.0" @@ -1625,9 +1602,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0-pre.5" +version = "4.0.0-rc.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67bc65846be335cb20f4e52d49a437b773a2c1fdb42b19fc84e79e6f6771536f" +checksum = "8d4ba9852b42210c7538b75484f9daa0655e9a3ac04f693747bb0f02cf3cfe16" dependencies = [ "cfg-if", "fiat-crypto", @@ -1639,9 +1616,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.86" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d1075c37807dcf850c379432f0df05ba52cc30f279c5cfc43cc221ce7f8579" +checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a" dependencies = [ "cc", "cxxbridge-flags", @@ -1651,9 +1628,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.86" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5044281f61b27bc598f2f6647d480aed48d2bf52d6eb0b627d84c0361b17aa70" +checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827" dependencies = [ "cc", "codespan-reporting", @@ -1666,15 +1643,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.86" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b50bc93ba22c27b0d31128d2d130a0a6b3d267ae27ef7e4fae2167dfe8781c" +checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a" [[package]] name = "cxxbridge-macro" -version = "1.0.86" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e61fda7e62115119469c7b3591fd913ecca96fb766cfd3f2e2502ab7bc87a5" +checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" dependencies = [ "proc-macro2", "quote", @@ -1788,9 +1765,9 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.3.3" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d8666cb01533c39dde32bcbab8e227b4ed6679b2c925eba05feabea39508fb" +checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" [[package]] name = "data-encoding-macro" @@ -1812,6 +1789,12 @@ dependencies = [ "syn", ] +[[package]] +name = "decoded-char" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5440d1dc8ea7cae44cda3c64568db29bfa2434aba51ae66a50c00488841a65a3" + [[package]] name = "der" version = "0.5.1" @@ -1825,11 +1808,11 @@ dependencies = [ [[package]] name = "der" -version = "0.6.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" +checksum = "13dd2ae565c0a381dde7fade45fce95984c568bdcb4700a4fdbe3175e0380b2f" dependencies = [ - "const-oid 0.9.1", + "const-oid 0.9.0", "pem-rfc7468 0.6.0", "zeroize", ] @@ -1850,11 +1833,11 @@ dependencies = [ [[package]] name = "der-parser" -version = "8.1.0" +version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42d4bc9b0db0a0df9ae64634ac5bdefb7afcb534e182275ca0beadbe486701c1" +checksum = "dbd676fbbab537128ef0278adb5576cf363cff6aa22a7b24effe97347cfab61e" dependencies = [ - "asn1-rs 0.5.1", + "asn1-rs 0.5.2", "displaydoc", "nom 7.1.3", "num-bigint", @@ -1862,6 +1845,17 @@ dependencies = [ "rusticata-macros", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "derive_builder" version = "0.9.0" @@ -1964,9 +1958,9 @@ dependencies = [ [[package]] name = "did-ethr" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75250c5ac4d2436007541e793f4cb4ff39734fffe9ed29c3a3d4e2f86299069b" +checksum = "0d22b1adcd156bf1041f87f80cd027bf6f82a34849bada30d59b869e831df19d" dependencies = [ "async-trait", "chrono", @@ -1981,9 +1975,9 @@ dependencies = [ [[package]] name = "did-method-key" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e30ffe2bc1957789ff1689ec03567c919a112193eec612ad55308998ebaf1a3" +checksum = "543b322ff52ab4892f4fd30ceb8fa1007aca4e3c5e89ad55793036846f0cc74e" dependencies = [ "async-trait", "multibase 0.8.0", @@ -1997,9 +1991,9 @@ dependencies = [ [[package]] name = "did-onion" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c8c2dd477d93ed2748b6ddc6c93e6dae99156a1fc99b3adbb7f8bdf0a385c63" +checksum = "d8e1ba10a5415931c5d436a6343bbd72673a42284a16d4acd501fbfb9d882db5" dependencies = [ "async-trait", "http", @@ -2011,27 +2005,29 @@ dependencies = [ [[package]] name = "did-pkh" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5e932607cfaf0a0120b944cda8ab10af564077e2738176e7f3a88c511d54ef0" +checksum = "074c4ae82880d60a25048cd3bf2e8aaaa881922d7c73fbb9ec29fc67fa0d33e4" dependencies = [ "async-trait", "bech32", "bs58", "chrono", + "iref", "serde", "serde_json", "ssi-caips", "ssi-crypto", "ssi-dids", "ssi-jwk", + "static-iref", ] [[package]] name = "did-tz" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a384ae6115903040836d8a4fc1068d5adf76cd899a3bfb3ed1cae738478c545f" +checksum = "562670fedf756b20c047dcf4ef88d020c5c86c2115f954fb3aef072952015ba4" dependencies = [ "anyhow", "async-trait", @@ -2050,9 +2046,9 @@ dependencies = [ [[package]] name = "did-web" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff7d4d4106efd76e30e19d0f19a6d3c4997cde18a0da7f9280ac4d84da3ffaf" +checksum = "9f8baea04ae1358a23bf460378573f4df91bab76c5f410455efcf2a8db476309" dependencies = [ "async-trait", "http", @@ -2063,9 +2059,9 @@ dependencies = [ [[package]] name = "did-webkey" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2102be2a97ee89322cf31fa37b2a1862f20d66fc663c761f9937296b17e5e10" +checksum = "a41245dcd63c5d9474d63b5117051f8b339497316210dab398b79237eb9417b6" dependencies = [ "anyhow", "async-trait", @@ -2101,9 +2097,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.6" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" dependencies = [ "block-buffer 0.10.3", "crypto-common", @@ -2123,9 +2119,9 @@ dependencies = [ [[package]] name = "dtoa" -version = "1.0.5" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c00704156a7de8df8da0911424e30c2049957b0a714542a44e05fe693dd85313" +checksum = "f8a6eee2d5d0d113f015688310da018bd1d864d86bd567c8fca9c266889e1bfa" [[package]] name = "ecdsa" @@ -2133,7 +2129,7 @@ version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" dependencies = [ - "der 0.6.1", + "der 0.6.0", "elliptic-curve", "rfc6979", "signature", @@ -2141,9 +2137,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.5.3" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" dependencies = [ "signature", ] @@ -2176,8 +2172,8 @@ checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" dependencies = [ "base16ct", "crypto-bigint 0.4.9", - "der 0.6.1", - "digest 0.10.6", + "der 0.6.0", + "digest 0.10.5", "ff", "generic-array 0.14.6", "group", @@ -2265,9 +2261,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a214f5bb88731d436478f3ae1f8a277b62124089ba9fb67f4f93fb100ef73c90" +checksum = "93ace6ec7cc19c8ed33a32eaa9ea692d7faea05006b5356b9e2b668ec4bc3955" [[package]] name = "figment" @@ -2300,9 +2296,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.25" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" dependencies = [ "crc32fast", "miniz_oxide", @@ -2356,9 +2352,9 @@ checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" [[package]] name = "futures" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" dependencies = [ "futures-channel", "futures-core", @@ -2371,9 +2367,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" dependencies = [ "futures-core", "futures-sink", @@ -2381,15 +2377,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" +checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" [[package]] name = "futures-executor" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" +checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" dependencies = [ "futures-core", "futures-task", @@ -2399,9 +2395,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" +checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" [[package]] name = "futures-lite" @@ -2420,9 +2416,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" +checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" dependencies = [ "proc-macro2", "quote", @@ -2436,21 +2432,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2411eed028cdf8c8034eaf21f9915f956b6c3abec4d4c7949ee67f0721127bd" dependencies = [ "futures-io", - "rustls 0.20.8", + "rustls 0.20.7", "webpki 0.22.0", ] [[package]] name = "futures-sink" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" +checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" [[package]] name = "futures-task" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" +checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" [[package]] name = "futures-timer" @@ -2460,9 +2456,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" +checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" dependencies = [ "futures-channel", "futures-core", @@ -2487,15 +2483,15 @@ dependencies = [ [[package]] name = "generator" -version = "0.7.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266041a359dfa931b370ef684cceb84b166beb14f7f0421f4a6a3d0c446d12e" +checksum = "cc184cace1cea8335047a471cc1da80f18acf8a76f3bab2028d499e328948ec7" dependencies = [ "cc", "libc", "log", "rustversion", - "windows 0.39.0", + "windows 0.32.0", ] [[package]] @@ -2543,16 +2539,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "ghash" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375" -dependencies = [ - "opaque-debug 0.3.0", - "polyval 0.4.5", -] - [[package]] name = "ghash" version = "0.4.4" @@ -2575,15 +2561,15 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "gloo-timers" -version = "0.2.5" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c4a8d6391675c6b2ee1a6c8d06e8e2d03605c44cec1270675985a4c2a5500b" +checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" dependencies = [ "futures-channel", "futures-core", @@ -2591,6 +2577,18 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "grdf" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9bbea22c05df8419a2bac76dcf144ef312c06de1db6f5d1304b1ce578890b00" +dependencies = [ + "derivative", + "hashbrown 0.13.2", + "iref", + "rdf-types", +] + [[package]] name = "group" version = "0.12.1" @@ -2632,6 +2630,18 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.6", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash 0.8.3", +] [[package]] name = "headers" @@ -2673,21 +2683,18 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex_fmt" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" + [[package]] name = "hkdf" version = "0.12.3" @@ -2697,23 +2704,13 @@ dependencies = [ "hmac 0.12.1", ] -[[package]] -name = "hmac" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" -dependencies = [ - "crypto-mac 0.10.1", - "digest 0.9.0", -] - [[package]] name = "hmac" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" dependencies = [ - "crypto-mac 0.11.1", + "crypto-mac", "digest 0.9.0", ] @@ -2723,7 +2720,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.6", + "digest 0.10.5", ] [[package]] @@ -2773,9 +2770,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "hyper" -version = "0.14.23" +version = "0.14.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" +checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064" dependencies = [ "bytes", "futures-channel", @@ -2814,13 +2811,13 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.23.2" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac" dependencies = [ "http", "hyper", - "rustls 0.20.8", + "rustls 0.20.7", "tokio", "tokio-rustls 0.23.4", ] @@ -2920,9 +2917,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.2" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", "hashbrown 0.12.3", @@ -2980,31 +2977,27 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" -dependencies = [ - "libc", - "windows-sys", -] +checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" [[package]] name = "ipconfig" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd302af1b90f2463a98fa5ad469fc212c8e3175a41c3068601bfa2727591c5be" +checksum = "723519edce41262b05d4143ceb95050e4c614f483e78e9fd9e39a8275a84ad98" dependencies = [ "socket2", "widestring", "winapi", - "winreg", + "winreg 0.7.0", ] [[package]] name = "ipnet" -version = "2.7.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "iref" @@ -3012,7 +3005,9 @@ version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72758dab8e7c250a8643189063072ab0abf48e27eb453e0a38bbd2d7770ee8ec" dependencies = [ + "hashbrown 0.13.2", "pct-str", + "serde", "smallvec", ] @@ -3043,9 +3038,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.5" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] name = "js-sys" @@ -3057,37 +3052,176 @@ dependencies = [ ] [[package]] -name = "json" -version = "0.12.4" +name = "json-ld" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" +checksum = "3e445d0986fc6a6e8bbe8b2c4ba0c847b7bebd201046cc37df645d632eb4202a" +dependencies = [ + "contextual", + "futures", + "json-ld-compaction", + "json-ld-context-processing", + "json-ld-core", + "json-ld-expansion", + "json-ld-syntax", + "json-syntax", + "locspan", + "rdf-types", + "thiserror", +] [[package]] -name = "json-ld" -version = "0.4.0" +name = "json-ld-compaction" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "730f40b0e5cf16f2b832f5308117271e9158718232b72235e466a71b43604983" +checksum = "cd69243e6b268c66c9cdd6f1aab73bd0d4f6df617d53e8d77238b676a9ab01c3" dependencies = [ + "contextual", + "derivative", "futures", "iref", - "json", + "json-ld-context-processing", + "json-ld-core", + "json-ld-expansion", + "json-ld-syntax", + "json-syntax", "langtag", + "locspan", + "mown", + "rdf-types", + "thiserror", +] + +[[package]] +name = "json-ld-context-processing" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6162a8b000517178a4a23f546fa7fef31a0cac466393ef922a351d8e6041fb8f" +dependencies = [ + "contextual", + "futures", + "iref", + "json-ld-core", + "json-ld-syntax", + "locspan", + "mown", + "rdf-types", + "thiserror", +] + +[[package]] +name = "json-ld-core" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f103ff1c30bf42b3b7d09c69cbe12869e5ad42497638c5199d83de6fd7d7b13e" +dependencies = [ + "contextual", + "derivative", + "futures", + "hashbrown 0.13.2", + "iref", + "json-ld-syntax", + "json-syntax", + "langtag", + "locspan", + "locspan-derive", "log", + "mime", "mown", "once_cell", + "permutohedron", + "pretty_dtoa", + "rdf-types", + "ryu-js", + "smallvec", + "static-iref", + "thiserror", +] + +[[package]] +name = "json-ld-expansion" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ec3b334e7ae66e64a139ac34f38d3559dd82e7a0deed8891d1897a933a006cc" +dependencies = [ + "contextual", + "derivative", + "futures", + "iref", + "json-ld-context-processing", + "json-ld-core", + "json-ld-syntax", + "json-syntax", + "langtag", + "locspan", + "mown", + "rdf-types", + "thiserror", +] + +[[package]] +name = "json-ld-syntax" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fe7e17ed956850ff813815c960dcf3ab80604d72a2590ddebf8112509fb3722" +dependencies = [ + "contextual", + "decoded-char", + "derivative", + "hashbrown 0.13.2", + "indexmap", + "iref", + "json-syntax", + "langtag", + "locspan", + "locspan-derive", + "rdf-types", + "smallvec", + "thiserror", +] + +[[package]] +name = "json-number" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c724484d970b5aabe46934b9571980e255fd50a9ef1b13f23ed2b5c2a19bbb69" +dependencies = [ + "lexical", + "ryu-js", + "serde", + "smallvec", ] [[package]] name = "json-patch" -version = "0.2.7" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3fa5a61630976fc4c353c70297f2e93f1930e3ccee574d59d618ccbd5154ce" +checksum = "f995a3c8f2bc3dd52a18a583e90f9ec109c047fa1603a853e46bcda14d2e279d" dependencies = [ "serde", "serde_json", "treediff", ] +[[package]] +name = "json-syntax" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e3473c7c1719795449173b4d4d89c653598df3ddbc2f32b73bd9ceab8cc2dfb" +dependencies = [ + "contextual", + "decoded-char", + "hashbrown 0.12.3", + "indexmap", + "json-number", + "locspan", + "locspan-derive", + "ryu-js", + "serde", + "smallstr", + "smallvec", +] + [[package]] name = "k256" version = "0.11.6" @@ -3103,12 +3237,9 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.3" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" -dependencies = [ - "cpufeatures", -] +checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" [[package]] name = "keccak-hash" @@ -3159,7 +3290,7 @@ dependencies = [ "sled", "tempfile", "thiserror", - "time 0.3.17", + "time 0.3.16", "tokio", "tokio-stream", "tokio-util", @@ -3212,7 +3343,7 @@ dependencies = [ "serde_json", "serde_with 1.14.0", "thiserror", - "time 0.3.17", + "time 0.3.16", "tokio", "tracing", ] @@ -3229,7 +3360,7 @@ dependencies = [ "serde", "serde_json", "serde_with 1.14.0", - "time 0.3.17", + "time 0.3.16", "wasm-bindgen", "wasm-bindgen-futures", ] @@ -3245,9 +3376,9 @@ dependencies = [ [[package]] name = "langtag" -version = "0.2.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb570ff14fe16874719449cb4834c4dfe32d79306ebcb2195ee89a2b597da3b" +checksum = "d78b08c3742c6e025dac6db28d42a961411470194bc4ec2ef22ba16bbc38da03" [[package]] name = "lazy_static" @@ -3258,11 +3389,84 @@ dependencies = [ "spin 0.5.2", ] +[[package]] +name = "lexical" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7aefb36fd43fef7003334742cbf77b243fcd36418a1d1bdd480d613a67968f6" +dependencies = [ + "lexical-core", +] + +[[package]] +name = "lexical-core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cde5de06e8d4c2faabc400238f9ae1c74d5412d03a7bd067645ccbc47070e46" +dependencies = [ + "lexical-parse-float", + "lexical-parse-integer", + "lexical-util", + "lexical-write-float", + "lexical-write-integer", +] + +[[package]] +name = "lexical-parse-float" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683b3a5ebd0130b8fb52ba0bdc718cc56815b6a097e28ae5a6997d0ad17dc05f" +dependencies = [ + "lexical-parse-integer", + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-parse-integer" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d0994485ed0c312f6d965766754ea177d07f9c00c9b82a5ee62ed5b47945ee9" +dependencies = [ + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-util" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5255b9ff16ff898710eb9eb63cb39248ea8a5bb036bea8085b1a767ff6c4e3fc" +dependencies = [ + "static_assertions", +] + +[[package]] +name = "lexical-write-float" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accabaa1c4581f05a3923d1b4cfd124c329352288b7b9da09e766b0668116862" +dependencies = [ + "lexical-util", + "lexical-write-integer", + "static_assertions", +] + +[[package]] +name = "lexical-write-integer" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1b6f3d1f4422866b68192d62f77bc5c700bee84f3069f2469d7bc8c77852446" +dependencies = [ + "lexical-util", + "static_assertions", +] + [[package]] name = "libc" -version = "0.2.139" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "libipld" @@ -3352,14 +3556,14 @@ checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" [[package]] name = "libm" -version = "0.2.6" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" +checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" [[package]] name = "libp2p" -version = "0.51.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +version = "0.51.1" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "bytes", "futures", @@ -3367,36 +3571,38 @@ dependencies = [ "getrandom 0.2.8", "instant", "libp2p-core", + "libp2p-dcutr", "libp2p-dns", + "libp2p-gossipsub", + "libp2p-identify", + "libp2p-identity", + "libp2p-kad", "libp2p-mdns", "libp2p-metrics", "libp2p-mplex", "libp2p-noise", "libp2p-ping", "libp2p-quic", + "libp2p-relay", "libp2p-swarm", "libp2p-tcp", "libp2p-webrtc", "libp2p-yamux", "multiaddr", - "parking_lot 0.12.1", "pin-project", - "smallvec", ] [[package]] name = "libp2p-core" -version = "0.39.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +version = "0.39.1" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ - "asn1_der", - "bs58", - "ed25519-dalek", "either", "fnv", "futures", "futures-timer", "instant", + "libp2p-identity", "log", "multiaddr", "multihash 0.17.0", @@ -3407,37 +3613,151 @@ dependencies = [ "quick-protobuf", "rand 0.8.5", "rw-stream-sink", - "sec1", - "sha2 0.10.6", "smallvec", "thiserror", "unsigned-varint", "void", - "zeroize", +] + +[[package]] +name = "libp2p-dcutr" +version = "0.9.1" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +dependencies = [ + "asynchronous-codec", + "either", + "futures", + "futures-timer", + "instant", + "libp2p-core", + "libp2p-identity", + "libp2p-swarm", + "log", + "quick-protobuf", + "quick-protobuf-codec", + "thiserror", + "void", ] [[package]] name = "libp2p-dns" version = "0.39.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "futures", "libp2p-core", + "libp2p-identity", "log", "parking_lot 0.12.1", "smallvec", "trust-dns-resolver", ] +[[package]] +name = "libp2p-gossipsub" +version = "0.44.1" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +dependencies = [ + "asynchronous-codec", + "base64 0.21.0", + "byteorder", + "bytes", + "fnv", + "futures", + "hex_fmt", + "instant", + "libp2p-core", + "libp2p-identity", + "libp2p-swarm", + "log", + "prometheus-client", + "quick-protobuf", + "quick-protobuf-codec", + "rand 0.8.5", + "regex", + "sha2 0.10.6", + "smallvec", + "thiserror", + "unsigned-varint", + "wasm-timer", +] + +[[package]] +name = "libp2p-identify" +version = "0.42.1" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +dependencies = [ + "asynchronous-codec", + "either", + "futures", + "futures-timer", + "libp2p-core", + "libp2p-identity", + "libp2p-swarm", + "log", + "lru", + "quick-protobuf", + "quick-protobuf-codec", + "smallvec", + "thiserror", + "void", +] + +[[package]] +name = "libp2p-identity" +version = "0.1.0" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +dependencies = [ + "bs58", + "ed25519-dalek", + "log", + "multiaddr", + "multihash 0.17.0", + "prost", + "prost-build", + "quick-protobuf", + "rand 0.8.5", + "thiserror", + "zeroize", +] + +[[package]] +name = "libp2p-kad" +version = "0.43.1" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +dependencies = [ + "arrayvec 0.7.2", + "asynchronous-codec", + "bytes", + "either", + "fnv", + "futures", + "futures-timer", + "instant", + "libp2p-core", + "libp2p-identity", + "libp2p-swarm", + "log", + "quick-protobuf", + "rand 0.8.5", + "sha2 0.10.6", + "smallvec", + "thiserror", + "uint", + "unsigned-varint", + "void", +] + [[package]] name = "libp2p-mdns" version = "0.43.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "data-encoding", "futures", "if-watch", "libp2p-core", + "libp2p-identity", "libp2p-swarm", "log", "rand 0.8.5", @@ -3451,10 +3771,16 @@ dependencies = [ [[package]] name = "libp2p-metrics" version = "0.12.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "libp2p-core", + "libp2p-dcutr", + "libp2p-gossipsub", + "libp2p-identify", + "libp2p-identity", + "libp2p-kad", "libp2p-ping", + "libp2p-relay", "libp2p-swarm", "prometheus-client", ] @@ -3462,12 +3788,13 @@ dependencies = [ [[package]] name = "libp2p-mplex" version = "0.39.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "asynchronous-codec", "bytes", "futures", "libp2p-core", + "libp2p-identity", "log", "nohash-hasher", "parking_lot 0.12.1", @@ -3478,13 +3805,14 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.42.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +version = "0.42.1" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "bytes", "curve25519-dalek 3.2.0", "futures", "libp2p-core", + "libp2p-identity", "log", "once_cell", "quick-protobuf", @@ -3500,12 +3828,14 @@ dependencies = [ [[package]] name = "libp2p-ping" version = "0.42.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ + "either", "futures", "futures-timer", "instant", "libp2p-core", + "libp2p-identity", "libp2p-swarm", "log", "rand 0.8.5", @@ -3514,28 +3844,52 @@ dependencies = [ [[package]] name = "libp2p-quic" -version = "0.7.0-alpha.2" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +version = "0.7.0-alpha.3" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "bytes", "futures", "futures-timer", "if-watch", "libp2p-core", + "libp2p-identity", "libp2p-tls", "log", "parking_lot 0.12.1", "quinn-proto", "rand 0.8.5", - "rustls 0.20.8", + "rustls 0.20.7", "thiserror", "tokio", ] +[[package]] +name = "libp2p-relay" +version = "0.15.1" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +dependencies = [ + "asynchronous-codec", + "bytes", + "either", + "futures", + "futures-timer", + "instant", + "libp2p-core", + "libp2p-identity", + "libp2p-swarm", + "log", + "quick-protobuf", + "quick-protobuf-codec", + "rand 0.8.5", + "static_assertions", + "thiserror", + "void", +] + [[package]] name = "libp2p-swarm" version = "0.42.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "either", "fnv", @@ -3543,11 +3897,10 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", + "libp2p-identity", "log", - "pin-project", "rand 0.8.5", "smallvec", - "thiserror", "tokio", "void", ] @@ -3555,13 +3908,14 @@ dependencies = [ [[package]] name = "libp2p-tcp" version = "0.39.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "futures", "futures-timer", "if-watch", "libc", "libp2p-core", + "libp2p-identity", "log", "socket2", "tokio", @@ -3569,15 +3923,16 @@ dependencies = [ [[package]] name = "libp2p-tls" -version = "0.1.0-alpha.2" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +version = "0.1.0" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "futures", "futures-rustls", "libp2p-core", + "libp2p-identity", "rcgen 0.10.0", "ring", - "rustls 0.20.8", + "rustls 0.20.7", "thiserror", "webpki 0.22.0", "x509-parser 0.14.0", @@ -3586,8 +3941,8 @@ dependencies = [ [[package]] name = "libp2p-webrtc" -version = "0.4.0-alpha.2" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +version = "0.4.0-alpha.3" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "async-trait", "asynchronous-codec", @@ -3597,12 +3952,12 @@ dependencies = [ "hex", "if-watch", "libp2p-core", + "libp2p-identity", "libp2p-noise", "log", "multihash 0.17.0", - "prost", - "prost-build", - "prost-codec", + "quick-protobuf", + "quick-protobuf-codec", "rand 0.8.5", "rcgen 0.9.3", "serde", @@ -3617,21 +3972,20 @@ dependencies = [ [[package]] name = "libp2p-yamux" version = "0.43.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "futures", "libp2p-core", "log", - "parking_lot 0.12.1", "thiserror", "yamux", ] [[package]] name = "link-cplusplus" -version = "1.0.8" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" dependencies = [ "cc", ] @@ -3644,18 +3998,40 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" -version = "0.1.4" +version = "0.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "locspan" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" +checksum = "685e26b5a3e4266c351baf3c00793a097e40f4293270ac508b3f4cbc41e72e54" +dependencies = [ + "contextual", + "hashbrown 0.13.2", +] [[package]] -name = "lock_api" -version = "0.4.9" +name = "locspan-derive" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +checksum = "e88991223b049a3d29ca1f60c05639581336a0f3ee4bf8a659dddecc11c4961a" dependencies = [ - "autocfg", - "scopeguard", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -3683,6 +4059,15 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "lru" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e7d46de488603ffdd5f30afbc64fbba2378214a2c3a2fb83abf3d33126df17" +dependencies = [ + "hashbrown 0.13.2", +] + [[package]] name = "lru-cache" version = "0.1.2" @@ -3730,7 +4115,7 @@ version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" dependencies = [ - "digest 0.10.6", + "digest 0.10.5", ] [[package]] @@ -3748,15 +4133,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "memoffset" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] - [[package]] name = "mime" version = "0.3.16" @@ -3771,9 +4147,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.6.2" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" dependencies = [ "adler", ] @@ -3787,7 +4163,7 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -3866,7 +4242,7 @@ dependencies = [ "blake2s_simd", "blake3", "core2", - "digest 0.10.6", + "digest 0.10.5", "multihash-derive", "serde", "serde-big-array", @@ -3882,7 +4258,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835d6ff01d610179fbce3de1694d007e500bf33a7f29689838941d6bf783ae40" dependencies = [ "core2", - "digest 0.10.6", + "digest 0.10.5", "multihash-derive", "sha2 0.10.6", "unsigned-varint", @@ -3911,7 +4287,7 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "multistream-select" version = "0.12.1" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "bytes", "futures", @@ -4007,14 +4383,14 @@ dependencies = [ [[package]] name = "nix" -version = "0.24.3" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" +checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" dependencies = [ "bitflags", "cfg-if", "libc", - "memoffset 0.6.5", + "memoffset", ] [[package]] @@ -4066,13 +4442,13 @@ dependencies = [ [[package]] name = "num-bigint-dig" -version = "0.8.2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2399c9463abc5f909349d8aa9ba080e0b88b3ce2885389b60b993f39b1a56905" +checksum = "566d173b2f9406afbc5510a90925d5a2cd80cae4605631f1212303df265de011" dependencies = [ "byteorder", "lazy_static", - "libm 0.2.6", + "libm 0.2.5", "num-integer", "num-iter", "num-traits", @@ -4121,16 +4497,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", - "libm 0.2.6", + "libm 0.2.5", ] [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" dependencies = [ - "hermit-abi 0.2.6", "libc", ] @@ -4149,14 +4534,14 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bedf36ffb6ba96c2eb7144ef6270557b52e54b20c0a8e1eb2ff99a6c6959bff" dependencies = [ - "asn1-rs 0.5.1", + "asn1-rs 0.5.2", ] [[package]] name = "once_cell" -version = "1.17.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "opaque-debug" @@ -4172,9 +4557,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.45" +version = "0.10.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" dependencies = [ "bitflags", "cfg-if", @@ -4213,9 +4598,9 @@ dependencies = [ [[package]] name = "openssl-sys" -version = "0.9.80" +version = "0.9.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" +checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" dependencies = [ "autocfg", "cc", @@ -4348,7 +4733,7 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core 0.8.6", + "parking_lot_core 0.8.5", ] [[package]] @@ -4358,14 +4743,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.6", + "parking_lot_core 0.9.4", ] [[package]] name = "parking_lot_core" -version = "0.8.6" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" dependencies = [ "cfg-if", "instant", @@ -4377,22 +4762,22 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.6" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf" +checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] name = "paste" -version = "1.0.11" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" +checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" [[package]] name = "pct-str" @@ -4456,6 +4841,12 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +[[package]] +name = "permutohedron" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b687ff7b5da449d39e418ad391e5e08da53ec334903ddbb921db208908fc372c" + [[package]] name = "petgraph" version = "0.6.2" @@ -4575,7 +4966,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" dependencies = [ - "der 0.6.1", + "der 0.6.0", "spki 0.6.0", ] @@ -4593,16 +4984,16 @@ checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" [[package]] name = "polling" -version = "2.5.2" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22122d5ec4f9fe1b3916419b76be1e80bcb93f618d071d2edf841b137b2a2bd6" +checksum = "ab4609a838d88b73d8238967b60dd115cc08d38e2bbaf51ee1e4b695f89122e2" dependencies = [ "autocfg", "cfg-if", "libc", "log", "wepoll-ffi", - "windows-sys", + "winapi", ] [[package]] @@ -4616,17 +5007,6 @@ dependencies = [ "universal-hash 0.4.1", ] -[[package]] -name = "polyval" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd" -dependencies = [ - "cpuid-bool", - "opaque-debug 0.3.0", - "universal-hash 0.4.1", -] - [[package]] name = "polyval" version = "0.5.3" @@ -4653,18 +5033,17 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] -name = "prettyplease" -version = "0.1.23" +name = "pretty_dtoa" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97e3215779627f01ee256d2fad52f3d95e8e1c11e9fc6fd08f7cd455d5d5c78" +checksum = "a239bcdfda2c685fda1add3b4695c06225f50075e3cfb5b954e91545587edff2" dependencies = [ - "proc-macro2", - "syn", + "ryu_floating_decimal", ] [[package]] @@ -4714,9 +5093,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] @@ -4736,9 +5115,9 @@ dependencies = [ [[package]] name = "procfs" -version = "0.14.2" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1de8dacb0873f77e6aefc6d71e044761fcc68060290f5b1089fcdf84626bb69" +checksum = "2dfb6451c91904606a1abe93e83a8ec851f45827fa84273f256ade45dc095818" dependencies = [ "bitflags", "byteorder", @@ -4766,21 +5145,21 @@ dependencies = [ [[package]] name = "prometheus-client" -version = "0.18.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83cd1b99916654a69008fd66b4f9397fbe08e6e51dfe23d4417acf5d3b8cb87c" +checksum = "5d6fa99d535dd930d1249e6c79cb3c2915f9172a540fe2b02a4c8f9ca954721e" dependencies = [ "dtoa", "itoa", "parking_lot 0.12.1", - "prometheus-client-derive-text-encode", + "prometheus-client-derive-encode", ] [[package]] -name = "prometheus-client-derive-text-encode" -version = "0.3.0" +name = "prometheus-client-derive-encode" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a455fbcb954c1a7decf3c586e860fd7889cddf4b8e164be736dbac95a953cd" +checksum = "72b6a5217beb0ad503ee7fa752d451c905113d70721b937126158f3106a48cc1" dependencies = [ "proc-macro2", "quote", @@ -4789,9 +5168,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.6" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21dc42e00223fc37204bd4aa177e69420c604ca4a183209a8f9de30c6d934698" +checksum = "399c3c31cdec40583bb68f0b18403400d01ec4289c383aa047560439952c4dd7" dependencies = [ "bytes", "prost-derive", @@ -4799,9 +5178,9 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.6" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f8ad728fb08fe212df3c05169e940fbb6d9d16a877ddde14644a983ba2012e" +checksum = "7f835c582e6bd972ba8347313300219fed5bfa52caf175298d860b61ff6069bb" dependencies = [ "bytes", "heck", @@ -4810,32 +5189,18 @@ dependencies = [ "log", "multimap", "petgraph", - "prettyplease", "prost", "prost-types", "regex", - "syn", "tempfile", "which", ] -[[package]] -name = "prost-codec" -version = "0.3.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" -dependencies = [ - "asynchronous-codec", - "bytes", - "prost", - "thiserror", - "unsigned-varint", -] - [[package]] name = "prost-derive" -version = "0.11.6" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda8c0881ea9f722eb9629376db3d0b903b462477c1aafcb0566610ac28ac5d" +checksum = "7345d5f0e08c0536d7ac7229952590239e77abf0a0100a1b1d890add6ea96364" dependencies = [ "anyhow", "itertools", @@ -4846,9 +5211,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.11.6" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e0526209433e96d83d750dd81a99118edbc55739e7e61a46764fd2ad537788" +checksum = "4dfaa718ad76a44b3415e6c4d53b17c8f99160dcb3a99b10470fce8ad43f6e3e" dependencies = [ "bytes", "prost", @@ -4875,6 +5240,18 @@ dependencies = [ "byteorder", ] +[[package]] +name = "quick-protobuf-codec" +version = "0.1.0" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +dependencies = [ + "asynchronous-codec", + "bytes", + "quick-protobuf", + "thiserror", + "unsigned-varint", +] + [[package]] name = "quinn-proto" version = "0.9.2" @@ -4885,7 +5262,7 @@ dependencies = [ "rand 0.8.5", "ring", "rustc-hash", - "rustls 0.20.8", + "rustls 0.20.7", "slab", "thiserror", "tinyvec", @@ -4895,9 +5272,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.23" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -4987,7 +5364,7 @@ checksum = "6413f3de1edee53342e6138e75b56d32e7bc6e332b3bd62d497b1929d4cfbcdd" dependencies = [ "pem", "ring", - "time 0.3.17", + "time 0.3.16", "x509-parser 0.13.2", "yasna", ] @@ -5000,10 +5377,23 @@ checksum = "ffbe84efe2f38dea12e9bfc1f65377fdf03e53a18cb3b995faedf7934c7e785b" dependencies = [ "pem", "ring", - "time 0.3.17", + "time 0.3.16", "yasna", ] +[[package]] +name = "rdf-types" +version = "0.12.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63d95f82a1f30f2d62e77b775ef4863f67ffafef1fc2c95ebfb55f3750be55df" +dependencies = [ + "contextual", + "iref", + "langtag", + "locspan", + "locspan-derive", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -5015,18 +5405,18 @@ dependencies = [ [[package]] name = "ref-cast" -version = "1.0.14" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c78fb8c9293bcd48ef6fce7b4ca950ceaf21210de6e105a883ee280c0f7b9ed" +checksum = "53b15debb4f9d60d767cd8ca9ef7abb2452922f3214671ff052defc7f3502c44" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.14" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f9c0c92af03644e4806106281fe2e068ac5bc0ae74a707266d06ea27bccee5f" +checksum = "abfa8511e9e94fd3de6585a3d3cd00e01ed556dc9814829280af0e8dc72a8f36" dependencies = [ "proc-macro2", "quote", @@ -5035,9 +5425,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ "aho-corasick", "memchr", @@ -5055,9 +5445,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "remove_dir_all" @@ -5070,9 +5460,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.13" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" dependencies = [ "base64 0.13.1", "bytes", @@ -5083,7 +5473,7 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-rustls 0.23.2", + "hyper-rustls 0.23.0", "hyper-tls", "ipnet", "js-sys", @@ -5093,7 +5483,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.20.8", + "rustls 0.20.7", "rustls-pemfile", "serde", "serde_json", @@ -5108,7 +5498,7 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "webpki-roots", - "winreg", + "winreg 0.10.1", ] [[package]] @@ -5123,9 +5513,9 @@ dependencies = [ [[package]] name = "rfc6979" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +checksum = "88c86280f057430a52f4861551b092a01b419b8eacefc7c995eacb9dc132fe32" dependencies = [ "crypto-bigint 0.4.9", "hmac 0.12.1", @@ -5188,7 +5578,7 @@ dependencies = [ "serde_json", "state", "tempfile", - "time 0.3.17", + "time 0.3.16", "tokio", "tokio-stream", "tokio-util", @@ -5235,7 +5625,7 @@ dependencies = [ "smallvec", "stable-pattern", "state", - "time 0.3.17", + "time 0.3.16", "tokio", "uncased", ] @@ -5247,7 +5637,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cf22754c49613d2b3b119f0e5d46e34a2c628a937e3024b8762de4e7d8c710b" dependencies = [ "byteorder", - "digest 0.10.6", + "digest 0.10.5", "num-bigint-dig", "num-integer", "num-iter", @@ -5326,16 +5716,16 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.6" +version = "0.35.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -5353,9 +5743,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.8" +version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" dependencies = [ "log", "ring", @@ -5377,23 +5767,23 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.2" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" +checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" dependencies = [ - "base64 0.21.0", + "base64 0.13.1", ] [[package]] name = "rustversion" -version = "1.0.11" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" +checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" [[package]] name = "rw-stream-sink" version = "0.3.0" -source = "git+https://github.com/kckeiks/rust-libp2p/?branch=use-quick-protobuf#ec86e1f44feac97559b1b786560dc6b7639d8664" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" dependencies = [ "futures", "pin-project", @@ -5402,9 +5792,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.12" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "ryu-js" @@ -5412,6 +5802,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6518fc26bced4d53678a22d6e423e9d8716377def84545fe328236e3af070e7f" +[[package]] +name = "ryu_floating_decimal" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "700de91d5fd6091442d00fdd9ee790af6d4f0f480562b0f5a1e8f59e90aafe73" + [[package]] name = "safemem" version = "0.3.3" @@ -5420,11 +5816,12 @@ checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" [[package]] name = "schannel" -version = "0.1.21" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ - "windows-sys", + "lazy_static", + "windows-sys 0.36.1", ] [[package]] @@ -5441,9 +5838,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "scratch" -version = "1.0.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" [[package]] name = "sct" @@ -5484,7 +5881,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" dependencies = [ "base16ct", - "der 0.6.1", + "der 0.6.0", "generic-array 0.14.6", "pkcs8 0.9.0", "subtle", @@ -5516,15 +5913,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.16" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.152" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" dependencies = [ "serde_derive", ] @@ -5540,18 +5937,18 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.8" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718dc5fff5b36f99093fc49b280cfc96ce6fc824317783bff5a1fed0c7a64819" +checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" dependencies = [ "proc-macro2", "quote", @@ -5571,9 +5968,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.91" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" dependencies = [ "itoa", "ryu", @@ -5606,9 +6003,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "2.2.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30d904179146de381af4c93d3af6ca4984b3152db687dacb9c3c35e86f39809c" +checksum = "368f2d60d049ea019a84dcd6687b0d1e0030fe663ae105039bdf967ed5e6a9a7" dependencies = [ "base64 0.13.1", "chrono", @@ -5616,8 +6013,8 @@ dependencies = [ "indexmap", "serde", "serde_json", - "serde_with_macros 2.2.0", - "time 0.3.17", + "serde_with_macros 2.0.1", + "time 0.3.16", ] [[package]] @@ -5634,9 +6031,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "2.2.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1966009f3c05f095697c537312f5415d1e3ed31ce0a56942bac4c771c5c335e" +checksum = "1ccadfacf6cf10faad22bbadf55986bdd0856edfb5d9210aa1dcf1f516e84e93" dependencies = [ "darling 0.14.2", "proc-macro2", @@ -5665,7 +6062,7 @@ checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.6", + "digest 0.10.5", ] [[package]] @@ -5701,7 +6098,7 @@ checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.6", + "digest 0.10.5", ] [[package]] @@ -5722,7 +6119,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" dependencies = [ - "digest 0.10.6", + "digest 0.10.5", "keccak", ] @@ -5750,7 +6147,7 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" dependencies = [ - "digest 0.10.6", + "digest 0.10.5", "rand_core 0.6.4", ] @@ -5779,7 +6176,7 @@ dependencies = [ "rand 0.8.5", "sha3 0.10.6", "thiserror", - "time 0.3.17", + "time 0.3.16", ] [[package]] @@ -5821,6 +6218,15 @@ dependencies = [ "parking_lot 0.11.2", ] +[[package]] +name = "smallstr" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b1aefdf380735ff8ded0b15f31aab05daf1f70216c01c02a12926badd1df9d" +dependencies = [ + "smallvec", +] + [[package]] name = "smallvec" version = "1.10.0" @@ -5829,14 +6235,14 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "snow" -version = "0.9.0" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "774d05a3edae07ce6d68ea6984f3c05e9bba8927e3dd591e3b479e5b03213d0d" +checksum = "5ccba027ba85743e09d15c03296797cad56395089b832b48b5a5217880f57733" dependencies = [ "aes-gcm 0.9.4", "blake2", "chacha20poly1305", - "curve25519-dalek 4.0.0-pre.5", + "curve25519-dalek 4.0.0-rc.1", "rand_core 0.6.4", "ring", "rustc_version", @@ -5883,7 +6289,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" dependencies = [ "base64ct", - "der 0.6.1", + "der 0.6.0", ] [[package]] @@ -5899,9 +6305,9 @@ dependencies = [ [[package]] name = "ssi" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62521adfd20b984c8d875c00127bbdc67915609249e17d79f4ce5122cfb8b7b" +checksum = "0a74add6dcfc3599495a73e953a7126ea19e9a0fc81860f5d593cabf1322cdf9" dependencies = [ "ssi-caips", "ssi-core", @@ -5965,9 +6371,9 @@ dependencies = [ [[package]] name = "ssi-dids" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6c4191aa84b78e5d1a726a5d9ee6c5927be2ee3052df56a94afad38a41af2a" +checksum = "62e3c375b0fb2129c691e65e776c9105290ade34b56f39755f4f9c40ba98e41c" dependencies = [ "anyhow", "async-trait", @@ -5975,6 +6381,7 @@ dependencies = [ "chrono", "derive_builder 0.9.0", "hex", + "iref", "multibase 0.8.0", "percent-encoding", "reqwest", @@ -5985,27 +6392,29 @@ dependencies = [ "ssi-core", "ssi-json-ld", "ssi-jwk", + "static-iref", "thiserror", ] [[package]] name = "ssi-json-ld" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91e421f426dad328e5ef7bf8e3b9cc237a58c8ab3168ebbcea58ed154684ef6" +checksum = "01f5f3d1fe13108148d89e54df870664f35b69e5c6d263b370521da4951a3854" dependencies = [ "async-std", - "chrono", "combination", "futures", + "grdf", "iref", - "json", "json-ld", + "json-syntax", "lazy_static", - "serde_jcs", - "serde_json", + "locspan", + "rdf-types", "ssi-contexts", "ssi-crypto", + "static-iref", "thiserror", ] @@ -6072,17 +6481,22 @@ dependencies = [ [[package]] name = "ssi-ldp" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ad5069e8f86afa0bff9f1985d39f27227679403176aa62302808c6b60245c6a" +checksum = "82090294dfa901a4b0015d1fffb0274ef2a63641b0a2805b87f59a2111dd6c44" dependencies = [ "async-trait", "bs58", "chrono", + "grdf", "hex", + "iref", + "json-syntax", "k256", "lazy_static", + "locspan", "multibase 0.8.0", + "rdf-types", "serde", "serde_jcs", "serde_json", @@ -6094,6 +6508,7 @@ dependencies = [ "ssi-json-ld", "ssi-jwk", "ssi-jws", + "static-iref", "thiserror", ] @@ -6123,9 +6538,9 @@ dependencies = [ [[package]] name = "ssi-ucan" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c6ad6188ca16843b56891f51a27a710c277df9ec2236506737b211324eceaaf" +checksum = "0982f62c7860922026a9d9edc6c604de79693ee4c5c6bd65be11e2ff66b1df09" dependencies = [ "base64 0.12.3", "chrono", @@ -6144,9 +6559,9 @@ dependencies = [ [[package]] name = "ssi-vc" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f15fe7dc4e5bb0f245831f0f46ca670cf4b6c49ce17bc4648f15a28c97f6e640" +checksum = "24416d7b6536a48bf3954d9c6596219cd0ebbbc37016ec8d365fe477209336d0" dependencies = [ "async-trait", "base64 0.12.3", @@ -6154,6 +6569,7 @@ dependencies = [ "cacaos", "chrono", "flate2", + "iref", "libipld", "multihash 0.16.3", "reqwest", @@ -6172,11 +6588,12 @@ dependencies = [ [[package]] name = "ssi-zcap-ld" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bc022f05ed4fcca2865f27fb9dbf38b5ff3c3e12c8f34cb8ff11666f4cfad76" +checksum = "7c6b6a1e8e36842c9f69209f3ea0da7e979da126d352734a94a5eae2ed01ede1" dependencies = [ "async-trait", + "iref", "serde", "serde_json", "ssi-core", @@ -6205,6 +6622,15 @@ dependencies = [ "loom", ] +[[package]] +name = "static-iref" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9786d4b8e9e5423fe85c57a826d7e0f0774746149a2ccd21e2104ff74b71ce7" +dependencies = [ + "iref", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -6259,9 +6685,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.107" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", @@ -6323,27 +6749,27 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.2.0" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] [[package]] name = "thiserror" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" dependencies = [ "proc-macro2", "quote", @@ -6383,9 +6809,9 @@ dependencies = [ [[package]] name = "time" -version = "0.1.45" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", @@ -6394,12 +6820,14 @@ dependencies = [ [[package]] name = "time" -version = "0.3.17" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" +checksum = "0fab5c8b9980850e06d92ddbe3ab839c062c801f3927c0fb8abd6fc8e918fbca" dependencies = [ "itoa", "js-sys", + "libc", + "num_threads", "serde", "time-core", "time-macros", @@ -6413,9 +6841,9 @@ checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" [[package]] name = "time-macros" -version = "0.2.6" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" +checksum = "65bb801831d812c562ae7d2bfb531f26e66e4e1f6b17307ba4149c5064710e5b" dependencies = [ "time-core", ] @@ -6456,9 +6884,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.24.2" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", @@ -6471,14 +6899,14 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "winapi", ] [[package]] name = "tokio-macros" -version = "1.8.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" dependencies = [ "proc-macro2", "quote", @@ -6512,7 +6940,7 @@ version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" dependencies = [ - "rustls 0.20.8", + "rustls 0.20.7", "tokio", "webpki 0.22.0", ] @@ -6557,9 +6985,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.10" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" dependencies = [ "serde", ] @@ -6739,9 +7167,9 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.4" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "turn" @@ -6775,9 +7203,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.16.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "ubyte" @@ -6790,9 +7218,9 @@ dependencies = [ [[package]] name = "uint" -version = "0.9.5" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +checksum = "a45526d29728d135c2900b0d30573fe3ee79fceb12ef534c7bb30e810a91b601" dependencies = [ "byteorder", "crunchy", @@ -6818,9 +7246,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-normalization" @@ -6898,9 +7326,9 @@ checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" [[package]] name = "uuid" -version = "1.2.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" +checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83" dependencies = [ "getrandom 0.2.8", "wasm-bindgen", @@ -7055,6 +7483,21 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +[[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 0.11.2", + "pin-utils", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "web-sys" version = "0.3.60" @@ -7087,9 +7530,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.6" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be" dependencies = [ "webpki 0.22.0", ] @@ -7120,7 +7563,7 @@ dependencies = [ "sha2 0.10.6", "stun", "thiserror", - "time 0.3.17", + "time 0.3.16", "tokio", "turn", "url", @@ -7152,22 +7595,22 @@ dependencies = [ [[package]] name = "webrtc-dtls" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7021987ae0a2ed6c8cd33f68e98e49bb6e74ffe9543310267b48a1bbe3900e5f" +checksum = "942be5bd85f072c3128396f6e5a9bfb93ca8c1939ded735d177b7bcba9a13d05" dependencies = [ "aes 0.6.0", - "aes-gcm 0.8.0", + "aes-gcm 0.10.1", "async-trait", "bincode", "block-modes 0.7.0", "byteorder", "ccm", "curve25519-dalek 3.2.0", - "der-parser 8.1.0", + "der-parser 8.2.0", "elliptic-curve", "hkdf", - "hmac 0.10.1", + "hmac 0.12.1", "log", "oid-registry 0.6.1", "p256", @@ -7179,8 +7622,8 @@ dependencies = [ "rustls 0.19.1", "sec1", "serde", - "sha-1", - "sha2 0.9.9", + "sha1", + "sha2 0.10.6", "signature", "subtle", "thiserror", @@ -7193,9 +7636,9 @@ dependencies = [ [[package]] name = "webrtc-ice" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494483fbb2f5492620871fdc78b084aed8807377f6e3fe88b2e49f0a9c9c41d7" +checksum = "465a03cc11e9a7d7b4f9f99870558fe37a102b65b93f8045392fef7c67b39e80" dependencies = [ "arc-swap", "async-trait", @@ -7363,6 +7806,19 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbedf6db9096bc2364adce0ae0aa636dcd89f3c3f2cd67947062aaf0ca2a10ec" +dependencies = [ + "windows_aarch64_msvc 0.32.0", + "windows_i686_gnu 0.32.0", + "windows_i686_msvc 0.32.0", + "windows_x86_64_gnu 0.32.0", + "windows_x86_64_msvc 0.32.0", +] + [[package]] name = "windows" version = "0.34.0" @@ -7377,16 +7833,16 @@ dependencies = [ ] [[package]] -name = "windows" -version = "0.39.0" +name = "windows-sys" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1c4bd0a50ac6020f65184721f758dba47bb9fbc2133df715ec74a237b26794a" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc 0.39.0", - "windows_i686_gnu 0.39.0", - "windows_i686_msvc 0.39.0", - "windows_x86_64_gnu 0.39.0", - "windows_x86_64_msvc 0.39.0", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] [[package]] @@ -7396,19 +7852,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.1", - "windows_i686_gnu 0.42.1", - "windows_i686_msvc 0.42.1", - "windows_x86_64_gnu 0.42.1", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.1", + "windows_x86_64_msvc 0.42.0", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" [[package]] name = "windows_aarch64_msvc" @@ -7418,15 +7880,21 @@ checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" [[package]] name = "windows_aarch64_msvc" -version = "0.39.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec7711666096bd4096ffa835238905bb33fb87267910e154b18b44eaabb340f2" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" [[package]] name = "windows_i686_gnu" @@ -7436,15 +7904,21 @@ checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" [[package]] name = "windows_i686_gnu" -version = "0.39.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "763fc57100a5f7042e3057e7e8d9bdd7860d330070251a73d003563a3bb49e1b" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" [[package]] name = "windows_i686_msvc" @@ -7454,15 +7928,21 @@ checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" [[package]] name = "windows_i686_msvc" -version = "0.39.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bc7cbfe58828921e10a9f446fcaaf649204dcfe6c1ddd712c5eebae6bda1106" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" [[package]] name = "windows_x86_64_gnu" @@ -7472,21 +7952,27 @@ checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" [[package]] name = "windows_x86_64_gnu" -version = "0.39.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6868c165637d653ae1e8dc4d82c25d4f97dd6605eaa8d784b5c6e0ab2a252b65" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" [[package]] name = "windows_x86_64_msvc" @@ -7496,15 +7982,24 @@ checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" [[package]] name = "windows_x86_64_msvc" -version = "0.39.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e4d40883ae9cae962787ca76ba76390ffa29214667a111db9e0a1ad8377e809" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + +[[package]] +name = "winreg" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi", +] [[package]] name = "winreg" @@ -7559,7 +8054,7 @@ dependencies = [ "ring", "rusticata-macros", "thiserror", - "time 0.3.17", + "time 0.3.16", ] [[package]] @@ -7568,16 +8063,16 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0ecbeb7b67ce215e40e3cc7f2ff902f94a223acf44995934763467e7b1febc8" dependencies = [ - "asn1-rs 0.5.1", + "asn1-rs 0.5.2", "base64 0.13.1", "data-encoding", - "der-parser 8.1.0", + "der-parser 8.2.0", "lazy_static", "nom 7.1.3", "oid-registry 0.6.1", "rusticata-macros", "thiserror", - "time 0.3.17", + "time 0.3.16", ] [[package]] @@ -7612,7 +8107,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aed2e7a52e3744ab4d0c05c20aa065258e84c49fd4226f5191b2ed29712710b4" dependencies = [ - "time 0.3.17", + "time 0.3.16", ] [[package]] @@ -7626,9 +8121,9 @@ dependencies = [ [[package]] name = "zeroize_derive" -version = "1.3.3" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" +checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 197c967b..f3bb1a0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ hyper = "0.14" # Prometheus server iri-string = "0.5" lazy_static = "1.4.0" libipld = { version = "0.14", default-features = false, features = ["dag-cbor", "dag-json", "derive", "serde-codec"]} -libp2p = { default-features = false, features = ["tcp", "mplex", "noise", "ping", "yamux", "dns", "tokio"], version = "0.51.0", git = "https://github.com/kckeiks/rust-libp2p/", branch = "use-quick-protobuf" } +libp2p = { default-features = false, features = ["gossipsub", "identify", "kad", "tcp", "mplex", "noise", "ping", "yamux", "dns", "tokio", "relay", "dcutr"], version = "0.51.0", git = "https://github.com/libp2p/rust-libp2p/", branch = "master" } opentelemetry = { version = "0.17.0", features = ["rt-tokio"] } opentelemetry-jaeger = { version = "0.16.0", features = ["rt-tokio", "reqwest_collector_client"] } pin-project = "1" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 5a5194ac..34ad75c0 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -30,7 +30,7 @@ uuid = { version = "1", features = ["v4", "js"] } uuid = { version = "1", features = ["v4"] } [dependencies.ssi] -version = "0.5" +version = "0.6" default-features = false features = ["ed25519", "rsa", "secp256k1"] diff --git a/src/behaviour.rs b/src/behaviour.rs new file mode 100644 index 00000000..82bf4d82 --- /dev/null +++ b/src/behaviour.rs @@ -0,0 +1,104 @@ +use core::time::Duration; +use derive_builder::Builder; +use libp2p::{ + dcutr::behaviour::Behaviour as DcutrBehaviour, + gossipsub::{ + Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, + }, + identify::{Behaviour as Identify, Config as OIdentifyConfig}, + identity::{Keypair, PublicKey}, + kad::{ + record::store::{MemoryStore, MemoryStoreConfig}, + Kademlia, KademliaConfig, + }, + ping::{Behaviour as Ping, Config as PingConfig}, + relay::v2::client::Client, + swarm::behaviour::toggle::Toggle, + NetworkBehaviour, +}; +use thiserror::Error; + +const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; + +#[derive(Builder, Default, Debug)] +pub struct IdentifyConfig { + #[builder(setter(into), default = "Duration::from_millis(500)")] + initial_delay: Duration, + #[builder(setter(into), default = "Duration::from_secs(300)")] + interval: Duration, + #[builder(setter(into), default = "false")] + push_listen_addr_updates: bool, + #[builder(setter(into), default = "0")] + cache_size: usize, +} + +impl IdentifyConfig { + pub fn to_config(self, key: PublicKey) -> OIdentifyConfig { + OIdentifyConfig::new(PROTOCOL_VERSION.to_string(), key) + .with_initial_delay(self.initial_delay) + .with_interval(self.interval) + .with_push_listen_addr_updates(self.push_listen_addr_updates) + .with_cache_size(self.cache_size) + } +} + +#[derive(Builder)] +#[builder(pattern = "owned")] +pub struct OrbitNodeConfig { + #[builder(setter(into))] + identity: Keypair, + #[builder(setter(into), default)] + identify: IdentifyConfig, + #[builder(setter(into), default)] + ping: PingConfig, + #[builder(setter(into), default)] + gossipsub: GossipsubConfig, + #[builder(setter(into), default)] + kademlia: KademliaConfig, + #[builder(setter(into), default)] + kademlia_store: MemoryStoreConfig, + #[builder(setter(into, strip_option), default)] + relay: Option, +} + +#[derive(NetworkBehaviour)] +pub struct OrbitNode { + identify: Identify, + ping: Ping, + gossipsub: Gossipsub, + relay: Toggle, + kademlia: Kademlia, + dcutr: DcutrBehaviour, +} + +#[derive(Error, Debug)] +pub enum OrbitNodeInitError { + #[error("{0}")] + Gossipsub(&'static str), +} + +impl OrbitNode { + pub fn new(c: OrbitNodeConfig) -> Result { + let peer_id = c.identity.public().to_peer_id(); + Ok(Self { + identify: Identify::new(c.identify.to_config(c.identity.public())), + ping: Ping::new(c.ping), + gossipsub: Gossipsub::new( + MessageAuthenticity::Signed(c.identity), + GossipsubConfigBuilder::from(c.gossipsub) + // always ensure validation + .validation_mode(ValidationMode::Strict) + .build() + .map_err(OrbitNodeInitError::Gossipsub)?, + ) + .map_err(OrbitNodeInitError::Gossipsub)?, + relay: c.relay.into(), + kademlia: Kademlia::with_config( + peer_id, + MemoryStore::with_config(peer_id, c.kademlia_store), + c.kademlia, + ), + dcutr: DcutrBehaviour::new(), + }) + } +} diff --git a/src/lib.rs b/src/lib.rs index 2a12f395..0c15f9c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ use rocket::{fairing::AdHoc, figment::Figment, http::Header, Build, Rocket}; pub mod allow_list; pub mod auth_guards; pub mod authorization; +pub mod behaviour; pub mod capabilities; pub mod cas; pub mod config; From 463aac6382d19fec0ef7566c52abaee48c8a80f4 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 3 Nov 2022 19:23:09 +0100 Subject: [PATCH 02/48] move relay out of config --- src/behaviour.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/behaviour.rs b/src/behaviour.rs index 82bf4d82..88594a33 100644 --- a/src/behaviour.rs +++ b/src/behaviour.rs @@ -1,6 +1,7 @@ use core::time::Duration; use derive_builder::Builder; use libp2p::{ + core::PeerId, dcutr::behaviour::Behaviour as DcutrBehaviour, gossipsub::{ Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, @@ -57,8 +58,6 @@ pub struct OrbitNodeConfig { kademlia: KademliaConfig, #[builder(setter(into), default)] kademlia_store: MemoryStoreConfig, - #[builder(setter(into, strip_option), default)] - relay: Option, } #[derive(NetworkBehaviour)] @@ -92,13 +91,23 @@ impl OrbitNode { .map_err(OrbitNodeInitError::Gossipsub)?, ) .map_err(OrbitNodeInitError::Gossipsub)?, - relay: c.relay.into(), kademlia: Kademlia::with_config( peer_id, MemoryStore::with_config(peer_id, c.kademlia_store), c.kademlia, ), + relay: None.into(), dcutr: DcutrBehaviour::new(), }) } + + pub fn new_with_relay( + c: OrbitNodeConfig, + relay_client: Client, + ) -> Result { + Ok(Self { + relay: Some(relay_client).into(), + ..Self::new(c)? + }) + } } From 344be6906a519a4abef9f2475b7d056c9e02caa3 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 3 Nov 2022 19:23:19 +0100 Subject: [PATCH 03/48] make generic over kad store and kad store config --- src/behaviour.rs | 54 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/behaviour.rs b/src/behaviour.rs index 88594a33..5c2a0bf0 100644 --- a/src/behaviour.rs +++ b/src/behaviour.rs @@ -9,7 +9,7 @@ use libp2p::{ identify::{Behaviour as Identify, Config as OIdentifyConfig}, identity::{Keypair, PublicKey}, kad::{ - record::store::{MemoryStore, MemoryStoreConfig}, + record::store::{MemoryStore, MemoryStoreConfig, RecordStore}, Kademlia, KademliaConfig, }, ping::{Behaviour as Ping, Config as PingConfig}, @@ -45,7 +45,10 @@ impl IdentifyConfig { #[derive(Builder)] #[builder(pattern = "owned")] -pub struct OrbitNodeConfig { +pub struct OrbitNodeConfig +where + KSC: Default, +{ #[builder(setter(into))] identity: Keypair, #[builder(setter(into), default)] @@ -57,16 +60,19 @@ pub struct OrbitNodeConfig { #[builder(setter(into), default)] kademlia: KademliaConfig, #[builder(setter(into), default)] - kademlia_store: MemoryStoreConfig, + kademlia_store: KSC, } #[derive(NetworkBehaviour)] -pub struct OrbitNode { +pub struct OrbitNode +where + KS: 'static + for<'a> RecordStore<'a> + Send, +{ identify: Identify, ping: Ping, gossipsub: Gossipsub, relay: Toggle, - kademlia: Kademlia, + kademlia: Kademlia, dcutr: DcutrBehaviour, } @@ -76,8 +82,14 @@ pub enum OrbitNodeInitError { Gossipsub(&'static str), } -impl OrbitNode { - pub fn new(c: OrbitNodeConfig) -> Result { +impl OrbitNode +where + KS: 'static + for<'a> RecordStore<'a> + Send, +{ + pub fn new(c: OrbitNodeConfig) -> Result + where + KSC: RecordStoreConfig + Default, + { let peer_id = c.identity.public().to_peer_id(); Ok(Self { identify: Identify::new(c.identify.to_config(c.identity.public())), @@ -91,23 +103,35 @@ impl OrbitNode { .map_err(OrbitNodeInitError::Gossipsub)?, ) .map_err(OrbitNodeInitError::Gossipsub)?, - kademlia: Kademlia::with_config( - peer_id, - MemoryStore::with_config(peer_id, c.kademlia_store), - c.kademlia, - ), relay: None.into(), + kademlia: Kademlia::with_config(peer_id, c.kademlia_store.init(peer_id), c.kademlia), dcutr: DcutrBehaviour::new(), }) } - pub fn new_with_relay( - c: OrbitNodeConfig, + pub fn new_with_relay( + c: OrbitNodeConfig, relay_client: Client, - ) -> Result { + ) -> Result + where + KSC: RecordStoreConfig + Default, + { Ok(Self { relay: Some(relay_client).into(), ..Self::new(c)? }) } } + +pub trait RecordStoreConfig +where + S: for<'a> RecordStore<'a>, +{ + fn init(self, id: PeerId) -> S; +} + +impl RecordStoreConfig for MemoryStoreConfig { + fn init(self, id: PeerId) -> MemoryStore { + MemoryStore::with_config(id, self) + } +} From c4fd4ea272e664d74d8c0db8a5dc4ae3f0f7027b Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 3 Nov 2022 20:24:58 +0100 Subject: [PATCH 04/48] extra config stuff, add swarm type --- src/behaviour.rs | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/behaviour.rs b/src/behaviour.rs index 5c2a0bf0..8fe0c43f 100644 --- a/src/behaviour.rs +++ b/src/behaviour.rs @@ -1,7 +1,7 @@ use core::time::Duration; use derive_builder::Builder; use libp2p::{ - core::PeerId, + core::{muxing::StreamMuxerBox, transport::Boxed, PeerId}, dcutr::behaviour::Behaviour as DcutrBehaviour, gossipsub::{ Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, @@ -14,13 +14,15 @@ use libp2p::{ }, ping::{Behaviour as Ping, Config as PingConfig}, relay::v2::client::Client, - swarm::behaviour::toggle::Toggle, + swarm::{behaviour::toggle::Toggle, Swarm}, NetworkBehaviour, }; use thiserror::Error; const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; +pub type OrbitSwarm = Swarm>; + #[derive(Builder, Default, Debug)] pub struct IdentifyConfig { #[builder(setter(into), default = "Duration::from_millis(500)")] @@ -63,8 +65,42 @@ where kademlia_store: KSC, } +impl OrbitNodeConfig +where + KSC: Default, +{ + fn init_behaviour(self) -> Result, OrbitNodeInitError> + where + KSC: RecordStoreConfig + Default, + KS: for<'a> RecordStore<'a> + Send, + { + OrbitNodeBehaviour::new(self) + } + fn init_behaviour_with_relay( + self, + relay: Client, + ) -> Result, OrbitNodeInitError> + where + KSC: RecordStoreConfig + Default, + KS: for<'a> RecordStore<'a> + Send, + { + OrbitNodeBehaviour::new_with_relay(self, relay) + } + pub fn init( + self, + transport: Boxed<(PeerId, StreamMuxerBox)>, + ) -> Result, OrbitNodeInitError> + where + KSC: RecordStoreConfig + Default, + KS: for<'a> RecordStore<'a> + Send, + { + let peer_id = self.identity.public().to_peer_id(); + Ok(OrbitSwarm::new(transport, self.init_behaviour()?, peer_id)) + } +} + #[derive(NetworkBehaviour)] -pub struct OrbitNode +pub struct OrbitNodeBehaviour where KS: 'static + for<'a> RecordStore<'a> + Send, { @@ -82,11 +118,11 @@ pub enum OrbitNodeInitError { Gossipsub(&'static str), } -impl OrbitNode +impl OrbitNodeBehaviour where KS: 'static + for<'a> RecordStore<'a> + Send, { - pub fn new(c: OrbitNodeConfig) -> Result + fn new(c: OrbitNodeConfig) -> Result where KSC: RecordStoreConfig + Default, { @@ -109,7 +145,7 @@ where }) } - pub fn new_with_relay( + fn new_with_relay( c: OrbitNodeConfig, relay_client: Client, ) -> Result From ccf7c7121aa0a0b7fe0de544e31e261a2b27b1b0 Mon Sep 17 00:00:00 2001 From: chunningham Date: Fri, 4 Nov 2022 12:54:01 +0100 Subject: [PATCH 05/48] IdentifyConfig conveniance changes --- src/behaviour.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/behaviour.rs b/src/behaviour.rs index 8fe0c43f..b700386a 100644 --- a/src/behaviour.rs +++ b/src/behaviour.rs @@ -23,7 +23,7 @@ const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; pub type OrbitSwarm = Swarm>; -#[derive(Builder, Default, Debug)] +#[derive(Builder, Default, Debug, Clone)] pub struct IdentifyConfig { #[builder(setter(into), default = "Duration::from_millis(500)")] initial_delay: Duration, @@ -36,7 +36,7 @@ pub struct IdentifyConfig { } impl IdentifyConfig { - pub fn to_config(self, key: PublicKey) -> OIdentifyConfig { + fn to_config(self, key: PublicKey) -> OIdentifyConfig { OIdentifyConfig::new(PROTOCOL_VERSION.to_string(), key) .with_initial_delay(self.initial_delay) .with_interval(self.interval) @@ -45,8 +45,18 @@ impl IdentifyConfig { } } +impl From for IdentifyConfig { + fn from(c: OIdentifyConfig) -> Self { + Self { + initial_delay: c.initial_delay, + interval: c.interval, + push_listen_addr_updates: c.push_listen_addr_updates, + cache_size: c.cache_size, + } + } +} + #[derive(Builder)] -#[builder(pattern = "owned")] pub struct OrbitNodeConfig where KSC: Default, From 1fac014eba4ef6ad9b20d261c54e14a6a074d21d Mon Sep 17 00:00:00 2001 From: chunningham Date: Fri, 4 Nov 2022 13:33:50 +0100 Subject: [PATCH 06/48] renames and streamline the builder process --- src/behaviour.rs | 221 ++++++++++++++++++++--------------------------- 1 file changed, 93 insertions(+), 128 deletions(-) diff --git a/src/behaviour.rs b/src/behaviour.rs index b700386a..f4a16960 100644 --- a/src/behaviour.rs +++ b/src/behaviour.rs @@ -2,7 +2,7 @@ use core::time::Duration; use derive_builder::Builder; use libp2p::{ core::{muxing::StreamMuxerBox, transport::Boxed, PeerId}, - dcutr::behaviour::Behaviour as DcutrBehaviour, + dcutr::behaviour::Behaviour as Dcutr, gossipsub::{ Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, }, @@ -21,96 +21,75 @@ use thiserror::Error; const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; -pub type OrbitSwarm = Swarm>; +pub type OrbitSwarm = Swarm>; -#[derive(Builder, Default, Debug, Clone)] -pub struct IdentifyConfig { - #[builder(setter(into), default = "Duration::from_millis(500)")] - initial_delay: Duration, - #[builder(setter(into), default = "Duration::from_secs(300)")] - interval: Duration, - #[builder(setter(into), default = "false")] - push_listen_addr_updates: bool, - #[builder(setter(into), default = "0")] - cache_size: usize, -} - -impl IdentifyConfig { - fn to_config(self, key: PublicKey) -> OIdentifyConfig { - OIdentifyConfig::new(PROTOCOL_VERSION.to_string(), key) - .with_initial_delay(self.initial_delay) - .with_interval(self.interval) - .with_push_listen_addr_updates(self.push_listen_addr_updates) - .with_cache_size(self.cache_size) - } -} - -impl From for IdentifyConfig { - fn from(c: OIdentifyConfig) -> Self { - Self { - initial_delay: c.initial_delay, - interval: c.interval, - push_listen_addr_updates: c.push_listen_addr_updates, - cache_size: c.cache_size, - } - } -} - -#[derive(Builder)] -pub struct OrbitNodeConfig -where - KSC: Default, -{ - #[builder(setter(into))] - identity: Keypair, - #[builder(setter(into), default)] - identify: IdentifyConfig, - #[builder(setter(into), default)] - ping: PingConfig, - #[builder(setter(into), default)] - gossipsub: GossipsubConfig, - #[builder(setter(into), default)] - kademlia: KademliaConfig, - #[builder(setter(into), default)] - kademlia_store: KSC, -} - -impl OrbitNodeConfig -where - KSC: Default, -{ - fn init_behaviour(self) -> Result, OrbitNodeInitError> +mod builder { + use super::*; + #[derive(Builder, Clone, Debug)] + #[builder(build_fn(skip), setter(into), name = "BehaviourBuilder", derive(Debug))] + pub struct BehaviourConfig where - KSC: RecordStoreConfig + Default, - KS: for<'a> RecordStore<'a> + Send, + KSC: Default, { - OrbitNodeBehaviour::new(self) + #[builder(field(type = "IdentifyConfig"))] + identify: IdentifyConfig, + #[builder(field(type = "PingConfig"))] + ping: PingConfig, + #[builder(field(type = "GossipsubConfig"))] + gossipsub: GossipsubConfig, + #[builder(field(type = "KademliaConfig"))] + kademlia: KademliaConfig, + #[builder(field(type = "KSC"))] + kademlia_store: KSC, } - fn init_behaviour_with_relay( - self, - relay: Client, - ) -> Result, OrbitNodeInitError> + + impl BehaviourBuilder where - KSC: RecordStoreConfig + Default, - KS: for<'a> RecordStore<'a> + Send, + KSC: Default, { - OrbitNodeBehaviour::new_with_relay(self, relay) + pub fn build( + self, + keypair: Keypair, + relay: Option, + ) -> Result, OrbitBehaviourBuildError> + where + KSC: Default + RecordStoreConfig, + KS: for<'a> RecordStore<'a> + Send, + { + let peer_id = keypair.public().to_peer_id(); + Ok(Behaviour { + identify: Identify::new(self.identify.to_config(keypair.public())), + ping: Ping::new(self.ping), + gossipsub: Gossipsub::new( + MessageAuthenticity::Signed(keypair), + GossipsubConfigBuilder::from(self.gossipsub) + // always ensure validation + .validation_mode(ValidationMode::Strict) + .build() + .map_err(OrbitBehaviourBuildError::Gossipsub)?, + ) + .map_err(OrbitBehaviourBuildError::Gossipsub)?, + relay: relay.into(), + kademlia: Kademlia::with_config( + peer_id, + self.kademlia_store.init(peer_id), + self.kademlia, + ), + dcutr: Dcutr::new(), + }) + } } - pub fn init( - self, - transport: Boxed<(PeerId, StreamMuxerBox)>, - ) -> Result, OrbitNodeInitError> - where - KSC: RecordStoreConfig + Default, - KS: for<'a> RecordStore<'a> + Send, - { - let peer_id = self.identity.public().to_peer_id(); - Ok(OrbitSwarm::new(transport, self.init_behaviour()?, peer_id)) + + #[derive(Error, Debug)] + pub enum OrbitBehaviourBuildError { + #[error("{0}")] + Gossipsub(&'static str), } } +pub use builder::{BehaviourBuilder, OrbitBehaviourBuildError}; #[derive(NetworkBehaviour)] -pub struct OrbitNodeBehaviour +pub struct Behaviour where KS: 'static + for<'a> RecordStore<'a> + Send, { @@ -119,54 +98,7 @@ where gossipsub: Gossipsub, relay: Toggle, kademlia: Kademlia, - dcutr: DcutrBehaviour, -} - -#[derive(Error, Debug)] -pub enum OrbitNodeInitError { - #[error("{0}")] - Gossipsub(&'static str), -} - -impl OrbitNodeBehaviour -where - KS: 'static + for<'a> RecordStore<'a> + Send, -{ - fn new(c: OrbitNodeConfig) -> Result - where - KSC: RecordStoreConfig + Default, - { - let peer_id = c.identity.public().to_peer_id(); - Ok(Self { - identify: Identify::new(c.identify.to_config(c.identity.public())), - ping: Ping::new(c.ping), - gossipsub: Gossipsub::new( - MessageAuthenticity::Signed(c.identity), - GossipsubConfigBuilder::from(c.gossipsub) - // always ensure validation - .validation_mode(ValidationMode::Strict) - .build() - .map_err(OrbitNodeInitError::Gossipsub)?, - ) - .map_err(OrbitNodeInitError::Gossipsub)?, - relay: None.into(), - kademlia: Kademlia::with_config(peer_id, c.kademlia_store.init(peer_id), c.kademlia), - dcutr: DcutrBehaviour::new(), - }) - } - - fn new_with_relay( - c: OrbitNodeConfig, - relay_client: Client, - ) -> Result - where - KSC: RecordStoreConfig + Default, - { - Ok(Self { - relay: Some(relay_client).into(), - ..Self::new(c)? - }) - } + dcutr: Dcutr, } pub trait RecordStoreConfig @@ -181,3 +113,36 @@ impl RecordStoreConfig for MemoryStoreConfig { MemoryStore::with_config(id, self) } } + +#[derive(Builder, Default, Debug, Clone)] +pub struct IdentifyConfig { + #[builder(setter(into), default = "Duration::from_millis(500)")] + initial_delay: Duration, + #[builder(setter(into), default = "Duration::from_secs(300)")] + interval: Duration, + #[builder(setter(into), default = "false")] + push_listen_addr_updates: bool, + #[builder(setter(into), default = "0")] + cache_size: usize, +} + +impl IdentifyConfig { + fn to_config(self, key: PublicKey) -> OIdentifyConfig { + OIdentifyConfig::new(PROTOCOL_VERSION.to_string(), key) + .with_initial_delay(self.initial_delay) + .with_interval(self.interval) + .with_push_listen_addr_updates(self.push_listen_addr_updates) + .with_cache_size(self.cache_size) + } +} + +impl From for IdentifyConfig { + fn from(c: OIdentifyConfig) -> Self { + Self { + initial_delay: c.initial_delay, + interval: c.interval, + push_listen_addr_updates: c.push_listen_addr_updates, + cache_size: c.cache_size, + } + } +} From 623889b2680e2b42c95cb05a1b3c6ffa9d16089e Mon Sep 17 00:00:00 2001 From: chunningham Date: Fri, 4 Nov 2022 13:44:00 +0100 Subject: [PATCH 07/48] move behaviour to p2p mod and split into sub-mods --- src/behaviour.rs | 148 ----------------------------------- src/lib.rs | 2 +- src/p2p/behaviour/builder.rs | 129 ++++++++++++++++++++++++++++++ src/p2p/behaviour/mod.rs | 40 ++++++++++ src/p2p/mod.rs | 1 + 5 files changed, 171 insertions(+), 149 deletions(-) delete mode 100644 src/behaviour.rs create mode 100644 src/p2p/behaviour/builder.rs create mode 100644 src/p2p/behaviour/mod.rs create mode 100644 src/p2p/mod.rs diff --git a/src/behaviour.rs b/src/behaviour.rs deleted file mode 100644 index f4a16960..00000000 --- a/src/behaviour.rs +++ /dev/null @@ -1,148 +0,0 @@ -use core::time::Duration; -use derive_builder::Builder; -use libp2p::{ - core::{muxing::StreamMuxerBox, transport::Boxed, PeerId}, - dcutr::behaviour::Behaviour as Dcutr, - gossipsub::{ - Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, - }, - identify::{Behaviour as Identify, Config as OIdentifyConfig}, - identity::{Keypair, PublicKey}, - kad::{ - record::store::{MemoryStore, MemoryStoreConfig, RecordStore}, - Kademlia, KademliaConfig, - }, - ping::{Behaviour as Ping, Config as PingConfig}, - relay::v2::client::Client, - swarm::{behaviour::toggle::Toggle, Swarm}, - NetworkBehaviour, -}; -use thiserror::Error; - -const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; - -pub type OrbitSwarm = Swarm>; - -mod builder { - use super::*; - #[derive(Builder, Clone, Debug)] - #[builder(build_fn(skip), setter(into), name = "BehaviourBuilder", derive(Debug))] - pub struct BehaviourConfig - where - KSC: Default, - { - #[builder(field(type = "IdentifyConfig"))] - identify: IdentifyConfig, - #[builder(field(type = "PingConfig"))] - ping: PingConfig, - #[builder(field(type = "GossipsubConfig"))] - gossipsub: GossipsubConfig, - #[builder(field(type = "KademliaConfig"))] - kademlia: KademliaConfig, - #[builder(field(type = "KSC"))] - kademlia_store: KSC, - } - - impl BehaviourBuilder - where - KSC: Default, - { - pub fn build( - self, - keypair: Keypair, - relay: Option, - ) -> Result, OrbitBehaviourBuildError> - where - KSC: Default + RecordStoreConfig, - KS: for<'a> RecordStore<'a> + Send, - { - let peer_id = keypair.public().to_peer_id(); - Ok(Behaviour { - identify: Identify::new(self.identify.to_config(keypair.public())), - ping: Ping::new(self.ping), - gossipsub: Gossipsub::new( - MessageAuthenticity::Signed(keypair), - GossipsubConfigBuilder::from(self.gossipsub) - // always ensure validation - .validation_mode(ValidationMode::Strict) - .build() - .map_err(OrbitBehaviourBuildError::Gossipsub)?, - ) - .map_err(OrbitBehaviourBuildError::Gossipsub)?, - relay: relay.into(), - kademlia: Kademlia::with_config( - peer_id, - self.kademlia_store.init(peer_id), - self.kademlia, - ), - dcutr: Dcutr::new(), - }) - } - } - - #[derive(Error, Debug)] - pub enum OrbitBehaviourBuildError { - #[error("{0}")] - Gossipsub(&'static str), - } -} -pub use builder::{BehaviourBuilder, OrbitBehaviourBuildError}; - -#[derive(NetworkBehaviour)] -pub struct Behaviour -where - KS: 'static + for<'a> RecordStore<'a> + Send, -{ - identify: Identify, - ping: Ping, - gossipsub: Gossipsub, - relay: Toggle, - kademlia: Kademlia, - dcutr: Dcutr, -} - -pub trait RecordStoreConfig -where - S: for<'a> RecordStore<'a>, -{ - fn init(self, id: PeerId) -> S; -} - -impl RecordStoreConfig for MemoryStoreConfig { - fn init(self, id: PeerId) -> MemoryStore { - MemoryStore::with_config(id, self) - } -} - -#[derive(Builder, Default, Debug, Clone)] -pub struct IdentifyConfig { - #[builder(setter(into), default = "Duration::from_millis(500)")] - initial_delay: Duration, - #[builder(setter(into), default = "Duration::from_secs(300)")] - interval: Duration, - #[builder(setter(into), default = "false")] - push_listen_addr_updates: bool, - #[builder(setter(into), default = "0")] - cache_size: usize, -} - -impl IdentifyConfig { - fn to_config(self, key: PublicKey) -> OIdentifyConfig { - OIdentifyConfig::new(PROTOCOL_VERSION.to_string(), key) - .with_initial_delay(self.initial_delay) - .with_interval(self.interval) - .with_push_listen_addr_updates(self.push_listen_addr_updates) - .with_cache_size(self.cache_size) - } -} - -impl From for IdentifyConfig { - fn from(c: OIdentifyConfig) -> Self { - Self { - initial_delay: c.initial_delay, - interval: c.interval, - push_listen_addr_updates: c.push_listen_addr_updates, - cache_size: c.cache_size, - } - } -} diff --git a/src/lib.rs b/src/lib.rs index 0c15f9c4..d2c423fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,6 @@ use rocket::{fairing::AdHoc, figment::Figment, http::Header, Build, Rocket}; pub mod allow_list; pub mod auth_guards; pub mod authorization; -pub mod behaviour; pub mod capabilities; pub mod cas; pub mod config; @@ -21,6 +20,7 @@ pub mod indexes; pub mod kv; pub mod manifest; pub mod orbit; +pub mod p2p; pub mod prometheus; pub mod relay; pub mod routes; diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs new file mode 100644 index 00000000..6617766e --- /dev/null +++ b/src/p2p/behaviour/builder.rs @@ -0,0 +1,129 @@ +use core::time::Duration; +use derive_builder::Builder; +use libp2p::{ + core::{muxing::StreamMuxerBox, transport::Boxed, PeerId}, + dcutr::behaviour::Behaviour as Dcutr, + gossipsub::{ + Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, + }, + identify::{Behaviour as Identify, Config as OIdentifyConfig}, + identity::{Keypair, PublicKey}, + kad::{ + record::store::{MemoryStore, MemoryStoreConfig, RecordStore}, + Kademlia, KademliaConfig, + }, + ping::{Behaviour as Ping, Config as PingConfig}, + relay::v2::client::Client, + swarm::{behaviour::toggle::Toggle, Swarm}, + NetworkBehaviour, +}; +use thiserror::Error; + +const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; + +#[derive(Builder, Clone, Debug)] +#[builder(build_fn(skip), setter(into), name = "BehaviourBuilder", derive(Debug))] +pub struct BehaviourConfig +where + KSC: Default, +{ + #[builder(field(type = "IdentifyConfig"))] + identify: IdentifyConfig, + #[builder(field(type = "PingConfig"))] + ping: PingConfig, + #[builder(field(type = "GossipsubConfig"))] + gossipsub: GossipsubConfig, + #[builder(field(type = "KademliaConfig"))] + kademlia: KademliaConfig, + #[builder(field(type = "KSC"))] + kademlia_store: KSC, +} + +impl BehaviourBuilder +where + KSC: Default, +{ + pub fn build( + self, + keypair: Keypair, + relay: Option, + ) -> Result, OrbitBehaviourBuildError> + where + KSC: Default + RecordStoreConfig, + KS: for<'a> RecordStore<'a> + Send, + { + let peer_id = keypair.public().to_peer_id(); + Ok(Behaviour { + identify: Identify::new(self.identify.to_config(keypair.public())), + ping: Ping::new(self.ping), + gossipsub: Gossipsub::new( + MessageAuthenticity::Signed(keypair), + GossipsubConfigBuilder::from(self.gossipsub) + // always ensure validation + .validation_mode(ValidationMode::Strict) + .build() + .map_err(OrbitBehaviourBuildError::Gossipsub)?, + ) + .map_err(OrbitBehaviourBuildError::Gossipsub)?, + relay: relay.into(), + kademlia: Kademlia::with_config( + peer_id, + self.kademlia_store.init(peer_id), + self.kademlia, + ), + dcutr: Dcutr::new(), + }) + } +} + +#[derive(Error, Debug)] +pub enum OrbitBehaviourBuildError { + #[error("{0}")] + Gossipsub(&'static str), +} + +pub trait RecordStoreConfig +where + S: for<'a> RecordStore<'a>, +{ + fn init(self, id: PeerId) -> S; +} + +impl RecordStoreConfig for MemoryStoreConfig { + fn init(self, id: PeerId) -> MemoryStore { + MemoryStore::with_config(id, self) + } +} + +#[derive(Builder, Default, Debug, Clone)] +pub struct IdentifyConfig { + #[builder(setter(into), default = "Duration::from_millis(500)")] + initial_delay: Duration, + #[builder(setter(into), default = "Duration::from_secs(300)")] + interval: Duration, + #[builder(setter(into), default = "false")] + push_listen_addr_updates: bool, + #[builder(setter(into), default = "0")] + cache_size: usize, +} + +impl IdentifyConfig { + fn to_config(self, key: PublicKey) -> OIdentifyConfig { + OIdentifyConfig::new(PROTOCOL_VERSION.to_string(), key) + .with_initial_delay(self.initial_delay) + .with_interval(self.interval) + .with_push_listen_addr_updates(self.push_listen_addr_updates) + .with_cache_size(self.cache_size) + } +} + +impl From for IdentifyConfig { + fn from(c: OIdentifyConfig) -> Self { + Self { + initial_delay: c.initial_delay, + interval: c.interval, + push_listen_addr_updates: c.push_listen_addr_updates, + cache_size: c.cache_size, + } + } +} diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs new file mode 100644 index 00000000..b60cd7ff --- /dev/null +++ b/src/p2p/behaviour/mod.rs @@ -0,0 +1,40 @@ +use core::time::Duration; +use derive_builder::Builder; +use libp2p::{ + core::{muxing::StreamMuxerBox, transport::Boxed, PeerId}, + dcutr::behaviour::Behaviour as Dcutr, + gossipsub::{ + Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, + }, + identify::{Behaviour as Identify, Config as OIdentifyConfig}, + identity::{Keypair, PublicKey}, + kad::{ + record::store::{MemoryStore, MemoryStoreConfig, RecordStore}, + Kademlia, KademliaConfig, + }, + ping::{Behaviour as Ping, Config as PingConfig}, + relay::v2::client::Client, + swarm::{behaviour::toggle::Toggle, Swarm}, + NetworkBehaviour, +}; +use thiserror::Error; + +const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; + +pub type OrbitSwarm = Swarm>; +mod builder; + +pub use builder::{BehaviourBuilder, OrbitBehaviourBuildError}; + +#[derive(NetworkBehaviour)] +pub struct Behaviour +where + KS: 'static + for<'a> RecordStore<'a> + Send, +{ + identify: Identify, + ping: Ping, + gossipsub: Gossipsub, + relay: Toggle, + kademlia: Kademlia, + dcutr: Dcutr, +} diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs new file mode 100644 index 00000000..833e52df --- /dev/null +++ b/src/p2p/mod.rs @@ -0,0 +1 @@ +pub mod behaviour; From e4db46ff4335b72a409f13bad7e6bc8ea147bf9b Mon Sep 17 00:00:00 2001 From: chunningham Date: Fri, 4 Nov 2022 13:58:06 +0100 Subject: [PATCH 08/48] unused warns and stuff --- src/p2p/behaviour/builder.rs | 37 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs index 6617766e..634f1d56 100644 --- a/src/p2p/behaviour/builder.rs +++ b/src/p2p/behaviour/builder.rs @@ -1,7 +1,8 @@ +use super::Behaviour; use core::time::Duration; use derive_builder::Builder; use libp2p::{ - core::{muxing::StreamMuxerBox, transport::Boxed, PeerId}, + core::PeerId, dcutr::behaviour::Behaviour as Dcutr, gossipsub::{ Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, @@ -14,29 +15,29 @@ use libp2p::{ }, ping::{Behaviour as Ping, Config as PingConfig}, relay::v2::client::Client, - swarm::{behaviour::toggle::Toggle, Swarm}, - NetworkBehaviour, }; use thiserror::Error; const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; +// we use derive_builder here to make a conveniant builder, but we do not export +// the actual config struct #[derive(Builder, Clone, Debug)] #[builder(build_fn(skip), setter(into), name = "BehaviourBuilder", derive(Debug))] pub struct BehaviourConfig where KSC: Default, { - #[builder(field(type = "IdentifyConfig"))] - identify: IdentifyConfig, - #[builder(field(type = "PingConfig"))] - ping: PingConfig, - #[builder(field(type = "GossipsubConfig"))] - gossipsub: GossipsubConfig, - #[builder(field(type = "KademliaConfig"))] - kademlia: KademliaConfig, - #[builder(field(type = "KSC"))] - kademlia_store: KSC, + #[builder(field(type = "IdentifyConfig"), setter(name = "identify"))] + _identify: IdentifyConfig, + #[builder(field(type = "PingConfig"), setter(name = "ping"))] + _ping: PingConfig, + #[builder(field(type = "GossipsubConfig"), setter(name = "gossipsub"))] + _gossipsub: GossipsubConfig, + #[builder(field(type = "KademliaConfig"), setter(name = "kademlia"))] + _kademlia: KademliaConfig, + #[builder(field(type = "KSC"), setter(name = "kademlia_store"))] + _kademlia_store: KSC, } impl BehaviourBuilder @@ -54,11 +55,11 @@ where { let peer_id = keypair.public().to_peer_id(); Ok(Behaviour { - identify: Identify::new(self.identify.to_config(keypair.public())), - ping: Ping::new(self.ping), + identify: Identify::new(self._identify.to_config(keypair.public())), + ping: Ping::new(self._ping), gossipsub: Gossipsub::new( MessageAuthenticity::Signed(keypair), - GossipsubConfigBuilder::from(self.gossipsub) + GossipsubConfigBuilder::from(self._gossipsub) // always ensure validation .validation_mode(ValidationMode::Strict) .build() @@ -68,8 +69,8 @@ where relay: relay.into(), kademlia: Kademlia::with_config( peer_id, - self.kademlia_store.init(peer_id), - self.kademlia, + self._kademlia_store.init(peer_id), + self._kademlia, ), dcutr: Dcutr::new(), }) From 6a58a9b99443ca2cdf3cca255e4baaef94d48d27 Mon Sep 17 00:00:00 2001 From: chunningham Date: Fri, 4 Nov 2022 15:00:18 +0100 Subject: [PATCH 09/48] add autonat to behaviour --- Cargo.lock | 34 ++++++++++++++++++++++++++ Cargo.toml | 2 +- src/p2p/behaviour/builder.rs | 46 ++++++------------------------------ src/p2p/behaviour/mod.rs | 21 ++++++---------- src/p2p/mod.rs | 38 +++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f53c908f..1ee1fb74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3570,6 +3570,7 @@ dependencies = [ "futures-timer", "getrandom 0.2.8", "instant", + "libp2p-autonat", "libp2p-core", "libp2p-dcutr", "libp2p-dns", @@ -3592,6 +3593,24 @@ dependencies = [ "pin-project", ] +[[package]] +name = "libp2p-autonat" +version = "0.10.1" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +dependencies = [ + "async-trait", + "futures", + "futures-timer", + "instant", + "libp2p-core", + "libp2p-identity", + "libp2p-request-response", + "libp2p-swarm", + "log", + "quick-protobuf", + "rand 0.8.5", +] + [[package]] name = "libp2p-core" version = "0.39.1" @@ -3886,6 +3905,21 @@ dependencies = [ "void", ] +[[package]] +name = "libp2p-request-response" +version = "0.24.0" +source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +dependencies = [ + "async-trait", + "futures", + "instant", + "libp2p-core", + "libp2p-identity", + "libp2p-swarm", + "rand 0.8.5", + "smallvec", +] + [[package]] name = "libp2p-swarm" version = "0.42.0" diff --git a/Cargo.toml b/Cargo.toml index f3bb1a0c..19e2777c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ hyper = "0.14" # Prometheus server iri-string = "0.5" lazy_static = "1.4.0" libipld = { version = "0.14", default-features = false, features = ["dag-cbor", "dag-json", "derive", "serde-codec"]} -libp2p = { default-features = false, features = ["gossipsub", "identify", "kad", "tcp", "mplex", "noise", "ping", "yamux", "dns", "tokio", "relay", "dcutr"], version = "0.51.0", git = "https://github.com/libp2p/rust-libp2p/", branch = "master" } +libp2p = { default-features = false, features = ["autonat", "gossipsub", "identify", "kad", "tcp", "mplex", "noise", "ping", "yamux", "dns", "tokio", "relay", "dcutr"], version = "0.51.0", git = "https://github.com/libp2p/rust-libp2p/", branch = "master" } opentelemetry = { version = "0.17.0", features = ["rt-tokio"] } opentelemetry-jaeger = { version = "0.16.0", features = ["rt-tokio", "reqwest_collector_client"] } pin-project = "1" diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs index 634f1d56..f2d7c9ee 100644 --- a/src/p2p/behaviour/builder.rs +++ b/src/p2p/behaviour/builder.rs @@ -1,14 +1,14 @@ -use super::Behaviour; -use core::time::Duration; +use crate::p2p::{behaviour::Behaviour, IdentifyConfig}; use derive_builder::Builder; use libp2p::{ + autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, core::PeerId, dcutr::behaviour::Behaviour as Dcutr, gossipsub::{ Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, }, - identify::{Behaviour as Identify, Config as OIdentifyConfig}, - identity::{Keypair, PublicKey}, + identify::Behaviour as Identify, + identity::Keypair, kad::{ record::store::{MemoryStore, MemoryStoreConfig, RecordStore}, Kademlia, KademliaConfig, @@ -18,8 +18,6 @@ use libp2p::{ }; use thiserror::Error; -const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; - // we use derive_builder here to make a conveniant builder, but we do not export // the actual config struct #[derive(Builder, Clone, Debug)] @@ -38,6 +36,8 @@ where _kademlia: KademliaConfig, #[builder(field(type = "KSC"), setter(name = "kademlia_store"))] _kademlia_store: KSC, + #[builder(field(type = "AutoNatConfig"), setter(name = "autonat"))] + _autonat: AutoNatConfig, } impl BehaviourBuilder @@ -73,6 +73,7 @@ where self._kademlia, ), dcutr: Dcutr::new(), + autonat: AutoNat::new(peer_id, self._autonat), }) } } @@ -95,36 +96,3 @@ impl RecordStoreConfig for MemoryStoreConfig { MemoryStore::with_config(id, self) } } - -#[derive(Builder, Default, Debug, Clone)] -pub struct IdentifyConfig { - #[builder(setter(into), default = "Duration::from_millis(500)")] - initial_delay: Duration, - #[builder(setter(into), default = "Duration::from_secs(300)")] - interval: Duration, - #[builder(setter(into), default = "false")] - push_listen_addr_updates: bool, - #[builder(setter(into), default = "0")] - cache_size: usize, -} - -impl IdentifyConfig { - fn to_config(self, key: PublicKey) -> OIdentifyConfig { - OIdentifyConfig::new(PROTOCOL_VERSION.to_string(), key) - .with_initial_delay(self.initial_delay) - .with_interval(self.interval) - .with_push_listen_addr_updates(self.push_listen_addr_updates) - .with_cache_size(self.cache_size) - } -} - -impl From for IdentifyConfig { - fn from(c: OIdentifyConfig) -> Self { - Self { - initial_delay: c.initial_delay, - interval: c.interval, - push_listen_addr_updates: c.push_listen_addr_updates, - cache_size: c.cache_size, - } - } -} diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs index b60cd7ff..3343ce55 100644 --- a/src/p2p/behaviour/mod.rs +++ b/src/p2p/behaviour/mod.rs @@ -1,25 +1,17 @@ -use core::time::Duration; -use derive_builder::Builder; use libp2p::{ - core::{muxing::StreamMuxerBox, transport::Boxed, PeerId}, + autonat::Behaviour as AutoNat, dcutr::behaviour::Behaviour as Dcutr, - gossipsub::{ - Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, - }, - identify::{Behaviour as Identify, Config as OIdentifyConfig}, - identity::{Keypair, PublicKey}, + gossipsub::Gossipsub, + identify::Behaviour as Identify, kad::{ - record::store::{MemoryStore, MemoryStoreConfig, RecordStore}, - Kademlia, KademliaConfig, + record::store::{MemoryStore, RecordStore}, + Kademlia, }, - ping::{Behaviour as Ping, Config as PingConfig}, + ping::Behaviour as Ping, relay::v2::client::Client, swarm::{behaviour::toggle::Toggle, Swarm}, NetworkBehaviour, }; -use thiserror::Error; - -const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; pub type OrbitSwarm = Swarm>; mod builder; @@ -37,4 +29,5 @@ where relay: Toggle, kademlia: Kademlia, dcutr: Dcutr, + autonat: AutoNat, } diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index 833e52df..0e62dfc4 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -1 +1,39 @@ +use core::time::Duration; +use derive_builder::Builder; +use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; pub mod behaviour; + +#[derive(Builder, Default, Debug, Clone)] +pub struct IdentifyConfig { + #[builder(setter(into), default = "Duration::from_millis(500)")] + initial_delay: Duration, + #[builder(setter(into), default = "Duration::from_secs(300)")] + interval: Duration, + #[builder(setter(into), default = "false")] + push_listen_addr_updates: bool, + #[builder(setter(into), default = "0")] + cache_size: usize, +} + +const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; + +impl IdentifyConfig { + fn to_config(self, key: PublicKey) -> OIdentifyConfig { + OIdentifyConfig::new(PROTOCOL_VERSION.to_string(), key) + .with_initial_delay(self.initial_delay) + .with_interval(self.interval) + .with_push_listen_addr_updates(self.push_listen_addr_updates) + .with_cache_size(self.cache_size) + } +} + +impl From for IdentifyConfig { + fn from(c: OIdentifyConfig) -> Self { + Self { + initial_delay: c.initial_delay, + interval: c.interval, + push_listen_addr_updates: c.push_listen_addr_updates, + cache_size: c.cache_size, + } + } +} From df9819505bd8ff049b1d2093c6ace8e1a7aab42c Mon Sep 17 00:00:00 2001 From: chunningham Date: Fri, 4 Nov 2022 16:13:02 +0100 Subject: [PATCH 10/48] add an incomplete relay impl --- src/auth_guards.rs | 2 +- src/lib.rs | 3 +- src/p2p/mod.rs | 1 + src/p2p/relay.rs | 87 ++++++++++++++++++++++++++++++++++++++++++++++ src/relay.rs | 35 ------------------- src/routes/mod.rs | 2 +- 6 files changed, 91 insertions(+), 39 deletions(-) create mode 100644 src/p2p/relay.rs delete mode 100644 src/relay.rs diff --git a/src/auth_guards.rs b/src/auth_guards.rs index 40b7d232..72fc9a06 100644 --- a/src/auth_guards.rs +++ b/src/auth_guards.rs @@ -2,7 +2,7 @@ use crate::authorization::{Delegation, Invocation, Verifiable}; use crate::capabilities::store::{InvokeError, ToBlock, Updates}; use crate::config; use crate::orbit::{create_orbit, load_orbit, Orbit}; -use crate::relay::RelayNode; +use crate::p2p::relay::RelayNode; use crate::routes::Metadata; use crate::BlockStores; use anyhow::Result; diff --git a/src/lib.rs b/src/lib.rs index d2c423fc..d7214436 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,6 @@ pub mod manifest; pub mod orbit; pub mod p2p; pub mod prometheus; -pub mod relay; pub mod routes; pub mod storage; mod tracing; @@ -34,7 +33,7 @@ use libp2p::{ PeerId, }; use orbit::ProviderUtils; -use relay::RelayNode; +use p2p::relay::RelayNode; use routes::{delegate, invoke, open_host_key, relay_addr, util_routes::*}; use std::{collections::HashMap, sync::RwLock}; use storage::{ diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index 0e62dfc4..3ad452a7 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -2,6 +2,7 @@ use core::time::Duration; use derive_builder::Builder; use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; pub mod behaviour; +pub mod relay; #[derive(Builder, Default, Debug, Clone)] pub struct IdentifyConfig { diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs new file mode 100644 index 00000000..df93777d --- /dev/null +++ b/src/p2p/relay.rs @@ -0,0 +1,87 @@ +use crate::p2p::IdentifyConfig; +use anyhow::Result; +use derive_builder::Builder; +use libp2p::{ + autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, + core::{identity::Keypair, multiaddr::multiaddr, Multiaddr, PeerId}, + identify::Behaviour as Identify, + identity::PublicKey, + ping::{Behaviour as Ping, Config as PingConfig}, + relay::v2::relay::{Config as RelayConfig, Relay}, + swarm::Swarm, + NetworkBehaviour, +}; + +pub type RelaySwarm = Swarm; + +pub struct RelayNode { + pub port: u16, + pub id: PeerId, +} + +#[derive(NetworkBehaviour)] +pub struct Behaviour { + identify: Identify, + ping: Ping, + relay: Relay, + autonat: AutoNat, +} + +#[derive(Builder, Debug)] +#[builder( + build_fn(skip), + setter(into), + name = "BehaviourBuilder", + derive(Debug), + pattern = "owned" +)] +pub struct BehaviourConfig { + #[builder(field(type = "IdentifyConfig"), setter(name = "identify"))] + _identify: IdentifyConfig, + #[builder(field(type = "PingConfig"), setter(name = "ping"))] + _ping: PingConfig, + #[builder(field(type = "RelayConfig"), setter(name = "relay"))] + _relay: RelayConfig, + #[builder(field(type = "AutoNatConfig"), setter(name = "autonat"))] + _autonat: AutoNatConfig, +} + +impl BehaviourBuilder { + pub fn build(self, pubkey: PublicKey) -> Behaviour { + let peer_id = pubkey.to_peer_id(); + Behaviour { + identify: Identify::new(self._identify.to_config(pubkey)), + ping: Ping::new(self._ping), + relay: Relay::new(peer_id, self._relay), + autonat: AutoNat::new(peer_id, self._autonat), + } + } +} + +impl RelayNode { + pub async fn new(port: u16, keypair: Keypair) -> Result { + let local_public_key = keypair.public(); + let id = local_public_key.to_peer_id(); + + Ok(Self { port, id }) + } + + fn _internal(port: u16) -> Multiaddr { + multiaddr!(Memory(port)) + } + + pub fn internal(&self) -> Multiaddr { + Self::_internal(self.port) + } + + fn _external(port: u16) -> Multiaddr { + multiaddr!(Ip4([127, 0, 0, 1]), Tcp(port)) + } + + pub fn external(&self) -> Multiaddr { + Self::_external(self.port) + } +} + +#[cfg(test)] +pub mod test {} diff --git a/src/relay.rs b/src/relay.rs deleted file mode 100644 index 26234d54..00000000 --- a/src/relay.rs +++ /dev/null @@ -1,35 +0,0 @@ -use anyhow::Result; -use libp2p::core::{identity::Keypair, multiaddr::multiaddr, Multiaddr, PeerId}; - -pub struct RelayNode { - pub port: u16, - pub id: PeerId, -} - -impl RelayNode { - pub async fn new(port: u16, keypair: Keypair) -> Result { - let local_public_key = keypair.public(); - let id = local_public_key.to_peer_id(); - - Ok(Self { port, id }) - } - - fn _internal(port: u16) -> Multiaddr { - multiaddr!(Memory(port)) - } - - pub fn internal(&self) -> Multiaddr { - Self::_internal(self.port) - } - - fn _external(port: u16) -> Multiaddr { - multiaddr!(Ip4([127, 0, 0, 1]), Tcp(port)) - } - - pub fn external(&self) -> Multiaddr { - Self::_external(self.port) - } -} - -#[cfg(test)] -pub mod test {} diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 18c6840f..4bd62eba 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -28,7 +28,7 @@ use crate::{ auth_guards::{CapAction, DelegateAuthWrapper, InvokeAuthWrapper, KVAction}, authorization::{Capability, Delegation}, kv::{ObjectBuilder, ReadResponse}, - relay::RelayNode, + p2p::relay::RelayNode, storage::{Content, ImmutableStore}, tracing::TracingSpan, BlockStores, From 8f40fb48bcb7e08e1809c3a9befb75cfcc5a58da Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 10 Nov 2022 10:38:31 +0100 Subject: [PATCH 11/48] impl partially stubbed relay node with task --- Cargo.lock | 103 +++++++++++++------ Cargo.toml | 2 +- src/auth_guards.rs | 2 +- src/lib.rs | 2 +- src/p2p/behaviour/builder.rs | 6 +- src/p2p/behaviour/mod.rs | 5 +- src/p2p/relay.rs | 191 ++++++++++++++++++++++++++--------- src/routes/mod.rs | 2 +- src/storage/file_system.rs | 2 +- src/storage/s3.rs | 2 +- 10 files changed, 227 insertions(+), 90 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ee1fb74..2d6bec63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3563,7 +3563,8 @@ checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" [[package]] name = "libp2p" version = "0.51.1" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53e068bb83ef4e0bed45de5ca4a4118018ac1f70ea3ecb1f4878742d08a97473" dependencies = [ "bytes", "futures", @@ -3596,7 +3597,8 @@ dependencies = [ [[package]] name = "libp2p-autonat" version = "0.10.1" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d85a24ab50a85cbcfccf20ccdb02d903e6198d9cee5e67aa122dbfe66824d087" dependencies = [ "async-trait", "futures", @@ -3614,7 +3616,8 @@ dependencies = [ [[package]] name = "libp2p-core" version = "0.39.1" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7f8b7d65c070a5a1b5f8f0510648189da08f787b8963f8e21219e0710733af" dependencies = [ "either", "fnv", @@ -3641,7 +3644,8 @@ dependencies = [ [[package]] name = "libp2p-dcutr" version = "0.9.1" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a8854d223a4145d7cf0652553fe606df397cfd96f9bb7f62d7d0a2b2332ca1b" dependencies = [ "asynchronous-codec", "either", @@ -3661,11 +3665,11 @@ dependencies = [ [[package]] name = "libp2p-dns" version = "0.39.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146ff7034daae62077c415c2376b8057368042df6ab95f5432ad5e88568b1554" dependencies = [ "futures", "libp2p-core", - "libp2p-identity", "log", "parking_lot 0.12.1", "smallvec", @@ -3675,7 +3679,8 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" version = "0.44.1" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "708235886ca7c8f3792a8683ef81f9b7fb0a952bbd15fe5038b7610689a88390" dependencies = [ "asynchronous-codec", "base64 0.21.0", @@ -3704,7 +3709,8 @@ dependencies = [ [[package]] name = "libp2p-identify" version = "0.42.1" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40d1da1f75baf824cfdc80f6aced51f7cbf8dc14e32363e9443570a80d4ee337" dependencies = [ "asynchronous-codec", "either", @@ -3725,7 +3731,8 @@ dependencies = [ [[package]] name = "libp2p-identity" version = "0.1.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff6c9cb71e2333d31f18e7556b9a5f1d0a2e013effc9325e36f436be65fe7bd2" dependencies = [ "bs58", "ed25519-dalek", @@ -3743,7 +3750,8 @@ dependencies = [ [[package]] name = "libp2p-kad" version = "0.43.1" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bc57e02d7ad49a63792370f24b829af38f34982ff56556e59e4cb325a4dbf6b" dependencies = [ "arrayvec 0.7.2", "asynchronous-codec", @@ -3770,13 +3778,13 @@ dependencies = [ [[package]] name = "libp2p-mdns" version = "0.43.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "687a0b54ee8f7106be36f012b32bd30faceeb4cd857ebad96e512566886ffea5" dependencies = [ "data-encoding", "futures", "if-watch", "libp2p-core", - "libp2p-identity", "libp2p-swarm", "log", "rand 0.8.5", @@ -3790,13 +3798,13 @@ dependencies = [ [[package]] name = "libp2p-metrics" version = "0.12.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a42ec91e227d7d0dafa4ce88b333cdf5f277253873ab087555c92798db2ddd46" dependencies = [ "libp2p-core", "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", - "libp2p-identity", "libp2p-kad", "libp2p-ping", "libp2p-relay", @@ -3807,13 +3815,13 @@ dependencies = [ [[package]] name = "libp2p-mplex" version = "0.39.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d34780b514b159e6f3fd70ba3e72664ec89da28dca2d1e7856ee55e2c7031ba" dependencies = [ "asynchronous-codec", "bytes", "futures", "libp2p-core", - "libp2p-identity", "log", "nohash-hasher", "parking_lot 0.12.1", @@ -3825,7 +3833,8 @@ dependencies = [ [[package]] name = "libp2p-noise" version = "0.42.1" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c87c2803deffeae94108072a0387f8c9ff494af68a4908454c11c811e27b5e5" dependencies = [ "bytes", "curve25519-dalek 3.2.0", @@ -3847,14 +3856,14 @@ dependencies = [ [[package]] name = "libp2p-ping" version = "0.42.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e57759c19c28a73ef1eb3585ca410cefb72c1a709fcf6de1612a378e4219202" dependencies = [ "either", "futures", "futures-timer", "instant", "libp2p-core", - "libp2p-identity", "libp2p-swarm", "log", "rand 0.8.5", @@ -3864,7 +3873,8 @@ dependencies = [ [[package]] name = "libp2p-quic" version = "0.7.0-alpha.3" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6b26abd81cd2398382a1edfe739b539775be8a90fa6914f39b2ab49571ec735" dependencies = [ "bytes", "futures", @@ -3885,7 +3895,8 @@ dependencies = [ [[package]] name = "libp2p-relay" version = "0.15.1" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a56a60045a02298defcd7633e770ad1277fea68ca6e9620b52c79bba277ae21" dependencies = [ "asynchronous-codec", "bytes", @@ -3908,22 +3919,26 @@ dependencies = [ [[package]] name = "libp2p-request-response" version = "0.24.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872b9d63fed44d9f81110c30be6c7ca5593a093576d2a95c5d018051e294d2e9" dependencies = [ "async-trait", + "bytes", "futures", "instant", "libp2p-core", - "libp2p-identity", "libp2p-swarm", + "log", "rand 0.8.5", "smallvec", + "unsigned-varint", ] [[package]] name = "libp2p-swarm" version = "0.42.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92c22a83d70703d140092c969c1ca06ecdffff8ca7ce8ac2fd3b7eb2c1f0da86" dependencies = [ "either", "fnv", @@ -3931,25 +3946,38 @@ dependencies = [ "futures-timer", "instant", "libp2p-core", - "libp2p-identity", + "libp2p-swarm-derive", "log", + "pin-project", "rand 0.8.5", "smallvec", + "thiserror", "tokio", "void", ] +[[package]] +name = "libp2p-swarm-derive" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fba456131824ab6acd4c7bf61e9c0f0a3014b5fc9868ccb8e10d344594cdc4f" +dependencies = [ + "heck", + "quote", + "syn", +] + [[package]] name = "libp2p-tcp" version = "0.39.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33d33698596d7722d85d3ab0c86c2c322254fce1241e91208e3679b4eb3026cf" dependencies = [ "futures", "futures-timer", "if-watch", "libc", "libp2p-core", - "libp2p-identity", "log", "socket2", "tokio", @@ -3958,7 +3986,8 @@ dependencies = [ [[package]] name = "libp2p-tls" version = "0.1.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff08d13d0dc66e5e9ba6279c1de417b84fa0d0adc3b03e5732928c180ec02781" dependencies = [ "futures", "futures-rustls", @@ -3976,7 +4005,8 @@ dependencies = [ [[package]] name = "libp2p-webrtc" version = "0.4.0-alpha.3" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffd0c3af5921e3bdd5fecdf3eef3be5a197def64c1d23cd3ea79abcadbd461f7" dependencies = [ "async-trait", "asynchronous-codec", @@ -4006,11 +4036,13 @@ dependencies = [ [[package]] name = "libp2p-yamux" version = "0.43.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d048cd82f72c8800655aa1ee9b808ea8c9d523a649d3579b3ef0cfe23952d7fd" dependencies = [ "futures", "libp2p-core", "log", + "parking_lot 0.12.1", "thiserror", "yamux", ] @@ -4321,7 +4353,8 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "multistream-select" version = "0.12.1" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8552ab875c1313b97b8d20cb857b9fd63e2d1d6a0a1b53ce9821e575405f27a" dependencies = [ "bytes", "futures", @@ -5277,7 +5310,8 @@ dependencies = [ [[package]] name = "quick-protobuf-codec" version = "0.1.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1693116345026436eb2f10b677806169c1a1260c1c60eaaffe3fb5a29ae23d8b" dependencies = [ "asynchronous-codec", "bytes", @@ -5817,7 +5851,8 @@ checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" [[package]] name = "rw-stream-sink" version = "0.3.0" -source = "git+https://github.com/libp2p/rust-libp2p/?branch=master#8927abf176e59fceb02eab50f50cc4ec28c4075b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26338f5e09bb721b85b135ea05af7767c90b52f6de4f087d4f4a3a9d64e7dc04" dependencies = [ "futures", "pin-project", @@ -7333,6 +7368,8 @@ checksum = "d86a8dc7f45e4c1b0d30e43038c38f274e77af056aa5f74b93c2cf9eb3c1c836" dependencies = [ "asynchronous-codec", "bytes", + "futures-io", + "futures-util", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 19e2777c..776e3502 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ hyper = "0.14" # Prometheus server iri-string = "0.5" lazy_static = "1.4.0" libipld = { version = "0.14", default-features = false, features = ["dag-cbor", "dag-json", "derive", "serde-codec"]} -libp2p = { default-features = false, features = ["autonat", "gossipsub", "identify", "kad", "tcp", "mplex", "noise", "ping", "yamux", "dns", "tokio", "relay", "dcutr"], version = "0.51.0", git = "https://github.com/libp2p/rust-libp2p/", branch = "master" } +libp2p = { default-features = false, features = ["autonat", "gossipsub", "identify", "kad", "tcp", "mplex", "noise", "ping", "yamux", "dns", "tokio", "relay", "dcutr", "macros"], version = "0.51.1" } opentelemetry = { version = "0.17.0", features = ["rt-tokio"] } opentelemetry-jaeger = { version = "0.16.0", features = ["rt-tokio", "reqwest_collector_client"] } pin-project = "1" diff --git a/src/auth_guards.rs b/src/auth_guards.rs index 72fc9a06..20f6df6e 100644 --- a/src/auth_guards.rs +++ b/src/auth_guards.rs @@ -82,7 +82,7 @@ fn get_state(req: &Request<'_>) -> Result<(config::Config, (PeerId, Multiaddr))> .ok_or_else(|| anyhow!("Could not retrieve config"))?, req.rocket() .state::() - .map(|r| (r.id, r.internal())) + .map(|r| (r.id().clone(), r.internal())) .ok_or_else(|| anyhow!("Could not retrieve relay node information"))?, )) } diff --git a/src/lib.rs b/src/lib.rs index d7214436..688bccf4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ use libp2p::{ PeerId, }; use orbit::ProviderUtils; -use p2p::relay::RelayNode; +use p2p::relay::{Config as RelayConfig, RelayNode}; use routes::{delegate, invoke, open_host_key, relay_addr, util_routes::*}; use std::{collections::HashMap, sync::RwLock}; use storage::{ diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs index f2d7c9ee..676b07b2 100644 --- a/src/p2p/behaviour/builder.rs +++ b/src/p2p/behaviour/builder.rs @@ -51,7 +51,7 @@ where ) -> Result, OrbitBehaviourBuildError> where KSC: Default + RecordStoreConfig, - KS: for<'a> RecordStore<'a> + Send, + KS: RecordStore + Send, { let peer_id = keypair.public().to_peer_id(); Ok(Behaviour { @@ -72,7 +72,7 @@ where self._kademlia_store.init(peer_id), self._kademlia, ), - dcutr: Dcutr::new(), + dcutr: Dcutr::new(peer_id), autonat: AutoNat::new(peer_id, self._autonat), }) } @@ -86,7 +86,7 @@ pub enum OrbitBehaviourBuildError { pub trait RecordStoreConfig where - S: for<'a> RecordStore<'a>, + S: RecordStore, { fn init(self, id: PeerId) -> S; } diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs index 3343ce55..ff3a6706 100644 --- a/src/p2p/behaviour/mod.rs +++ b/src/p2p/behaviour/mod.rs @@ -9,8 +9,7 @@ use libp2p::{ }, ping::Behaviour as Ping, relay::v2::client::Client, - swarm::{behaviour::toggle::Toggle, Swarm}, - NetworkBehaviour, + swarm::{behaviour::toggle::Toggle, NetworkBehaviour, Swarm}, }; pub type OrbitSwarm = Swarm>; @@ -21,7 +20,7 @@ pub use builder::{BehaviourBuilder, OrbitBehaviourBuildError}; #[derive(NetworkBehaviour)] pub struct Behaviour where - KS: 'static + for<'a> RecordStore<'a> + Send, + KS: RecordStore + Send, { identify: Identify, ping: Ping, diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index df93777d..4b2a7ce3 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -1,69 +1,68 @@ -use crate::p2p::IdentifyConfig; +use crate::{orbit::AbortOnDrop, p2p::IdentifyConfig}; use anyhow::Result; -use derive_builder::Builder; +use futures::{ + channel::{mpsc, oneshot}, + future::{select, Either}, + io::{AsyncRead, AsyncWrite}, + sink::{Sink, SinkExt}, + stream::{iter, Stream, StreamExt}, +}; use libp2p::{ - autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, - core::{identity::Keypair, multiaddr::multiaddr, Multiaddr, PeerId}, + autonat::Behaviour as AutoNat, + core::{ + identity::Keypair, multiaddr::multiaddr, transport::upgrade::Builder, upgrade, Multiaddr, + PeerId, + }, identify::Behaviour as Identify, - identity::PublicKey, - ping::{Behaviour as Ping, Config as PingConfig}, - relay::v2::relay::{Config as RelayConfig, Relay}, - swarm::Swarm, - NetworkBehaviour, + mplex, noise, + ping::Behaviour as Ping, + relay::v2::relay::Relay, + swarm::{Swarm, SwarmBuilder, NetworkBehaviour}, + yamux, }; +pub use builder::Config; + pub type RelaySwarm = Swarm; +#[derive(Clone, Debug)] pub struct RelayNode { - pub port: u16, - pub id: PeerId, + id: PeerId, + sender: mpsc::Sender, + port: u16, } #[derive(NetworkBehaviour)] -pub struct Behaviour { +struct Behaviour { identify: Identify, ping: Ping, relay: Relay, autonat: AutoNat, } -#[derive(Builder, Debug)] -#[builder( - build_fn(skip), - setter(into), - name = "BehaviourBuilder", - derive(Debug), - pattern = "owned" -)] -pub struct BehaviourConfig { - #[builder(field(type = "IdentifyConfig"), setter(name = "identify"))] - _identify: IdentifyConfig, - #[builder(field(type = "PingConfig"), setter(name = "ping"))] - _ping: PingConfig, - #[builder(field(type = "RelayConfig"), setter(name = "relay"))] - _relay: RelayConfig, - #[builder(field(type = "AutoNatConfig"), setter(name = "autonat"))] - _autonat: AutoNatConfig, -} - -impl BehaviourBuilder { - pub fn build(self, pubkey: PublicKey) -> Behaviour { - let peer_id = pubkey.to_peer_id(); - Behaviour { - identify: Identify::new(self._identify.to_config(pubkey)), - ping: Ping::new(self._ping), - relay: Relay::new(peer_id, self._relay), - autonat: AutoNat::new(peer_id, self._autonat), - } - } +#[derive(Debug)] +pub enum Message { + GetAddresses(oneshot::Sender>), + ListenOn(Multiaddr), } impl RelayNode { - pub async fn new(port: u16, keypair: Keypair) -> Result { - let local_public_key = keypair.public(); - let id = local_public_key.to_peer_id(); + pub fn id(&self) -> &PeerId { + &self.id + } + async fn get_addresses(&mut self) -> Result> { + let (s, r) = oneshot::channel(); + self.sender.send(Message::GetAddresses(s)).await?; + Ok(r.await?) + } - Ok(Self { port, id }) + async fn listen_on(&mut self, addr: impl IntoIterator) -> Result<()> { + Ok(self + .sender + .send_all(&mut iter( + addr.into_iter().map(|a| Ok(Message::ListenOn(a.clone()))), + )) + .await?) } fn _internal(port: u16) -> Multiaddr { @@ -83,5 +82,107 @@ impl RelayNode { } } +mod builder { + use super::*; + use derive_builder::Builder; + use libp2p::{ + autonat::Config as AutoNatConfig, core::Transport, identity::PublicKey, + ping::Config as PingConfig, relay::v2::relay::Config as RelayConfig, + }; + + #[derive(Builder, Debug)] + #[builder( + build_fn(skip), + setter(into), + name = "Config", + derive(Debug), + pattern = "owned" + )] + pub struct BehaviourConfigDummy { + #[builder(field(type = "IdentifyConfig"))] + identify: IdentifyConfig, + #[builder(field(type = "PingConfig"))] + ping: PingConfig, + #[builder(field(type = "RelayConfig"))] + relay: RelayConfig, + #[builder(field(type = "AutoNatConfig"))] + autonat: AutoNatConfig, + } + + impl Config { + fn build(self, pubkey: PublicKey) -> Behaviour { + let peer_id = pubkey.to_peer_id(); + Behaviour { + identify: Identify::new(self.identify.to_config(pubkey)), + ping: Ping::new(self.ping), + relay: Relay::new(peer_id, self.relay), + autonat: AutoNat::new(peer_id, self.autonat), + } + } + + pub fn launch( + self, + keypair: Keypair, + transport: Builder, + port: u16, + ) -> Result + where + T: Transport + Send, + T::Output: AsyncRead + AsyncWrite + Unpin + Send, + T::Error: Send + Sync, + T: Unpin, + T::Dial: Send, + T::ListenerUpgrade: Send, + { + let local_public_key = keypair.public(); + let id = local_public_key.to_peer_id(); + let b = self.build(local_public_key); + let (sender, reciever) = mpsc::channel(100); + let r = RelayNode { id, sender, port }; + + let mut swarm = SwarmBuilder::with_tokio_executor( + transport + .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) + .multiplex(upgrade::SelectUpgrade::new( + yamux::YamuxConfig::default(), + mplex::MplexConfig::default(), + )) + .timeout(std::time::Duration::from_secs(20)) + .boxed(), + b, + id, + ) + .build(); + + swarm.listen_on(r.external())?; + swarm.listen_on(r.internal())?; + + tokio::spawn(async move { + loop { + match select(reciever.next(), swarm.next()).await { + // if the swarm or the channel are closed, close the relay + Either::Right((None, _)) | Either::Left((None, _)) => { + break; + } + // process command + Either::Left((Some(e), _)) => match e { + Message::ListenOn(a) => swarm.listen_on(a).map(|_| ())?, + Message::GetAddresses(s) => { + s.send(swarm.listeners().map(|a| a.clone()).collect()) + .map_err(|_| anyhow!("failed to return listeners"))?; + } + }, + Either::Right((Some(e), _)) => { + // process swarm event + } + } + } + Result::<(), anyhow::Error>::Ok(()) + }); + Ok(r) + } + } +} + #[cfg(test)] pub mod test {} diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 4bd62eba..9294bca9 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -95,7 +95,7 @@ pub mod util_routes { pub fn relay_addr(relay: &State) -> String { relay .external() - .with(Protocol::P2p(relay.id.into())) + .with(Protocol::P2p(relay.id().clone().into())) .to_string() } diff --git a/src/storage/file_system.rs b/src/storage/file_system.rs index f9e5b0c5..fc5313e0 100644 --- a/src/storage/file_system.rs +++ b/src/storage/file_system.rs @@ -9,7 +9,7 @@ use kepler_lib::{ }, resource::OrbitId, }; -use libp2p::identity::{ed25519::Keypair as Ed25519Keypair, error::DecodingError}; +use libp2p::identity::{ed25519::Keypair as Ed25519Keypair, DecodingError}; use serde::{Deserialize, Serialize}; use std::{ io::{Error as IoError, ErrorKind}, diff --git a/src/storage/s3.rs b/src/storage/s3.rs index a7e829db..f4c5bd61 100644 --- a/src/storage/s3.rs +++ b/src/storage/s3.rs @@ -16,7 +16,7 @@ use kepler_lib::{ }, resource::OrbitId, }; -use libp2p::identity::{ed25519::Keypair as Ed25519Keypair, error::DecodingError}; +use libp2p::identity::{ed25519::Keypair as Ed25519Keypair, DecodingError}; use rocket::{async_trait, http::hyper::Uri}; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; From ff46d56c4c56173499cc02da2ef43bf29428e9d9 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 10 Nov 2022 10:38:56 +0100 Subject: [PATCH 12/48] minor builder refactors --- src/p2p/behaviour/builder.rs | 42 ++++++++++++++--------------- src/p2p/behaviour/mod.rs | 2 +- src/p2p/mod.rs | 51 ++++++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs index 676b07b2..1d506cc3 100644 --- a/src/p2p/behaviour/builder.rs +++ b/src/p2p/behaviour/builder.rs @@ -21,26 +21,26 @@ use thiserror::Error; // we use derive_builder here to make a conveniant builder, but we do not export // the actual config struct #[derive(Builder, Clone, Debug)] -#[builder(build_fn(skip), setter(into), name = "BehaviourBuilder", derive(Debug))] -pub struct BehaviourConfig +#[builder(build_fn(skip), setter(into), name = "BehaviourConfig", derive(Debug))] +pub struct BehaviourConfigDummy where KSC: Default, { - #[builder(field(type = "IdentifyConfig"), setter(name = "identify"))] - _identify: IdentifyConfig, - #[builder(field(type = "PingConfig"), setter(name = "ping"))] - _ping: PingConfig, - #[builder(field(type = "GossipsubConfig"), setter(name = "gossipsub"))] - _gossipsub: GossipsubConfig, - #[builder(field(type = "KademliaConfig"), setter(name = "kademlia"))] - _kademlia: KademliaConfig, - #[builder(field(type = "KSC"), setter(name = "kademlia_store"))] - _kademlia_store: KSC, - #[builder(field(type = "AutoNatConfig"), setter(name = "autonat"))] - _autonat: AutoNatConfig, + #[builder(field(type = "IdentifyConfig"))] + identify: IdentifyConfig, + #[builder(field(type = "PingConfig"))] + ping: PingConfig, + #[builder(field(type = "GossipsubConfig"))] + gossipsub: GossipsubConfig, + #[builder(field(type = "KademliaConfig"))] + kademlia: KademliaConfig, + #[builder(field(type = "KSC"))] + kademlia_store: KSC, + #[builder(field(type = "AutoNatConfig"))] + autonat: AutoNatConfig, } -impl BehaviourBuilder +impl BehaviourConfig where KSC: Default, { @@ -55,11 +55,11 @@ where { let peer_id = keypair.public().to_peer_id(); Ok(Behaviour { - identify: Identify::new(self._identify.to_config(keypair.public())), - ping: Ping::new(self._ping), + identify: Identify::new(self.identify.to_config(keypair.public())), + ping: Ping::new(self.ping), gossipsub: Gossipsub::new( MessageAuthenticity::Signed(keypair), - GossipsubConfigBuilder::from(self._gossipsub) + GossipsubConfigBuilder::from(self.gossipsub) // always ensure validation .validation_mode(ValidationMode::Strict) .build() @@ -69,11 +69,11 @@ where relay: relay.into(), kademlia: Kademlia::with_config( peer_id, - self._kademlia_store.init(peer_id), - self._kademlia, + self.kademlia_store.init(peer_id), + self.kademlia, ), dcutr: Dcutr::new(peer_id), - autonat: AutoNat::new(peer_id, self._autonat), + autonat: AutoNat::new(peer_id, self.autonat), }) } } diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs index ff3a6706..264d6d79 100644 --- a/src/p2p/behaviour/mod.rs +++ b/src/p2p/behaviour/mod.rs @@ -15,7 +15,7 @@ use libp2p::{ pub type OrbitSwarm = Swarm>; mod builder; -pub use builder::{BehaviourBuilder, OrbitBehaviourBuildError}; +pub use builder::{BehaviourConfig, OrbitBehaviourBuildError}; #[derive(NetworkBehaviour)] pub struct Behaviour diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index 3ad452a7..aa2ffcf5 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -1,36 +1,49 @@ -use core::time::Duration; -use derive_builder::Builder; use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; pub mod behaviour; pub mod relay; - -#[derive(Builder, Default, Debug, Clone)] -pub struct IdentifyConfig { - #[builder(setter(into), default = "Duration::from_millis(500)")] - initial_delay: Duration, - #[builder(setter(into), default = "Duration::from_secs(300)")] - interval: Duration, - #[builder(setter(into), default = "false")] - push_listen_addr_updates: bool, - #[builder(setter(into), default = "0")] - cache_size: usize, -} +pub mod transport; const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; +pub use builder::IdentifyConfig; + +mod builder { + use core::time::Duration; + use derive_builder::Builder; + use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; + #[derive(Builder, Default, Debug, Clone)] + #[builder(build_fn(skip), setter(into), name = "IdentifyConfig", derive(Debug))] + pub struct IdentifyConfigDummy { + #[builder(field(type = "String"), default = "PROTOCOL_VERSION.into()")] + protocol_version: String, + #[builder(field(type = "Duration"), default = "Duration::from_millis(500)")] + initial_delay: Duration, + #[builder(field(type = "Duration"), default = "Duration::from_secs(300)")] + interval: Duration, + #[builder(field(type = "bool"), default = "false")] + push_listen_addr_updates: bool, + #[builder(field(type = "usize"), default = "0")] + cache_size: usize, + } + pub fn convert(config: IdentifyConfig, key: PublicKey) -> OIdentifyConfig { + OIdentifyConfig::new(config.protocol_version, key) + .with_initial_delay(config.initial_delay) + .with_interval(config.interval) + .with_push_listen_addr_updates(config.push_listen_addr_updates) + .with_cache_size(config.cache_size) + } +} + impl IdentifyConfig { fn to_config(self, key: PublicKey) -> OIdentifyConfig { - OIdentifyConfig::new(PROTOCOL_VERSION.to_string(), key) - .with_initial_delay(self.initial_delay) - .with_interval(self.interval) - .with_push_listen_addr_updates(self.push_listen_addr_updates) - .with_cache_size(self.cache_size) + builder::convert(self, key) } } impl From for IdentifyConfig { fn from(c: OIdentifyConfig) -> Self { Self { + protocol_version: c.protocol_version, initial_delay: c.initial_delay, interval: c.interval, push_listen_addr_updates: c.push_listen_addr_updates, From 4110ff2219cacb90172e424513c73f22a262f109 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 10 Nov 2022 10:40:19 +0100 Subject: [PATCH 13/48] wip --- Cargo.toml | 2 +- src/p2p/transport.rs | 88 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/p2p/transport.rs diff --git a/Cargo.toml b/Cargo.toml index 776e3502..3677a69f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ hyper = "0.14" # Prometheus server iri-string = "0.5" lazy_static = "1.4.0" libipld = { version = "0.14", default-features = false, features = ["dag-cbor", "dag-json", "derive", "serde-codec"]} -libp2p = { default-features = false, features = ["autonat", "gossipsub", "identify", "kad", "tcp", "mplex", "noise", "ping", "yamux", "dns", "tokio", "relay", "dcutr", "macros"], version = "0.51.1" } +libp2p = { default-features = false, features = ["autonat", "websocket", "wasm-ext", "gossipsub", "identify", "kad", "tcp", "mplex", "noise", "ping", "yamux", "dns", "tokio", "relay", "dcutr", "macros"], version = "0.51.1" } opentelemetry = { version = "0.17.0", features = ["rt-tokio"] } opentelemetry-jaeger = { version = "0.16.0", features = ["rt-tokio", "reqwest_collector_client"] } pin-project = "1" diff --git a/src/p2p/transport.rs b/src/p2p/transport.rs new file mode 100644 index 00000000..24f89439 --- /dev/null +++ b/src/p2p/transport.rs @@ -0,0 +1,88 @@ +use derive_builder::Builder; +use libp2p::{ + core::transport::{dummy::DummyTransport, MemoryTransport}, + dns::{ResolverConfig, ResolverOpts}, + identity::Keypair, + mplex::MplexConfig, + tcp::GenTcpConfig, + wasm_ext::ffi, + websocket::tls::Config as WsTlsConfig, + yamux::YamuxConfig, + relay::v2::client::{Client, transport::ClientTransport} +}; +use std::time::Duration; + +#[derive(Clone, Debug)] +pub enum DnsResolver { + System, + Custom(DnsConfig), +} + +impl Default for DnsResolver { + fn default() -> Self { + Self::System + } +} + +#[derive(Builder, Debug, Clone)] +pub struct DnsConfig { + conf: ResolverConfig, + opts: ResolverOpts, +} + +pub const MAX_DATA_SIZE: usize = 256 * 1024 * 1024; + +fn client() -> WsTlsConfig { + WsTlsConfig::client() +} + +#[derive(Builder, Debug, Clone)] +#[builder( + build_fn(skip), + setter(into), + derive(Debug), + name = "WsConfig", + pattern = "owned" +)] +pub struct WsConfigDummy { + #[builder(field(type = "u8"), default = "0")] + max_redirects: u8, + #[builder(field(type = "usize"), default = "MAX_DATA_SIZE")] + max_data_size: usize, + #[builder(field(type = "bool"), default = "false")] + deflate: bool, + #[builder(field(type = "WsTlsConfig"), default = "client()")] + tls: WsTlsConfig, +} + +#[derive(Builder)] +#[builder( + build_fn(skip), + setter(into), + name = "TransportConfig", + pattern = "owned" +)] +pub struct TransportConfigDummy { + #[builder(field(type = "bool"), default = "false")] + memory: bool, + tcp: GenTcpConfig, + external: ffi::Transport, + dns: DnsResolver, + websocket: WsConfig, + #[builder(field(type = "bool"), default = "false")] + relay: bool, + mplex: MplexConfig, + yamux: YamuxConfig, + timeout_incoming: Duration, + timeout_outgoing: Duration, +} + +impl TransportConfig { + fn build(self, keypair: Keypair) -> (Boxed<(PeerId, StreamMuxerBox)>, Option) { + let d = match (&self.memory, &self.tcp, &self.external, &self.relay) { + (false, None, None, false) => DummyTransport::new(), + (true, None) => MemoryTransport::new(), + + } + } +} From 2c1c348aa731c2631d11d1c6a464bd43f0ef067f Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 10 Nov 2022 14:41:43 +0100 Subject: [PATCH 14/48] make transport configs actually convenient --- src/p2p/transport.rs | 251 ++++++++++++++++++++++++++++++++----------- 1 file changed, 190 insertions(+), 61 deletions(-) diff --git a/src/p2p/transport.rs b/src/p2p/transport.rs index 24f89439..73366bb5 100644 --- a/src/p2p/transport.rs +++ b/src/p2p/transport.rs @@ -1,21 +1,54 @@ +use crate::storage::either::EitherError; use derive_builder::Builder; +use futures::io::{AsyncRead, AsyncWrite}; use libp2p::{ - core::transport::{dummy::DummyTransport, MemoryTransport}, - dns::{ResolverConfig, ResolverOpts}, - identity::Keypair, - mplex::MplexConfig, - tcp::GenTcpConfig, - wasm_ext::ffi, - websocket::tls::Config as WsTlsConfig, - yamux::YamuxConfig, - relay::v2::client::{Client, transport::ClientTransport} + core::transport::{dummy::DummyTransport, MemoryTransport, OrTransport, Transport}, + dns::{ResolverConfig, ResolverOpts, TokioDnsConfig as DnsTransport}, + tcp::TokioTcpTransport as TcpTransport, + wasm_ext::ExtTransport, + websocket::{tls::Config as WsTlsConfig, WsConfig as WsTransport}, }; -use std::time::Duration; +use std::io::Error as IoError; + +pub trait IntoTransport { + type T: Transport; + type Error; + fn into_transport(self) -> Result; +} + +pub use dns::{CustomDnsResolver, DnsConfig}; +pub use libp2p::tcp::GenTcpConfig as TcpConfig; +pub use libp2p::wasm_ext::ffi::Transport as ExtConfig; +pub use ws::{WsConfig, WS_MAX_DATA_SIZE}; + +#[derive(Default, Debug, Clone, Hash, PartialEq, Eq)] +pub struct MemoryConfig; + +#[derive(Default, Debug, Clone, Hash, PartialEq, Eq)] +pub struct DummyConfig; + +#[derive(Default, Debug, Clone, Hash, PartialEq, Eq)] +pub struct Both(pub A, pub B); + +impl IntoTransport for Both +where + A: IntoTransport, + B: IntoTransport, +{ + type T = OrTransport; + type Error = EitherError; + fn into_transport(self) -> Result { + Ok(OrTransport::new( + self.0.into_transport().map_err(EitherError::A)?, + self.1.into_transport().map_err(EitherError::B)?, + )) + } +} #[derive(Clone, Debug)] pub enum DnsResolver { System, - Custom(DnsConfig), + Custom(CustomDnsResolver), } impl Default for DnsResolver { @@ -24,65 +57,161 @@ impl Default for DnsResolver { } } -#[derive(Builder, Debug, Clone)] -pub struct DnsConfig { - conf: ResolverConfig, - opts: ResolverOpts, +mod dns { + use super::*; + #[derive(Builder)] + #[builder( + build_fn(skip), + setter(into), + derive(Debug), + name = "CustomDnsResolver" + )] + pub struct CustomDnsResolverDummy { + #[builder(field(type = "ResolverConfig"))] + conf: ResolverConfig, + #[builder(field(type = "ResolverOpts"))] + opts: ResolverOpts, + } + + #[derive(Builder)] + #[builder(build_fn(skip), setter(into), derive(Debug), name = "DnsConfig")] + pub struct DnsConfigDummy + where + B: Default, + { + #[builder(field(type = "DnsResolver"))] + resolver: DnsResolver, + #[builder(field(type = "B"))] + base: B, + } + + pub fn convert(c: DnsConfig) -> Result, EitherError> + where + B: Default + IntoTransport, + B::T: 'static + Send + Unpin, + ::Output: 'static + AsyncRead + AsyncWrite + Send + Unpin, + ::Dial: Send, + ::Error: Send, + { + match c.resolver { + DnsResolver::System => { + DnsTransport::system(c.base.into_transport().map_err(EitherError::B)?) + .map_err(EitherError::A) + } + DnsResolver::Custom(custom) => DnsTransport::custom( + c.base.into_transport().map_err(EitherError::B)?, + custom.conf, + custom.opts, + ) + .map_err(EitherError::A), + } + } } -pub const MAX_DATA_SIZE: usize = 256 * 1024 * 1024; +impl IntoTransport for DnsConfig +where + B: Default + IntoTransport, + B::T: 'static + Send + Unpin, + ::Output: 'static + AsyncRead + AsyncWrite + Send + Unpin, + ::Dial: Send, + ::Error: Send, +{ + type T = DnsTransport; + type Error = EitherError; + fn into_transport(self) -> Result { + dns::convert(self) + } +} + +mod ws { + use super::*; + pub const WS_MAX_DATA_SIZE: usize = 256 * 1024 * 1024; + + fn client() -> WsTlsConfig { + WsTlsConfig::client() + } -fn client() -> WsTlsConfig { - WsTlsConfig::client() + #[derive(Builder)] + #[builder(build_fn(skip), setter(into), derive(Debug), name = "WsConfig")] + pub struct WsConfigDummy + where + T: Default, + { + #[builder(field(type = "T"))] + base: T, + #[builder(field(type = "u8"), default = "0")] + max_redirects: u8, + #[builder(field(type = "usize"), default = "WS_MAX_DATA_SIZE")] + max_data_size: usize, + #[builder(field(type = "bool"), default = "false")] + deflate: bool, + // TODO this is cause some kind of error cos it has no Default + // #[builder(field(type = "WsTlsConfig"), default = "client()")] + // tls: WsTlsConfig, + } + + pub fn convert(c: WsConfig) -> Result, B::Error> + where + B: Default + IntoTransport, + B::T: 'static + Send + Unpin, + ::Output: 'static + AsyncRead + AsyncWrite + Send + Unpin, + ::Dial: Send, + ::Error: Send, + ::ListenerUpgrade: Send, + { + let mut ws = WsTransport::new(c.base.into_transport()?); + ws.set_max_redirects(c.max_redirects) + .set_max_data_size(c.max_data_size) + // .set_tls_config(c.tls) + .use_deflate(c.deflate); + Ok(ws) + } } -#[derive(Builder, Debug, Clone)] -#[builder( - build_fn(skip), - setter(into), - derive(Debug), - name = "WsConfig", - pattern = "owned" -)] -pub struct WsConfigDummy { - #[builder(field(type = "u8"), default = "0")] - max_redirects: u8, - #[builder(field(type = "usize"), default = "MAX_DATA_SIZE")] - max_data_size: usize, - #[builder(field(type = "bool"), default = "false")] - deflate: bool, - #[builder(field(type = "WsTlsConfig"), default = "client()")] - tls: WsTlsConfig, +impl IntoTransport for WsConfig +where + B: Default + IntoTransport, + B::T: 'static + Send + Unpin, + ::Output: 'static + AsyncRead + AsyncWrite + Send + Unpin, + ::Dial: Send, + ::Error: Send, + ::ListenerUpgrade: Send, +{ + type T = WsTransport; + type Error = B::Error; + fn into_transport(self) -> Result { + ws::convert(self) + } } -#[derive(Builder)] -#[builder( - build_fn(skip), - setter(into), - name = "TransportConfig", - pattern = "owned" -)] -pub struct TransportConfigDummy { - #[builder(field(type = "bool"), default = "false")] - memory: bool, - tcp: GenTcpConfig, - external: ffi::Transport, - dns: DnsResolver, - websocket: WsConfig, - #[builder(field(type = "bool"), default = "false")] - relay: bool, - mplex: MplexConfig, - yamux: YamuxConfig, - timeout_incoming: Duration, - timeout_outgoing: Duration, +impl IntoTransport for ExtConfig { + type T = ExtTransport; + type Error = std::convert::Infallible; + fn into_transport(self) -> Result { + Ok(Self::T::new(self)) + } } -impl TransportConfig { - fn build(self, keypair: Keypair) -> (Boxed<(PeerId, StreamMuxerBox)>, Option) { - let d = match (&self.memory, &self.tcp, &self.external, &self.relay) { - (false, None, None, false) => DummyTransport::new(), - (true, None) => MemoryTransport::new(), +impl IntoTransport for MemoryConfig { + type T = MemoryTransport; + type Error = std::convert::Infallible; + fn into_transport(self) -> Result { + Ok(Self::T::new()) + } +} - } +impl IntoTransport for TcpConfig { + type T = TcpTransport; + type Error = std::convert::Infallible; + fn into_transport(self) -> Result { + Ok(Self::T::new(self)) + } +} + +impl IntoTransport for DummyConfig { + type T = DummyTransport; + type Error = std::convert::Infallible; + fn into_transport(self) -> Result { + Ok(Self::T::new()) } } From 18926923cdfd5fbbc3fb2f68a7d548d88f8aedce Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 10 Nov 2022 14:52:36 +0100 Subject: [PATCH 15/48] fix errors --- src/p2p/mod.rs | 21 ++++++++++++--------- src/p2p/relay.rs | 9 ++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index aa2ffcf5..6f3fd3a4 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -25,29 +25,32 @@ mod builder { #[builder(field(type = "usize"), default = "0")] cache_size: usize, } - pub fn convert(config: IdentifyConfig, key: PublicKey) -> OIdentifyConfig { + pub fn to_config(config: IdentifyConfig, key: PublicKey) -> OIdentifyConfig { OIdentifyConfig::new(config.protocol_version, key) .with_initial_delay(config.initial_delay) .with_interval(config.interval) .with_push_listen_addr_updates(config.push_listen_addr_updates) .with_cache_size(config.cache_size) } + pub fn convert(c: OIdentifyConfig) -> IdentifyConfig { + IdentifyConfig { + protocol_version: c.protocol_version, + initial_delay: c.initial_delay, + interval: c.interval, + push_listen_addr_updates: c.push_listen_addr_updates, + cache_size: c.cache_size, + } + } } impl IdentifyConfig { fn to_config(self, key: PublicKey) -> OIdentifyConfig { - builder::convert(self, key) + builder::to_config(self, key) } } impl From for IdentifyConfig { fn from(c: OIdentifyConfig) -> Self { - Self { - protocol_version: c.protocol_version, - initial_delay: c.initial_delay, - interval: c.interval, - push_listen_addr_updates: c.push_listen_addr_updates, - cache_size: c.cache_size, - } + builder::convert(c) } } diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index 4b2a7ce3..922c2b28 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -1,4 +1,7 @@ -use crate::{orbit::AbortOnDrop, p2p::IdentifyConfig}; +use crate::{ + orbit::AbortOnDrop, + p2p::{transport::IntoTransport, IdentifyConfig}, +}; use anyhow::Result; use futures::{ channel::{mpsc, oneshot}, @@ -33,7 +36,7 @@ pub struct RelayNode { } #[derive(NetworkBehaviour)] -struct Behaviour { +pub struct Behaviour { identify: Identify, ping: Ping, relay: Relay, @@ -137,7 +140,7 @@ mod builder { let local_public_key = keypair.public(); let id = local_public_key.to_peer_id(); let b = self.build(local_public_key); - let (sender, reciever) = mpsc::channel(100); + let (sender, mut reciever) = mpsc::channel(100); let r = RelayNode { id, sender, port }; let mut swarm = SwarmBuilder::with_tokio_executor( From 969e2c17e52fac886421b6eb6ee007cba645dbf5 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 10 Nov 2022 14:52:44 +0100 Subject: [PATCH 16/48] use IntoTransport in relay::launch --- src/lib.rs | 11 +++++++++-- src/p2p/relay.rs | 22 ++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 688bccf4..56163ce5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,10 @@ use libp2p::{ PeerId, }; use orbit::ProviderUtils; -use p2p::relay::{Config as RelayConfig, RelayNode}; +use p2p::{ + relay::{Config as RelayConfig, RelayNode}, + transport::{Both, DnsConfig, MemoryConfig, TcpConfig, WsConfig}, +}; use routes::{delegate, invoke, open_host_key, relay_addr, util_routes::*}; use std::{collections::HashMap, sync::RwLock}; use storage::{ @@ -78,7 +81,11 @@ pub async fn app(config: &Figment) -> Result> { storage::KV::healthcheck(kepler_config.storage.indexes.clone()).await?; let kp = kepler_config.storage.blocks.relay_key_pair().await?; - let relay_node = RelayNode::new(kepler_config.relay.port, Keypair::Ed25519(kp)).await?; + let relay_node = RelayConfig::default().launch( + Keypair::Ed25519(kp), + Both::>>::default(), + kepler_config.relay.port, + )?; let routes = routes![ healthcheck, diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index 922c2b28..e053268c 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -123,19 +123,15 @@ mod builder { } } - pub fn launch( - self, - keypair: Keypair, - transport: Builder, - port: u16, - ) -> Result + pub fn launch(self, keypair: Keypair, transport: T, port: u16) -> Result where - T: Transport + Send, - T::Output: AsyncRead + AsyncWrite + Unpin + Send, - T::Error: Send + Sync, - T: Unpin, - T::Dial: Send, - T::ListenerUpgrade: Send, + T: IntoTransport, + T::T: 'static + Send + Unpin, + T::Error: 'static + std::error::Error + Send + Sync, + ::Output: 'static + AsyncRead + AsyncWrite + Unpin + Send, + ::Error: 'static + Send + Sync, + ::Dial: Send, + ::ListenerUpgrade: Send, { let local_public_key = keypair.public(); let id = local_public_key.to_peer_id(); @@ -145,6 +141,8 @@ mod builder { let mut swarm = SwarmBuilder::with_tokio_executor( transport + .into_transport()? + .upgrade(upgrade::Version::V1) .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) .multiplex(upgrade::SelectUpgrade::new( yamux::YamuxConfig::default(), From d1a896e7d1a62f11e65631a7b2e627137b12019f Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 10 Nov 2022 16:07:59 +0100 Subject: [PATCH 17/48] clean up some unused builder stuff --- src/p2p/behaviour/builder.rs | 2 +- src/p2p/mod.rs | 4 ++-- src/p2p/relay.rs | 11 ++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs index 1d506cc3..37be5402 100644 --- a/src/p2p/behaviour/builder.rs +++ b/src/p2p/behaviour/builder.rs @@ -20,7 +20,7 @@ use thiserror::Error; // we use derive_builder here to make a conveniant builder, but we do not export // the actual config struct -#[derive(Builder, Clone, Debug)] +#[derive(Builder)] #[builder(build_fn(skip), setter(into), name = "BehaviourConfig", derive(Debug))] pub struct BehaviourConfigDummy where diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index 6f3fd3a4..51258dee 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -3,7 +3,7 @@ pub mod behaviour; pub mod relay; pub mod transport; -const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; +pub const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; pub use builder::IdentifyConfig; @@ -11,7 +11,7 @@ mod builder { use core::time::Duration; use derive_builder::Builder; use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; - #[derive(Builder, Default, Debug, Clone)] + #[derive(Builder)] #[builder(build_fn(skip), setter(into), name = "IdentifyConfig", derive(Debug))] pub struct IdentifyConfigDummy { #[builder(field(type = "String"), default = "PROTOCOL_VERSION.into()")] diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index e053268c..c5e7d51e 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -7,15 +7,12 @@ use futures::{ channel::{mpsc, oneshot}, future::{select, Either}, io::{AsyncRead, AsyncWrite}, - sink::{Sink, SinkExt}, - stream::{iter, Stream, StreamExt}, + sink::SinkExt, + stream::{iter, StreamExt}, }; use libp2p::{ autonat::Behaviour as AutoNat, - core::{ - identity::Keypair, multiaddr::multiaddr, transport::upgrade::Builder, upgrade, Multiaddr, - PeerId, - }, + core::{identity::Keypair, upgrade, Multiaddr, PeerId}, identify::Behaviour as Identify, mplex, noise, ping::Behaviour as Ping, @@ -93,7 +90,7 @@ mod builder { ping::Config as PingConfig, relay::v2::relay::Config as RelayConfig, }; - #[derive(Builder, Debug)] + #[derive(Builder)] #[builder( build_fn(skip), setter(into), From 6d686a943f6770efdfa54763c242b0621d818805 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 10 Nov 2022 16:08:21 +0100 Subject: [PATCH 18/48] get addrs and listen with relay via the event channels --- src/auth_guards.rs | 15 ++++++----- src/lib.rs | 13 +++++++--- src/p2p/relay.rs | 62 ++++++++++++++++++++++------------------------ src/routes/mod.rs | 15 ++++++----- 4 files changed, 58 insertions(+), 47 deletions(-) diff --git a/src/auth_guards.rs b/src/auth_guards.rs index 20f6df6e..7706afc8 100644 --- a/src/auth_guards.rs +++ b/src/auth_guards.rs @@ -12,7 +12,7 @@ use kepler_lib::{ resource::{OrbitId, ResourceId}, }; use libp2p::{ - core::{Multiaddr, PeerId}, + core::{multiaddr::multiaddr, Multiaddr, PeerId}, identity::ed25519::Keypair as Ed25519Keypair, }; use rocket::{ @@ -75,14 +75,17 @@ pub fn check_orbit_and_service( } fn get_state(req: &Request<'_>) -> Result<(config::Config, (PeerId, Multiaddr))> { + let config = req + .rocket() + .state::() + .cloned() + .ok_or_else(|| anyhow!("Could not retrieve config"))?; + let port = config.relay.port; Ok(( - req.rocket() - .state::() - .cloned() - .ok_or_else(|| anyhow!("Could not retrieve config"))?, + config, req.rocket() .state::() - .map(|r| (r.id().clone(), r.internal())) + .map(|r| (r.id().clone(), multiaddr!(Memory(port)))) .ok_or_else(|| anyhow!("Could not retrieve relay node information"))?, )) } diff --git a/src/lib.rs b/src/lib.rs index 56163ce5..53942887 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,12 +29,13 @@ pub mod transport; use config::{BlockStorage, Config}; use libp2p::{ + core::multiaddr::multiaddr, identity::{ed25519::Keypair as Ed25519Keypair, Keypair}, PeerId, }; use orbit::ProviderUtils; use p2p::{ - relay::{Config as RelayConfig, RelayNode}, + relay::Config as RelayConfig, transport::{Both, DnsConfig, MemoryConfig, TcpConfig, WsConfig}, }; use routes::{delegate, invoke, open_host_key, relay_addr, util_routes::*}; @@ -81,12 +82,18 @@ pub async fn app(config: &Figment) -> Result> { storage::KV::healthcheck(kepler_config.storage.indexes.clone()).await?; let kp = kepler_config.storage.blocks.relay_key_pair().await?; - let relay_node = RelayConfig::default().launch( + let mut relay_node = RelayConfig::default().launch( Keypair::Ed25519(kp), Both::>>::default(), - kepler_config.relay.port, )?; + relay_node + .listen_on([ + multiaddr!(Memory(kepler_config.relay.port)), + multiaddr!(Ip4([127, 0, 0, 1]), Tcp(kepler_config.relay.port)), + ]) + .await?; + let routes = routes![ healthcheck, cors, diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index c5e7d51e..e0dd3ba8 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -29,7 +29,6 @@ pub type RelaySwarm = Swarm; pub struct RelayNode { id: PeerId, sender: mpsc::Sender, - port: u16, } #[derive(NetworkBehaviour)] @@ -43,42 +42,25 @@ pub struct Behaviour { #[derive(Debug)] pub enum Message { GetAddresses(oneshot::Sender>), - ListenOn(Multiaddr), + ListenOn(Vec, oneshot::Sender>), } impl RelayNode { pub fn id(&self) -> &PeerId { &self.id } - async fn get_addresses(&mut self) -> Result> { + pub async fn get_addresses(&mut self) -> Result> { let (s, r) = oneshot::channel(); self.sender.send(Message::GetAddresses(s)).await?; Ok(r.await?) } - async fn listen_on(&mut self, addr: impl IntoIterator) -> Result<()> { - Ok(self - .sender - .send_all(&mut iter( - addr.into_iter().map(|a| Ok(Message::ListenOn(a.clone()))), - )) - .await?) - } - - fn _internal(port: u16) -> Multiaddr { - multiaddr!(Memory(port)) - } - - pub fn internal(&self) -> Multiaddr { - Self::_internal(self.port) - } - - fn _external(port: u16) -> Multiaddr { - multiaddr!(Ip4([127, 0, 0, 1]), Tcp(port)) - } - - pub fn external(&self) -> Multiaddr { - Self::_external(self.port) + pub async fn listen_on(&mut self, addr: impl IntoIterator) -> Result<()> { + let (s, r) = oneshot::channel(); + self.sender + .send(Message::ListenOn(addr.into_iter().collect(), s)) + .await?; + r.await? } } @@ -120,7 +102,7 @@ mod builder { } } - pub fn launch(self, keypair: Keypair, transport: T, port: u16) -> Result + pub fn launch(self, keypair: Keypair, transport: T) -> Result where T: IntoTransport, T::T: 'static + Send + Unpin, @@ -134,7 +116,7 @@ mod builder { let id = local_public_key.to_peer_id(); let b = self.build(local_public_key); let (sender, mut reciever) = mpsc::channel(100); - let r = RelayNode { id, sender, port }; + let r = RelayNode { id, sender }; let mut swarm = SwarmBuilder::with_tokio_executor( transport @@ -152,9 +134,6 @@ mod builder { ) .build(); - swarm.listen_on(r.external())?; - swarm.listen_on(r.internal())?; - tokio::spawn(async move { loop { match select(reciever.next(), swarm.next()).await { @@ -164,7 +143,26 @@ mod builder { } // process command Either::Left((Some(e), _)) => match e { - Message::ListenOn(a) => swarm.listen_on(a).map(|_| ())?, + Message::ListenOn(a, s) => { + match a.into_iter().try_fold(Vec::new(), |mut listeners, addr| { + match swarm.listen_on(addr) { + Ok(l) => { + listeners.push(l); + Ok(listeners) + } + Err(e) => Err((e, listeners)), + } + }) { + Ok(_) => s.send(Ok(())), + Err((e, listeners)) => { + for l in listeners { + swarm.remove_listener(l); + } + s.send(Err(e.into())) + } + } + .map_err(|_| anyhow!("failed to return listening result"))? + } Message::GetAddresses(s) => { s.send(swarm.listeners().map(|a| a.clone()).collect()) .map_err(|_| anyhow!("failed to return listeners"))?; diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 9294bca9..8e7cedbd 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -7,7 +7,7 @@ use kepler_lib::{ use libp2p::{ core::PeerId, identity::{ed25519::Keypair as Ed25519Keypair, PublicKey}, - multiaddr::Protocol, + multiaddr::multiaddr, }; use rocket::{ data::{Data, ToByteUnit}, @@ -27,6 +27,7 @@ use tracing::{info_span, Instrument}; use crate::{ auth_guards::{CapAction, DelegateAuthWrapper, InvokeAuthWrapper, KVAction}, authorization::{Capability, Delegation}, + config::Config, kv::{ObjectBuilder, ReadResponse}, p2p::relay::RelayNode, storage::{Content, ImmutableStore}, @@ -92,11 +93,13 @@ pub mod util_routes { } #[get("/peer/relay")] -pub fn relay_addr(relay: &State) -> String { - relay - .external() - .with(Protocol::P2p(relay.id().clone().into())) - .to_string() +pub fn relay_addr(relay: &State, config: &State) -> String { + multiaddr!( + Ip4([127, 0, 0, 1]), + Tcp(config.relay.port), + P2p(relay.id().clone()) + ) + .to_string() } #[get("/peer/generate")] From d505122a4b513b79694ef1465a450f3c72982619 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 23 Nov 2022 12:00:58 +0100 Subject: [PATCH 19/48] comments, add vanilla dns to kepler relay peer --- src/lib.rs | 3 ++- src/p2p/relay.rs | 6 ++++-- src/p2p/transport.rs | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 53942887..afabfa4d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,7 +84,8 @@ pub async fn app(config: &Figment) -> Result> { let mut relay_node = RelayConfig::default().launch( Keypair::Ed25519(kp), - Both::>>::default(), + // transport for memory, dns + tcp and websocket over dns + tcp + Both::, WsConfig>>>::default(), )?; relay_node diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index e0dd3ba8..e8eef532 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -102,7 +102,7 @@ mod builder { } } - pub fn launch(self, keypair: Keypair, transport: T) -> Result + pub fn launch(self, keypair: Keypair, transport: T) -> Result where T: IntoTransport, T::T: 'static + Send + Unpin, @@ -144,6 +144,7 @@ mod builder { // process command Either::Left((Some(e), _)) => match e { Message::ListenOn(a, s) => { + // try listen on each given address match a.into_iter().try_fold(Vec::new(), |mut listeners, addr| { match swarm.listen_on(addr) { Ok(l) => { @@ -154,6 +155,7 @@ mod builder { } }) { Ok(_) => s.send(Ok(())), + // if one fails, roll back all of them Err((e, listeners)) => { for l in listeners { swarm.remove_listener(l); @@ -161,7 +163,7 @@ mod builder { s.send(Err(e.into())) } } - .map_err(|_| anyhow!("failed to return listening result"))? + .map_err(|_| anyhow!("failed to return listening result"))?; } Message::GetAddresses(s) => { s.send(swarm.listeners().map(|a| a.clone()).collect()) diff --git a/src/p2p/transport.rs b/src/p2p/transport.rs index 73366bb5..a046ef98 100644 --- a/src/p2p/transport.rs +++ b/src/p2p/transport.rs @@ -14,6 +14,12 @@ pub trait IntoTransport { type T: Transport; type Error; fn into_transport(self) -> Result; + fn and(self, other: O) -> Both + where + Self: Sized, + { + Both(self, other) + } } pub use dns::{CustomDnsResolver, DnsConfig}; From 60914e141c1700255ba84b79c60d87244652c303 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 23 Nov 2022 12:34:13 +0100 Subject: [PATCH 20/48] remove currently unnecessary modules --- src/p2p/behaviour/builder.rs | 98 ------------------------------------ src/p2p/behaviour/mod.rs | 32 ------------ src/p2p/mod.rs | 1 - src/p2p/relay.rs | 3 -- 4 files changed, 134 deletions(-) delete mode 100644 src/p2p/behaviour/builder.rs delete mode 100644 src/p2p/behaviour/mod.rs diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs deleted file mode 100644 index 37be5402..00000000 --- a/src/p2p/behaviour/builder.rs +++ /dev/null @@ -1,98 +0,0 @@ -use crate::p2p::{behaviour::Behaviour, IdentifyConfig}; -use derive_builder::Builder; -use libp2p::{ - autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, - core::PeerId, - dcutr::behaviour::Behaviour as Dcutr, - gossipsub::{ - Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, - }, - identify::Behaviour as Identify, - identity::Keypair, - kad::{ - record::store::{MemoryStore, MemoryStoreConfig, RecordStore}, - Kademlia, KademliaConfig, - }, - ping::{Behaviour as Ping, Config as PingConfig}, - relay::v2::client::Client, -}; -use thiserror::Error; - -// we use derive_builder here to make a conveniant builder, but we do not export -// the actual config struct -#[derive(Builder)] -#[builder(build_fn(skip), setter(into), name = "BehaviourConfig", derive(Debug))] -pub struct BehaviourConfigDummy -where - KSC: Default, -{ - #[builder(field(type = "IdentifyConfig"))] - identify: IdentifyConfig, - #[builder(field(type = "PingConfig"))] - ping: PingConfig, - #[builder(field(type = "GossipsubConfig"))] - gossipsub: GossipsubConfig, - #[builder(field(type = "KademliaConfig"))] - kademlia: KademliaConfig, - #[builder(field(type = "KSC"))] - kademlia_store: KSC, - #[builder(field(type = "AutoNatConfig"))] - autonat: AutoNatConfig, -} - -impl BehaviourConfig -where - KSC: Default, -{ - pub fn build( - self, - keypair: Keypair, - relay: Option, - ) -> Result, OrbitBehaviourBuildError> - where - KSC: Default + RecordStoreConfig, - KS: RecordStore + Send, - { - let peer_id = keypair.public().to_peer_id(); - Ok(Behaviour { - identify: Identify::new(self.identify.to_config(keypair.public())), - ping: Ping::new(self.ping), - gossipsub: Gossipsub::new( - MessageAuthenticity::Signed(keypair), - GossipsubConfigBuilder::from(self.gossipsub) - // always ensure validation - .validation_mode(ValidationMode::Strict) - .build() - .map_err(OrbitBehaviourBuildError::Gossipsub)?, - ) - .map_err(OrbitBehaviourBuildError::Gossipsub)?, - relay: relay.into(), - kademlia: Kademlia::with_config( - peer_id, - self.kademlia_store.init(peer_id), - self.kademlia, - ), - dcutr: Dcutr::new(peer_id), - autonat: AutoNat::new(peer_id, self.autonat), - }) - } -} - -#[derive(Error, Debug)] -pub enum OrbitBehaviourBuildError { - #[error("{0}")] - Gossipsub(&'static str), -} - -pub trait RecordStoreConfig -where - S: RecordStore, -{ - fn init(self, id: PeerId) -> S; -} - -impl RecordStoreConfig for MemoryStoreConfig { - fn init(self, id: PeerId) -> MemoryStore { - MemoryStore::with_config(id, self) - } -} diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs deleted file mode 100644 index 264d6d79..00000000 --- a/src/p2p/behaviour/mod.rs +++ /dev/null @@ -1,32 +0,0 @@ -use libp2p::{ - autonat::Behaviour as AutoNat, - dcutr::behaviour::Behaviour as Dcutr, - gossipsub::Gossipsub, - identify::Behaviour as Identify, - kad::{ - record::store::{MemoryStore, RecordStore}, - Kademlia, - }, - ping::Behaviour as Ping, - relay::v2::client::Client, - swarm::{behaviour::toggle::Toggle, NetworkBehaviour, Swarm}, -}; - -pub type OrbitSwarm = Swarm>; -mod builder; - -pub use builder::{BehaviourConfig, OrbitBehaviourBuildError}; - -#[derive(NetworkBehaviour)] -pub struct Behaviour -where - KS: RecordStore + Send, -{ - identify: Identify, - ping: Ping, - gossipsub: Gossipsub, - relay: Toggle, - kademlia: Kademlia, - dcutr: Dcutr, - autonat: AutoNat, -} diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index 51258dee..fa723a21 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -1,5 +1,4 @@ use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; -pub mod behaviour; pub mod relay; pub mod transport; diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index e8eef532..230500fb 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -181,6 +181,3 @@ mod builder { } } } - -#[cfg(test)] -pub mod test {} From f3cfcb993154cc953f4f02c8fe2a340aae527f3b Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 23 Nov 2022 13:41:51 +0100 Subject: [PATCH 21/48] remove janky builder derive workaround --- src/p2p/mod.rs | 88 ++++++++++-------- src/p2p/relay.rs | 210 +++++++++++++++++++++---------------------- src/p2p/transport.rs | 181 +++++++++++++++++++------------------ 3 files changed, 248 insertions(+), 231 deletions(-) diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index fa723a21..1b256444 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -1,55 +1,73 @@ +use core::time::Duration; use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; + pub mod relay; pub mod transport; pub const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; -pub use builder::IdentifyConfig; +#[derive(Debug, Clone, Hash, PartialEq, Eq)] +pub struct IdentifyConfig { + protocol_version: String, + initial_delay: Duration, + interval: Duration, + push_listen_addr_updates: bool, + cache_size: usize, +} -mod builder { - use core::time::Duration; - use derive_builder::Builder; - use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; - #[derive(Builder)] - #[builder(build_fn(skip), setter(into), name = "IdentifyConfig", derive(Debug))] - pub struct IdentifyConfigDummy { - #[builder(field(type = "String"), default = "PROTOCOL_VERSION.into()")] - protocol_version: String, - #[builder(field(type = "Duration"), default = "Duration::from_millis(500)")] - initial_delay: Duration, - #[builder(field(type = "Duration"), default = "Duration::from_secs(300)")] - interval: Duration, - #[builder(field(type = "bool"), default = "false")] - push_listen_addr_updates: bool, - #[builder(field(type = "usize"), default = "0")] - cache_size: usize, - } - pub fn to_config(config: IdentifyConfig, key: PublicKey) -> OIdentifyConfig { - OIdentifyConfig::new(config.protocol_version, key) - .with_initial_delay(config.initial_delay) - .with_interval(config.interval) - .with_push_listen_addr_updates(config.push_listen_addr_updates) - .with_cache_size(config.cache_size) - } - pub fn convert(c: OIdentifyConfig) -> IdentifyConfig { - IdentifyConfig { - protocol_version: c.protocol_version, - initial_delay: c.initial_delay, - interval: c.interval, - push_listen_addr_updates: c.push_listen_addr_updates, - cache_size: c.cache_size, +impl IdentifyConfig { + pub fn protocol_version(&mut self, i: impl Into) -> &mut Self { + self.protocol_version = i.into(); + self + } + pub fn initial_delay(&mut self, i: impl Into) -> &mut Self { + self.initial_delay = i.into(); + self + } + pub fn interval(&mut self, i: impl Into) -> &mut Self { + self.interval = i.into(); + self + } + pub fn push_listen_addr_updates(&mut self, i: impl Into) -> &mut Self { + self.push_listen_addr_updates = i.into(); + self + } + pub fn cache_size(&mut self, i: impl Into) -> &mut Self { + self.cache_size = i.into(); + self + } +} + +impl Default for IdentifyConfig { + fn default() -> Self { + Self { + protocol_version: PROTOCOL_VERSION.into(), + initial_delay: Duration::from_millis(500), + interval: Duration::from_secs(300), + push_listen_addr_updates: false, + cache_size: 0, } } } impl IdentifyConfig { fn to_config(self, key: PublicKey) -> OIdentifyConfig { - builder::to_config(self, key) + OIdentifyConfig::new(self.protocol_version, key) + .with_initial_delay(self.initial_delay) + .with_interval(self.interval) + .with_push_listen_addr_updates(self.push_listen_addr_updates) + .with_cache_size(self.cache_size) } } impl From for IdentifyConfig { fn from(c: OIdentifyConfig) -> Self { - builder::convert(c) + IdentifyConfig { + protocol_version: c.protocol_version, + initial_delay: c.initial_delay, + interval: c.interval, + push_listen_addr_updates: c.push_listen_addr_updates, + cache_size: c.cache_size, + } } } diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index 230500fb..788e8541 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -11,18 +11,17 @@ use futures::{ stream::{iter, StreamExt}, }; use libp2p::{ - autonat::Behaviour as AutoNat, - core::{identity::Keypair, upgrade, Multiaddr, PeerId}, + autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, + core::{identity::Keypair, upgrade, Multiaddr, PeerId, Transport}, identify::Behaviour as Identify, + identity::PublicKey, mplex, noise, - ping::Behaviour as Ping, - relay::v2::relay::Relay, + ping::{Behaviour as Ping, Config as PingConfig}, + relay::v2::relay::{Config as RelayConfig, Relay}, swarm::{Swarm, SwarmBuilder, NetworkBehaviour}, yamux, }; -pub use builder::Config; - pub type RelaySwarm = Swarm; #[derive(Clone, Debug)] @@ -64,120 +63,117 @@ impl RelayNode { } } -mod builder { - use super::*; - use derive_builder::Builder; - use libp2p::{ - autonat::Config as AutoNatConfig, core::Transport, identity::PublicKey, - ping::Config as PingConfig, relay::v2::relay::Config as RelayConfig, - }; +#[derive(Debug, Default)] +pub struct Config { + identify: IdentifyConfig, + ping: PingConfig, + relay: RelayConfig, + autonat: AutoNatConfig, +} - #[derive(Builder)] - #[builder( - build_fn(skip), - setter(into), - name = "Config", - derive(Debug), - pattern = "owned" - )] - pub struct BehaviourConfigDummy { - #[builder(field(type = "IdentifyConfig"))] - identify: IdentifyConfig, - #[builder(field(type = "PingConfig"))] - ping: PingConfig, - #[builder(field(type = "RelayConfig"))] - relay: RelayConfig, - #[builder(field(type = "AutoNatConfig"))] - autonat: AutoNatConfig, +impl Config { + pub fn identify(&mut self, i: impl Into) -> &mut Self { + self.identify = i.into(); + self + } + pub fn ping(&mut self, i: impl Into) -> &mut Self { + self.ping = i.into(); + self + } + pub fn relay(&mut self, i: impl Into) -> &mut Self { + self.relay = i.into(); + self + } + pub fn autonat(&mut self, i: impl Into) -> &mut Self { + self.autonat = i.into(); + self } - impl Config { - fn build(self, pubkey: PublicKey) -> Behaviour { - let peer_id = pubkey.to_peer_id(); - Behaviour { - identify: Identify::new(self.identify.to_config(pubkey)), - ping: Ping::new(self.ping), - relay: Relay::new(peer_id, self.relay), - autonat: AutoNat::new(peer_id, self.autonat), - } + fn build(self, pubkey: PublicKey) -> Behaviour { + let peer_id = pubkey.to_peer_id(); + Behaviour { + identify: Identify::new(self.identify.to_config(pubkey)), + ping: Ping::new(self.ping), + relay: Relay::new(peer_id, self.relay), + autonat: AutoNat::new(peer_id, self.autonat), } + } - pub fn launch(self, keypair: Keypair, transport: T) -> Result - where - T: IntoTransport, - T::T: 'static + Send + Unpin, - T::Error: 'static + std::error::Error + Send + Sync, - ::Output: 'static + AsyncRead + AsyncWrite + Unpin + Send, - ::Error: 'static + Send + Sync, - ::Dial: Send, - ::ListenerUpgrade: Send, - { - let local_public_key = keypair.public(); - let id = local_public_key.to_peer_id(); - let b = self.build(local_public_key); - let (sender, mut reciever) = mpsc::channel(100); - let r = RelayNode { id, sender }; + pub fn launch(self, keypair: Keypair, transport: T) -> Result + where + T: IntoTransport, + T::T: 'static + Send + Unpin, + T::Error: 'static + std::error::Error + Send + Sync, + ::Output: 'static + AsyncRead + AsyncWrite + Unpin + Send, + ::Error: 'static + Send + Sync, + ::Dial: Send, + ::ListenerUpgrade: Send, + { + let local_public_key = keypair.public(); + let id = local_public_key.to_peer_id(); + let b = self.build(local_public_key); + let (sender, mut reciever) = mpsc::channel(100); + let r = RelayNode { id, sender }; - let mut swarm = SwarmBuilder::with_tokio_executor( - transport - .into_transport()? - .upgrade(upgrade::Version::V1) - .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) - .multiplex(upgrade::SelectUpgrade::new( - yamux::YamuxConfig::default(), - mplex::MplexConfig::default(), - )) - .timeout(std::time::Duration::from_secs(20)) - .boxed(), - b, - id, - ) - .build(); + let mut swarm = SwarmBuilder::with_tokio_executor( + transport + .into_transport()? + .upgrade(upgrade::Version::V1) + .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) + .multiplex(upgrade::SelectUpgrade::new( + yamux::YamuxConfig::default(), + mplex::MplexConfig::default(), + )) + .timeout(std::time::Duration::from_secs(20)) + .boxed(), + b, + id, + ) + .build(); - tokio::spawn(async move { - loop { - match select(reciever.next(), swarm.next()).await { - // if the swarm or the channel are closed, close the relay - Either::Right((None, _)) | Either::Left((None, _)) => { - break; - } - // process command - Either::Left((Some(e), _)) => match e { - Message::ListenOn(a, s) => { - // try listen on each given address - match a.into_iter().try_fold(Vec::new(), |mut listeners, addr| { - match swarm.listen_on(addr) { - Ok(l) => { - listeners.push(l); - Ok(listeners) - } - Err(e) => Err((e, listeners)), + tokio::spawn(async move { + loop { + match select(reciever.next(), swarm.next()).await { + // if the swarm or the channel are closed, close the relay + Either::Right((None, _)) | Either::Left((None, _)) => { + break; + } + // process command + Either::Left((Some(e), _)) => match e { + Message::ListenOn(a, s) => { + // try listen on each given address + match a.into_iter().try_fold(Vec::new(), |mut listeners, addr| { + match swarm.listen_on(addr) { + Ok(l) => { + listeners.push(l); + Ok(listeners) } - }) { - Ok(_) => s.send(Ok(())), - // if one fails, roll back all of them - Err((e, listeners)) => { - for l in listeners { - swarm.remove_listener(l); - } - s.send(Err(e.into())) + Err(e) => Err((e, listeners)), + } + }) { + Ok(_) => s.send(Ok(())), + // if one fails, roll back all of them + Err((e, listeners)) => { + for l in listeners { + swarm.remove_listener(l); } + s.send(Err(e.into())) } - .map_err(|_| anyhow!("failed to return listening result"))?; - } - Message::GetAddresses(s) => { - s.send(swarm.listeners().map(|a| a.clone()).collect()) - .map_err(|_| anyhow!("failed to return listeners"))?; } - }, - Either::Right((Some(e), _)) => { - // process swarm event + .map_err(|_| anyhow!("failed to return listening result"))?; } + Message::GetAddresses(s) => { + s.send(swarm.listeners().map(|a| a.clone()).collect()) + .map_err(|_| anyhow!("failed to return listeners"))?; + } + }, + Either::Right((Some(e), _)) => { + // process swarm event } } - Result::<(), anyhow::Error>::Ok(()) - }); - Ok(r) - } + } + Result::<(), anyhow::Error>::Ok(()) + }); + Ok(r) } } diff --git a/src/p2p/transport.rs b/src/p2p/transport.rs index a046ef98..c4b27aa9 100644 --- a/src/p2p/transport.rs +++ b/src/p2p/transport.rs @@ -1,5 +1,4 @@ use crate::storage::either::EitherError; -use derive_builder::Builder; use futures::io::{AsyncRead, AsyncWrite}; use libp2p::{ core::transport::{dummy::DummyTransport, MemoryTransport, OrTransport, Transport}, @@ -22,10 +21,8 @@ pub trait IntoTransport { } } -pub use dns::{CustomDnsResolver, DnsConfig}; pub use libp2p::tcp::GenTcpConfig as TcpConfig; pub use libp2p::wasm_ext::ffi::Transport as ExtConfig; -pub use ws::{WsConfig, WS_MAX_DATA_SIZE}; #[derive(Default, Debug, Clone, Hash, PartialEq, Eq)] pub struct MemoryConfig; @@ -63,54 +60,37 @@ impl Default for DnsResolver { } } -mod dns { - use super::*; - #[derive(Builder)] - #[builder( - build_fn(skip), - setter(into), - derive(Debug), - name = "CustomDnsResolver" - )] - pub struct CustomDnsResolverDummy { - #[builder(field(type = "ResolverConfig"))] - conf: ResolverConfig, - #[builder(field(type = "ResolverOpts"))] - opts: ResolverOpts, - } +#[derive(Debug, Clone, PartialEq, Eq, Default)] +pub struct CustomDnsResolver { + conf: ResolverConfig, + opts: ResolverOpts, +} - #[derive(Builder)] - #[builder(build_fn(skip), setter(into), derive(Debug), name = "DnsConfig")] - pub struct DnsConfigDummy - where - B: Default, - { - #[builder(field(type = "DnsResolver"))] - resolver: DnsResolver, - #[builder(field(type = "B"))] - base: B, +impl CustomDnsResolver { + pub fn config(&mut self, i: impl Into) -> &mut Self { + self.conf = i.into(); + self + } + pub fn options(&mut self, i: impl Into) -> &mut Self { + self.opts = i.into(); + self } +} - pub fn convert(c: DnsConfig) -> Result, EitherError> - where - B: Default + IntoTransport, - B::T: 'static + Send + Unpin, - ::Output: 'static + AsyncRead + AsyncWrite + Send + Unpin, - ::Dial: Send, - ::Error: Send, - { - match c.resolver { - DnsResolver::System => { - DnsTransport::system(c.base.into_transport().map_err(EitherError::B)?) - .map_err(EitherError::A) - } - DnsResolver::Custom(custom) => DnsTransport::custom( - c.base.into_transport().map_err(EitherError::B)?, - custom.conf, - custom.opts, - ) - .map_err(EitherError::A), - } +#[derive(Debug, Clone, Default)] +pub struct DnsConfig { + resolver: DnsResolver, + base: B, +} + +impl DnsConfig { + pub fn resolver(&mut self, i: impl Into) -> &mut Self { + self.resolver = i.into(); + self + } + pub fn base(&mut self, i: impl Into) -> &mut Self { + self.base = i.into(); + self } } @@ -125,52 +105,70 @@ where type T = DnsTransport; type Error = EitherError; fn into_transport(self) -> Result { - dns::convert(self) + match self.resolver { + DnsResolver::System => { + DnsTransport::system(self.base.into_transport().map_err(EitherError::B)?) + .map_err(EitherError::A) + } + DnsResolver::Custom(custom) => DnsTransport::custom( + self.base.into_transport().map_err(EitherError::B)?, + custom.conf, + custom.opts, + ) + .map_err(EitherError::A), + } } } -mod ws { - use super::*; - pub const WS_MAX_DATA_SIZE: usize = 256 * 1024 * 1024; +pub const WS_MAX_DATA_SIZE: usize = 256 * 1024 * 1024; + +#[derive(Debug, Clone)] +pub struct WsConfig { + base: T, + max_redirects: u8, + max_data_size: usize, + deflate: bool, + tls: WsTlsConfig, +} - fn client() -> WsTlsConfig { - WsTlsConfig::client() +impl WsConfig { + pub fn from_base(b: impl Into) -> Self { + Self { + base: b.into(), + max_redirects: 0, + max_data_size: WS_MAX_DATA_SIZE, + deflate: false, + tls: WsTlsConfig::client(), + } + } + pub fn base(&mut self, i: impl Into) -> &mut Self { + self.base = i.into(); + self + } + pub fn max_redirects(&mut self, i: impl Into) -> &mut Self { + self.max_redirects = i.into(); + self + } + pub fn max_data_size(&mut self, i: impl Into) -> &mut Self { + self.max_data_size = i.into(); + self + } + pub fn deflate(&mut self, i: impl Into) -> &mut Self { + self.deflate = i.into(); + self } + pub fn tls(&mut self, i: impl Into) -> &mut Self { + self.tls = i.into(); + self + } +} - #[derive(Builder)] - #[builder(build_fn(skip), setter(into), derive(Debug), name = "WsConfig")] - pub struct WsConfigDummy - where - T: Default, - { - #[builder(field(type = "T"))] - base: T, - #[builder(field(type = "u8"), default = "0")] - max_redirects: u8, - #[builder(field(type = "usize"), default = "WS_MAX_DATA_SIZE")] - max_data_size: usize, - #[builder(field(type = "bool"), default = "false")] - deflate: bool, - // TODO this is cause some kind of error cos it has no Default - // #[builder(field(type = "WsTlsConfig"), default = "client()")] - // tls: WsTlsConfig, - } - - pub fn convert(c: WsConfig) -> Result, B::Error> - where - B: Default + IntoTransport, - B::T: 'static + Send + Unpin, - ::Output: 'static + AsyncRead + AsyncWrite + Send + Unpin, - ::Dial: Send, - ::Error: Send, - ::ListenerUpgrade: Send, - { - let mut ws = WsTransport::new(c.base.into_transport()?); - ws.set_max_redirects(c.max_redirects) - .set_max_data_size(c.max_data_size) - // .set_tls_config(c.tls) - .use_deflate(c.deflate); - Ok(ws) +impl Default for WsConfig +where + T: Default, +{ + fn default() -> Self { + Self::from_base(T::default()) } } @@ -186,7 +184,12 @@ where type T = WsTransport; type Error = B::Error; fn into_transport(self) -> Result { - ws::convert(self) + let mut ws = WsTransport::new(self.base.into_transport()?); + ws.set_max_redirects(self.max_redirects) + .set_max_data_size(self.max_data_size) + .set_tls_config(self.tls) + .use_deflate(self.deflate); + Ok(ws) } } From 44349448a044a3d2748966ef6c8f553744af35d2 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 23 Nov 2022 13:43:15 +0100 Subject: [PATCH 22/48] warnings --- src/authorization.rs | 6 +++--- src/orbit.rs | 2 +- src/p2p/relay.rs | 9 +++------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/authorization.rs b/src/authorization.rs index 1097052b..43d27e00 100644 --- a/src/authorization.rs +++ b/src/authorization.rs @@ -514,7 +514,7 @@ mod test { }, }; - async fn gen( + async fn _gen( iss: &JWK, aud: String, caps: Vec, @@ -530,10 +530,10 @@ mod test { .await .1 .unwrap(), - gen_ucan((iss, did), aud, caps, exp, prf).await, + _gen_ucan((iss, did), aud, caps, exp, prf).await, ) } - async fn gen_ucan( + async fn _gen_ucan( iss: (&JWK, String), audience: String, attenuation: Vec, diff --git a/src/orbit.rs b/src/orbit.rs index ece9934d..305c23ef 100644 --- a/src/orbit.rs +++ b/src/orbit.rs @@ -284,6 +284,6 @@ mod tests { let md = Manifest::resolve_dyn(&oid, None).await.unwrap().unwrap(); - let (orbit, dir) = op(md).await.unwrap(); + let (_, _) = op(md).await.unwrap(); } } diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index 788e8541..4572f545 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -1,14 +1,11 @@ -use crate::{ - orbit::AbortOnDrop, - p2p::{transport::IntoTransport, IdentifyConfig}, -}; +use crate::p2p::{transport::IntoTransport, IdentifyConfig}; use anyhow::Result; use futures::{ channel::{mpsc, oneshot}, future::{select, Either}, io::{AsyncRead, AsyncWrite}, sink::SinkExt, - stream::{iter, StreamExt}, + stream::StreamExt, }; use libp2p::{ autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, @@ -167,7 +164,7 @@ impl Config { .map_err(|_| anyhow!("failed to return listeners"))?; } }, - Either::Right((Some(e), _)) => { + Either::Right((Some(_), _)) => { // process swarm event } } From 1fc7ee59de138bbf6b6e2d78794ad65d9ea1cb54 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 30 Nov 2022 12:39:34 +0100 Subject: [PATCH 23/48] minor cleanup, update to libp2p 0.50 --- src/cas.rs | 31 ------------------------------- src/lib.rs | 1 - src/p2p/relay.rs | 4 +--- src/p2p/transport.rs | 14 ++++++++++---- 4 files changed, 11 insertions(+), 39 deletions(-) delete mode 100644 src/cas.rs diff --git a/src/cas.rs b/src/cas.rs deleted file mode 100644 index 437be14d..00000000 --- a/src/cas.rs +++ /dev/null @@ -1,31 +0,0 @@ -use anyhow::Result; -use kepler_lib::libipld::cid::Cid; -use rocket::{ - form::{DataField, FromFormField}, - request::FromParam, -}; -use std::str::FromStr; - -#[derive(PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct CidWrap(pub Cid); - -// Orphan rule requires a wrapper type for this :( -impl<'a> FromParam<'a> for CidWrap { - type Error = anyhow::Error; - fn from_param(param: &'a str) -> Result { - Ok(CidWrap(Cid::from_str(param)?)) - } -} - -#[rocket::async_trait] -impl<'r> FromFormField<'r> for CidWrap { - async fn from_data(field: DataField<'r, '_>) -> rocket::form::Result<'r, Self> { - Ok(CidWrap( - field - .name - .source() - .parse() - .map_err(|_| field.unexpected())?, - )) - } -} diff --git a/src/lib.rs b/src/lib.rs index afabfa4d..08f42ebe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,6 @@ pub mod allow_list; pub mod auth_guards; pub mod authorization; pub mod capabilities; -pub mod cas; pub mod config; pub mod indexes; pub mod kv; diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index 4572f545..eafd0e55 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -15,12 +15,10 @@ use libp2p::{ mplex, noise, ping::{Behaviour as Ping, Config as PingConfig}, relay::v2::relay::{Config as RelayConfig, Relay}, - swarm::{Swarm, SwarmBuilder, NetworkBehaviour}, + swarm::{SwarmBuilder, NetworkBehaviour}, yamux, }; -pub type RelaySwarm = Swarm; - #[derive(Clone, Debug)] pub struct RelayNode { id: PeerId, diff --git a/src/p2p/transport.rs b/src/p2p/transport.rs index c4b27aa9..45c4cd58 100644 --- a/src/p2p/transport.rs +++ b/src/p2p/transport.rs @@ -84,6 +84,12 @@ pub struct DnsConfig { } impl DnsConfig { + pub fn new(i: impl Into) -> Self { + Self { + base: i.into(), + resolver: Default::default(), + } + } pub fn resolver(&mut self, i: impl Into) -> &mut Self { self.resolver = i.into(); self @@ -96,7 +102,7 @@ impl DnsConfig { impl IntoTransport for DnsConfig where - B: Default + IntoTransport, + B: IntoTransport, B::T: 'static + Send + Unpin, ::Output: 'static + AsyncRead + AsyncWrite + Send + Unpin, ::Dial: Send, @@ -132,7 +138,7 @@ pub struct WsConfig { } impl WsConfig { - pub fn from_base(b: impl Into) -> Self { + pub fn new(b: impl Into) -> Self { Self { base: b.into(), max_redirects: 0, @@ -168,13 +174,13 @@ where T: Default, { fn default() -> Self { - Self::from_base(T::default()) + Self::new(T::default()) } } impl IntoTransport for WsConfig where - B: Default + IntoTransport, + B: IntoTransport, B::T: 'static + Send + Unpin, ::Output: 'static + AsyncRead + AsyncWrite + Send + Unpin, ::Dial: Send, From ea1b72de784d489f0531779ea56e524b573c14f8 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 30 Nov 2022 12:39:52 +0100 Subject: [PATCH 24/48] copy request-response protocol crate to kepler --- Cargo.toml | 4 +- exchange-protocol/CHANGELOG.md | 190 +++++ exchange-protocol/Cargo.toml | 33 + exchange-protocol/src/codec.rs | 80 ++ exchange-protocol/src/handler.rs | 427 ++++++++++ exchange-protocol/src/handler/protocol.rs | 189 +++++ exchange-protocol/src/lib.rs | 939 ++++++++++++++++++++++ exchange-protocol/tests/ping.rs | 388 +++++++++ 8 files changed, 2248 insertions(+), 2 deletions(-) create mode 100644 exchange-protocol/CHANGELOG.md create mode 100644 exchange-protocol/Cargo.toml create mode 100644 exchange-protocol/src/codec.rs create mode 100644 exchange-protocol/src/handler.rs create mode 100644 exchange-protocol/src/handler/protocol.rs create mode 100644 exchange-protocol/src/lib.rs create mode 100644 exchange-protocol/tests/ping.rs diff --git a/Cargo.toml b/Cargo.toml index 3677a69f..d924acb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,11 +58,11 @@ percent-encoding = "2.1" path = "lib/" [workspace] - members = [ "lib", "sdk-wasm", - "sdk" + "sdk", + "exchange-protocol" ] exclude = [ diff --git a/exchange-protocol/CHANGELOG.md b/exchange-protocol/CHANGELOG.md new file mode 100644 index 00000000..a97d2400 --- /dev/null +++ b/exchange-protocol/CHANGELOG.md @@ -0,0 +1,190 @@ +# 0.23.0 + +- Update to `libp2p-core` `v0.38.0`. + +- Update to `libp2p-swarm` `v0.41.0`. + +- Replace `RequestResponse`'s `NetworkBehaviour` implemention `inject_*` methods with the new `on_*` methods. + See [PR 3011]. + +- Replace `RequestResponseHandler`'s `ConnectionHandler` implemention `inject_*` methods + with the new `on_*` methods. See [PR 3085]. + +- Update `rust-version` to reflect the actual MSRV: 1.62.0. See [PR 3090]. + +[PR 3085]: https://github.com/libp2p/rust-libp2p/pull/3085 +[PR 3011]: https://github.com/libp2p/rust-libp2p/pull/3011 +[PR 3090]: https://github.com/libp2p/rust-libp2p/pull/3090 + +# 0.22.0 + +- Bump rand to 0.8 and quickcheck to 1. See [PR 2857]. + +- Update to `libp2p-core` `v0.37.0`. + +- Update to `libp2p-swarm` `v0.40.0`. + +[PR 2857]: https://github.com/libp2p/rust-libp2p/pull/2857 + +# 0.21.0 + +- Update to `libp2p-swarm` `v0.39.0`. + +- Update to `libp2p-core` `v0.36.0`. + +# 0.20.0 + +- Update to `libp2p-swarm` `v0.38.0`. + +- Update to `libp2p-core` `v0.35.0`. + +# 0.19.0 + +- Update to `libp2p-core` `v0.34.0`. + +- Update to `libp2p-swarm` `v0.37.0`. + +# 0.18.0 + +- Update to `libp2p-core` `v0.33.0`. + +- Update to `libp2p-swarm` `v0.36.0`. + +# 0.17.0 + +- Update to `libp2p-swarm` `v0.35.0`. + +# 0.16.0 [2022-02-22] + +- Update to `libp2p-core` `v0.32.0`. + +- Update to `libp2p-swarm` `v0.34.0`. + +- Merge NetworkBehaviour's inject_\* paired methods (see PR 2445). + +[PR 2445]: https://github.com/libp2p/rust-libp2p/pull/2445 + +# 0.15.0 [2022-01-27] + +- Update dependencies. + +- Remove unused `lru` crate (see [PR 2358]). + +- Migrate to Rust edition 2021 (see [PR 2339]). + +[PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339 +[PR 2358]: https://github.com/libp2p/rust-libp2p/pull/2358 + +# 0.14.0 [2021-11-16] + +- Use `instant` instead of `wasm-timer` (see [PR 2245]). + +- Update dependencies. + +[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 + +# 0.13.0 [2021-11-01] + +- Make default features of `libp2p-core` optional. + [PR 2181](https://github.com/libp2p/rust-libp2p/pull/2181) + +- Update dependencies. + +- Manually implement `Debug` for `RequestResponseHandlerEvent` and + `RequestProtocol`. See [PR 2183]. + +- Remove `RequestResponse::throttled` and the `throttled` module. + See [PR 2236]. + +[PR 2183]: https://github.com/libp2p/rust-libp2p/pull/2183 +[PR 2236]: https://github.com/libp2p/rust-libp2p/pull/2236 + +# 0.12.0 [2021-07-12] + +- Update dependencies. + +# 0.11.0 [2021-04-13] + +- Update `libp2p-swarm`. +- Implement `std::error::Error` for `InboundFailure` and `OutboundFailure` [PR + 2033](https://github.com/libp2p/rust-libp2p/pull/2033). + +# 0.10.0 [2021-03-17] + +- Update `libp2p-swarm`. + +- Close stream even when no response has been sent. + [PR 1987](https://github.com/libp2p/rust-libp2p/pull/1987). + +- Update dependencies. + +# 0.9.1 [2021-02-15] + +- Make `is_pending_outbound` return true on pending connection. + [PR 1928](https://github.com/libp2p/rust-libp2p/pull/1928). + +- Update dependencies. + +# 0.9.0 [2021-01-12] + +- Update dependencies. + +- Re-export `throttled`-specific response channel. [PR + 1902](https://github.com/libp2p/rust-libp2p/pull/1902). + +# 0.8.0 [2020-12-17] + +- Update `libp2p-swarm` and `libp2p-core`. + +- Emit `InboundFailure::ConnectionClosed` for inbound requests that failed due + to the underlying connection closing. + [PR 1886](https://github.com/libp2p/rust-libp2p/pull/1886). + +- Derive Clone for `InboundFailure` and `Outbound}Failure`. + [PR 1891](https://github.com/libp2p/rust-libp2p/pull/1891) + +# 0.7.0 [2020-12-08] + +- Refine emitted events for inbound requests, introducing + the `ResponseSent` event and the `ResponseOmission` + inbound failures. This effectively removes previous + support for one-way protocols without responses. + [PR 1867](https://github.com/libp2p/rust-libp2p/pull/1867). + +# 0.6.0 [2020-11-25] + +- Update `libp2p-swarm` and `libp2p-core`. + +# 0.5.0 [2020-11-09] + +- Update dependencies. + +# 0.4.0 [2020-10-16] + +- Update dependencies. + +# 0.3.0 [2020-09-09] + +- Add support for opt-in request-based flow-control to any + request-response protocol via `RequestResponse::throttled()`. + [PR 1726](https://github.com/libp2p/rust-libp2p/pull/1726). + +- Update `libp2p-swarm` and `libp2p-core`. + +# 0.2.0 [2020-08-18] + +- Fixed connection keep-alive, permitting connections to close due + to inactivity. +- Bump `libp2p-core` and `libp2p-swarm` dependencies. + +# 0.1.1 + +- Always properly `close()` the substream after sending requests and +responses in the `InboundUpgrade` and `OutboundUpgrade`. Otherwise this is +left to `RequestResponseCodec::write_request` and `RequestResponseCodec::write_response`, +which can be a pitfall and lead to subtle problems (see e.g. +https://github.com/libp2p/rust-libp2p/pull/1606). + +# 0.1.0 + +- Initial release. diff --git a/exchange-protocol/Cargo.toml b/exchange-protocol/Cargo.toml new file mode 100644 index 00000000..216a21df --- /dev/null +++ b/exchange-protocol/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "exchange-protocol" +edition = "2021" +rust-version = "1.65.0" +description = "Streaming Request/Response Protocols" +version = "0.1.0" +authors = ["Parity Technologies "] +license = "MIT" +keywords = ["peer-to-peer", "libp2p", "networking"] +categories = ["network-programming", "asynchronous"] + +[dependencies] +async-trait = "0.1" +bytes = "1" +futures = { default-features = false, version = "0.3", features = ["alloc", "std"] } +instant = "0.1.11" +libp2p = { default-features = false, version = "0.50.0" } +log = "0.4.11" +rand = "0.8" +smallvec = "1.6.1" +unsigned-varint = { version = "0.7", features = ["std", "futures"] } + +[dev-dependencies] +async-std = "1.6.2" +env_logger = "0.9.0" +rand = "0.8" + +# Passing arguments to the docsrs builder in order to properly document cfg's. +# More information: https://docs.rs/about/builds#cross-compiling +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] +rustc-args = ["--cfg", "docsrs"] diff --git a/exchange-protocol/src/codec.rs b/exchange-protocol/src/codec.rs new file mode 100644 index 00000000..96cc93db --- /dev/null +++ b/exchange-protocol/src/codec.rs @@ -0,0 +1,80 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +pub use libp2p::core::ProtocolName; + +use async_trait::async_trait; +use futures::prelude::*; +use std::io; + +/// A `RequestResponseCodec` defines the request and response types +/// for a [`RequestResponse`](crate::RequestResponse) protocol or +/// protocol family and how they are encoded / decoded on an I/O stream. +#[async_trait] +pub trait RequestResponseCodec { + /// The type of protocol(s) or protocol versions being negotiated. + type Protocol: ProtocolName + Send + Clone; + /// The type of inbound and outbound requests. + type Request: Send; + /// The type of inbound and outbound responses. + type Response: Send; + + /// Reads a request from the given I/O stream according to the + /// negotiated protocol. + async fn read_request( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + ) -> io::Result + where + T: AsyncRead + Unpin + Send; + + /// Reads a response from the given I/O stream according to the + /// negotiated protocol. + async fn read_response( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + ) -> io::Result + where + T: AsyncRead + Unpin + Send; + + /// Writes a request to the given I/O stream according to the + /// negotiated protocol. + async fn write_request( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + req: Self::Request, + ) -> io::Result<()> + where + T: AsyncWrite + Unpin + Send; + + /// Writes a response to the given I/O stream according to the + /// negotiated protocol. + async fn write_response( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + res: Self::Response, + ) -> io::Result<()> + where + T: AsyncWrite + Unpin + Send; +} diff --git a/exchange-protocol/src/handler.rs b/exchange-protocol/src/handler.rs new file mode 100644 index 00000000..99ab4a29 --- /dev/null +++ b/exchange-protocol/src/handler.rs @@ -0,0 +1,427 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +mod protocol; + +use crate::codec::RequestResponseCodec; +use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD}; + +use libp2p::swarm::handler::{ + ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, + ListenUpgradeError, +}; +pub use protocol::{ProtocolSupport, RequestProtocol, ResponseProtocol}; + +use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered}; +use instant::Instant; +use libp2p::core::upgrade::{NegotiationError, UpgradeError}; +use libp2p::swarm::{ + handler::{ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive}, + SubstreamProtocol, +}; +use smallvec::SmallVec; +use std::{ + collections::VecDeque, + fmt, io, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, + }, + task::{Context, Poll}, + time::Duration, +}; + +/// A connection handler of a `RequestResponse` protocol. +#[doc(hidden)] +pub struct RequestResponseHandler +where + TCodec: RequestResponseCodec, +{ + /// The supported inbound protocols. + inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, + /// The request/response message codec. + codec: TCodec, + /// The keep-alive timeout of idle connections. A connection is considered + /// idle if there are no outbound substreams. + keep_alive_timeout: Duration, + /// The timeout for inbound and outbound substreams (i.e. request + /// and response processing). + substream_timeout: Duration, + /// The current connection keep-alive. + keep_alive: KeepAlive, + /// A pending fatal error that results in the connection being closed. + pending_error: Option>, + /// Queue of events to emit in `poll()`. + pending_events: VecDeque>, + /// Outbound upgrades waiting to be emitted as an `OutboundSubstreamRequest`. + outbound: VecDeque>, + /// Inbound upgrades waiting for the incoming request. + inbound: FuturesUnordered< + BoxFuture< + 'static, + Result< + ( + (RequestId, TCodec::Request), + oneshot::Sender, + ), + oneshot::Canceled, + >, + >, + >, + inbound_request_id: Arc, +} + +impl RequestResponseHandler +where + TCodec: RequestResponseCodec + Send + Clone + 'static, +{ + pub(super) fn new( + inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, + codec: TCodec, + keep_alive_timeout: Duration, + substream_timeout: Duration, + inbound_request_id: Arc, + ) -> Self { + Self { + inbound_protocols, + codec, + keep_alive: KeepAlive::Yes, + keep_alive_timeout, + substream_timeout, + outbound: VecDeque::new(), + inbound: FuturesUnordered::new(), + pending_events: VecDeque::new(), + pending_error: None, + inbound_request_id, + } + } + + fn on_fully_negotiated_inbound( + &mut self, + FullyNegotiatedInbound { + protocol: sent, + info: request_id, + }: FullyNegotiatedInbound< + ::InboundProtocol, + ::InboundOpenInfo, + >, + ) { + if sent { + self.pending_events + .push_back(RequestResponseHandlerEvent::ResponseSent(request_id)) + } else { + self.pending_events + .push_back(RequestResponseHandlerEvent::ResponseOmission(request_id)) + } + } + + fn on_dial_upgrade_error( + &mut self, + DialUpgradeError { info, error }: DialUpgradeError< + ::OutboundOpenInfo, + ::OutboundProtocol, + >, + ) { + match error { + ConnectionHandlerUpgrErr::Timeout => { + self.pending_events + .push_back(RequestResponseHandlerEvent::OutboundTimeout(info)); + } + ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => { + // The remote merely doesn't support the protocol(s) we requested. + // This is no reason to close the connection, which may + // successfully communicate with other protocols already. + // An event is reported to permit user code to react to the fact that + // the remote peer does not support the requested protocol(s). + self.pending_events.push_back( + RequestResponseHandlerEvent::OutboundUnsupportedProtocols(info), + ); + } + _ => { + // Anything else is considered a fatal error or misbehaviour of + // the remote peer and results in closing the connection. + self.pending_error = Some(error); + } + } + } + fn on_listen_upgrade_error( + &mut self, + ListenUpgradeError { info, error }: ListenUpgradeError< + ::InboundOpenInfo, + ::InboundProtocol, + >, + ) { + match error { + ConnectionHandlerUpgrErr::Timeout => self + .pending_events + .push_back(RequestResponseHandlerEvent::InboundTimeout(info)), + ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => { + // The local peer merely doesn't support the protocol(s) requested. + // This is no reason to close the connection, which may + // successfully communicate with other protocols already. + // An event is reported to permit user code to react to the fact that + // the local peer does not support the requested protocol(s). + self.pending_events.push_back( + RequestResponseHandlerEvent::InboundUnsupportedProtocols(info), + ); + } + _ => { + // Anything else is considered a fatal error or misbehaviour of + // the remote peer and results in closing the connection. + self.pending_error = Some(error); + } + } + } +} + +/// The events emitted by the [`RequestResponseHandler`]. +#[doc(hidden)] +pub enum RequestResponseHandlerEvent +where + TCodec: RequestResponseCodec, +{ + /// A request has been received. + Request { + request_id: RequestId, + request: TCodec::Request, + sender: oneshot::Sender, + }, + /// A response has been received. + Response { + request_id: RequestId, + response: TCodec::Response, + }, + /// A response to an inbound request has been sent. + ResponseSent(RequestId), + /// A response to an inbound request was omitted as a result + /// of dropping the response `sender` of an inbound `Request`. + ResponseOmission(RequestId), + /// An outbound request timed out while sending the request + /// or waiting for the response. + OutboundTimeout(RequestId), + /// An outbound request failed to negotiate a mutually supported protocol. + OutboundUnsupportedProtocols(RequestId), + /// An inbound request timed out while waiting for the request + /// or sending the response. + InboundTimeout(RequestId), + /// An inbound request failed to negotiate a mutually supported protocol. + InboundUnsupportedProtocols(RequestId), +} + +impl fmt::Debug for RequestResponseHandlerEvent { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + RequestResponseHandlerEvent::Request { + request_id, + request: _, + sender: _, + } => f + .debug_struct("RequestResponseHandlerEvent::Request") + .field("request_id", request_id) + .finish(), + RequestResponseHandlerEvent::Response { + request_id, + response: _, + } => f + .debug_struct("RequestResponseHandlerEvent::Response") + .field("request_id", request_id) + .finish(), + RequestResponseHandlerEvent::ResponseSent(request_id) => f + .debug_tuple("RequestResponseHandlerEvent::ResponseSent") + .field(request_id) + .finish(), + RequestResponseHandlerEvent::ResponseOmission(request_id) => f + .debug_tuple("RequestResponseHandlerEvent::ResponseOmission") + .field(request_id) + .finish(), + RequestResponseHandlerEvent::OutboundTimeout(request_id) => f + .debug_tuple("RequestResponseHandlerEvent::OutboundTimeout") + .field(request_id) + .finish(), + RequestResponseHandlerEvent::OutboundUnsupportedProtocols(request_id) => f + .debug_tuple("RequestResponseHandlerEvent::OutboundUnsupportedProtocols") + .field(request_id) + .finish(), + RequestResponseHandlerEvent::InboundTimeout(request_id) => f + .debug_tuple("RequestResponseHandlerEvent::InboundTimeout") + .field(request_id) + .finish(), + RequestResponseHandlerEvent::InboundUnsupportedProtocols(request_id) => f + .debug_tuple("RequestResponseHandlerEvent::InboundUnsupportedProtocols") + .field(request_id) + .finish(), + } + } +} + +impl ConnectionHandler for RequestResponseHandler +where + TCodec: RequestResponseCodec + Send + Clone + 'static, +{ + type InEvent = RequestProtocol; + type OutEvent = RequestResponseHandlerEvent; + type Error = ConnectionHandlerUpgrErr; + type InboundProtocol = ResponseProtocol; + type OutboundProtocol = RequestProtocol; + type OutboundOpenInfo = RequestId; + type InboundOpenInfo = RequestId; + + fn listen_protocol(&self) -> SubstreamProtocol { + // A channel for notifying the handler when the inbound + // upgrade received the request. + let (rq_send, rq_recv) = oneshot::channel(); + + // A channel for notifying the inbound upgrade when the + // response is sent. + let (rs_send, rs_recv) = oneshot::channel(); + + let request_id = RequestId(self.inbound_request_id.fetch_add(1, Ordering::Relaxed)); + + // By keeping all I/O inside the `ResponseProtocol` and thus the + // inbound substream upgrade via above channels, we ensure that it + // is all subject to the configured timeout without extra bookkeeping + // for inbound substreams as well as their timeouts and also make the + // implementation of inbound and outbound upgrades symmetric in + // this sense. + let proto = ResponseProtocol { + protocols: self.inbound_protocols.clone(), + codec: self.codec.clone(), + request_sender: rq_send, + response_receiver: rs_recv, + request_id, + }; + + // The handler waits for the request to come in. It then emits + // `RequestResponseHandlerEvent::Request` together with a + // `ResponseChannel`. + self.inbound + .push(rq_recv.map_ok(move |rq| (rq, rs_send)).boxed()); + + SubstreamProtocol::new(proto, request_id).with_timeout(self.substream_timeout) + } + + fn on_behaviour_event(&mut self, request: Self::InEvent) { + self.keep_alive = KeepAlive::Yes; + self.outbound.push_back(request); + } + + fn connection_keep_alive(&self) -> KeepAlive { + self.keep_alive + } + + fn poll( + &mut self, + cx: &mut Context<'_>, + ) -> Poll, RequestId, Self::OutEvent, Self::Error>> + { + // Check for a pending (fatal) error. + if let Some(err) = self.pending_error.take() { + // The handler will not be polled again by the `Swarm`. + return Poll::Ready(ConnectionHandlerEvent::Close(err)); + } + + // Drain pending events. + if let Some(event) = self.pending_events.pop_front() { + return Poll::Ready(ConnectionHandlerEvent::Custom(event)); + } else if self.pending_events.capacity() > EMPTY_QUEUE_SHRINK_THRESHOLD { + self.pending_events.shrink_to_fit(); + } + + // Check for inbound requests. + while let Poll::Ready(Some(result)) = self.inbound.poll_next_unpin(cx) { + match result { + Ok(((id, rq), rs_sender)) => { + // We received an inbound request. + self.keep_alive = KeepAlive::Yes; + return Poll::Ready(ConnectionHandlerEvent::Custom( + RequestResponseHandlerEvent::Request { + request_id: id, + request: rq, + sender: rs_sender, + }, + )); + } + Err(oneshot::Canceled) => { + // The inbound upgrade has errored or timed out reading + // or waiting for the request. The handler is informed + // via `inject_listen_upgrade_error`. + } + } + } + + // Emit outbound requests. + if let Some(request) = self.outbound.pop_front() { + let info = request.request_id; + return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { + protocol: SubstreamProtocol::new(request, info) + .with_timeout(self.substream_timeout), + }); + } + + debug_assert!(self.outbound.is_empty()); + + if self.outbound.capacity() > EMPTY_QUEUE_SHRINK_THRESHOLD { + self.outbound.shrink_to_fit(); + } + + if self.inbound.is_empty() && self.keep_alive.is_yes() { + // No new inbound or outbound requests. However, we may just have + // started the latest inbound or outbound upgrade(s), so make sure + // the keep-alive timeout is preceded by the substream timeout. + let until = Instant::now() + self.substream_timeout + self.keep_alive_timeout; + self.keep_alive = KeepAlive::Until(until); + } + + Poll::Pending + } + + fn on_connection_event( + &mut self, + event: ConnectionEvent< + Self::InboundProtocol, + Self::OutboundProtocol, + Self::InboundOpenInfo, + Self::OutboundOpenInfo, + >, + ) { + match event { + ConnectionEvent::FullyNegotiatedInbound(fully_negotiated_inbound) => { + self.on_fully_negotiated_inbound(fully_negotiated_inbound) + } + ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { + protocol: response, + info: request_id, + }) => { + self.pending_events + .push_back(RequestResponseHandlerEvent::Response { + request_id, + response, + }); + } + ConnectionEvent::DialUpgradeError(dial_upgrade_error) => { + self.on_dial_upgrade_error(dial_upgrade_error) + } + ConnectionEvent::ListenUpgradeError(listen_upgrade_error) => { + self.on_listen_upgrade_error(listen_upgrade_error) + } + ConnectionEvent::AddressChange(_) => {} + } + } +} diff --git a/exchange-protocol/src/handler/protocol.rs b/exchange-protocol/src/handler/protocol.rs new file mode 100644 index 00000000..2a46eb5f --- /dev/null +++ b/exchange-protocol/src/handler/protocol.rs @@ -0,0 +1,189 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +//! The definition of a request/response protocol via inbound +//! and outbound substream upgrades. The inbound upgrade +//! receives a request and sends a response, whereas the +//! outbound upgrade send a request and receives a response. + +use crate::codec::RequestResponseCodec; +use crate::RequestId; + +use futures::{channel::oneshot, future::BoxFuture, prelude::*}; +use libp2p::core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p::swarm::NegotiatedSubstream; +use smallvec::SmallVec; +use std::{fmt, io}; + +/// The level of support for a particular protocol. +#[derive(Debug, Clone)] +pub enum ProtocolSupport { + /// The protocol is only supported for inbound requests. + Inbound, + /// The protocol is only supported for outbound requests. + Outbound, + /// The protocol is supported for inbound and outbound requests. + Full, +} + +impl ProtocolSupport { + /// Whether inbound requests are supported. + pub fn inbound(&self) -> bool { + match self { + ProtocolSupport::Inbound | ProtocolSupport::Full => true, + ProtocolSupport::Outbound => false, + } + } + + /// Whether outbound requests are supported. + pub fn outbound(&self) -> bool { + match self { + ProtocolSupport::Outbound | ProtocolSupport::Full => true, + ProtocolSupport::Inbound => false, + } + } +} + +/// Response substream upgrade protocol. +/// +/// Receives a request and sends a response. +#[derive(Debug)] +pub struct ResponseProtocol +where + TCodec: RequestResponseCodec, +{ + pub(crate) codec: TCodec, + pub(crate) protocols: SmallVec<[TCodec::Protocol; 2]>, + pub(crate) request_sender: oneshot::Sender<(RequestId, TCodec::Request)>, + pub(crate) response_receiver: oneshot::Receiver, + pub(crate) request_id: RequestId, +} + +impl UpgradeInfo for ResponseProtocol +where + TCodec: RequestResponseCodec, +{ + type Info = TCodec::Protocol; + type InfoIter = smallvec::IntoIter<[Self::Info; 2]>; + + fn protocol_info(&self) -> Self::InfoIter { + self.protocols.clone().into_iter() + } +} + +impl InboundUpgrade for ResponseProtocol +where + TCodec: RequestResponseCodec + Send + 'static, +{ + type Output = bool; + type Error = io::Error; + type Future = BoxFuture<'static, Result>; + + fn upgrade_inbound( + mut self, + mut io: NegotiatedSubstream, + protocol: Self::Info, + ) -> Self::Future { + async move { + let read = self.codec.read_request(&protocol, &mut io); + let request = read.await?; + match self.request_sender.send((self.request_id, request)) { + Ok(()) => {}, + Err(_) => panic!( + "Expect request receiver to be alive i.e. protocol handler to be alive.", + ), + } + + if let Ok(response) = self.response_receiver.await { + let write = self.codec.write_response(&protocol, &mut io, response); + write.await?; + + io.close().await?; + // Response was sent. Indicate to handler to emit a `ResponseSent` event. + Ok(true) + } else { + io.close().await?; + // No response was sent. Indicate to handler to emit a `ResponseOmission` event. + Ok(false) + } + }.boxed() + } +} + +/// Request substream upgrade protocol. +/// +/// Sends a request and receives a response. +pub struct RequestProtocol +where + TCodec: RequestResponseCodec, +{ + pub(crate) codec: TCodec, + pub(crate) protocols: SmallVec<[TCodec::Protocol; 2]>, + pub(crate) request_id: RequestId, + pub(crate) request: TCodec::Request, +} + +impl fmt::Debug for RequestProtocol +where + TCodec: RequestResponseCodec, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RequestProtocol") + .field("request_id", &self.request_id) + .finish() + } +} + +impl UpgradeInfo for RequestProtocol +where + TCodec: RequestResponseCodec, +{ + type Info = TCodec::Protocol; + type InfoIter = smallvec::IntoIter<[Self::Info; 2]>; + + fn protocol_info(&self) -> Self::InfoIter { + self.protocols.clone().into_iter() + } +} + +impl OutboundUpgrade for RequestProtocol +where + TCodec: RequestResponseCodec + Send + 'static, +{ + type Output = TCodec::Response; + type Error = io::Error; + type Future = BoxFuture<'static, Result>; + + fn upgrade_outbound( + mut self, + mut io: NegotiatedSubstream, + protocol: Self::Info, + ) -> Self::Future { + async move { + let write = self.codec.write_request(&protocol, &mut io, self.request); + write.await?; + io.close().await?; + let read = self.codec.read_response(&protocol, &mut io); + let response = read.await?; + Ok(response) + } + .boxed() + } +} diff --git a/exchange-protocol/src/lib.rs b/exchange-protocol/src/lib.rs new file mode 100644 index 00000000..f558b496 --- /dev/null +++ b/exchange-protocol/src/lib.rs @@ -0,0 +1,939 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +//! Generic request/response protocols. +//! +//! ## General Usage +//! +//! [`RequestResponse`] is a `NetworkBehaviour` that implements a generic +//! request/response protocol or protocol family, whereby each request is +//! sent over a new substream on a connection. `RequestResponse` is generic +//! over the actual messages being sent, which are defined in terms of a +//! [`RequestResponseCodec`]. Creating a request/response protocol thus amounts +//! to providing an implementation of this trait which can then be +//! given to [`RequestResponse::new`]. Further configuration options are +//! available via the [`RequestResponseConfig`]. +//! +//! Requests are sent using [`RequestResponse::send_request`] and the +//! responses received as [`RequestResponseMessage::Response`] via +//! [`RequestResponseEvent::Message`]. +//! +//! Responses are sent using [`RequestResponse::send_response`] upon +//! receiving a [`RequestResponseMessage::Request`] via +//! [`RequestResponseEvent::Message`]. +//! +//! ## Protocol Families +//! +//! A single [`RequestResponse`] instance can be used with an entire +//! protocol family that share the same request and response types. +//! For that purpose, [`RequestResponseCodec::Protocol`] is typically +//! instantiated with a sum type. +//! +//! ## Limited Protocol Support +//! +//! It is possible to only support inbound or outbound requests for +//! a particular protocol. This is achieved by instantiating `RequestResponse` +//! with protocols using [`ProtocolSupport::Inbound`] or +//! [`ProtocolSupport::Outbound`]. Any subset of protocols of a protocol +//! family can be configured in this way. Such protocols will not be +//! advertised during inbound respectively outbound protocol negotiation +//! on the substreams. + +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + +pub mod codec; +pub mod handler; + +pub use codec::{ProtocolName, RequestResponseCodec}; +pub use handler::ProtocolSupport; + +use futures::channel::oneshot; +use handler::{RequestProtocol, RequestResponseHandler, RequestResponseHandlerEvent}; +use libp2p::core::{connection::ConnectionId, ConnectedPoint, Multiaddr, PeerId}; +use libp2p::swarm::{ + behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}, + dial_opts::DialOpts, + IntoConnectionHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters, +}; +use smallvec::SmallVec; +use std::{ + collections::{HashMap, HashSet, VecDeque}, + fmt, + sync::{atomic::AtomicU64, Arc}, + task::{Context, Poll}, + time::Duration, +}; + +/// An inbound request or response. +#[derive(Debug)] +pub enum RequestResponseMessage { + /// A request message. + Request { + /// The ID of this request. + request_id: RequestId, + /// The request message. + request: TRequest, + /// The channel waiting for the response. + /// + /// If this channel is dropped instead of being used to send a response + /// via [`RequestResponse::send_response`], a [`RequestResponseEvent::InboundFailure`] + /// with [`InboundFailure::ResponseOmission`] is emitted. + channel: ResponseChannel, + }, + /// A response message. + Response { + /// The ID of the request that produced this response. + /// + /// See [`RequestResponse::send_request`]. + request_id: RequestId, + /// The response message. + response: TResponse, + }, +} + +/// The events emitted by a [`RequestResponse`] protocol. +#[derive(Debug)] +pub enum RequestResponseEvent { + /// An incoming message (request or response). + Message { + /// The peer who sent the message. + peer: PeerId, + /// The incoming message. + message: RequestResponseMessage, + }, + /// An outbound request failed. + OutboundFailure { + /// The peer to whom the request was sent. + peer: PeerId, + /// The (local) ID of the failed request. + request_id: RequestId, + /// The error that occurred. + error: OutboundFailure, + }, + /// An inbound request failed. + InboundFailure { + /// The peer from whom the request was received. + peer: PeerId, + /// The ID of the failed inbound request. + request_id: RequestId, + /// The error that occurred. + error: InboundFailure, + }, + /// A response to an inbound request has been sent. + /// + /// When this event is received, the response has been flushed on + /// the underlying transport connection. + ResponseSent { + /// The peer to whom the response was sent. + peer: PeerId, + /// The ID of the inbound request whose response was sent. + request_id: RequestId, + }, +} + +/// Possible failures occurring in the context of sending +/// an outbound request and receiving the response. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum OutboundFailure { + /// The request could not be sent because a dialing attempt failed. + DialFailure, + /// The request timed out before a response was received. + /// + /// It is not known whether the request may have been + /// received (and processed) by the remote peer. + Timeout, + /// The connection closed before a response was received. + /// + /// It is not known whether the request may have been + /// received (and processed) by the remote peer. + ConnectionClosed, + /// The remote supports none of the requested protocols. + UnsupportedProtocols, +} + +impl fmt::Display for OutboundFailure { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + OutboundFailure::DialFailure => write!(f, "Failed to dial the requested peer"), + OutboundFailure::Timeout => write!(f, "Timeout while waiting for a response"), + OutboundFailure::ConnectionClosed => { + write!(f, "Connection was closed before a response was received") + } + OutboundFailure::UnsupportedProtocols => { + write!(f, "The remote supports none of the requested protocols") + } + } + } +} + +impl std::error::Error for OutboundFailure {} + +/// Possible failures occurring in the context of receiving an +/// inbound request and sending a response. +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum InboundFailure { + /// The inbound request timed out, either while reading the + /// incoming request or before a response is sent, e.g. if + /// [`RequestResponse::send_response`] is not called in a + /// timely manner. + Timeout, + /// The connection closed before a response could be send. + ConnectionClosed, + /// The local peer supports none of the protocols requested + /// by the remote. + UnsupportedProtocols, + /// The local peer failed to respond to an inbound request + /// due to the [`ResponseChannel`] being dropped instead of + /// being passed to [`RequestResponse::send_response`]. + ResponseOmission, +} + +impl fmt::Display for InboundFailure { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + InboundFailure::Timeout => { + write!(f, "Timeout while receiving request or sending response") + } + InboundFailure::ConnectionClosed => { + write!(f, "Connection was closed before a response could be sent") + } + InboundFailure::UnsupportedProtocols => write!( + f, + "The local peer supports none of the protocols requested by the remote" + ), + InboundFailure::ResponseOmission => write!( + f, + "The response channel was dropped without sending a response to the remote" + ), + } + } +} + +impl std::error::Error for InboundFailure {} + +/// A channel for sending a response to an inbound request. +/// +/// See [`RequestResponse::send_response`]. +#[derive(Debug)] +pub struct ResponseChannel { + sender: oneshot::Sender, +} + +impl ResponseChannel { + /// Checks whether the response channel is still open, i.e. + /// the `RequestResponse` behaviour is still waiting for a + /// a response to be sent via [`RequestResponse::send_response`] + /// and this response channel. + /// + /// If the response channel is no longer open then the inbound + /// request timed out waiting for the response. + pub fn is_open(&self) -> bool { + !self.sender.is_canceled() + } +} + +/// The ID of an inbound or outbound request. +/// +/// Note: [`RequestId`]'s uniqueness is only guaranteed between two +/// inbound and likewise between two outbound requests. There is no +/// uniqueness guarantee in a set of both inbound and outbound +/// [`RequestId`]s nor in a set of inbound or outbound requests +/// originating from different [`RequestResponse`] behaviours. +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub struct RequestId(u64); + +impl fmt::Display for RequestId { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +/// The configuration for a `RequestResponse` protocol. +#[derive(Debug, Clone)] +pub struct RequestResponseConfig { + request_timeout: Duration, + connection_keep_alive: Duration, +} + +impl Default for RequestResponseConfig { + fn default() -> Self { + Self { + connection_keep_alive: Duration::from_secs(10), + request_timeout: Duration::from_secs(10), + } + } +} + +impl RequestResponseConfig { + /// Sets the keep-alive timeout of idle connections. + pub fn set_connection_keep_alive(&mut self, v: Duration) -> &mut Self { + self.connection_keep_alive = v; + self + } + + /// Sets the timeout for inbound and outbound requests. + pub fn set_request_timeout(&mut self, v: Duration) -> &mut Self { + self.request_timeout = v; + self + } +} + +/// A request/response protocol for some message codec. +pub struct RequestResponse +where + TCodec: RequestResponseCodec + Clone + Send + 'static, +{ + /// The supported inbound protocols. + inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, + /// The supported outbound protocols. + outbound_protocols: SmallVec<[TCodec::Protocol; 2]>, + /// The next (local) request ID. + next_request_id: RequestId, + /// The next (inbound) request ID. + next_inbound_id: Arc, + /// The protocol configuration. + config: RequestResponseConfig, + /// The protocol codec for reading and writing requests and responses. + codec: TCodec, + /// Pending events to return from `poll`. + pending_events: VecDeque< + NetworkBehaviourAction< + RequestResponseEvent, + RequestResponseHandler, + >, + >, + /// The currently connected peers, their pending outbound and inbound responses and their known, + /// reachable addresses, if any. + connected: HashMap>, + /// Externally managed addresses via `add_address` and `remove_address`. + addresses: HashMap>, + /// Requests that have not yet been sent and are waiting for a connection + /// to be established. + pending_outbound_requests: HashMap; 10]>>, +} + +impl RequestResponse +where + TCodec: RequestResponseCodec + Clone + Send + 'static, +{ + /// Creates a new `RequestResponse` behaviour for the given + /// protocols, codec and configuration. + pub fn new(codec: TCodec, protocols: I, cfg: RequestResponseConfig) -> Self + where + I: IntoIterator, + { + let mut inbound_protocols = SmallVec::new(); + let mut outbound_protocols = SmallVec::new(); + for (p, s) in protocols { + if s.inbound() { + inbound_protocols.push(p.clone()); + } + if s.outbound() { + outbound_protocols.push(p.clone()); + } + } + RequestResponse { + inbound_protocols, + outbound_protocols, + next_request_id: RequestId(1), + next_inbound_id: Arc::new(AtomicU64::new(1)), + config: cfg, + codec, + pending_events: VecDeque::new(), + connected: HashMap::new(), + pending_outbound_requests: HashMap::new(), + addresses: HashMap::new(), + } + } + + /// Initiates sending a request. + /// + /// If the targeted peer is currently not connected, a dialing + /// attempt is initiated and the request is sent as soon as a + /// connection is established. + /// + /// > **Note**: In order for such a dialing attempt to succeed, + /// > the `RequestResonse` protocol must either be embedded + /// > in another `NetworkBehaviour` that provides peer and + /// > address discovery, or known addresses of peers must be + /// > managed via [`RequestResponse::add_address`] and + /// > [`RequestResponse::remove_address`]. + pub fn send_request(&mut self, peer: &PeerId, request: TCodec::Request) -> RequestId { + let request_id = self.next_request_id(); + let request = RequestProtocol { + request_id, + codec: self.codec.clone(), + protocols: self.outbound_protocols.clone(), + request, + }; + + if let Some(request) = self.try_send_request(peer, request) { + let handler = self.new_handler(); + self.pending_events.push_back(NetworkBehaviourAction::Dial { + opts: DialOpts::peer_id(*peer).build(), + handler, + }); + self.pending_outbound_requests + .entry(*peer) + .or_default() + .push(request); + } + + request_id + } + + /// Initiates sending a response to an inbound request. + /// + /// If the [`ResponseChannel`] is already closed due to a timeout or the + /// connection being closed, the response is returned as an `Err` for + /// further handling. Once the response has been successfully sent on the + /// corresponding connection, [`RequestResponseEvent::ResponseSent`] is + /// emitted. In all other cases [`RequestResponseEvent::InboundFailure`] + /// will be or has been emitted. + /// + /// The provided `ResponseChannel` is obtained from an inbound + /// [`RequestResponseMessage::Request`]. + pub fn send_response( + &mut self, + ch: ResponseChannel, + rs: TCodec::Response, + ) -> Result<(), TCodec::Response> { + ch.sender.send(rs) + } + + /// Adds a known address for a peer that can be used for + /// dialing attempts by the `Swarm`, i.e. is returned + /// by [`NetworkBehaviour::addresses_of_peer`]. + /// + /// Addresses added in this way are only removed by `remove_address`. + pub fn add_address(&mut self, peer: &PeerId, address: Multiaddr) { + self.addresses.entry(*peer).or_default().push(address); + } + + /// Removes an address of a peer previously added via `add_address`. + pub fn remove_address(&mut self, peer: &PeerId, address: &Multiaddr) { + let mut last = false; + if let Some(addresses) = self.addresses.get_mut(peer) { + addresses.retain(|a| a != address); + last = addresses.is_empty(); + } + if last { + self.addresses.remove(peer); + } + } + + /// Checks whether a peer is currently connected. + pub fn is_connected(&self, peer: &PeerId) -> bool { + if let Some(connections) = self.connected.get(peer) { + !connections.is_empty() + } else { + false + } + } + + /// Checks whether an outbound request to the peer with the provided + /// [`PeerId`] initiated by [`RequestResponse::send_request`] is still + /// pending, i.e. waiting for a response. + pub fn is_pending_outbound(&self, peer: &PeerId, request_id: &RequestId) -> bool { + // Check if request is already sent on established connection. + let est_conn = self + .connected + .get(peer) + .map(|cs| { + cs.iter() + .any(|c| c.pending_inbound_responses.contains(request_id)) + }) + .unwrap_or(false); + // Check if request is still pending to be sent. + let pen_conn = self + .pending_outbound_requests + .get(peer) + .map(|rps| rps.iter().any(|rp| rp.request_id == *request_id)) + .unwrap_or(false); + + est_conn || pen_conn + } + + /// Checks whether an inbound request from the peer with the provided + /// [`PeerId`] is still pending, i.e. waiting for a response by the local + /// node through [`RequestResponse::send_response`]. + pub fn is_pending_inbound(&self, peer: &PeerId, request_id: &RequestId) -> bool { + self.connected + .get(peer) + .map(|cs| { + cs.iter() + .any(|c| c.pending_outbound_responses.contains(request_id)) + }) + .unwrap_or(false) + } + + /// Returns the next request ID. + fn next_request_id(&mut self) -> RequestId { + let request_id = self.next_request_id; + self.next_request_id.0 += 1; + request_id + } + + /// Tries to send a request by queueing an appropriate event to be + /// emitted to the `Swarm`. If the peer is not currently connected, + /// the given request is return unchanged. + fn try_send_request( + &mut self, + peer: &PeerId, + request: RequestProtocol, + ) -> Option> { + if let Some(connections) = self.connected.get_mut(peer) { + if connections.is_empty() { + return Some(request); + } + let ix = (request.request_id.0 as usize) % connections.len(); + let conn = &mut connections[ix]; + conn.pending_inbound_responses.insert(request.request_id); + self.pending_events + .push_back(NetworkBehaviourAction::NotifyHandler { + peer_id: *peer, + handler: NotifyHandler::One(conn.id), + event: request, + }); + None + } else { + Some(request) + } + } + + /// Remove pending outbound response for the given peer and connection. + /// + /// Returns `true` if the provided connection to the given peer is still + /// alive and the [`RequestId`] was previously present and is now removed. + /// Returns `false` otherwise. + fn remove_pending_outbound_response( + &mut self, + peer: &PeerId, + connection: ConnectionId, + request: RequestId, + ) -> bool { + self.get_connection_mut(peer, connection) + .map(|c| c.pending_outbound_responses.remove(&request)) + .unwrap_or(false) + } + + /// Remove pending inbound response for the given peer and connection. + /// + /// Returns `true` if the provided connection to the given peer is still + /// alive and the [`RequestId`] was previously present and is now removed. + /// Returns `false` otherwise. + fn remove_pending_inbound_response( + &mut self, + peer: &PeerId, + connection: ConnectionId, + request: &RequestId, + ) -> bool { + self.get_connection_mut(peer, connection) + .map(|c| c.pending_inbound_responses.remove(request)) + .unwrap_or(false) + } + + /// Returns a mutable reference to the connection in `self.connected` + /// corresponding to the given [`PeerId`] and [`ConnectionId`]. + fn get_connection_mut( + &mut self, + peer: &PeerId, + connection: ConnectionId, + ) -> Option<&mut Connection> { + self.connected + .get_mut(peer) + .and_then(|connections| connections.iter_mut().find(|c| c.id == connection)) + } + + fn on_address_change( + &mut self, + AddressChange { + peer_id, + connection_id, + new, + .. + }: AddressChange, + ) { + let new_address = match new { + ConnectedPoint::Dialer { address, .. } => Some(address.clone()), + ConnectedPoint::Listener { .. } => None, + }; + let connections = self + .connected + .get_mut(&peer_id) + .expect("Address change can only happen on an established connection."); + + let connection = connections + .iter_mut() + .find(|c| c.id == connection_id) + .expect("Address change can only happen on an established connection."); + connection.address = new_address; + } + + fn on_connection_established( + &mut self, + ConnectionEstablished { + peer_id, + connection_id, + endpoint, + other_established, + .. + }: ConnectionEstablished, + ) { + let address = match endpoint { + ConnectedPoint::Dialer { address, .. } => Some(address.clone()), + ConnectedPoint::Listener { .. } => None, + }; + self.connected + .entry(peer_id) + .or_default() + .push(Connection::new(connection_id, address)); + + if other_established == 0 { + if let Some(pending) = self.pending_outbound_requests.remove(&peer_id) { + for request in pending { + let request = self.try_send_request(&peer_id, request); + assert!(request.is_none()); + } + } + } + } + + fn on_connection_closed( + &mut self, + ConnectionClosed { + peer_id, + connection_id, + remaining_established, + .. + }: ConnectionClosed<::ConnectionHandler>, + ) { + let connections = self + .connected + .get_mut(&peer_id) + .expect("Expected some established connection to peer before closing."); + + let connection = connections + .iter() + .position(|c| c.id == connection_id) + .map(|p: usize| connections.remove(p)) + .expect("Expected connection to be established before closing."); + + debug_assert_eq!(connections.is_empty(), remaining_established == 0); + if connections.is_empty() { + self.connected.remove(&peer_id); + } + + for request_id in connection.pending_outbound_responses { + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::InboundFailure { + peer: peer_id, + request_id, + error: InboundFailure::ConnectionClosed, + }, + )); + } + + for request_id in connection.pending_inbound_responses { + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::OutboundFailure { + peer: peer_id, + request_id, + error: OutboundFailure::ConnectionClosed, + }, + )); + } + } + + fn on_dial_failure( + &mut self, + DialFailure { peer_id, .. }: DialFailure<::ConnectionHandler>, + ) { + if let Some(peer) = peer_id { + // If there are pending outgoing requests when a dial failure occurs, + // it is implied that we are not connected to the peer, since pending + // outgoing requests are drained when a connection is established and + // only created when a peer is not connected when a request is made. + // Thus these requests must be considered failed, even if there is + // another, concurrent dialing attempt ongoing. + if let Some(pending) = self.pending_outbound_requests.remove(&peer) { + for request in pending { + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::OutboundFailure { + peer, + request_id: request.request_id, + error: OutboundFailure::DialFailure, + }, + )); + } + } + } + } +} + +impl NetworkBehaviour for RequestResponse +where + TCodec: RequestResponseCodec + Send + Clone + 'static, +{ + type ConnectionHandler = RequestResponseHandler; + type OutEvent = RequestResponseEvent; + + fn new_handler(&mut self) -> Self::ConnectionHandler { + RequestResponseHandler::new( + self.inbound_protocols.clone(), + self.codec.clone(), + self.config.connection_keep_alive, + self.config.request_timeout, + self.next_inbound_id.clone(), + ) + } + + fn addresses_of_peer(&mut self, peer: &PeerId) -> Vec { + let mut addresses = Vec::new(); + if let Some(connections) = self.connected.get(peer) { + addresses.extend(connections.iter().filter_map(|c| c.address.clone())) + } + if let Some(more) = self.addresses.get(peer) { + addresses.extend(more.into_iter().cloned()); + } + addresses + } + + fn on_swarm_event(&mut self, event: FromSwarm) { + match event { + FromSwarm::ConnectionEstablished(connection_established) => { + self.on_connection_established(connection_established) + } + FromSwarm::ConnectionClosed(connection_closed) => { + self.on_connection_closed(connection_closed) + } + FromSwarm::AddressChange(address_change) => self.on_address_change(address_change), + FromSwarm::DialFailure(dial_failure) => self.on_dial_failure(dial_failure), + FromSwarm::ListenFailure(_) => {} + FromSwarm::NewListener(_) => {} + FromSwarm::NewListenAddr(_) => {} + FromSwarm::ExpiredListenAddr(_) => {} + FromSwarm::ListenerError(_) => {} + FromSwarm::ListenerClosed(_) => {} + FromSwarm::NewExternalAddr(_) => {} + FromSwarm::ExpiredExternalAddr(_) => {} + } + } + + fn on_connection_handler_event( + &mut self, + peer: PeerId, + connection: ConnectionId, + event: <::Handler as + libp2p::swarm::ConnectionHandler>::OutEvent, + ) { + match event { + RequestResponseHandlerEvent::Response { + request_id, + response, + } => { + let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); + debug_assert!( + removed, + "Expect request_id to be pending before receiving response.", + ); + + let message = RequestResponseMessage::Response { + request_id, + response, + }; + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::Message { peer, message }, + )); + } + RequestResponseHandlerEvent::Request { + request_id, + request, + sender, + } => { + let channel = ResponseChannel { sender }; + let message = RequestResponseMessage::Request { + request_id, + request, + channel, + }; + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::Message { peer, message }, + )); + + match self.get_connection_mut(&peer, connection) { + Some(connection) => { + let inserted = connection.pending_outbound_responses.insert(request_id); + debug_assert!(inserted, "Expect id of new request to be unknown."); + } + // Connection closed after `RequestResponseEvent::Request` has been emitted. + None => { + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::InboundFailure { + peer, + request_id, + error: InboundFailure::ConnectionClosed, + }, + )); + } + } + } + RequestResponseHandlerEvent::ResponseSent(request_id) => { + let removed = self.remove_pending_outbound_response(&peer, connection, request_id); + debug_assert!( + removed, + "Expect request_id to be pending before response is sent." + ); + + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::ResponseSent { peer, request_id }, + )); + } + RequestResponseHandlerEvent::ResponseOmission(request_id) => { + let removed = self.remove_pending_outbound_response(&peer, connection, request_id); + debug_assert!( + removed, + "Expect request_id to be pending before response is omitted.", + ); + + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::InboundFailure { + peer, + request_id, + error: InboundFailure::ResponseOmission, + }, + )); + } + RequestResponseHandlerEvent::OutboundTimeout(request_id) => { + let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); + debug_assert!( + removed, + "Expect request_id to be pending before request times out." + ); + + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::OutboundFailure { + peer, + request_id, + error: OutboundFailure::Timeout, + }, + )); + } + RequestResponseHandlerEvent::InboundTimeout(request_id) => { + // Note: `RequestResponseHandlerEvent::InboundTimeout` is emitted both for timing + // out to receive the request and for timing out sending the response. In the former + // case the request is never added to `pending_outbound_responses` and thus one can + // not assert the request_id to be present before removing it. + self.remove_pending_outbound_response(&peer, connection, request_id); + + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::InboundFailure { + peer, + request_id, + error: InboundFailure::Timeout, + }, + )); + } + RequestResponseHandlerEvent::OutboundUnsupportedProtocols(request_id) => { + let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); + debug_assert!( + removed, + "Expect request_id to be pending before failing to connect.", + ); + + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::OutboundFailure { + peer, + request_id, + error: OutboundFailure::UnsupportedProtocols, + }, + )); + } + RequestResponseHandlerEvent::InboundUnsupportedProtocols(request_id) => { + // Note: No need to call `self.remove_pending_outbound_response`, + // `RequestResponseHandlerEvent::Request` was never emitted for this request and + // thus request was never added to `pending_outbound_responses`. + self.pending_events + .push_back(NetworkBehaviourAction::GenerateEvent( + RequestResponseEvent::InboundFailure { + peer, + request_id, + error: InboundFailure::UnsupportedProtocols, + }, + )); + } + } + } + + fn poll( + &mut self, + _: &mut Context<'_>, + _: &mut impl PollParameters, + ) -> Poll> { + if let Some(ev) = self.pending_events.pop_front() { + return Poll::Ready(ev); + } else if self.pending_events.capacity() > EMPTY_QUEUE_SHRINK_THRESHOLD { + self.pending_events.shrink_to_fit(); + } + + Poll::Pending + } +} + +/// Internal threshold for when to shrink the capacity +/// of empty queues. If the capacity of an empty queue +/// exceeds this threshold, the associated memory is +/// released. +const EMPTY_QUEUE_SHRINK_THRESHOLD: usize = 100; + +/// Internal information tracked for an established connection. +struct Connection { + id: ConnectionId, + address: Option, + /// Pending outbound responses where corresponding inbound requests have + /// been received on this connection and emitted via `poll` but have not yet + /// been answered. + pending_outbound_responses: HashSet, + /// Pending inbound responses for previously sent requests on this + /// connection. + pending_inbound_responses: HashSet, +} + +impl Connection { + fn new(id: ConnectionId, address: Option) -> Self { + Self { + id, + address, + pending_outbound_responses: Default::default(), + pending_inbound_responses: Default::default(), + } + } +} diff --git a/exchange-protocol/tests/ping.rs b/exchange-protocol/tests/ping.rs new file mode 100644 index 00000000..44bdaf05 --- /dev/null +++ b/exchange-protocol/tests/ping.rs @@ -0,0 +1,388 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +//! Integration tests for the `RequestResponse` network behaviour. + +use async_trait::async_trait; +use futures::{channel::mpsc, prelude::*, AsyncWriteExt}; +use libp2p::core::{ + identity, + muxing::StreamMuxerBox, + transport, + upgrade::{self, read_length_prefixed, write_length_prefixed}, + Multiaddr, PeerId, +}; +use libp2p::noise::NoiseAuthenticated; +use libp2p::request_response::*; +use libp2p::swarm::{Swarm, SwarmEvent}; +use libp2p::tcp; +use libp2p::core::Transport; +use rand::{self, Rng}; +use std::{io, iter}; + +#[test] +fn is_response_outbound() { + let _ = env_logger::try_init(); + let ping = Ping("ping".to_string().into_bytes()); + let offline_peer = PeerId::random(); + + let protocols = iter::once((PingProtocol(), ProtocolSupport::Full)); + let cfg = RequestResponseConfig::default(); + + let (peer1_id, trans) = mk_transport(); + let ping_proto1 = RequestResponse::new(PingCodec(), protocols, cfg); + let mut swarm1 = Swarm::without_executor(trans, ping_proto1, peer1_id); + + let request_id1 = swarm1 + .behaviour_mut() + .send_request(&offline_peer, ping.clone()); + + match futures::executor::block_on(swarm1.select_next_some()) { + SwarmEvent::Behaviour(RequestResponseEvent::OutboundFailure { + peer, + request_id: req_id, + error: _error, + }) => { + assert_eq!(&offline_peer, &peer); + assert_eq!(req_id, request_id1); + } + e => panic!("Peer: Unexpected event: {:?}", e), + } + + let request_id2 = swarm1.behaviour_mut().send_request(&offline_peer, ping); + + assert!(!swarm1 + .behaviour() + .is_pending_outbound(&offline_peer, &request_id1)); + assert!(swarm1 + .behaviour() + .is_pending_outbound(&offline_peer, &request_id2)); +} + +/// Exercises a simple ping protocol. +#[test] +fn ping_protocol() { + let ping = Ping("ping".to_string().into_bytes()); + let pong = Pong("pong".to_string().into_bytes()); + + let protocols = iter::once((PingProtocol(), ProtocolSupport::Full)); + let cfg = RequestResponseConfig::default(); + + let (peer1_id, trans) = mk_transport(); + let ping_proto1 = RequestResponse::new(PingCodec(), protocols.clone(), cfg.clone()); + let mut swarm1 = Swarm::without_executor(trans, ping_proto1, peer1_id); + + let (peer2_id, trans) = mk_transport(); + let ping_proto2 = RequestResponse::new(PingCodec(), protocols, cfg); + let mut swarm2 = Swarm::without_executor(trans, ping_proto2, peer2_id); + + let (mut tx, mut rx) = mpsc::channel::(1); + + let addr = "/ip4/127.0.0.1/tcp/0".parse().unwrap(); + swarm1.listen_on(addr).unwrap(); + + let expected_ping = ping.clone(); + let expected_pong = pong.clone(); + + let peer1 = async move { + loop { + match swarm1.select_next_some().await { + SwarmEvent::NewListenAddr { address, .. } => tx.send(address).await.unwrap(), + SwarmEvent::Behaviour(RequestResponseEvent::Message { + peer, + message: + RequestResponseMessage::Request { + request, channel, .. + }, + }) => { + assert_eq!(&request, &expected_ping); + assert_eq!(&peer, &peer2_id); + swarm1 + .behaviour_mut() + .send_response(channel, pong.clone()) + .unwrap(); + } + SwarmEvent::Behaviour(RequestResponseEvent::ResponseSent { peer, .. }) => { + assert_eq!(&peer, &peer2_id); + } + SwarmEvent::Behaviour(e) => panic!("Peer1: Unexpected event: {:?}", e), + _ => {} + } + } + }; + + let num_pings: u8 = rand::thread_rng().gen_range(1..100); + + let peer2 = async move { + let mut count = 0; + let addr = rx.next().await.unwrap(); + swarm2.behaviour_mut().add_address(&peer1_id, addr.clone()); + let mut req_id = swarm2.behaviour_mut().send_request(&peer1_id, ping.clone()); + assert!(swarm2.behaviour().is_pending_outbound(&peer1_id, &req_id)); + + loop { + match swarm2.select_next_some().await { + SwarmEvent::Behaviour(RequestResponseEvent::Message { + peer, + message: + RequestResponseMessage::Response { + request_id, + response, + }, + }) => { + count += 1; + assert_eq!(&response, &expected_pong); + assert_eq!(&peer, &peer1_id); + assert_eq!(req_id, request_id); + if count >= num_pings { + return; + } else { + req_id = swarm2.behaviour_mut().send_request(&peer1_id, ping.clone()); + } + } + SwarmEvent::Behaviour(e) => panic!("Peer2: Unexpected event: {:?}", e), + _ => {} + } + } + }; + + async_std::task::spawn(Box::pin(peer1)); + let () = async_std::task::block_on(peer2); +} + +#[test] +fn emits_inbound_connection_closed_failure() { + let ping = Ping("ping".to_string().into_bytes()); + + let protocols = iter::once((PingProtocol(), ProtocolSupport::Full)); + let cfg = RequestResponseConfig::default(); + + let (peer1_id, trans) = mk_transport(); + let ping_proto1 = RequestResponse::new(PingCodec(), protocols.clone(), cfg.clone()); + let mut swarm1 = Swarm::without_executor(trans, ping_proto1, peer1_id); + + let (peer2_id, trans) = mk_transport(); + let ping_proto2 = RequestResponse::new(PingCodec(), protocols, cfg); + let mut swarm2 = Swarm::without_executor(trans, ping_proto2, peer2_id); + + let addr = "/ip4/127.0.0.1/tcp/0".parse().unwrap(); + swarm1.listen_on(addr).unwrap(); + + futures::executor::block_on(async move { + while swarm1.next().now_or_never().is_some() {} + let addr1 = Swarm::listeners(&swarm1).next().unwrap(); + + swarm2.behaviour_mut().add_address(&peer1_id, addr1.clone()); + swarm2.behaviour_mut().send_request(&peer1_id, ping.clone()); + + // Wait for swarm 1 to receive request by swarm 2. + let _channel = loop { + futures::select!( + event = swarm1.select_next_some() => match event { + SwarmEvent::Behaviour(RequestResponseEvent::Message { + peer, + message: RequestResponseMessage::Request { request, channel, .. } + }) => { + assert_eq!(&request, &ping); + assert_eq!(&peer, &peer2_id); + break channel; + }, + SwarmEvent::Behaviour(ev) => panic!("Peer1: Unexpected event: {:?}", ev), + _ => {} + }, + event = swarm2.select_next_some() => { + if let SwarmEvent::Behaviour(ev) = event { + panic!("Peer2: Unexpected event: {:?}", ev); + } + } + ) + }; + + // Drop swarm 2 in order for the connection between swarm 1 and 2 to close. + drop(swarm2); + + loop { + match swarm1.select_next_some().await { + SwarmEvent::Behaviour(RequestResponseEvent::InboundFailure { + error: InboundFailure::ConnectionClosed, + .. + }) => break, + SwarmEvent::Behaviour(e) => panic!("Peer1: Unexpected event: {:?}", e), + _ => {} + } + } + }); +} + +/// We expect the substream to be properly closed when response channel is dropped. +/// Since the ping protocol used here expects a response, the sender considers this +/// early close as a protocol violation which results in the connection being closed. +/// If the substream were not properly closed when dropped, the sender would instead +/// run into a timeout waiting for the response. +#[test] +fn emits_inbound_connection_closed_if_channel_is_dropped() { + let ping = Ping("ping".to_string().into_bytes()); + + let protocols = iter::once((PingProtocol(), ProtocolSupport::Full)); + let cfg = RequestResponseConfig::default(); + + let (peer1_id, trans) = mk_transport(); + let ping_proto1 = RequestResponse::new(PingCodec(), protocols.clone(), cfg.clone()); + let mut swarm1 = Swarm::without_executor(trans, ping_proto1, peer1_id); + + let (peer2_id, trans) = mk_transport(); + let ping_proto2 = RequestResponse::new(PingCodec(), protocols, cfg); + let mut swarm2 = Swarm::without_executor(trans, ping_proto2, peer2_id); + + let addr = "/ip4/127.0.0.1/tcp/0".parse().unwrap(); + swarm1.listen_on(addr).unwrap(); + + futures::executor::block_on(async move { + while swarm1.next().now_or_never().is_some() {} + let addr1 = Swarm::listeners(&swarm1).next().unwrap(); + + swarm2.behaviour_mut().add_address(&peer1_id, addr1.clone()); + swarm2.behaviour_mut().send_request(&peer1_id, ping.clone()); + + // Wait for swarm 1 to receive request by swarm 2. + let event = loop { + futures::select!( + event = swarm1.select_next_some() => { + if let SwarmEvent::Behaviour(RequestResponseEvent::Message { + peer, + message: RequestResponseMessage::Request { request, channel, .. } + }) = event { + assert_eq!(&request, &ping); + assert_eq!(&peer, &peer2_id); + + drop(channel); + continue; + } + }, + event = swarm2.select_next_some() => { + if let SwarmEvent::Behaviour(ev) = event { + break ev; + } + }, + ) + }; + + let error = match event { + RequestResponseEvent::OutboundFailure { error, .. } => error, + e => panic!("unexpected event from peer 2: {:?}", e), + }; + + assert_eq!(error, OutboundFailure::ConnectionClosed); + }); +} + +fn mk_transport() -> (PeerId, transport::Boxed<(PeerId, StreamMuxerBox)>) { + let id_keys = identity::Keypair::generate_ed25519(); + let peer_id = id_keys.public().to_peer_id(); + + ( + peer_id, + tcp::async_io::Transport::new(tcp::Config::default().nodelay(true)) + .upgrade(upgrade::Version::V1) + .authenticate(NoiseAuthenticated::xx(&id_keys).unwrap()) + .multiplex(libp2p::yamux::YamuxConfig::default()) + .boxed(), + ) +} + +// Simple Ping-Pong Protocol + +#[derive(Debug, Clone)] +struct PingProtocol(); +#[derive(Clone)] +struct PingCodec(); +#[derive(Debug, Clone, PartialEq, Eq)] +struct Ping(Vec); +#[derive(Debug, Clone, PartialEq, Eq)] +struct Pong(Vec); + +impl ProtocolName for PingProtocol { + fn protocol_name(&self) -> &[u8] { + "/ping/1".as_bytes() + } +} + +#[async_trait] +impl RequestResponseCodec for PingCodec { + type Protocol = PingProtocol; + type Request = Ping; + type Response = Pong; + + async fn read_request(&mut self, _: &PingProtocol, io: &mut T) -> io::Result + where + T: AsyncRead + Unpin + Send, + { + let vec = read_length_prefixed(io, 1024).await?; + + if vec.is_empty() { + return Err(io::ErrorKind::UnexpectedEof.into()); + } + + Ok(Ping(vec)) + } + + async fn read_response(&mut self, _: &PingProtocol, io: &mut T) -> io::Result + where + T: AsyncRead + Unpin + Send, + { + let vec = read_length_prefixed(io, 1024).await?; + + if vec.is_empty() { + return Err(io::ErrorKind::UnexpectedEof.into()); + } + + Ok(Pong(vec)) + } + + async fn write_request( + &mut self, + _: &PingProtocol, + io: &mut T, + Ping(data): Ping, + ) -> io::Result<()> + where + T: AsyncWrite + Unpin + Send, + { + write_length_prefixed(io, data).await?; + io.close().await?; + + Ok(()) + } + + async fn write_response( + &mut self, + _: &PingProtocol, + io: &mut T, + Pong(data): Pong, + ) -> io::Result<()> + where + T: AsyncWrite + Unpin + Send, + { + write_length_prefixed(io, data).await?; + io.close().await?; + + Ok(()) + } +} From b1b2b75e9dfc3f39bee73a0c32f9c233feb5f751 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 30 Nov 2022 12:44:37 +0100 Subject: [PATCH 25/48] allow AsyncRead responses for stream req-res protocol --- Cargo.lock | 1 + Cargo.toml | 1 + exchange-protocol/src/codec.rs | 21 ++++++++------ exchange-protocol/src/handler.rs | 30 +++++++++++-------- exchange-protocol/src/handler/protocol.rs | 30 +++++++++---------- exchange-protocol/src/lib.rs | 35 ++++++++++++++++------- 6 files changed, 71 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d6bec63..965ee361 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3268,6 +3268,7 @@ dependencies = [ "bs58", "cached 0.40.0", "derive_builder 0.11.2", + "exchange-protocol", "futures", "hex", "hyper", diff --git a/Cargo.toml b/Cargo.toml index d924acb8..f43e1540 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ bincode = "1.3" bs58 = "0.4" cached = "0.40" derive_builder = "0.11" +exchange-protocol = { path = "./exchange-protocol" } futures = { default-features = false, version = "0.3", features = ["alloc", "std"] } hex = "0.4" hyper = "0.14" # Prometheus server diff --git a/exchange-protocol/src/codec.rs b/exchange-protocol/src/codec.rs index 96cc93db..34c6a349 100644 --- a/exchange-protocol/src/codec.rs +++ b/exchange-protocol/src/codec.rs @@ -34,14 +34,16 @@ pub trait RequestResponseCodec { /// The type of inbound and outbound requests. type Request: Send; /// The type of inbound and outbound responses. - type Response: Send; + type Response: Send + where + T: AsyncRead + Send; /// Reads a request from the given I/O stream according to the /// negotiated protocol. async fn read_request( &mut self, protocol: &Self::Protocol, - io: &mut T, + io: T, ) -> io::Result where T: AsyncRead + Unpin + Send; @@ -51,8 +53,8 @@ pub trait RequestResponseCodec { async fn read_response( &mut self, protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result + io: T, + ) -> io::Result> where T: AsyncRead + Unpin + Send; @@ -61,7 +63,7 @@ pub trait RequestResponseCodec { async fn write_request( &mut self, protocol: &Self::Protocol, - io: &mut T, + io: T, req: Self::Request, ) -> io::Result<()> where @@ -69,12 +71,13 @@ pub trait RequestResponseCodec { /// Writes a response to the given I/O stream according to the /// negotiated protocol. - async fn write_response( + async fn write_response( &mut self, protocol: &Self::Protocol, - io: &mut T, - res: Self::Response, + io: T, + res: Self::Response, ) -> io::Result<()> where - T: AsyncWrite + Unpin + Send; + T: AsyncWrite + Unpin + Send, + R: AsyncRead; } diff --git a/exchange-protocol/src/handler.rs b/exchange-protocol/src/handler.rs index 99ab4a29..4f6d2a30 100644 --- a/exchange-protocol/src/handler.rs +++ b/exchange-protocol/src/handler.rs @@ -34,7 +34,7 @@ use instant::Instant; use libp2p::core::upgrade::{NegotiationError, UpgradeError}; use libp2p::swarm::{ handler::{ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive}, - SubstreamProtocol, + NegotiatedSubstream, SubstreamProtocol, }; use smallvec::SmallVec; use std::{ @@ -50,9 +50,10 @@ use std::{ /// A connection handler of a `RequestResponse` protocol. #[doc(hidden)] -pub struct RequestResponseHandler +pub struct RequestResponseHandler where TCodec: RequestResponseCodec, + R: AsyncRead, { /// The supported inbound protocols. inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, @@ -69,7 +70,7 @@ where /// A pending fatal error that results in the connection being closed. pending_error: Option>, /// Queue of events to emit in `poll()`. - pending_events: VecDeque>, + pending_events: VecDeque>, /// Outbound upgrades waiting to be emitted as an `OutboundSubstreamRequest`. outbound: VecDeque>, /// Inbound upgrades waiting for the incoming request. @@ -79,7 +80,7 @@ where Result< ( (RequestId, TCodec::Request), - oneshot::Sender, + oneshot::Sender>, ), oneshot::Canceled, >, @@ -88,9 +89,10 @@ where inbound_request_id: Arc, } -impl RequestResponseHandler +impl RequestResponseHandler where TCodec: RequestResponseCodec + Send + Clone + 'static, + R: AsyncRead + 'static, { pub(super) fn new( inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, @@ -193,20 +195,21 @@ where /// The events emitted by the [`RequestResponseHandler`]. #[doc(hidden)] -pub enum RequestResponseHandlerEvent +pub enum RequestResponseHandlerEvent where TCodec: RequestResponseCodec, + R: AsyncRead, { /// A request has been received. Request { request_id: RequestId, request: TCodec::Request, - sender: oneshot::Sender, + sender: oneshot::Sender>, }, /// A response has been received. Response { request_id: RequestId, - response: TCodec::Response, + response: TCodec::Response, }, /// A response to an inbound request has been sent. ResponseSent(RequestId), @@ -225,7 +228,9 @@ where InboundUnsupportedProtocols(RequestId), } -impl fmt::Debug for RequestResponseHandlerEvent { +impl fmt::Debug + for RequestResponseHandlerEvent +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { RequestResponseHandlerEvent::Request { @@ -271,14 +276,15 @@ impl fmt::Debug for RequestResponseHandlerEvent ConnectionHandler for RequestResponseHandler +impl ConnectionHandler for RequestResponseHandler where TCodec: RequestResponseCodec + Send + Clone + 'static, + R: AsyncRead + 'static, { type InEvent = RequestProtocol; - type OutEvent = RequestResponseHandlerEvent; + type OutEvent = RequestResponseHandlerEvent; type Error = ConnectionHandlerUpgrErr; - type InboundProtocol = ResponseProtocol; + type InboundProtocol = ResponseProtocol; type OutboundProtocol = RequestProtocol; type OutboundOpenInfo = RequestId; type InboundOpenInfo = RequestId; diff --git a/exchange-protocol/src/handler/protocol.rs b/exchange-protocol/src/handler/protocol.rs index 2a46eb5f..4bf555e0 100644 --- a/exchange-protocol/src/handler/protocol.rs +++ b/exchange-protocol/src/handler/protocol.rs @@ -65,20 +65,22 @@ impl ProtocolSupport { /// /// Receives a request and sends a response. #[derive(Debug)] -pub struct ResponseProtocol +pub struct ResponseProtocol where TCodec: RequestResponseCodec, + R: AsyncRead, { pub(crate) codec: TCodec, pub(crate) protocols: SmallVec<[TCodec::Protocol; 2]>, pub(crate) request_sender: oneshot::Sender<(RequestId, TCodec::Request)>, - pub(crate) response_receiver: oneshot::Receiver, + pub(crate) response_receiver: oneshot::Receiver>, pub(crate) request_id: RequestId, } -impl UpgradeInfo for ResponseProtocol +impl UpgradeInfo for ResponseProtocol where TCodec: RequestResponseCodec, + R: AsyncRead, { type Info = TCodec::Protocol; type InfoIter = smallvec::IntoIter<[Self::Info; 2]>; @@ -88,21 +90,19 @@ where } } -impl InboundUpgrade for ResponseProtocol +impl InboundUpgrade for ResponseProtocol where TCodec: RequestResponseCodec + Send + 'static, + R: AsyncRead + 'static, { type Output = bool; type Error = io::Error; type Future = BoxFuture<'static, Result>; - fn upgrade_inbound( - mut self, - mut io: NegotiatedSubstream, - protocol: Self::Info, - ) -> Self::Future { + fn upgrade_inbound(mut self, io: NegotiatedSubstream, protocol: Self::Info) -> Self::Future { + let (reader, mut writer) = io.split(); async move { - let read = self.codec.read_request(&protocol, &mut io); + let read = self.codec.read_request(&protocol, reader); let request = read.await?; match self.request_sender.send((self.request_id, request)) { Ok(()) => {}, @@ -112,14 +112,14 @@ where } if let Ok(response) = self.response_receiver.await { - let write = self.codec.write_response(&protocol, &mut io, response); + let write = self.codec.write_response(&protocol, &mut writer, response); write.await?; - io.close().await?; + writer.close().await?; // Response was sent. Indicate to handler to emit a `ResponseSent` event. Ok(true) } else { - io.close().await?; + writer.close().await?; // No response was sent. Indicate to handler to emit a `ResponseOmission` event. Ok(false) } @@ -167,7 +167,7 @@ impl OutboundUpgrade for RequestProtocol where TCodec: RequestResponseCodec + Send + 'static, { - type Output = TCodec::Response; + type Output = TCodec::Response; type Error = io::Error; type Future = BoxFuture<'static, Result>; @@ -180,7 +180,7 @@ where let write = self.codec.write_request(&protocol, &mut io, self.request); write.await?; io.close().await?; - let read = self.codec.read_response(&protocol, &mut io); + let read = self.codec.read_response(&protocol, io); let response = read.await?; Ok(response) } diff --git a/exchange-protocol/src/lib.rs b/exchange-protocol/src/lib.rs index f558b496..89afd6ea 100644 --- a/exchange-protocol/src/lib.rs +++ b/exchange-protocol/src/lib.rs @@ -65,12 +65,14 @@ pub use codec::{ProtocolName, RequestResponseCodec}; pub use handler::ProtocolSupport; use futures::channel::oneshot; +use futures::io::AsyncRead; use handler::{RequestProtocol, RequestResponseHandler, RequestResponseHandlerEvent}; use libp2p::core::{connection::ConnectionId, ConnectedPoint, Multiaddr, PeerId}; use libp2p::swarm::{ behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}, dial_opts::DialOpts, - IntoConnectionHandler, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters, + IntoConnectionHandler, NegotiatedSubstream, NetworkBehaviour, NetworkBehaviourAction, + NotifyHandler, PollParameters, }; use smallvec::SmallVec; use std::{ @@ -296,9 +298,10 @@ impl RequestResponseConfig { } /// A request/response protocol for some message codec. -pub struct RequestResponse +pub struct RequestResponse where TCodec: RequestResponseCodec + Clone + Send + 'static, + R: AsyncRead + 'static, { /// The supported inbound protocols. inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, @@ -315,8 +318,12 @@ where /// Pending events to return from `poll`. pending_events: VecDeque< NetworkBehaviourAction< - RequestResponseEvent, - RequestResponseHandler, + RequestResponseEvent< + TCodec::Request, + TCodec::Response, + TCodec::Response, + >, + RequestResponseHandler, >, >, /// The currently connected peers, their pending outbound and inbound responses and their known, @@ -329,9 +336,10 @@ where pending_outbound_requests: HashMap; 10]>>, } -impl RequestResponse +impl RequestResponse where TCodec: RequestResponseCodec + Clone + Send + 'static, + R: AsyncRead + 'static, { /// Creates a new `RequestResponse` behaviour for the given /// protocols, codec and configuration. @@ -412,9 +420,9 @@ where /// [`RequestResponseMessage::Request`]. pub fn send_response( &mut self, - ch: ResponseChannel, - rs: TCodec::Response, - ) -> Result<(), TCodec::Response> { + ch: ResponseChannel>, + rs: TCodec::Response, + ) -> Result<(), TCodec::Response> { ch.sender.send(rs) } @@ -691,12 +699,17 @@ where } } -impl NetworkBehaviour for RequestResponse +impl NetworkBehaviour for RequestResponse where TCodec: RequestResponseCodec + Send + Clone + 'static, + R: AsyncRead + 'static, { - type ConnectionHandler = RequestResponseHandler; - type OutEvent = RequestResponseEvent; + type ConnectionHandler = RequestResponseHandler; + type OutEvent = RequestResponseEvent< + TCodec::Request, + TCodec::Response, + TCodec::Response, + >; fn new_handler(&mut self) -> Self::ConnectionHandler { RequestResponseHandler::new( From b817823d151e0c48029385170e873e002715a51a Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 30 Nov 2022 16:18:33 +0100 Subject: [PATCH 26/48] basic behaviour and builder for it --- src/p2p/behaviour/builder.rs | 175 +++++++++++++++++++++++++++++++++++ src/p2p/behaviour/mod.rs | 42 +++++++++ 2 files changed, 217 insertions(+) create mode 100644 src/p2p/behaviour/builder.rs create mode 100644 src/p2p/behaviour/mod.rs diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs new file mode 100644 index 00000000..290813cc --- /dev/null +++ b/src/p2p/behaviour/builder.rs @@ -0,0 +1,175 @@ +use crate::p2p::{behaviour::Behaviour, transport::IntoTransport, IdentifyConfig}; +use futures::{ + channel::{mpsc, oneshot}, + future::{select, Either}, + io::{AsyncRead, AsyncWrite}, + sink::SinkExt, + stream::StreamExt, +}; +use libp2p::{ + autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, + core::{upgrade, PeerId, Transport}, + dcutr::behaviour::Behaviour as Dcutr, + gossipsub::{ + Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, + }, + identify::Behaviour as Identify, + identity::Keypair, + kad::{ + record::store::{MemoryStore, MemoryStoreConfig, RecordStore}, + Kademlia, KademliaConfig, + }, + ping::{Behaviour as Ping, Config as PingConfig}, + relay::v2::client::Client, +}; +use thiserror::Error; + +#[derive(Debug, Clone, Default)] +pub struct BehaviourConfig { + identify: IdentifyConfig, + ping: PingConfig, + gossipsub: GossipsubConfig, + kademlia: KademliaConfig, + kademlia_store: KSC, + autonat: AutoNatConfig, + relay: bool, +} + +impl BehaviourConfig { + pub fn new(ksc: impl Into) -> Self { + Self { + identify: Default::default(), + ping: Default::default(), + gossipsub: Default::default(), + kademlia: Default::default(), + kademlia_store: ksc.into(), + autonat: Default::default(), + relay: Default::default(), + } + } + pub fn identify(&mut self, i: impl Into) -> &mut Self { + self.identify = i.into(); + self + } + pub fn ping(&mut self, i: impl Into) -> &mut Self { + self.ping = i.into(); + self + } + pub fn gossipsub(&mut self, i: impl Into) -> &mut Self { + self.gossipsub = i.into(); + self + } + pub fn kademlia(&mut self, i: impl Into) -> &mut Self { + self.kademlia = i.into(); + self + } + pub fn kademlia_store(&mut self, i: impl Into) -> &mut Self { + self.kademlia_store = i.into(); + self + } + pub fn autonat(&mut self, i: impl Into) -> &mut Self { + self.autonat = i.into(); + self + } + pub fn relay(&mut self, i: impl Into) -> &mut Self { + self.relay = i.into(); + self + } + fn build( + self, + keypair: Keypair, + relay: Option, + ) -> Result, OrbitBehaviourBuildError> + where + KSC: RecordStoreConfig, + KS: for<'a> RecordStore<'a> + Send, + { + let peer_id = keypair.public().to_peer_id(); + Ok(Behaviour { + capabilities: (), + identify: Identify::new(self.identify.to_config(keypair.public())), + ping: Ping::new(self.ping), + gossipsub: Gossipsub::new( + MessageAuthenticity::Signed(keypair), + GossipsubConfigBuilder::from(self.gossipsub) + // always ensure validation + .validation_mode(ValidationMode::Strict) + .build() + .map_err(OrbitBehaviourBuildError::Gossipsub)?, + ) + .map_err(OrbitBehaviourBuildError::Gossipsub)?, + relay: relay.into(), + kademlia: Kademlia::with_config( + peer_id, + self.kademlia_store.init(peer_id), + self.kademlia, + ), + dcutr: Dcutr::new(), + autonat: AutoNat::new(peer_id, self.autonat), + }) + } + pub fn launch( + self, + keypair: Keypair, + transport: T, + ) -> Result<(), OrbitLaunchError> + where + T: IntoTransport, + T::T: 'static + Send + Unpin, + T::Error: 'static + std::error::Error + Send + Sync, + ::Output: 'static + AsyncRead + AsyncWrite + Unpin + Send, + ::Error: 'static + Send + Sync, + ::Dial: Send, + ::ListenerUpgrade: Send, + { + let local_public_key = keypair.public(); + let id = local_public_key.to_peer_id(); + let b = self.build(local_public_key); + let (sender, mut reciever) = mpsc::channel(100); + let r = RelayNode { id, sender }; + + let mut swarm = SwarmBuilder::new( + transport + .into_transport() + .map_err(OrbitLaunchError::Transport)? + .upgrade(upgrade::Version::V1) + .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) + .multiplex(upgrade::SelectUpgrade::new( + yamux::YamuxConfig::default(), + mplex::MplexConfig::default(), + )) + .timeout(std::time::Duration::from_secs(20)) + .boxed(), + b, + id, + ) + .build(); + } +} + +#[derive(Error, Debug)] +pub enum OrbitBehaviourBuildError { + #[error("{0}")] + Gossipsub(&'static str), +} + +#[derive(Error, Debug)] +pub enum OrbitLaunchError { + #[error(transparent)] + Config(#[from] OrbitBehaviourBuildError), + #[error(transparent)] + Transport(T), +} + +pub trait RecordStoreConfig +where + S: for<'a> RecordStore<'a>, +{ + fn init(self, id: PeerId) -> S; +} + +impl RecordStoreConfig for MemoryStoreConfig { + fn init(self, id: PeerId) -> MemoryStore { + MemoryStore::with_config(id, self) + } +} diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs new file mode 100644 index 00000000..0d0aaf97 --- /dev/null +++ b/src/p2p/behaviour/mod.rs @@ -0,0 +1,42 @@ +use crate::storage::ImmutableStore; +use core::task::Poll; +use exchange_protocol::RequestResponseCodec; +use futures::{ + io::{copy, AsyncRead, AsyncReadExt, AsyncWrite, Error as FIoError, Take}, + task::Context, +}; +use libipld::Cid; +use libp2p::{ + autonat::Behaviour as AutoNat, + dcutr::behaviour::Behaviour as Dcutr, + gossipsub::Gossipsub, + identify::Behaviour as Identify, + kad::{ + record::store::{MemoryStore, RecordStore}, + Kademlia, + }, + ping::Behaviour as Ping, + relay::v2::client::Client, + swarm::{ + behaviour::toggle::Toggle, NetworkBehaviour, NetworkBehaviourAction, PollParameters, Swarm, + }, +}; +use std::io::Error as IoError; + +pub type OrbitSwarm = Swarm>; +mod builder; + +pub use builder::{BehaviourConfig, OrbitBehaviourBuildError}; + +pub struct Behaviour +where + KS: 'static + for<'a> RecordStore<'a> + Send, +{ + identify: Identify, + ping: Ping, + gossipsub: Gossipsub, + relay: Toggle, + kademlia: Kademlia, + dcutr: Dcutr, + autonat: AutoNat, +} From 520a9bbea4e7dc6859c5b1bf709003ddac73d4f5 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 30 Nov 2022 16:18:51 +0100 Subject: [PATCH 27/48] add write_keyed to immutablestorage trait --- Cargo.lock | 357 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 288 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 965ee361..7069419a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,6 +256,12 @@ dependencies = [ "syn", ] +[[package]] +name = "asn1_der" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" + [[package]] name = "async-attributes" version = "1.1.2" @@ -368,7 +374,7 @@ dependencies = [ "log", "memchr", "once_cell", - "pin-project-lite", + "pin-project-lite 0.2.9", "pin-utils", "slab", "wasm-bindgen-futures", @@ -428,7 +434,7 @@ dependencies = [ "futures-sink", "futures-util", "memchr", - "pin-project-lite", + "pin-project-lite 0.2.9", ] [[package]] @@ -519,7 +525,7 @@ dependencies = [ "http-body", "lazy_static", "percent-encoding", - "pin-project-lite", + "pin-project-lite 0.2.9", "tracing", ] @@ -659,7 +665,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc604f278bae64bbd15854baa9c46ed69a56dfb0669d04aab80974749f2d6599" dependencies = [ "futures-util", - "pin-project-lite", + "pin-project-lite 0.2.9", "tokio", "tokio-stream", ] @@ -679,7 +685,7 @@ dependencies = [ "http", "http-body", "md-5 0.10.5", - "pin-project-lite", + "pin-project-lite 0.2.9", "sha1", "sha2 0.10.6", "tracing", @@ -702,7 +708,7 @@ dependencies = [ "hyper", "hyper-rustls 0.22.1", "lazy_static", - "pin-project-lite", + "pin-project-lite 0.2.9", "tokio", "tower", "tracing", @@ -735,7 +741,7 @@ dependencies = [ "hyper", "once_cell", "percent-encoding", - "pin-project-lite", + "pin-project-lite 0.2.9", "tokio", "tokio-util", "tracing", @@ -751,7 +757,7 @@ dependencies = [ "bytes", "http", "http-body", - "pin-project-lite", + "pin-project-lite 0.2.9", "tower", "tracing", ] @@ -2207,6 +2213,19 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "errno" version = "0.2.8" @@ -2234,6 +2253,23 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +[[package]] +name = "exchange-protocol" +version = "0.1.0" +dependencies = [ + "async-std", + "async-trait", + "bytes", + "env_logger", + "futures", + "instant", + "libp2p 0.50.1", + "log", + "rand 0.8.5", + "smallvec", + "unsigned-varint", +] + [[package]] name = "fake-simd" version = "0.1.2" @@ -2301,6 +2337,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" dependencies = [ "crc32fast", + "libz-sys", "miniz_oxide", ] @@ -2410,7 +2447,7 @@ dependencies = [ "futures-io", "memchr", "parking", - "pin-project-lite", + "pin-project-lite 0.2.9", "waker-fn", ] @@ -2467,7 +2504,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite", + "pin-project-lite 0.2.9", "pin-utils", "slab", ] @@ -2753,7 +2790,7 @@ checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", "http", - "pin-project-lite", + "pin-project-lite 0.2.9", ] [[package]] @@ -2768,6 +2805,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.22" @@ -2784,7 +2827,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project-lite", + "pin-project-lite 0.2.9", "socket2", "tokio", "tower-service", @@ -3044,9 +3087,9 @@ checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] name = "js-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -3276,7 +3319,7 @@ dependencies = [ "kepler-lib", "lazy_static", "libipld", - "libp2p", + "libp2p 0.51.1", "opentelemetry", "opentelemetry-jaeger", "percent-encoding", @@ -3561,6 +3604,25 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" +[[package]] +name = "libp2p" +version = "0.50.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c7b0104790be871edcf97db9bd2356604984e623a08d825c3f27852290266b8" +dependencies = [ + "bytes", + "futures", + "futures-timer", + "getrandom 0.2.8", + "instant", + "libp2p-core 0.38.0", + "libp2p-swarm 0.41.1", + "multiaddr 0.16.0", + "parking_lot 0.12.1", + "pin-project", + "smallvec", +] + [[package]] name = "libp2p" version = "0.51.1" @@ -3573,7 +3635,7 @@ dependencies = [ "getrandom 0.2.8", "instant", "libp2p-autonat", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-dcutr", "libp2p-dns", "libp2p-gossipsub", @@ -3587,11 +3649,13 @@ dependencies = [ "libp2p-ping", "libp2p-quic", "libp2p-relay", - "libp2p-swarm", + "libp2p-swarm 0.42.0", "libp2p-tcp", + "libp2p-wasm-ext", "libp2p-webrtc", + "libp2p-websocket", "libp2p-yamux", - "multiaddr", + "multiaddr 0.17.0", "pin-project", ] @@ -3605,15 +3669,49 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-identity", "libp2p-request-response", - "libp2p-swarm", + "libp2p-swarm 0.42.0", "log", "quick-protobuf", "rand 0.8.5", ] +[[package]] +name = "libp2p-core" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6a8fcd392ff67af6cc3f03b1426c41f7f26b6b9aff2dc632c1c56dd649e571f" +dependencies = [ + "asn1_der", + "bs58", + "ed25519-dalek", + "either", + "fnv", + "futures", + "futures-timer", + "instant", + "log", + "multiaddr 0.16.0", + "multihash 0.16.3", + "multistream-select", + "once_cell", + "parking_lot 0.12.1", + "pin-project", + "prost", + "prost-build", + "rand 0.8.5", + "rw-stream-sink", + "sec1", + "sha2 0.10.6", + "smallvec", + "thiserror", + "unsigned-varint", + "void", + "zeroize", +] + [[package]] name = "libp2p-core" version = "0.39.1" @@ -3627,7 +3725,7 @@ dependencies = [ "instant", "libp2p-identity", "log", - "multiaddr", + "multiaddr 0.17.0", "multihash 0.17.0", "multistream-select", "once_cell", @@ -3653,9 +3751,9 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-identity", - "libp2p-swarm", + "libp2p-swarm 0.42.0", "log", "quick-protobuf", "quick-protobuf-codec", @@ -3670,7 +3768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "146ff7034daae62077c415c2376b8057368042df6ab95f5432ad5e88568b1554" dependencies = [ "futures", - "libp2p-core", + "libp2p-core 0.39.1", "log", "parking_lot 0.12.1", "smallvec", @@ -3691,9 +3789,9 @@ dependencies = [ "futures", "hex_fmt", "instant", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-identity", - "libp2p-swarm", + "libp2p-swarm 0.42.0", "log", "prometheus-client", "quick-protobuf", @@ -3717,9 +3815,9 @@ dependencies = [ "either", "futures", "futures-timer", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-identity", - "libp2p-swarm", + "libp2p-swarm 0.42.0", "log", "lru", "quick-protobuf", @@ -3738,7 +3836,7 @@ dependencies = [ "bs58", "ed25519-dalek", "log", - "multiaddr", + "multiaddr 0.17.0", "multihash 0.17.0", "prost", "prost-build", @@ -3762,9 +3860,9 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-identity", - "libp2p-swarm", + "libp2p-swarm 0.42.0", "log", "quick-protobuf", "rand 0.8.5", @@ -3785,8 +3883,8 @@ dependencies = [ "data-encoding", "futures", "if-watch", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.39.1", + "libp2p-swarm 0.42.0", "log", "rand 0.8.5", "smallvec", @@ -3802,14 +3900,14 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a42ec91e227d7d0dafa4ce88b333cdf5f277253873ab087555c92798db2ddd46" dependencies = [ - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", "libp2p-kad", "libp2p-ping", "libp2p-relay", - "libp2p-swarm", + "libp2p-swarm 0.42.0", "prometheus-client", ] @@ -3822,7 +3920,7 @@ dependencies = [ "asynchronous-codec", "bytes", "futures", - "libp2p-core", + "libp2p-core 0.39.1", "log", "nohash-hasher", "parking_lot 0.12.1", @@ -3840,7 +3938,7 @@ dependencies = [ "bytes", "curve25519-dalek 3.2.0", "futures", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-identity", "log", "once_cell", @@ -3864,8 +3962,8 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.39.1", + "libp2p-swarm 0.42.0", "log", "rand 0.8.5", "void", @@ -3881,7 +3979,7 @@ dependencies = [ "futures", "futures-timer", "if-watch", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-identity", "libp2p-tls", "log", @@ -3905,9 +4003,9 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-identity", - "libp2p-swarm", + "libp2p-swarm 0.42.0", "log", "quick-protobuf", "quick-protobuf-codec", @@ -3927,14 +4025,34 @@ dependencies = [ "bytes", "futures", "instant", - "libp2p-core", - "libp2p-swarm", + "libp2p-core 0.39.1", + "libp2p-swarm 0.42.0", "log", "rand 0.8.5", "smallvec", "unsigned-varint", ] +[[package]] +name = "libp2p-swarm" +version = "0.41.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a35472fe3276b3855c00f1c032ea8413615e030256429ad5349cdf67c6e1a0" +dependencies = [ + "either", + "fnv", + "futures", + "futures-timer", + "instant", + "libp2p-core 0.38.0", + "log", + "pin-project", + "rand 0.8.5", + "smallvec", + "thiserror", + "void", +] + [[package]] name = "libp2p-swarm" version = "0.42.0" @@ -3946,7 +4064,7 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-swarm-derive", "log", "pin-project", @@ -3978,7 +4096,7 @@ dependencies = [ "futures-timer", "if-watch", "libc", - "libp2p-core", + "libp2p-core 0.39.1", "log", "socket2", "tokio", @@ -3992,7 +4110,7 @@ checksum = "ff08d13d0dc66e5e9ba6279c1de417b84fa0d0adc3b03e5732928c180ec02781" dependencies = [ "futures", "futures-rustls", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-identity", "rcgen 0.10.0", "ring", @@ -4003,6 +4121,20 @@ dependencies = [ "yasna", ] +[[package]] +name = "libp2p-wasm-ext" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77dff9d32353a5887adb86c8afc1de1a94d9e8c3bc6df8b2201d7cdf5c848f43" +dependencies = [ + "futures", + "js-sys", + "libp2p-core 0.39.1", + "parity-send-wrapper", + "wasm-bindgen", + "wasm-bindgen-futures", +] + [[package]] name = "libp2p-webrtc" version = "0.4.0-alpha.3" @@ -4016,7 +4148,7 @@ dependencies = [ "futures-timer", "hex", "if-watch", - "libp2p-core", + "libp2p-core 0.39.1", "libp2p-identity", "libp2p-noise", "log", @@ -4034,6 +4166,25 @@ dependencies = [ "webrtc", ] +[[package]] +name = "libp2p-websocket" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "111273f7b3d3510524c752e8b7a5314b7f7a1fee7e68161c01a7d72cbb06db9f" +dependencies = [ + "either", + "futures", + "futures-rustls", + "libp2p-core 0.39.1", + "log", + "parking_lot 0.12.1", + "quicksink", + "rw-stream-sink", + "soketto", + "url", + "webpki-roots", +] + [[package]] name = "libp2p-yamux" version = "0.43.0" @@ -4041,13 +4192,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d048cd82f72c8800655aa1ee9b808ea8c9d523a649d3579b3ef0cfe23952d7fd" dependencies = [ "futures", - "libp2p-core", + "libp2p-core 0.39.1", "log", "parking_lot 0.12.1", "thiserror", "yamux", ] +[[package]] +name = "libz-sys" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "link-cplusplus" version = "1.0.7" @@ -4259,6 +4421,24 @@ dependencies = [ "version_check 0.9.4", ] +[[package]] +name = "multiaddr" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4aebdb21e90f81d13ed01dc84123320838e53963c2ca94b60b305d3fa64f31e" +dependencies = [ + "arrayref", + "byteorder", + "data-encoding", + "multibase 0.9.1", + "multihash 0.16.3", + "percent-encoding", + "serde", + "static_assertions", + "unsigned-varint", + "url", +] + [[package]] name = "multiaddr" version = "0.17.0" @@ -4787,6 +4967,12 @@ dependencies = [ "libm 0.1.4", ] +[[package]] +name = "parity-send-wrapper" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9777aa91b8ad9dd5aaa04a9b6bcb02c7f1deb952fca5a66034d5e63afc5c6f" + [[package]] name = "parking" version = "2.0.0" @@ -4994,6 +5180,12 @@ dependencies = [ "syn", ] +[[package]] +name = "pin-project-lite" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -5321,6 +5513,17 @@ dependencies = [ "unsigned-varint", ] +[[package]] +name = "quicksink" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77de3c815e5a160b1539c6592796801df2043ae35e123b46d73380cfa57af858" +dependencies = [ + "futures-core", + "futures-sink", + "pin-project-lite 0.1.12", +] + [[package]] name = "quinn-proto" version = "0.9.2" @@ -5551,7 +5754,7 @@ dependencies = [ "native-tls", "once_cell", "percent-encoding", - "pin-project-lite", + "pin-project-lite 0.2.9", "rustls 0.20.7", "rustls-pemfile", "serde", @@ -5638,7 +5841,7 @@ dependencies = [ "multer", "num_cpus", "parking_lot 0.12.1", - "pin-project-lite", + "pin-project-lite 0.2.9", "rand 0.8.5", "ref-cast", "rocket_codegen", @@ -5688,7 +5891,7 @@ dependencies = [ "memchr", "pear", "percent-encoding", - "pin-project-lite", + "pin-project-lite 0.2.9", "ref-cast", "serde", "smallvec", @@ -6330,6 +6533,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "soketto" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" +dependencies = [ + "base64 0.13.1", + "bytes", + "flate2", + "futures", + "httparse", + "log", + "rand 0.8.5", + "sha-1", +] + [[package]] name = "spin" version = "0.5.2" @@ -6965,7 +7184,7 @@ dependencies = [ "mio", "num_cpus", "parking_lot 0.12.1", - "pin-project-lite", + "pin-project-lite 0.2.9", "signal-hook-registry", "socket2", "tokio-macros", @@ -7034,7 +7253,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" dependencies = [ "futures-core", - "pin-project-lite", + "pin-project-lite 0.2.9", "tokio", ] @@ -7048,7 +7267,7 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "pin-project-lite", + "pin-project-lite 0.2.9", "tokio", "tracing", ] @@ -7071,7 +7290,7 @@ dependencies = [ "futures-core", "futures-util", "pin-project", - "pin-project-lite", + "pin-project-lite 0.2.9", "tokio", "tower-layer", "tower-service", @@ -7098,7 +7317,7 @@ checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", "log", - "pin-project-lite", + "pin-project-lite 0.2.9", "tracing-attributes", "tracing-core", ] @@ -7491,9 +7710,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -7501,9 +7720,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", @@ -7516,9 +7735,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.33" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" dependencies = [ "cfg-if", "js-sys", @@ -7528,9 +7747,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -7538,9 +7757,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", @@ -7551,9 +7770,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "wasm-timer" From 1e2a0d5de374a9b8a763152e5ceb1858f2ba108e Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 30 Nov 2022 16:19:31 +0100 Subject: [PATCH 28/48] initial stubbed data swap behaviour --- src/p2p/behaviour/mod.rs | 1 + src/p2p/behaviour/swap.rs | 129 ++++++++++++++++++++++++++++++++++++++ src/p2p/mod.rs | 1 + 3 files changed, 131 insertions(+) create mode 100644 src/p2p/behaviour/swap.rs diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs index 0d0aaf97..36557cef 100644 --- a/src/p2p/behaviour/mod.rs +++ b/src/p2p/behaviour/mod.rs @@ -25,6 +25,7 @@ use std::io::Error as IoError; pub type OrbitSwarm = Swarm>; mod builder; +pub mod swap; pub use builder::{BehaviourConfig, OrbitBehaviourBuildError}; diff --git a/src/p2p/behaviour/swap.rs b/src/p2p/behaviour/swap.rs new file mode 100644 index 00000000..1db4be12 --- /dev/null +++ b/src/p2p/behaviour/swap.rs @@ -0,0 +1,129 @@ +use crate::storage::ImmutableStore; +use core::task::Poll; +use exchange_protocol::RequestResponseCodec; +use futures::{ + io::{copy, AsyncRead, AsyncReadExt, AsyncWrite, Error as FIoError, Take}, + task::Context, +}; +use libipld::Cid; +use libp2p::{ + autonat::Behaviour as AutoNat, + dcutr::behaviour::Behaviour as Dcutr, + gossipsub::Gossipsub, + identify::Behaviour as Identify, + kad::{ + record::store::{MemoryStore, RecordStore}, + Kademlia, + }, + ping::Behaviour as Ping, + relay::v2::client::Client, + swarm::{ + behaviour::toggle::Toggle, NetworkBehaviour, NetworkBehaviourAction, PollParameters, Swarm, + }, +}; +use std::io::Error as IoError; + +pub struct KeplerSwap; + +pub struct SwapRequest { + roots: Vec, + bloom: [u8; 256], +} + +pub struct SwapResponse { + stream: R, +} + +const ROOTLESS_CAR_V1_HEADER: [u8; 11] = [ + 0x0a, 0xa1, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x01, +]; + +impl SwapResponse +where + R: AsyncRead + Unpin, +{ + pub async fn new(r: R) -> Result { + let mut header = [0u8; 11]; + r.read_exact(&mut header).await?; + if header != ROOTLESS_CAR_V1_HEADER { + return Err(todo!()); + }; + Ok(Self { stream: r }) + } + pub async fn first(self) -> Option, ()>> { + CarV1StreamBlock::new(self.stream) + } +} + +pub struct CarV1StreamBlock { + cid: Cid, + block: Take, +} + +impl CarV1StreamBlock { + pub async fn write_and_next(self, store: impl ImmutableStore) -> Option> { + store.write_keyed(&mut self.block, self.cid.hash()).await?; + Self::new(self.block.into_inner()).await + } + pub async fn new(r: R) -> Option> { + // read len + // read cid + // take r with len + todo!() + } +} + +#[async_trait] +impl RequestResponseCodec for KeplerSwap { + type Protocol = &'static str; + type Request = SwapRequest; + type Response = SwapResponse where R: AsyncRead + Send; + + async fn read_request( + &mut self, + protocol: &Self::Protocol, + io: T, + ) -> Result + where + T: AsyncRead + Unpin + Send, + { + todo!() + } + + async fn read_response( + &mut self, + protocol: &Self::Protocol, + io: T, + ) -> Result, IoError> + where + T: AsyncRead + Unpin + Send, + { + SwapResponse::new(io).await + } + + async fn write_request( + &mut self, + protocol: &Self::Protocol, + io: T, + req: Self::Request, + ) -> Result<(), IoError> + where + T: AsyncWrite + Unpin + Send, + { + todo!() + } + + async fn write_response( + &mut self, + protocol: &Self::Protocol, + io: T, + res: Self::Response, + ) -> Result<(), IoError> + where + T: AsyncWrite + Unpin + Send, + R: AsyncRead, + { + copy(res.stream, &mut io).await?; + Ok(()) + } +} diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index 1b256444..1e53eaee 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -1,6 +1,7 @@ use core::time::Duration; use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; +pub mod behaviour; pub mod relay; pub mod transport; From c9ddba572c442d7ad7cce6bd10376daadfd98333 Mon Sep 17 00:00:00 2001 From: chunningham Date: Tue, 6 Dec 2022 12:09:24 +0100 Subject: [PATCH 29/48] exchange fixes --- exchange-protocol/src/codec.rs | 2 +- exchange-protocol/src/handler.rs | 10 ++++++---- exchange-protocol/src/handler/protocol.rs | 6 +++--- exchange-protocol/src/lib.rs | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/exchange-protocol/src/codec.rs b/exchange-protocol/src/codec.rs index 34c6a349..3e7590b1 100644 --- a/exchange-protocol/src/codec.rs +++ b/exchange-protocol/src/codec.rs @@ -79,5 +79,5 @@ pub trait RequestResponseCodec { ) -> io::Result<()> where T: AsyncWrite + Unpin + Send, - R: AsyncRead; + R: AsyncRead + Send; } diff --git a/exchange-protocol/src/handler.rs b/exchange-protocol/src/handler.rs index 4f6d2a30..55a899dc 100644 --- a/exchange-protocol/src/handler.rs +++ b/exchange-protocol/src/handler.rs @@ -53,7 +53,7 @@ use std::{ pub struct RequestResponseHandler where TCodec: RequestResponseCodec, - R: AsyncRead, + R: AsyncRead + Send, { /// The supported inbound protocols. inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, @@ -92,7 +92,7 @@ where impl RequestResponseHandler where TCodec: RequestResponseCodec + Send + Clone + 'static, - R: AsyncRead + 'static, + R: AsyncRead + Send + 'static, { pub(super) fn new( inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, @@ -198,7 +198,7 @@ where pub enum RequestResponseHandlerEvent where TCodec: RequestResponseCodec, - R: AsyncRead, + R: AsyncRead + Send, { /// A request has been received. Request { @@ -230,6 +230,8 @@ where impl fmt::Debug for RequestResponseHandlerEvent +where + R: Send, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -279,7 +281,7 @@ impl fmt::Debug impl ConnectionHandler for RequestResponseHandler where TCodec: RequestResponseCodec + Send + Clone + 'static, - R: AsyncRead + 'static, + R: AsyncRead + Send + 'static, { type InEvent = RequestProtocol; type OutEvent = RequestResponseHandlerEvent; diff --git a/exchange-protocol/src/handler/protocol.rs b/exchange-protocol/src/handler/protocol.rs index 4bf555e0..e7be4f37 100644 --- a/exchange-protocol/src/handler/protocol.rs +++ b/exchange-protocol/src/handler/protocol.rs @@ -68,7 +68,7 @@ impl ProtocolSupport { pub struct ResponseProtocol where TCodec: RequestResponseCodec, - R: AsyncRead, + R: AsyncRead + Send, { pub(crate) codec: TCodec, pub(crate) protocols: SmallVec<[TCodec::Protocol; 2]>, @@ -80,7 +80,7 @@ where impl UpgradeInfo for ResponseProtocol where TCodec: RequestResponseCodec, - R: AsyncRead, + R: AsyncRead + Send, { type Info = TCodec::Protocol; type InfoIter = smallvec::IntoIter<[Self::Info; 2]>; @@ -93,7 +93,7 @@ where impl InboundUpgrade for ResponseProtocol where TCodec: RequestResponseCodec + Send + 'static, - R: AsyncRead + 'static, + R: AsyncRead + Send + 'static, { type Output = bool; type Error = io::Error; diff --git a/exchange-protocol/src/lib.rs b/exchange-protocol/src/lib.rs index 89afd6ea..dd06d91e 100644 --- a/exchange-protocol/src/lib.rs +++ b/exchange-protocol/src/lib.rs @@ -301,7 +301,7 @@ impl RequestResponseConfig { pub struct RequestResponse where TCodec: RequestResponseCodec + Clone + Send + 'static, - R: AsyncRead + 'static, + R: AsyncRead + Send + 'static, { /// The supported inbound protocols. inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, @@ -339,7 +339,7 @@ where impl RequestResponse where TCodec: RequestResponseCodec + Clone + Send + 'static, - R: AsyncRead + 'static, + R: AsyncRead + Send + 'static, { /// Creates a new `RequestResponse` behaviour for the given /// protocols, codec and configuration. @@ -702,7 +702,7 @@ where impl NetworkBehaviour for RequestResponse where TCodec: RequestResponseCodec + Send + Clone + 'static, - R: AsyncRead + 'static, + R: AsyncRead + Send + 'static, { type ConnectionHandler = RequestResponseHandler; type OutEvent = RequestResponseEvent< From cb6a54b9df896aa1cec1ac4cae6e90e8a7c81543 Mon Sep 17 00:00:00 2001 From: chunningham Date: Tue, 6 Dec 2022 12:10:37 +0100 Subject: [PATCH 30/48] wip --- src/p2p/behaviour/mod.rs | 124 +++++++++++++++++++++++++++++++++----- src/p2p/behaviour/swap.rs | 1 + src/p2p/mod.rs | 82 ++++++++++++++++++++++++- src/p2p/relay.rs | 2 +- 4 files changed, 192 insertions(+), 17 deletions(-) diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs index 36557cef..76cceaf2 100644 --- a/src/p2p/behaviour/mod.rs +++ b/src/p2p/behaviour/mod.rs @@ -1,13 +1,15 @@ use crate::storage::ImmutableStore; use core::task::Poll; -use exchange_protocol::RequestResponseCodec; +use exchange_protocol::RequestResponse; use futures::{ + future::Pending, io::{copy, AsyncRead, AsyncReadExt, AsyncWrite, Error as FIoError, Take}, task::Context, }; use libipld::Cid; use libp2p::{ autonat::Behaviour as AutoNat, + core::{ConnectedPoint, PeerId}, dcutr::behaviour::Behaviour as Dcutr, gossipsub::Gossipsub, identify::Behaviour as Identify, @@ -17,27 +19,119 @@ use libp2p::{ }, ping::Behaviour as Ping, relay::v2::client::Client, + simple::SimpleProtocol, swarm::{ - behaviour::toggle::Toggle, NetworkBehaviour, NetworkBehaviourAction, PollParameters, Swarm, + behaviour::toggle::Toggle, ConnectionHandler, ConnectionHandlerEvent, + IntoConnectionHandler, KeepAlive, NetworkBehaviour, NetworkBehaviourAction, PollParameters, + SubstreamProtocol, Swarm, }, }; use std::io::Error as IoError; -pub type OrbitSwarm = Swarm>; mod builder; -pub mod swap; +mod swap; pub use builder::{BehaviourConfig, OrbitBehaviourBuildError}; +pub use swap::KeplerSwap; -pub struct Behaviour -where - KS: 'static + for<'a> RecordStore<'a> + Send, -{ - identify: Identify, - ping: Ping, - gossipsub: Gossipsub, - relay: Toggle, - kademlia: Kademlia, - dcutr: Dcutr, - autonat: AutoNat, +pub struct Config { + commit_epoch: (), +} + +pub struct Behaviour { + config: Config, + exchange: RequestResponse, +} + +/// An Epoch is a builder for a block in the capabilities graph. +pub struct Epoch { + invocations: Vec<()>, + delegations: Vec<()>, + revocations: Vec<()>, +} + +impl Behaviour { + pub fn new_epoch(&self) -> Epoch { + Epoch { + invocations: vec![], + delegations: vec![], + revocations: vec![], + } + } + + pub fn submit_epoch(&mut self, epoch: Epoch) -> Result { + todo!() + } + + fn process_event(&mut self, event: ()) -> Result<(), ()> { + todo!() + } +} + +pub enum Event {} +pub struct Handler {} +pub struct IntoHandler {} +pub enum HandlerError {} +pub enum HandlerInEvent {} +pub enum HandlerOutEvent {} + +impl NetworkBehaviour for Behaviour { + type ConnectionHandler = IntoHandler; + type OutEvent = Event; + + fn new_handler(&mut self) -> Self::ConnectionHandler { + IntoHandler {} + } + fn poll( + &mut self, + cx: &mut Context<'_>, + params: &mut impl PollParameters + ) -> Poll::Handler as ConnectionHandler>::InEvent>>{ + Poll::Pending + } +} + +impl ConnectionHandler for Handler { + type InEvent = HandlerInEvent; + type OutEvent = HandlerOutEvent; + type Error = HandlerError; + type InboundProtocol = SimpleProtocol Pending>>; + type OutboundProtocol = SimpleProtocol Pending>>; + type InboundOpenInfo = SimpleProtocol Pending>>; + type OutboundOpenInfo = SimpleProtocol Pending>>; + + fn listen_protocol(&self) -> SubstreamProtocol { + SubstreamProtocol::new(SimpleProtocol::new([], || async {}), ()) + } + fn connection_keep_alive(&self) -> KeepAlive { + KeepAlive::Yes + } + fn poll( + &mut self, + cx: &mut Context<'_>, + ) -> Poll< + ConnectionHandlerEvent< + Self::OutboundProtocol, + Self::OutboundOpenInfo, + Self::OutEvent, + Self::Error, + >, + > { + Poll::Pending + } +} + +impl IntoConnectionHandler for IntoHandler { + type Handler = Handler; + + fn into_handler( + self, + remote_peer_id: &PeerId, + connected_point: &ConnectedPoint, + ) -> Self::Handler { + Handler {} + } + fn inbound_protocol(&self) -> ::InboundProtocol { + SimpleProtocol::new([], || async {}) + } } diff --git a/src/p2p/behaviour/swap.rs b/src/p2p/behaviour/swap.rs index 1db4be12..051539cd 100644 --- a/src/p2p/behaviour/swap.rs +++ b/src/p2p/behaviour/swap.rs @@ -23,6 +23,7 @@ use libp2p::{ }; use std::io::Error as IoError; +#[derive(Clone, Debug)] pub struct KeplerSwap; pub struct SwapRequest { diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index 1e53eaee..5c64f293 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -1,5 +1,21 @@ +use core::future::IntoFuture; use core::time::Duration; -use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; +use futures::{ + channel::{mpsc, oneshot}, + future::{select, Either}, + io::{AsyncRead, AsyncWrite}, + sink::{Sink, SinkExt}, + stream::{Stream, StreamExt}, +}; +use libp2p::{ + identify::Config as OIdentifyConfig, + identity::{Keypair, PublicKey}, + swarm::{ + behaviour::toggle::Toggle, ConnectionHandler, IntoConnectionHandler, NetworkBehaviour, + Swarm, SwarmEvent, + }, +}; +use std::fmt::Display; pub mod behaviour; pub mod relay; @@ -7,6 +23,70 @@ pub mod transport; pub const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; +pub trait BehaviourConfig { + type Error; + type Behaviour: NetworkBehaviour; + fn build( + self, + keypair: Keypair, + transport: T, + ) -> Result, Self::Error>; +} + +#[async_trait] +pub trait Logic +where + B: NetworkBehaviour, +{ + type Error; + type Message; + type Event; + async fn process_message( + &mut self, + swarm: &mut Swarm, + event: Self::Event, + ) -> Result, Self::Error>; + async fn process_swarm( + &mut self, + swarm: &mut Swarm, + event: SwarmEvent< + B::OutEvent, + <::Handler as ConnectionHandler>::Error, + >, + ) -> Result, Self::Error>; +} + +pub async fn launch( + logic: L, + swarm: Swarm, + messages: impl Stream + Unpin, + events: impl Sink + Unpin, +) -> Result<(), L::Error> +where + L: Logic, + B: NetworkBehaviour, +{ + loop { + match select(messages.next(), swarm.next()).await { + // if the swarm or the channel are closed, close the relay + Either::Right((None, _)) | Either::Left((None, _)) => { + break; + } + // process message + Either::Left((Some(m), _)) => match logic.process_message(&mut swarm, m).await? { + Some(e) => events.send(e).await, + _ => (), + }, + // process swarm event + Either::Right((Some(m), _)) => match logic.process_swarm(&mut swarm, m).await? { + Some(e) => events.send(e).await, + _ => (), + }, + }; + } + Ok(()) +} + #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct IdentifyConfig { protocol_version: String, diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index eafd0e55..dde0d0fa 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -15,7 +15,7 @@ use libp2p::{ mplex, noise, ping::{Behaviour as Ping, Config as PingConfig}, relay::v2::relay::{Config as RelayConfig, Relay}, - swarm::{SwarmBuilder, NetworkBehaviour}, + swarm::{NetworkBehaviour, SwarmBuilder}, yamux, }; From c8e950bf6c1ae93f57cdae43384195552bb4dbfa Mon Sep 17 00:00:00 2001 From: chunningham Date: Tue, 21 Mar 2023 16:39:34 +0900 Subject: [PATCH 31/48] fix import deprecation warnings and relay instantiation in app() --- src/lib.rs | 28 ++++++++------------- src/p2p/behaviour/builder.rs | 22 ++++++++++------ src/p2p/behaviour/mod.rs | 16 ++++++------ src/p2p/relay.rs | 49 ++++++++++++++++++++++++++++++++---- src/p2p/transport.rs | 4 +-- 5 files changed, 80 insertions(+), 39 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 08f42ebe..1bb0f916 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,16 +27,10 @@ mod tracing; pub mod transport; use config::{BlockStorage, Config}; -use libp2p::{ - core::multiaddr::multiaddr, - identity::{ed25519::Keypair as Ed25519Keypair, Keypair}, - PeerId, -}; +use libp2p::{build_multiaddr, identity::ed25519::Keypair as Ed25519Keypair, PeerId}; use orbit::ProviderUtils; -use p2p::{ - relay::Config as RelayConfig, - transport::{Both, DnsConfig, MemoryConfig, TcpConfig, WsConfig}, -}; +use p2p::relay::Config as RelayConfig; +use p2p::transport::{Both, DnsConfig, MemoryConfig, TcpConfig, WsConfig}; use routes::{delegate, invoke, open_host_key, relay_addr, util_routes::*}; use std::{collections::HashMap, sync::RwLock}; use storage::{ @@ -79,18 +73,18 @@ pub async fn app(config: &Figment) -> Result> { tracing::tracing_try_init(&kepler_config.log); storage::KV::healthcheck(kepler_config.storage.indexes.clone()).await?; - let kp = kepler_config.storage.blocks.relay_key_pair().await?; - let mut relay_node = RelayConfig::default().launch( - Keypair::Ed25519(kp), - // transport for memory, dns + tcp and websocket over dns + tcp - Both::, WsConfig>>>::default(), - )?; + let relay_node = RelayConfig::default() + .launch( + kepler_config.storage.blocks.relay_key_pair().await?, + Both::::default(), + ) + .await?; relay_node .listen_on([ - multiaddr!(Memory(kepler_config.relay.port)), - multiaddr!(Ip4([127, 0, 0, 1]), Tcp(kepler_config.relay.port)), + build_multiaddr!(Memory(kepler_config.relay.port)), + build_multiaddr!(Ip4([127, 0, 0, 1]), Tcp(kepler_config.relay.port)), ]) .await?; diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs index 290813cc..644ddcc3 100644 --- a/src/p2p/behaviour/builder.rs +++ b/src/p2p/behaviour/builder.rs @@ -1,4 +1,8 @@ -use crate::p2p::{behaviour::Behaviour, transport::IntoTransport, IdentifyConfig}; +use crate::p2p::{ + behaviour::{BaseBehaviour, Behaviour}, + transport::IntoTransport, + IdentifyConfig, +}; use futures::{ channel::{mpsc, oneshot}, future::{select, Either}, @@ -8,19 +12,23 @@ use futures::{ }; use libp2p::{ autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, - core::{upgrade, PeerId, Transport}, - dcutr::behaviour::Behaviour as Dcutr, + core::{upgrade, Transport}, + dcutr::Behaviour as Dcutr, gossipsub::{ - Gossipsub, GossipsubConfig, GossipsubConfigBuilder, MessageAuthenticity, ValidationMode, + Behaviour as Gossipsub, Config as GossipsubConfig, ConfigBuilder as GossipsubConfigBuilder, + MessageAuthenticity, ValidationMode, }, identify::Behaviour as Identify, - identity::Keypair, + identity::{Keypair, PeerId}, kad::{ record::store::{MemoryStore, MemoryStoreConfig, RecordStore}, Kademlia, KademliaConfig, }, + mplex, noise, ping::{Behaviour as Ping, Config as PingConfig}, - relay::v2::client::Client, + relay::client::{new, Behaviour as Client}, + swarm::{Swarm, SwarmBuilder}, + yamux, }; use thiserror::Error; @@ -163,7 +171,7 @@ pub enum OrbitLaunchError { pub trait RecordStoreConfig where - S: for<'a> RecordStore<'a>, + S: RecordStore + Send + 'static, { fn init(self, id: PeerId) -> S; } diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs index 76cceaf2..bf90b164 100644 --- a/src/p2p/behaviour/mod.rs +++ b/src/p2p/behaviour/mod.rs @@ -9,21 +9,21 @@ use futures::{ use libipld::Cid; use libp2p::{ autonat::Behaviour as AutoNat, - core::{ConnectedPoint, PeerId}, - dcutr::behaviour::Behaviour as Dcutr, - gossipsub::Gossipsub, + core::ConnectedPoint, + dcutr::Behaviour as Dcutr, + gossipsub::Behaviour as GossipSub, identify::Behaviour as Identify, + identity::PeerId, kad::{ record::store::{MemoryStore, RecordStore}, Kademlia, }, ping::Behaviour as Ping, - relay::v2::client::Client, - simple::SimpleProtocol, + relay::client::Behaviour as Client, swarm::{ - behaviour::toggle::Toggle, ConnectionHandler, ConnectionHandlerEvent, - IntoConnectionHandler, KeepAlive, NetworkBehaviour, NetworkBehaviourAction, PollParameters, - SubstreamProtocol, Swarm, + behaviour::toggle::Toggle, ConnectionHandler, ConnectionHandlerEvent, ConnectionId, + FromSwarm, KeepAlive, NetworkBehaviour, NetworkBehaviourAction, PollParameters, + SubstreamProtocol, }, }; use std::io::Error as IoError; diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index dde0d0fa..2feb8abf 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -9,14 +9,14 @@ use futures::{ }; use libp2p::{ autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, - core::{identity::Keypair, upgrade, Multiaddr, PeerId, Transport}, + core::{identity::Keypair, upgrade, Multiaddr, Transport}, identify::Behaviour as Identify, identity::PublicKey, mplex, noise, ping::{Behaviour as Ping, Config as PingConfig}, - relay::v2::relay::{Config as RelayConfig, Relay}, + relay::{Behaviour as Relay, Config as RelayConfig}, swarm::{NetworkBehaviour, SwarmBuilder}, - yamux, + yamux, PeerId, }; #[derive(Clone, Debug)] @@ -34,7 +34,7 @@ pub struct Behaviour { } #[derive(Debug)] -pub enum Message { +enum Message { GetAddresses(oneshot::Sender>), ListenOn(Vec, oneshot::Sender>), } @@ -58,12 +58,25 @@ impl RelayNode { } } -#[derive(Debug, Default)] +#[derive(Debug)] pub struct Config { identify: IdentifyConfig, ping: PingConfig, relay: RelayConfig, autonat: AutoNatConfig, + channel_size: usize, +} + +impl Default for Config { + fn default() -> Self { + Self { + identify: IdentifyConfig::default(), + ping: PingConfig::default(), + relay: RelayConfig::default(), + autonat: AutoNatConfig::default(), + channel_size: 100, + } + } } impl Config { @@ -83,6 +96,10 @@ impl Config { self.autonat = i.into(); self } + pub fn channel_size(&mut self, i: impl Into) -> &mut Self { + self.channel_size = i.into(); + self + } fn build(self, pubkey: PublicKey) -> Behaviour { let peer_id = pubkey.to_peer_id(); @@ -172,3 +189,25 @@ impl Config { Ok(r) } } + +#[cfg(test)] +mod test { + use super::*; + use crate::p2p::transport::MemoryConfig; + use libp2p::build_multiaddr; + + #[test] + async fn basic_test() { + let addr = build_multiaddr!(Memory(0)); + + let relay = RelayConfig::default() + .launch(Keypair::generate_ed25519(), MemoryConfig) + .await + .unwrap(); + + relay.listen_on([addr.clone()]).await.unwrap(); + let listened = relay.get_addresses().await.unwrap(); + + assert_eq!(listened, vec![addr]); + } +} diff --git a/src/p2p/transport.rs b/src/p2p/transport.rs index 45c4cd58..4f901a10 100644 --- a/src/p2p/transport.rs +++ b/src/p2p/transport.rs @@ -3,7 +3,7 @@ use futures::io::{AsyncRead, AsyncWrite}; use libp2p::{ core::transport::{dummy::DummyTransport, MemoryTransport, OrTransport, Transport}, dns::{ResolverConfig, ResolverOpts, TokioDnsConfig as DnsTransport}, - tcp::TokioTcpTransport as TcpTransport, + tcp::tokio::Transport as TcpTransport, wasm_ext::ExtTransport, websocket::{tls::Config as WsTlsConfig, WsConfig as WsTransport}, }; @@ -21,7 +21,7 @@ pub trait IntoTransport { } } -pub use libp2p::tcp::GenTcpConfig as TcpConfig; +pub use libp2p::tcp::Config as TcpConfig; pub use libp2p::wasm_ext::ffi::Transport as ExtConfig; #[derive(Default, Debug, Clone, Hash, PartialEq, Eq)] From bb21e204fe63dcc9eb2f4e822b4b3d4a24691588 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 29 Mar 2023 16:14:45 +1000 Subject: [PATCH 32/48] updates for libp2p 0.51 --- Cargo.lock | 1 + Cargo.toml | 1 + src/p2p/behaviour/builder.rs | 63 ++++++++++++++++++-------------- src/p2p/behaviour/mod.rs | 71 +++++++++++++++++++++++------------- 4 files changed, 83 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7069419a..0289e016 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3311,6 +3311,7 @@ dependencies = [ "bs58", "cached 0.40.0", "derive_builder 0.11.2", + "either", "exchange-protocol", "futures", "hex", diff --git a/Cargo.toml b/Cargo.toml index f43e1540..e32cdc62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ bincode = "1.3" bs58 = "0.4" cached = "0.40" derive_builder = "0.11" +either = "1.8" exchange-protocol = { path = "./exchange-protocol" } futures = { default-features = false, version = "0.3", features = ["alloc", "std"] } hex = "0.4" diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs index 644ddcc3..c05d2838 100644 --- a/src/p2p/behaviour/builder.rs +++ b/src/p2p/behaviour/builder.rs @@ -90,30 +90,32 @@ impl BehaviourConfig { ) -> Result, OrbitBehaviourBuildError> where KSC: RecordStoreConfig, - KS: for<'a> RecordStore<'a> + Send, + KS: RecordStore + Send + 'static, { let peer_id = keypair.public().to_peer_id(); Ok(Behaviour { - capabilities: (), - identify: Identify::new(self.identify.to_config(keypair.public())), - ping: Ping::new(self.ping), - gossipsub: Gossipsub::new( - MessageAuthenticity::Signed(keypair), - GossipsubConfigBuilder::from(self.gossipsub) - // always ensure validation - .validation_mode(ValidationMode::Strict) - .build() - .map_err(OrbitBehaviourBuildError::Gossipsub)?, - ) - .map_err(OrbitBehaviourBuildError::Gossipsub)?, - relay: relay.into(), - kademlia: Kademlia::with_config( - peer_id, - self.kademlia_store.init(peer_id), - self.kademlia, - ), - dcutr: Dcutr::new(), - autonat: AutoNat::new(peer_id, self.autonat), + exchange: todo!(), + base: BaseBehaviour { + identify: Identify::new(self.identify.to_config(keypair.public())), + ping: Ping::new(self.ping), + gossipsub: Gossipsub::new( + MessageAuthenticity::Signed(keypair), + GossipsubConfigBuilder::from(self.gossipsub) + // always ensure validation + .validation_mode(ValidationMode::Strict) + .build() + .map_err(OrbitBehaviourBuildError::Gossipsub)?, + ) + .map_err(OrbitBehaviourBuildError::Gossipsub)?, + relay: relay.into(), + kademlia: Kademlia::with_config( + peer_id, + self.kademlia_store.init(peer_id), + self.kademlia, + ), + dcutr: Dcutr::new(peer_id), + autonat: AutoNat::new(peer_id, self.autonat), + }, }) } pub fn launch( @@ -129,18 +131,22 @@ impl BehaviourConfig { ::Error: 'static + Send + Sync, ::Dial: Send, ::ListenerUpgrade: Send, + KS: RecordStore + Send + 'static, { let local_public_key = keypair.public(); let id = local_public_key.to_peer_id(); - let b = self.build(local_public_key); - let (sender, mut reciever) = mpsc::channel(100); - let r = RelayNode { id, sender }; + let transport = transport.into_transport()?; + let (transport, behaviour) = if self.relay { + let (t, b) = new(id); + (transport.or_transport(t), self.build(keypair, Some(b))?) + } else { + (transport, self.build(keypair, None)?) + }; - let mut swarm = SwarmBuilder::new( + let mut swarm = SwarmBuilder::with_tokio_executor( transport - .into_transport() - .map_err(OrbitLaunchError::Transport)? .upgrade(upgrade::Version::V1) + // TODO replace with AWAKE protcol (or similar) .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) .multiplex(upgrade::SelectUpgrade::new( yamux::YamuxConfig::default(), @@ -148,10 +154,11 @@ impl BehaviourConfig { )) .timeout(std::time::Duration::from_secs(20)) .boxed(), - b, + behaviour, id, ) .build(); + Ok(()) } } diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs index bf90b164..3139bc6d 100644 --- a/src/p2p/behaviour/mod.rs +++ b/src/p2p/behaviour/mod.rs @@ -1,5 +1,6 @@ use crate::storage::ImmutableStore; use core::task::Poll; +use either::Either; use exchange_protocol::RequestResponse; use futures::{ future::Pending, @@ -38,9 +39,26 @@ pub struct Config { commit_epoch: (), } -pub struct Behaviour { - config: Config, +pub struct Behaviour +where + KS: RecordStore + Send + 'static, +{ exchange: RequestResponse, + base: BaseBehaviour, +} + +#[derive(NetworkBehaviour, Debug)] +pub struct BaseBehaviour +where + KS: RecordStore + Send + 'static, +{ + identify: Identify, + ping: Ping, + gossipsub: GossipSub, + relay: Toggle, + kademlia: Kademlia, + dcutr: Dcutr, + autonat: AutoNat, } /// An Epoch is a builder for a block in the capabilities graph. @@ -68,25 +86,43 @@ impl Behaviour { } } -pub enum Event {} +pub enum Event { + NewEpoch, + GossipSub, +} pub struct Handler {} -pub struct IntoHandler {} pub enum HandlerError {} pub enum HandlerInEvent {} pub enum HandlerOutEvent {} -impl NetworkBehaviour for Behaviour { - type ConnectionHandler = IntoHandler; +impl NetworkBehaviour for Behaviour +where + KS: RecordStore + Send + 'static, +{ + type ConnectionHandler = + Either as NetworkBehaviour>::ConnectionHandler>; type OutEvent = Event; - fn new_handler(&mut self) -> Self::ConnectionHandler { - IntoHandler {} + fn on_swarm_event(&mut self, event: FromSwarm<'_, Self::ConnectionHandler>) {} + + fn on_connection_handler_event( + &mut self, + _peer_id: PeerId, + _connection_id: ConnectionId, + _event: ::OutEvent, + ) { } + fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters - ) -> Poll::Handler as ConnectionHandler>::InEvent>>{ + params: &mut impl PollParameters, + ) -> Poll< + NetworkBehaviourAction< + Self::OutEvent, + ::InEvent, + >, + > { Poll::Pending } } @@ -120,18 +156,3 @@ impl ConnectionHandler for Handler { Poll::Pending } } - -impl IntoConnectionHandler for IntoHandler { - type Handler = Handler; - - fn into_handler( - self, - remote_peer_id: &PeerId, - connected_point: &ConnectedPoint, - ) -> Self::Handler { - Handler {} - } - fn inbound_protocol(&self) -> ::InboundProtocol { - SimpleProtocol::new([], || async {}) - } -} From 73f7f5909efb1bc2fff95d8cf817a7a8e8f6347f Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 5 Apr 2023 23:48:18 +1000 Subject: [PATCH 33/48] use KeyPair instead of Ed25519 everywhere --- src/auth_guards.rs | 25 ++++--- src/lib.rs | 6 +- src/orbit.rs | 22 +++---- src/p2p/behaviour/swap.rs | 130 ------------------------------------- src/routes/mod.rs | 12 ++-- src/storage/either.rs | 8 +-- src/storage/file_system.rs | 18 ++--- src/storage/s3.rs | 18 ++--- src/storage/utils.rs | 1 + src/transport.rs | 5 +- 10 files changed, 52 insertions(+), 193 deletions(-) delete mode 100644 src/p2p/behaviour/swap.rs diff --git a/src/auth_guards.rs b/src/auth_guards.rs index 7706afc8..3b6e383d 100644 --- a/src/auth_guards.rs +++ b/src/auth_guards.rs @@ -12,8 +12,9 @@ use kepler_lib::{ resource::{OrbitId, ResourceId}, }; use libp2p::{ - core::{multiaddr::multiaddr, Multiaddr, PeerId}, - identity::ed25519::Keypair as Ed25519Keypair, + core::{multiaddr::multiaddr, Multiaddr}, + identity::Keypair, + PeerId, }; use rocket::{ futures::future::try_join_all, @@ -156,17 +157,15 @@ impl<'l> FromRequest<'l> for DelegateAuthWrapper { .await, ) { (Some(p), Ok(None)) => { - let keys = match req - .rocket() - .state::>>() - { - Some(k) => k, - _ => { - return Err(internal_server_error(anyhow!( - "could not retrieve open key set" - ))) - } - }; + let keys = + match req.rocket().state::>>() { + Some(k) => k, + _ => { + return Err(internal_server_error(anyhow!( + "could not retrieve open key set" + ))) + } + }; if let Err(e) = token .verify( diff --git a/src/lib.rs b/src/lib.rs index 1bb0f916..4fc679b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,10 +27,10 @@ mod tracing; pub mod transport; use config::{BlockStorage, Config}; -use libp2p::{build_multiaddr, identity::ed25519::Keypair as Ed25519Keypair, PeerId}; +use libp2p::{build_multiaddr, identity::Keypair, PeerId}; use orbit::ProviderUtils; use p2p::relay::Config as RelayConfig; -use p2p::transport::{Both, DnsConfig, MemoryConfig, TcpConfig, WsConfig}; +use p2p::transport::{Both, MemoryConfig, TcpConfig}; use routes::{delegate, invoke, open_host_key, relay_addr, util_routes::*}; use std::{collections::HashMap, sync::RwLock}; use storage::{ @@ -104,7 +104,7 @@ pub async fn app(config: &Figment) -> Result> { header_name: kepler_config.log.tracing.traceheader, }) .manage(relay_node) - .manage(RwLock::new(HashMap::::new())); + .manage(RwLock::new(HashMap::::new())); if kepler_config.cors { Ok(rocket.attach(AdHoc::on_response("CORS", |_, resp| { diff --git a/src/orbit.rs b/src/orbit.rs index 305c23ef..940483d6 100644 --- a/src/orbit.rs +++ b/src/orbit.rs @@ -13,11 +13,7 @@ use kepler_lib::libipld::cid::{ Cid, }; use kepler_lib::resource::OrbitId; -use libp2p::{ - core::Multiaddr, - identity::{ed25519::Keypair as Ed25519Keypair, PublicKey}, - PeerId, -}; +use libp2p::{core::Multiaddr, identity::Keypair, PeerId}; use rocket::tokio::task::JoinHandle; use cached::proc_macro::cached; @@ -56,7 +52,7 @@ pub struct Orbit { #[derive(Clone, Debug, Builder)] pub struct OrbitPeerConfig { #[builder(setter(into))] - identity: Ed25519Keypair, + identity: Keypair, #[builder(setter(into))] manifest: Manifest, #[builder(setter(into, strip_option), default)] @@ -78,7 +74,7 @@ where B::Error: 'static, { let id = config.manifest.id().get_cid(); - let _local_peer_id = PeerId::from_public_key(&PublicKey::Ed25519(config.identity.public())); + let _local_peer_id = PeerId::from_public_key(&config.identity.public()); let _relay = &config.relay; let blocks = match config.blocks.open(config.manifest.id()).await? { @@ -106,7 +102,7 @@ where B::Error: 'static, { let id = config.manifest.id().get_cid(); - let _local_peer_id = PeerId::from_public_key(&PublicKey::Ed25519(config.identity.public())); + let _local_peer_id = PeerId::from_public_key(&config.identity.public()); let _relay = &config.relay; let blocks = config.blocks.create(config.manifest.id()).await?; @@ -129,9 +125,9 @@ where pub trait ProviderUtils { type Error: StdError; async fn exists(&self, orbit: &OrbitId) -> Result; - async fn relay_key_pair(&self) -> Result; - async fn key_pair(&self, orbit: &OrbitId) -> Result, Self::Error>; - async fn setup_orbit(&self, orbit: &OrbitId, key: &Ed25519Keypair) -> Result<(), Self::Error>; + async fn relay_key_pair(&self) -> Result; + async fn key_pair(&self, orbit: &OrbitId) -> Result, Self::Error>; + async fn setup_orbit(&self, orbit: &OrbitId, key: &Keypair) -> Result<(), Self::Error>; } // Using Option to distinguish when the orbit already exists from a hard error @@ -140,7 +136,7 @@ pub async fn create_orbit( store_config: &BlockConfig, index_config: &config::IndexStorage, relay: (PeerId, Multiaddr), - kp: Ed25519Keypair, + kp: Keypair, ) -> Result>> { match Manifest::resolve_dyn(id, None).await? { Some(_) => {} @@ -254,7 +250,7 @@ mod tests { Ok(( Orbit::create( &OrbitPeerConfigBuilder::::default() - .identity(Ed25519Keypair::generate()) + .identity(Keypair::generate_ed25519()) .manifest(md) .blocks(BlockConfig::B(FileSystemConfig::new(dir.path()))) .index(IndexStorage::Local(LocalIndexStorage { diff --git a/src/p2p/behaviour/swap.rs b/src/p2p/behaviour/swap.rs deleted file mode 100644 index 051539cd..00000000 --- a/src/p2p/behaviour/swap.rs +++ /dev/null @@ -1,130 +0,0 @@ -use crate::storage::ImmutableStore; -use core::task::Poll; -use exchange_protocol::RequestResponseCodec; -use futures::{ - io::{copy, AsyncRead, AsyncReadExt, AsyncWrite, Error as FIoError, Take}, - task::Context, -}; -use libipld::Cid; -use libp2p::{ - autonat::Behaviour as AutoNat, - dcutr::behaviour::Behaviour as Dcutr, - gossipsub::Gossipsub, - identify::Behaviour as Identify, - kad::{ - record::store::{MemoryStore, RecordStore}, - Kademlia, - }, - ping::Behaviour as Ping, - relay::v2::client::Client, - swarm::{ - behaviour::toggle::Toggle, NetworkBehaviour, NetworkBehaviourAction, PollParameters, Swarm, - }, -}; -use std::io::Error as IoError; - -#[derive(Clone, Debug)] -pub struct KeplerSwap; - -pub struct SwapRequest { - roots: Vec, - bloom: [u8; 256], -} - -pub struct SwapResponse { - stream: R, -} - -const ROOTLESS_CAR_V1_HEADER: [u8; 11] = [ - 0x0a, 0xa1, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x01, -]; - -impl SwapResponse -where - R: AsyncRead + Unpin, -{ - pub async fn new(r: R) -> Result { - let mut header = [0u8; 11]; - r.read_exact(&mut header).await?; - if header != ROOTLESS_CAR_V1_HEADER { - return Err(todo!()); - }; - Ok(Self { stream: r }) - } - pub async fn first(self) -> Option, ()>> { - CarV1StreamBlock::new(self.stream) - } -} - -pub struct CarV1StreamBlock { - cid: Cid, - block: Take, -} - -impl CarV1StreamBlock { - pub async fn write_and_next(self, store: impl ImmutableStore) -> Option> { - store.write_keyed(&mut self.block, self.cid.hash()).await?; - Self::new(self.block.into_inner()).await - } - pub async fn new(r: R) -> Option> { - // read len - // read cid - // take r with len - todo!() - } -} - -#[async_trait] -impl RequestResponseCodec for KeplerSwap { - type Protocol = &'static str; - type Request = SwapRequest; - type Response = SwapResponse where R: AsyncRead + Send; - - async fn read_request( - &mut self, - protocol: &Self::Protocol, - io: T, - ) -> Result - where - T: AsyncRead + Unpin + Send, - { - todo!() - } - - async fn read_response( - &mut self, - protocol: &Self::Protocol, - io: T, - ) -> Result, IoError> - where - T: AsyncRead + Unpin + Send, - { - SwapResponse::new(io).await - } - - async fn write_request( - &mut self, - protocol: &Self::Protocol, - io: T, - req: Self::Request, - ) -> Result<(), IoError> - where - T: AsyncWrite + Unpin + Send, - { - todo!() - } - - async fn write_response( - &mut self, - protocol: &Self::Protocol, - io: T, - res: Self::Response, - ) -> Result<(), IoError> - where - T: AsyncWrite + Unpin + Send, - R: AsyncRead, - { - copy(res.stream, &mut io).await?; - Ok(()) - } -} diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 8e7cedbd..82a9452e 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -4,11 +4,7 @@ use kepler_lib::{ authorization::{EncodingError, HeaderEncode}, libipld::Cid, }; -use libp2p::{ - core::PeerId, - identity::{ed25519::Keypair as Ed25519Keypair, PublicKey}, - multiaddr::multiaddr, -}; +use libp2p::{identity::Keypair, multiaddr::multiaddr, PeerId}; use rocket::{ data::{Data, ToByteUnit}, http::{Header, Status}, @@ -104,10 +100,10 @@ pub fn relay_addr(relay: &State, config: &State) -> String { #[get("/peer/generate")] pub fn open_host_key( - s: &State>>, + s: &State>>, ) -> Result { - let keypair = Ed25519Keypair::generate(); - let id = PublicKey::Ed25519(keypair.public()).to_peer_id(); + let keypair = Keypair::generate_ed25519(); + let id = keypair.public().to_peer_id(); s.write() .map_err(|_| (Status::InternalServerError, "cant read keys"))? .insert(id, keypair); diff --git a/src/storage/either.rs b/src/storage/either.rs index 448983db..9d65f7b2 100644 --- a/src/storage/either.rs +++ b/src/storage/either.rs @@ -7,7 +7,7 @@ use kepler_lib::{ libipld::cid::multihash::{Code, Multihash}, resource::OrbitId, }; -use libp2p::identity::ed25519::Keypair as Ed25519Keypair; +use libp2p::identity::Keypair; #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub enum Either { @@ -139,19 +139,19 @@ where Self::B(b) => b.exists(orbit).await.map_err(Self::Error::B), } } - async fn relay_key_pair(&self) -> Result { + async fn relay_key_pair(&self) -> Result { match self { Self::A(a) => a.relay_key_pair().await.map_err(Self::Error::A), Self::B(b) => b.relay_key_pair().await.map_err(Self::Error::B), } } - async fn key_pair(&self, orbit: &OrbitId) -> Result, Self::Error> { + async fn key_pair(&self, orbit: &OrbitId) -> Result, Self::Error> { match self { Self::A(a) => a.key_pair(orbit).await.map_err(Self::Error::A), Self::B(b) => b.key_pair(orbit).await.map_err(Self::Error::B), } } - async fn setup_orbit(&self, orbit: &OrbitId, key: &Ed25519Keypair) -> Result<(), Self::Error> { + async fn setup_orbit(&self, orbit: &OrbitId, key: &Keypair) -> Result<(), Self::Error> { match self { Self::A(a) => a.setup_orbit(orbit, key).await.map_err(Self::Error::A), Self::B(b) => b.setup_orbit(orbit, key).await.map_err(Self::Error::B), diff --git a/src/storage/file_system.rs b/src/storage/file_system.rs index fc5313e0..c001d8ff 100644 --- a/src/storage/file_system.rs +++ b/src/storage/file_system.rs @@ -9,7 +9,7 @@ use kepler_lib::{ }, resource::OrbitId, }; -use libp2p::identity::{ed25519::Keypair as Ed25519Keypair, DecodingError}; +use libp2p::identity::{DecodingError, Keypair}; use serde::{Deserialize, Serialize}; use std::{ io::{Error as IoError, ErrorKind}, @@ -97,29 +97,29 @@ impl ProviderUtils for FileSystemConfig { .join("blocks") .is_dir()) } - async fn relay_key_pair(&self) -> Result { + async fn relay_key_pair(&self) -> Result { let path = self.path.join("kp"); match read(&path).await { - Ok(mut k) => Ok(Ed25519Keypair::decode(&mut k)?), + Ok(mut k) => Ok(Keypair::from_protobuf_encoding(&mut k)?), Err(e) if e.kind() == ErrorKind::NotFound => { - let k = Ed25519Keypair::generate(); - write(&path, k.encode()).await?; + let k = Keypair::generate_ed25519(); + write(&path, k.to_protobuf_encoding()?).await?; Ok(k) } Err(e) => Err(e.into()), } } - async fn key_pair(&self, orbit: &OrbitId) -> Result, Self::Error> { + async fn key_pair(&self, orbit: &OrbitId) -> Result, Self::Error> { match read(self.path.join(orbit.get_cid().to_string()).join("kp")).await { - Ok(mut k) => Ok(Some(Ed25519Keypair::decode(&mut k)?)), + Ok(mut k) => Ok(Some(Keypair::from_protobuf_encoding(&mut k)?)), Err(e) if e.kind() == ErrorKind::NotFound => Ok(None), Err(e) => Err(e.into()), } } - async fn setup_orbit(&self, orbit: &OrbitId, key: &Ed25519Keypair) -> Result<(), Self::Error> { + async fn setup_orbit(&self, orbit: &OrbitId, key: &Keypair) -> Result<(), Self::Error> { let dir = self.path.join(orbit.get_cid().to_string()); create_dir_all(&dir).await?; - write(dir.join("kp"), key.encode()).await?; + write(dir.join("kp"), key.to_protobuf_encoding()?).await?; write(dir.join("id"), orbit.to_string()).await?; Ok(()) } diff --git a/src/storage/s3.rs b/src/storage/s3.rs index f4c5bd61..3dee2d4d 100644 --- a/src/storage/s3.rs +++ b/src/storage/s3.rs @@ -16,7 +16,7 @@ use kepler_lib::{ }, resource::OrbitId, }; -use libp2p::identity::{ed25519::Keypair as Ed25519Keypair, DecodingError}; +use libp2p::identity::{DecodingError, Keypair}; use rocket::{async_trait, http::hyper::Uri}; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; @@ -90,7 +90,7 @@ impl ProviderUtils for S3BlockConfig { async fn exists(&self, orbit: &OrbitId) -> Result { self.key_pair(orbit).await.map(|o| o.is_some()) } - async fn relay_key_pair(&self) -> Result { + async fn relay_key_pair(&self) -> Result { let client = new_client(self); match client .get_object() @@ -99,7 +99,7 @@ impl ProviderUtils for S3BlockConfig { .send() .await { - Ok(o) => Ok(Ed25519Keypair::decode( + Ok(o) => Ok(Keypair::from_protobuf_encoding( &mut o.body.collect().await?.into_bytes().to_vec(), )?), Err(SdkError::ServiceError { @@ -110,12 +110,12 @@ impl ProviderUtils for S3BlockConfig { }, .. }) => { - let kp = Ed25519Keypair::generate(); + let kp = Keypair::generate_ed25519(); client .put_object() .bucket(&self.bucket) .key("kp") - .body(ByteStream::new(SdkBody::from(kp.encode().to_vec()))) + .body(ByteStream::new(SdkBody::from(kp.to_protobuf_encoding()?))) .send() .await?; Ok(kp) @@ -123,7 +123,7 @@ impl ProviderUtils for S3BlockConfig { Err(e) => Err(e.into()), } } - async fn key_pair(&self, orbit: &OrbitId) -> Result, Self::Error> { + async fn key_pair(&self, orbit: &OrbitId) -> Result, Self::Error> { match new_client(self) .get_object() .bucket(&self.bucket) @@ -131,7 +131,7 @@ impl ProviderUtils for S3BlockConfig { .send() .await { - Ok(o) => Ok(Some(Ed25519Keypair::decode( + Ok(o) => Ok(Some(Keypair::from_protobuf_encoding( &mut o.body.collect().await?.into_bytes().to_vec(), )?)), Err(SdkError::ServiceError { @@ -145,13 +145,13 @@ impl ProviderUtils for S3BlockConfig { Err(e) => Err(e.into()), } } - async fn setup_orbit(&self, orbit: &OrbitId, key: &Ed25519Keypair) -> Result<(), Self::Error> { + async fn setup_orbit(&self, orbit: &OrbitId, key: &Keypair) -> Result<(), Self::Error> { let client = new_client(self); client .put_object() .bucket(&self.bucket) .key(format!("{}/keypair", orbit.get_cid())) - .body(ByteStream::new(SdkBody::from(key.encode().to_vec()))) + .body(ByteStream::new(SdkBody::from(key.to_protobuf_encoding()?))) .send() .await?; client diff --git a/src/storage/utils.rs b/src/storage/utils.rs index 800d20f5..d40560e9 100644 --- a/src/storage/utils.rs +++ b/src/storage/utils.rs @@ -53,6 +53,7 @@ macro_rules! write_with_multihash { let (mut h, b) = hb.into_inner(); Ok((Code::$hashes.wrap(h.finalize())?, b)) },)* + _ => Err(MultihashError::UnsupportedCode($code.into())), } }; } diff --git a/src/transport.rs b/src/transport.rs index e63cc306..be5a7484 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -3,10 +3,7 @@ use std::{ future::{ready, Ready}, }; -use libp2p::{ - core::{Endpoint, PeerId}, - noise::NoiseError, -}; +use libp2p::{core::Endpoint, noise::NoiseError, PeerId}; pub fn auth_mapper( i: I, From 5b8051527ccb18787539728f74a50081dd4e1006 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 5 Apr 2023 23:51:06 +1000 Subject: [PATCH 34/48] clean up a bunch of unused stuff and imports --- src/p2p/behaviour/mod.rs | 131 +++------------------------------------ src/p2p/mod.rs | 83 +------------------------ src/p2p/transport.rs | 2 +- 3 files changed, 12 insertions(+), 204 deletions(-) diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs index 3139bc6d..f1dde56b 100644 --- a/src/p2p/behaviour/mod.rs +++ b/src/p2p/behaviour/mod.rs @@ -1,53 +1,29 @@ -use crate::storage::ImmutableStore; -use core::task::Poll; -use either::Either; -use exchange_protocol::RequestResponse; -use futures::{ - future::Pending, - io::{copy, AsyncRead, AsyncReadExt, AsyncWrite, Error as FIoError, Take}, - task::Context, -}; -use libipld::Cid; use libp2p::{ autonat::Behaviour as AutoNat, - core::ConnectedPoint, dcutr::Behaviour as Dcutr, gossipsub::Behaviour as GossipSub, identify::Behaviour as Identify, - identity::PeerId, - kad::{ - record::store::{MemoryStore, RecordStore}, - Kademlia, - }, + kad::{record::store::RecordStore, Kademlia}, ping::Behaviour as Ping, relay::client::Behaviour as Client, - swarm::{ - behaviour::toggle::Toggle, ConnectionHandler, ConnectionHandlerEvent, ConnectionId, - FromSwarm, KeepAlive, NetworkBehaviour, NetworkBehaviourAction, PollParameters, - SubstreamProtocol, - }, + swarm::{behaviour::toggle::Toggle, NetworkBehaviour, Swarm}, }; -use std::io::Error as IoError; mod builder; -mod swap; pub use builder::{BehaviourConfig, OrbitBehaviourBuildError}; -pub use swap::KeplerSwap; - -pub struct Config { - commit_epoch: (), -} -pub struct Behaviour +// TODO impl network behaviour +// this is temporary as a checkpoint +#[derive(NetworkBehaviour)] +pub struct Behaviour where KS: RecordStore + Send + 'static, { - exchange: RequestResponse, base: BaseBehaviour, } -#[derive(NetworkBehaviour, Debug)] +#[derive(NetworkBehaviour)] pub struct BaseBehaviour where KS: RecordStore + Send + 'static, @@ -61,98 +37,9 @@ where autonat: AutoNat, } -/// An Epoch is a builder for a block in the capabilities graph. -pub struct Epoch { - invocations: Vec<()>, - delegations: Vec<()>, - revocations: Vec<()>, -} - -impl Behaviour { - pub fn new_epoch(&self) -> Epoch { - Epoch { - invocations: vec![], - delegations: vec![], - revocations: vec![], - } - } - - pub fn submit_epoch(&mut self, epoch: Epoch) -> Result { - todo!() - } - - fn process_event(&mut self, event: ()) -> Result<(), ()> { - todo!() - } -} - -pub enum Event { - NewEpoch, - GossipSub, -} -pub struct Handler {} -pub enum HandlerError {} -pub enum HandlerInEvent {} -pub enum HandlerOutEvent {} - -impl NetworkBehaviour for Behaviour +async fn poll_swarm(mut swarm: Swarm>) -> Result<(), ()> where KS: RecordStore + Send + 'static, { - type ConnectionHandler = - Either as NetworkBehaviour>::ConnectionHandler>; - type OutEvent = Event; - - fn on_swarm_event(&mut self, event: FromSwarm<'_, Self::ConnectionHandler>) {} - - fn on_connection_handler_event( - &mut self, - _peer_id: PeerId, - _connection_id: ConnectionId, - _event: ::OutEvent, - ) { - } - - fn poll( - &mut self, - cx: &mut Context<'_>, - params: &mut impl PollParameters, - ) -> Poll< - NetworkBehaviourAction< - Self::OutEvent, - ::InEvent, - >, - > { - Poll::Pending - } -} - -impl ConnectionHandler for Handler { - type InEvent = HandlerInEvent; - type OutEvent = HandlerOutEvent; - type Error = HandlerError; - type InboundProtocol = SimpleProtocol Pending>>; - type OutboundProtocol = SimpleProtocol Pending>>; - type InboundOpenInfo = SimpleProtocol Pending>>; - type OutboundOpenInfo = SimpleProtocol Pending>>; - - fn listen_protocol(&self) -> SubstreamProtocol { - SubstreamProtocol::new(SimpleProtocol::new([], || async {}), ()) - } - fn connection_keep_alive(&self) -> KeepAlive { - KeepAlive::Yes - } - fn poll( - &mut self, - cx: &mut Context<'_>, - ) -> Poll< - ConnectionHandlerEvent< - Self::OutboundProtocol, - Self::OutboundOpenInfo, - Self::OutEvent, - Self::Error, - >, - > { - Poll::Pending - } + Ok(()) } diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index 5c64f293..e0711b5b 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -1,21 +1,6 @@ -use core::future::IntoFuture; use core::time::Duration; -use futures::{ - channel::{mpsc, oneshot}, - future::{select, Either}, - io::{AsyncRead, AsyncWrite}, - sink::{Sink, SinkExt}, - stream::{Stream, StreamExt}, -}; -use libp2p::{ - identify::Config as OIdentifyConfig, - identity::{Keypair, PublicKey}, - swarm::{ - behaviour::toggle::Toggle, ConnectionHandler, IntoConnectionHandler, NetworkBehaviour, - Swarm, SwarmEvent, - }, -}; -use std::fmt::Display; + +use libp2p::{identify::Config as OIdentifyConfig, identity::PublicKey}; pub mod behaviour; pub mod relay; @@ -23,70 +8,6 @@ pub mod transport; pub const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; -pub trait BehaviourConfig { - type Error; - type Behaviour: NetworkBehaviour; - fn build( - self, - keypair: Keypair, - transport: T, - ) -> Result, Self::Error>; -} - -#[async_trait] -pub trait Logic -where - B: NetworkBehaviour, -{ - type Error; - type Message; - type Event; - async fn process_message( - &mut self, - swarm: &mut Swarm, - event: Self::Event, - ) -> Result, Self::Error>; - async fn process_swarm( - &mut self, - swarm: &mut Swarm, - event: SwarmEvent< - B::OutEvent, - <::Handler as ConnectionHandler>::Error, - >, - ) -> Result, Self::Error>; -} - -pub async fn launch( - logic: L, - swarm: Swarm, - messages: impl Stream + Unpin, - events: impl Sink + Unpin, -) -> Result<(), L::Error> -where - L: Logic, - B: NetworkBehaviour, -{ - loop { - match select(messages.next(), swarm.next()).await { - // if the swarm or the channel are closed, close the relay - Either::Right((None, _)) | Either::Left((None, _)) => { - break; - } - // process message - Either::Left((Some(m), _)) => match logic.process_message(&mut swarm, m).await? { - Some(e) => events.send(e).await, - _ => (), - }, - // process swarm event - Either::Right((Some(m), _)) => match logic.process_swarm(&mut swarm, m).await? { - Some(e) => events.send(e).await, - _ => (), - }, - }; - } - Ok(()) -} - #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct IdentifyConfig { protocol_version: String, diff --git a/src/p2p/transport.rs b/src/p2p/transport.rs index 4f901a10..e120e746 100644 --- a/src/p2p/transport.rs +++ b/src/p2p/transport.rs @@ -11,7 +11,7 @@ use std::io::Error as IoError; pub trait IntoTransport { type T: Transport; - type Error; + type Error: std::error::Error; fn into_transport(self) -> Result; fn and(self, other: O) -> Both where From 92427eba6113cfc0916f6ab2ef5d75d726cf9b98 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 5 Apr 2023 23:52:19 +1000 Subject: [PATCH 35/48] fix relay and fully-specify errors --- src/lib.rs | 10 +-- src/p2p/relay.rs | 189 +++++++++++++++++++++++++++---------------- src/p2p/transport.rs | 33 +++++++- 3 files changed, 157 insertions(+), 75 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4fc679b4..456b3b42 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,12 +74,10 @@ pub async fn app(config: &Figment) -> Result> { storage::KV::healthcheck(kepler_config.storage.indexes.clone()).await?; - let relay_node = RelayConfig::default() - .launch( - kepler_config.storage.blocks.relay_key_pair().await?, - Both::::default(), - ) - .await?; + let mut relay_node = RelayConfig::default().launch( + kepler_config.storage.blocks.relay_key_pair().await?, + Both::::default(), + )?; relay_node .listen_on([ diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index 2feb8abf..409c0d22 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -1,5 +1,7 @@ -use crate::p2p::{transport::IntoTransport, IdentifyConfig}; -use anyhow::Result; +use crate::p2p::{ + transport::{build_transport, IntoTransport}, + IdentifyConfig, +}; use futures::{ channel::{mpsc, oneshot}, future::{select, Either}, @@ -9,14 +11,14 @@ use futures::{ }; use libp2p::{ autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, - core::{identity::Keypair, upgrade, Multiaddr, Transport}, + core::{identity::Keypair, Multiaddr, Transport}, identify::Behaviour as Identify, identity::PublicKey, - mplex, noise, + noise, ping::{Behaviour as Ping, Config as PingConfig}, relay::{Behaviour as Relay, Config as RelayConfig}, - swarm::{NetworkBehaviour, SwarmBuilder}, - yamux, PeerId, + swarm::{NetworkBehaviour, Swarm, SwarmBuilder}, + PeerId, }; #[derive(Clone, Debug)] @@ -33,29 +35,53 @@ pub struct Behaviour { autonat: AutoNat, } +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("failed to listen on multiaddress: {0}")] + Listen(Multiaddr), + #[error("failed to dial multiaddress: {0}")] + Dial(Multiaddr), + #[error("failed to send message: {0}")] + SendError(#[from] mpsc::SendError), + #[error("failed to recieve behaviour response: {0}")] + RecieveError(#[from] oneshot::Canceled), + #[error("failed to open listener: {0}")] + TransportError(#[from] libp2p::TransportError), +} + #[derive(Debug)] enum Message { GetAddresses(oneshot::Sender>), - ListenOn(Vec, oneshot::Sender>), + ListenOn(Vec, oneshot::Sender>), + Dial(Multiaddr, oneshot::Sender>), } impl RelayNode { pub fn id(&self) -> &PeerId { &self.id } - pub async fn get_addresses(&mut self) -> Result> { + pub async fn get_addresses(&mut self) -> Result, Error> { let (s, r) = oneshot::channel(); self.sender.send(Message::GetAddresses(s)).await?; Ok(r.await?) } - pub async fn listen_on(&mut self, addr: impl IntoIterator) -> Result<()> { + pub async fn listen_on( + &mut self, + addr: impl IntoIterator, + ) -> Result<(), Error> { let (s, r) = oneshot::channel(); self.sender .send(Message::ListenOn(addr.into_iter().collect(), s)) .await?; r.await? } + + pub async fn dial(&mut self, addr: Multiaddr) -> Result<(), Error> { + let (s, r) = oneshot::channel(); + self.sender.send(Message::Dial(addr, s)).await?; + r.await? + } } #[derive(Debug)] @@ -65,6 +91,7 @@ pub struct Config { relay: RelayConfig, autonat: AutoNatConfig, channel_size: usize, + transport_timeout: std::time::Duration, } impl Default for Config { @@ -75,6 +102,7 @@ impl Default for Config { relay: RelayConfig::default(), autonat: AutoNatConfig::default(), channel_size: 100, + transport_timeout: std::time::Duration::from_secs(20), } } } @@ -100,6 +128,10 @@ impl Config { self.channel_size = i.into(); self } + pub fn transport_timeout(&mut self, i: impl Into) -> &mut Self { + self.transport_timeout = i.into(); + self + } fn build(self, pubkey: PublicKey) -> Behaviour { let peer_id = pubkey.to_peer_id(); @@ -111,7 +143,7 @@ impl Config { } } - pub fn launch(self, keypair: Keypair, transport: T) -> Result + pub fn launch(self, keypair: Keypair, transport: T) -> Result> where T: IntoTransport, T::T: 'static + Send + Unpin, @@ -123,71 +155,93 @@ impl Config { { let local_public_key = keypair.public(); let id = local_public_key.to_peer_id(); - let b = self.build(local_public_key); - let (sender, mut reciever) = mpsc::channel(100); - let r = RelayNode { id, sender }; - - let mut swarm = SwarmBuilder::with_tokio_executor( - transport - .into_transport()? - .upgrade(upgrade::Version::V1) - .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) - .multiplex(upgrade::SelectUpgrade::new( - yamux::YamuxConfig::default(), - mplex::MplexConfig::default(), - )) - .timeout(std::time::Duration::from_secs(20)) - .boxed(), - b, + let (sender, reciever) = mpsc::channel(self.channel_size); + + let swarm = SwarmBuilder::with_tokio_executor( + build_transport( + transport + .into_transport() + .map_err(BuildError::TransportConfig)?, + self.transport_timeout, + &keypair, + )?, + self.build(local_public_key), id, ) .build(); - tokio::spawn(async move { - loop { - match select(reciever.next(), swarm.next()).await { - // if the swarm or the channel are closed, close the relay - Either::Right((None, _)) | Either::Left((None, _)) => { - break; - } - // process command - Either::Left((Some(e), _)) => match e { - Message::ListenOn(a, s) => { - // try listen on each given address - match a.into_iter().try_fold(Vec::new(), |mut listeners, addr| { - match swarm.listen_on(addr) { - Ok(l) => { - listeners.push(l); - Ok(listeners) - } - Err(e) => Err((e, listeners)), - } - }) { - Ok(_) => s.send(Ok(())), - // if one fails, roll back all of them - Err((e, listeners)) => { - for l in listeners { - swarm.remove_listener(l); - } - s.send(Err(e.into())) - } + tokio::spawn(poll_swarm(swarm, reciever)); + + Ok(RelayNode { id, sender }) + } +} + +#[derive(thiserror::Error, Debug)] +pub enum BuildError +where + T: IntoTransport, +{ + #[error(transparent)] + TransportConfig(T::Error), + #[error(transparent)] + Noise(#[from] noise::NoiseError), +} + +#[derive(thiserror::Error, Debug)] +pub enum SwarmError { + #[error("failed to send response via oneshot")] + SendError, + #[error("failed to dial multiaddress: {0}")] + DialError(#[from] libp2p::swarm::DialError), +} + +async fn poll_swarm( + mut swarm: Swarm, + mut reciever: mpsc::Receiver, +) -> Result<(), SwarmError> { + loop { + match select(reciever.next(), swarm.next()).await { + // if the swarm or the channel are closed, close the relay + Either::Right((None, _)) | Either::Left((None, _)) => { + break; + } + // process command + Either::Left((Some(e), _)) => match e { + Message::ListenOn(a, s) => { + // try listen on each given address + match a.into_iter().try_fold(Vec::new(), |mut listeners, addr| { + match swarm.listen_on(addr) { + Ok(l) => { + listeners.push(l); + Ok(listeners) } - .map_err(|_| anyhow!("failed to return listening result"))?; + Err(e) => Err((e, listeners)), } - Message::GetAddresses(s) => { - s.send(swarm.listeners().map(|a| a.clone()).collect()) - .map_err(|_| anyhow!("failed to return listeners"))?; + }) { + Ok(_) => s.send(Ok(())).map_err(|_| SwarmError::SendError)?, + // if one fails, roll back all of them + Err((e, listeners)) => { + for l in listeners { + swarm.remove_listener(l); + } + s.send(Err(e.into())).map_err(|_| SwarmError::SendError)? } - }, - Either::Right((Some(_), _)) => { - // process swarm event - } + }; } + Message::GetAddresses(s) => s + .send(swarm.listeners().map(|a| a.clone()).collect()) + .map_err(|_| SwarmError::SendError)?, + Message::Dial(addr, s) => { + swarm.dial(addr)?; + s.send(Ok(())).map_err(|_| SwarmError::SendError)? + } + }, + Either::Right((Some(_), _)) => { + // process swarm event } - Result::<(), anyhow::Error>::Ok(()) - }); - Ok(r) + } } + Result::Ok(()) } #[cfg(test)] @@ -198,11 +252,10 @@ mod test { #[test] async fn basic_test() { - let addr = build_multiaddr!(Memory(0)); + let addr = build_multiaddr!(Memory(1u8)); - let relay = RelayConfig::default() + let mut relay = Config::default() .launch(Keypair::generate_ed25519(), MemoryConfig) - .await .unwrap(); relay.listen_on([addr.clone()]).await.unwrap(); diff --git a/src/p2p/transport.rs b/src/p2p/transport.rs index e120e746..d8ce5ba3 100644 --- a/src/p2p/transport.rs +++ b/src/p2p/transport.rs @@ -1,14 +1,45 @@ use crate::storage::either::EitherError; use futures::io::{AsyncRead, AsyncWrite}; use libp2p::{ - core::transport::{dummy::DummyTransport, MemoryTransport, OrTransport, Transport}, + core::{ + muxing::StreamMuxerBox, + transport::{dummy::DummyTransport, Boxed, MemoryTransport, OrTransport, Transport}, + upgrade, + }, dns::{ResolverConfig, ResolverOpts, TokioDnsConfig as DnsTransport}, + identity::Keypair, + mplex, + noise::{NoiseAuthenticated, NoiseError}, tcp::tokio::Transport as TcpTransport, wasm_ext::ExtTransport, websocket::{tls::Config as WsTlsConfig, WsConfig as WsTransport}, + yamux, PeerId, }; use std::io::Error as IoError; +pub fn build_transport( + t: T, + timeout: std::time::Duration, + keypair: &Keypair, +) -> Result, NoiseError> +where + T: 'static + Transport + Send + Unpin, + T::Output: 'static + AsyncRead + AsyncWrite + Unpin + Send, + T::Dial: Send, + T::Error: 'static + Send + Sync, + T::ListenerUpgrade: Send, +{ + Ok(t.upgrade(upgrade::Version::V1) + // TODO replace with AWAKE protcol (or similar) + .authenticate(NoiseAuthenticated::xx(keypair)?) + .multiplex(upgrade::SelectUpgrade::new( + yamux::YamuxConfig::default(), + mplex::MplexConfig::default(), + )) + .timeout(timeout) + .boxed()) +} + pub trait IntoTransport { type T: Transport; type Error: std::error::Error; From 12cd9e9df9ec72f21ed8a089ca5d4b7b737a06e2 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 5 Apr 2023 23:52:57 +1000 Subject: [PATCH 36/48] fix orbit behaviour builder and use specific errors --- src/p2p/behaviour/builder.rs | 74 +++++++++++++++++------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs index c05d2838..4cfa437f 100644 --- a/src/p2p/behaviour/builder.rs +++ b/src/p2p/behaviour/builder.rs @@ -1,18 +1,12 @@ use crate::p2p::{ - behaviour::{BaseBehaviour, Behaviour}, - transport::IntoTransport, + behaviour::{poll_swarm, BaseBehaviour, Behaviour}, + transport::{build_transport, IntoTransport}, IdentifyConfig, }; -use futures::{ - channel::{mpsc, oneshot}, - future::{select, Either}, - io::{AsyncRead, AsyncWrite}, - sink::SinkExt, - stream::StreamExt, -}; +use futures::io::{AsyncRead, AsyncWrite}; use libp2p::{ autonat::{Behaviour as AutoNat, Config as AutoNatConfig}, - core::{upgrade, Transport}, + core::Transport, dcutr::Behaviour as Dcutr, gossipsub::{ Behaviour as Gossipsub, Config as GossipsubConfig, ConfigBuilder as GossipsubConfigBuilder, @@ -24,12 +18,12 @@ use libp2p::{ record::store::{MemoryStore, MemoryStoreConfig, RecordStore}, Kademlia, KademliaConfig, }, - mplex, noise, + noise::NoiseError, ping::{Behaviour as Ping, Config as PingConfig}, relay::client::{new, Behaviour as Client}, - swarm::{Swarm, SwarmBuilder}, - yamux, + swarm::SwarmBuilder, }; +use std::time::Duration; use thiserror::Error; #[derive(Debug, Clone, Default)] @@ -41,6 +35,7 @@ pub struct BehaviourConfig { kademlia_store: KSC, autonat: AutoNatConfig, relay: bool, + transport_timeout: Duration, } impl BehaviourConfig { @@ -53,6 +48,7 @@ impl BehaviourConfig { kademlia_store: ksc.into(), autonat: Default::default(), relay: Default::default(), + transport_timeout: Duration::from_secs(20), } } pub fn identify(&mut self, i: impl Into) -> &mut Self { @@ -94,7 +90,6 @@ impl BehaviourConfig { { let peer_id = keypair.public().to_peer_id(); Ok(Behaviour { - exchange: todo!(), base: BaseBehaviour { identify: Identify::new(self.identify.to_config(keypair.public())), ping: Ping::new(self.ping), @@ -118,11 +113,8 @@ impl BehaviourConfig { }, }) } - pub fn launch( - self, - keypair: Keypair, - transport: T, - ) -> Result<(), OrbitLaunchError> + + pub fn launch(self, keypair: Keypair, transport: T) -> Result<(), OrbitLaunchError> where T: IntoTransport, T::T: 'static + Send + Unpin, @@ -132,32 +124,29 @@ impl BehaviourConfig { ::Dial: Send, ::ListenerUpgrade: Send, KS: RecordStore + Send + 'static, + KSC: RecordStoreConfig, { let local_public_key = keypair.public(); let id = local_public_key.to_peer_id(); - let transport = transport.into_transport()?; + let transport = transport + .into_transport() + .map_err(OrbitLaunchError::TransportConfig)?; let (transport, behaviour) = if self.relay { let (t, b) = new(id); - (transport.or_transport(t), self.build(keypair, Some(b))?) + ( + build_transport(transport.or_transport(t), self.transport_timeout, &keypair)?, + self.build(keypair, Some(b))?, + ) } else { - (transport, self.build(keypair, None)?) + ( + build_transport(transport, self.transport_timeout, &keypair)?, + self.build(keypair, None)?, + ) }; - let mut swarm = SwarmBuilder::with_tokio_executor( - transport - .upgrade(upgrade::Version::V1) - // TODO replace with AWAKE protcol (or similar) - .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) - .multiplex(upgrade::SelectUpgrade::new( - yamux::YamuxConfig::default(), - mplex::MplexConfig::default(), - )) - .timeout(std::time::Duration::from_secs(20)) - .boxed(), - behaviour, - id, - ) - .build(); + let swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, id).build(); + tokio::spawn(poll_swarm(swarm)); + Ok(()) } } @@ -169,11 +158,18 @@ pub enum OrbitBehaviourBuildError { } #[derive(Error, Debug)] -pub enum OrbitLaunchError { +pub enum OrbitLaunchError +where + T: IntoTransport, +{ #[error(transparent)] Config(#[from] OrbitBehaviourBuildError), #[error(transparent)] - Transport(T), + Transport(::Error), + #[error(transparent)] + TransportConfig(T::Error), + #[error(transparent)] + Noise(#[from] NoiseError), } pub trait RecordStoreConfig From 67bba630fe12058a6ce250cf51193342bf120398 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 6 Apr 2023 01:03:54 +1000 Subject: [PATCH 37/48] warnings + relay connected_peers fn --- src/p2p/behaviour/mod.rs | 2 +- src/p2p/relay.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/p2p/behaviour/mod.rs b/src/p2p/behaviour/mod.rs index f1dde56b..7c4ee823 100644 --- a/src/p2p/behaviour/mod.rs +++ b/src/p2p/behaviour/mod.rs @@ -37,7 +37,7 @@ where autonat: AutoNat, } -async fn poll_swarm(mut swarm: Swarm>) -> Result<(), ()> +async fn poll_swarm(_swarm: Swarm>) -> Result<(), ()> where KS: RecordStore + Send + 'static, { diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index 409c0d22..b86c4700 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -54,6 +54,7 @@ enum Message { GetAddresses(oneshot::Sender>), ListenOn(Vec, oneshot::Sender>), Dial(Multiaddr, oneshot::Sender>), + GetConnectedPeers(oneshot::Sender>), } impl RelayNode { @@ -82,6 +83,12 @@ impl RelayNode { self.sender.send(Message::Dial(addr, s)).await?; r.await? } + + pub async fn connected_peers(&mut self) -> Result, Error> { + let (s, r) = oneshot::channel(); + self.sender.send(Message::GetConnectedPeers(s)).await?; + Ok(r.await?) + } } #[derive(Debug)] @@ -235,6 +242,9 @@ async fn poll_swarm( swarm.dial(addr)?; s.send(Ok(())).map_err(|_| SwarmError::SendError)? } + Message::GetConnectedPeers(s) => s + .send(swarm.connected_peers().map(|p| p.to_owned()).collect()) + .map_err(|_| SwarmError::SendError)?, }, Either::Right((Some(_), _)) => { // process swarm event From 7acd79e8b4e481f66c130db3e7e0689114495699 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 6 Apr 2023 01:15:37 +1000 Subject: [PATCH 38/48] remove exchange-protocol subcrate --- Cargo.toml | 4 +- exchange-protocol/CHANGELOG.md | 190 ----- exchange-protocol/Cargo.toml | 33 - exchange-protocol/src/codec.rs | 83 -- exchange-protocol/src/handler.rs | 435 ---------- exchange-protocol/src/handler/protocol.rs | 189 ----- exchange-protocol/src/lib.rs | 952 ---------------------- exchange-protocol/tests/ping.rs | 388 --------- 8 files changed, 1 insertion(+), 2273 deletions(-) delete mode 100644 exchange-protocol/CHANGELOG.md delete mode 100644 exchange-protocol/Cargo.toml delete mode 100644 exchange-protocol/src/codec.rs delete mode 100644 exchange-protocol/src/handler.rs delete mode 100644 exchange-protocol/src/handler/protocol.rs delete mode 100644 exchange-protocol/src/lib.rs delete mode 100644 exchange-protocol/tests/ping.rs diff --git a/Cargo.toml b/Cargo.toml index e32cdc62..0e095968 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ bs58 = "0.4" cached = "0.40" derive_builder = "0.11" either = "1.8" -exchange-protocol = { path = "./exchange-protocol" } futures = { default-features = false, version = "0.3", features = ["alloc", "std"] } hex = "0.4" hyper = "0.14" # Prometheus server @@ -63,8 +62,7 @@ path = "lib/" members = [ "lib", "sdk-wasm", - "sdk", - "exchange-protocol" + "sdk" ] exclude = [ diff --git a/exchange-protocol/CHANGELOG.md b/exchange-protocol/CHANGELOG.md deleted file mode 100644 index a97d2400..00000000 --- a/exchange-protocol/CHANGELOG.md +++ /dev/null @@ -1,190 +0,0 @@ -# 0.23.0 - -- Update to `libp2p-core` `v0.38.0`. - -- Update to `libp2p-swarm` `v0.41.0`. - -- Replace `RequestResponse`'s `NetworkBehaviour` implemention `inject_*` methods with the new `on_*` methods. - See [PR 3011]. - -- Replace `RequestResponseHandler`'s `ConnectionHandler` implemention `inject_*` methods - with the new `on_*` methods. See [PR 3085]. - -- Update `rust-version` to reflect the actual MSRV: 1.62.0. See [PR 3090]. - -[PR 3085]: https://github.com/libp2p/rust-libp2p/pull/3085 -[PR 3011]: https://github.com/libp2p/rust-libp2p/pull/3011 -[PR 3090]: https://github.com/libp2p/rust-libp2p/pull/3090 - -# 0.22.0 - -- Bump rand to 0.8 and quickcheck to 1. See [PR 2857]. - -- Update to `libp2p-core` `v0.37.0`. - -- Update to `libp2p-swarm` `v0.40.0`. - -[PR 2857]: https://github.com/libp2p/rust-libp2p/pull/2857 - -# 0.21.0 - -- Update to `libp2p-swarm` `v0.39.0`. - -- Update to `libp2p-core` `v0.36.0`. - -# 0.20.0 - -- Update to `libp2p-swarm` `v0.38.0`. - -- Update to `libp2p-core` `v0.35.0`. - -# 0.19.0 - -- Update to `libp2p-core` `v0.34.0`. - -- Update to `libp2p-swarm` `v0.37.0`. - -# 0.18.0 - -- Update to `libp2p-core` `v0.33.0`. - -- Update to `libp2p-swarm` `v0.36.0`. - -# 0.17.0 - -- Update to `libp2p-swarm` `v0.35.0`. - -# 0.16.0 [2022-02-22] - -- Update to `libp2p-core` `v0.32.0`. - -- Update to `libp2p-swarm` `v0.34.0`. - -- Merge NetworkBehaviour's inject_\* paired methods (see PR 2445). - -[PR 2445]: https://github.com/libp2p/rust-libp2p/pull/2445 - -# 0.15.0 [2022-01-27] - -- Update dependencies. - -- Remove unused `lru` crate (see [PR 2358]). - -- Migrate to Rust edition 2021 (see [PR 2339]). - -[PR 2339]: https://github.com/libp2p/rust-libp2p/pull/2339 -[PR 2358]: https://github.com/libp2p/rust-libp2p/pull/2358 - -# 0.14.0 [2021-11-16] - -- Use `instant` instead of `wasm-timer` (see [PR 2245]). - -- Update dependencies. - -[PR 2245]: https://github.com/libp2p/rust-libp2p/pull/2245 - -# 0.13.0 [2021-11-01] - -- Make default features of `libp2p-core` optional. - [PR 2181](https://github.com/libp2p/rust-libp2p/pull/2181) - -- Update dependencies. - -- Manually implement `Debug` for `RequestResponseHandlerEvent` and - `RequestProtocol`. See [PR 2183]. - -- Remove `RequestResponse::throttled` and the `throttled` module. - See [PR 2236]. - -[PR 2183]: https://github.com/libp2p/rust-libp2p/pull/2183 -[PR 2236]: https://github.com/libp2p/rust-libp2p/pull/2236 - -# 0.12.0 [2021-07-12] - -- Update dependencies. - -# 0.11.0 [2021-04-13] - -- Update `libp2p-swarm`. -- Implement `std::error::Error` for `InboundFailure` and `OutboundFailure` [PR - 2033](https://github.com/libp2p/rust-libp2p/pull/2033). - -# 0.10.0 [2021-03-17] - -- Update `libp2p-swarm`. - -- Close stream even when no response has been sent. - [PR 1987](https://github.com/libp2p/rust-libp2p/pull/1987). - -- Update dependencies. - -# 0.9.1 [2021-02-15] - -- Make `is_pending_outbound` return true on pending connection. - [PR 1928](https://github.com/libp2p/rust-libp2p/pull/1928). - -- Update dependencies. - -# 0.9.0 [2021-01-12] - -- Update dependencies. - -- Re-export `throttled`-specific response channel. [PR - 1902](https://github.com/libp2p/rust-libp2p/pull/1902). - -# 0.8.0 [2020-12-17] - -- Update `libp2p-swarm` and `libp2p-core`. - -- Emit `InboundFailure::ConnectionClosed` for inbound requests that failed due - to the underlying connection closing. - [PR 1886](https://github.com/libp2p/rust-libp2p/pull/1886). - -- Derive Clone for `InboundFailure` and `Outbound}Failure`. - [PR 1891](https://github.com/libp2p/rust-libp2p/pull/1891) - -# 0.7.0 [2020-12-08] - -- Refine emitted events for inbound requests, introducing - the `ResponseSent` event and the `ResponseOmission` - inbound failures. This effectively removes previous - support for one-way protocols without responses. - [PR 1867](https://github.com/libp2p/rust-libp2p/pull/1867). - -# 0.6.0 [2020-11-25] - -- Update `libp2p-swarm` and `libp2p-core`. - -# 0.5.0 [2020-11-09] - -- Update dependencies. - -# 0.4.0 [2020-10-16] - -- Update dependencies. - -# 0.3.0 [2020-09-09] - -- Add support for opt-in request-based flow-control to any - request-response protocol via `RequestResponse::throttled()`. - [PR 1726](https://github.com/libp2p/rust-libp2p/pull/1726). - -- Update `libp2p-swarm` and `libp2p-core`. - -# 0.2.0 [2020-08-18] - -- Fixed connection keep-alive, permitting connections to close due - to inactivity. -- Bump `libp2p-core` and `libp2p-swarm` dependencies. - -# 0.1.1 - -- Always properly `close()` the substream after sending requests and -responses in the `InboundUpgrade` and `OutboundUpgrade`. Otherwise this is -left to `RequestResponseCodec::write_request` and `RequestResponseCodec::write_response`, -which can be a pitfall and lead to subtle problems (see e.g. -https://github.com/libp2p/rust-libp2p/pull/1606). - -# 0.1.0 - -- Initial release. diff --git a/exchange-protocol/Cargo.toml b/exchange-protocol/Cargo.toml deleted file mode 100644 index 216a21df..00000000 --- a/exchange-protocol/Cargo.toml +++ /dev/null @@ -1,33 +0,0 @@ -[package] -name = "exchange-protocol" -edition = "2021" -rust-version = "1.65.0" -description = "Streaming Request/Response Protocols" -version = "0.1.0" -authors = ["Parity Technologies "] -license = "MIT" -keywords = ["peer-to-peer", "libp2p", "networking"] -categories = ["network-programming", "asynchronous"] - -[dependencies] -async-trait = "0.1" -bytes = "1" -futures = { default-features = false, version = "0.3", features = ["alloc", "std"] } -instant = "0.1.11" -libp2p = { default-features = false, version = "0.50.0" } -log = "0.4.11" -rand = "0.8" -smallvec = "1.6.1" -unsigned-varint = { version = "0.7", features = ["std", "futures"] } - -[dev-dependencies] -async-std = "1.6.2" -env_logger = "0.9.0" -rand = "0.8" - -# Passing arguments to the docsrs builder in order to properly document cfg's. -# More information: https://docs.rs/about/builds#cross-compiling -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--cfg", "docsrs"] -rustc-args = ["--cfg", "docsrs"] diff --git a/exchange-protocol/src/codec.rs b/exchange-protocol/src/codec.rs deleted file mode 100644 index 3e7590b1..00000000 --- a/exchange-protocol/src/codec.rs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -pub use libp2p::core::ProtocolName; - -use async_trait::async_trait; -use futures::prelude::*; -use std::io; - -/// A `RequestResponseCodec` defines the request and response types -/// for a [`RequestResponse`](crate::RequestResponse) protocol or -/// protocol family and how they are encoded / decoded on an I/O stream. -#[async_trait] -pub trait RequestResponseCodec { - /// The type of protocol(s) or protocol versions being negotiated. - type Protocol: ProtocolName + Send + Clone; - /// The type of inbound and outbound requests. - type Request: Send; - /// The type of inbound and outbound responses. - type Response: Send - where - T: AsyncRead + Send; - - /// Reads a request from the given I/O stream according to the - /// negotiated protocol. - async fn read_request( - &mut self, - protocol: &Self::Protocol, - io: T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send; - - /// Reads a response from the given I/O stream according to the - /// negotiated protocol. - async fn read_response( - &mut self, - protocol: &Self::Protocol, - io: T, - ) -> io::Result> - where - T: AsyncRead + Unpin + Send; - - /// Writes a request to the given I/O stream according to the - /// negotiated protocol. - async fn write_request( - &mut self, - protocol: &Self::Protocol, - io: T, - req: Self::Request, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send; - - /// Writes a response to the given I/O stream according to the - /// negotiated protocol. - async fn write_response( - &mut self, - protocol: &Self::Protocol, - io: T, - res: Self::Response, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send, - R: AsyncRead + Send; -} diff --git a/exchange-protocol/src/handler.rs b/exchange-protocol/src/handler.rs deleted file mode 100644 index 55a899dc..00000000 --- a/exchange-protocol/src/handler.rs +++ /dev/null @@ -1,435 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -mod protocol; - -use crate::codec::RequestResponseCodec; -use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD}; - -use libp2p::swarm::handler::{ - ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, - ListenUpgradeError, -}; -pub use protocol::{ProtocolSupport, RequestProtocol, ResponseProtocol}; - -use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered}; -use instant::Instant; -use libp2p::core::upgrade::{NegotiationError, UpgradeError}; -use libp2p::swarm::{ - handler::{ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive}, - NegotiatedSubstream, SubstreamProtocol, -}; -use smallvec::SmallVec; -use std::{ - collections::VecDeque, - fmt, io, - sync::{ - atomic::{AtomicU64, Ordering}, - Arc, - }, - task::{Context, Poll}, - time::Duration, -}; - -/// A connection handler of a `RequestResponse` protocol. -#[doc(hidden)] -pub struct RequestResponseHandler -where - TCodec: RequestResponseCodec, - R: AsyncRead + Send, -{ - /// The supported inbound protocols. - inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, - /// The request/response message codec. - codec: TCodec, - /// The keep-alive timeout of idle connections. A connection is considered - /// idle if there are no outbound substreams. - keep_alive_timeout: Duration, - /// The timeout for inbound and outbound substreams (i.e. request - /// and response processing). - substream_timeout: Duration, - /// The current connection keep-alive. - keep_alive: KeepAlive, - /// A pending fatal error that results in the connection being closed. - pending_error: Option>, - /// Queue of events to emit in `poll()`. - pending_events: VecDeque>, - /// Outbound upgrades waiting to be emitted as an `OutboundSubstreamRequest`. - outbound: VecDeque>, - /// Inbound upgrades waiting for the incoming request. - inbound: FuturesUnordered< - BoxFuture< - 'static, - Result< - ( - (RequestId, TCodec::Request), - oneshot::Sender>, - ), - oneshot::Canceled, - >, - >, - >, - inbound_request_id: Arc, -} - -impl RequestResponseHandler -where - TCodec: RequestResponseCodec + Send + Clone + 'static, - R: AsyncRead + Send + 'static, -{ - pub(super) fn new( - inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, - codec: TCodec, - keep_alive_timeout: Duration, - substream_timeout: Duration, - inbound_request_id: Arc, - ) -> Self { - Self { - inbound_protocols, - codec, - keep_alive: KeepAlive::Yes, - keep_alive_timeout, - substream_timeout, - outbound: VecDeque::new(), - inbound: FuturesUnordered::new(), - pending_events: VecDeque::new(), - pending_error: None, - inbound_request_id, - } - } - - fn on_fully_negotiated_inbound( - &mut self, - FullyNegotiatedInbound { - protocol: sent, - info: request_id, - }: FullyNegotiatedInbound< - ::InboundProtocol, - ::InboundOpenInfo, - >, - ) { - if sent { - self.pending_events - .push_back(RequestResponseHandlerEvent::ResponseSent(request_id)) - } else { - self.pending_events - .push_back(RequestResponseHandlerEvent::ResponseOmission(request_id)) - } - } - - fn on_dial_upgrade_error( - &mut self, - DialUpgradeError { info, error }: DialUpgradeError< - ::OutboundOpenInfo, - ::OutboundProtocol, - >, - ) { - match error { - ConnectionHandlerUpgrErr::Timeout => { - self.pending_events - .push_back(RequestResponseHandlerEvent::OutboundTimeout(info)); - } - ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => { - // The remote merely doesn't support the protocol(s) we requested. - // This is no reason to close the connection, which may - // successfully communicate with other protocols already. - // An event is reported to permit user code to react to the fact that - // the remote peer does not support the requested protocol(s). - self.pending_events.push_back( - RequestResponseHandlerEvent::OutboundUnsupportedProtocols(info), - ); - } - _ => { - // Anything else is considered a fatal error or misbehaviour of - // the remote peer and results in closing the connection. - self.pending_error = Some(error); - } - } - } - fn on_listen_upgrade_error( - &mut self, - ListenUpgradeError { info, error }: ListenUpgradeError< - ::InboundOpenInfo, - ::InboundProtocol, - >, - ) { - match error { - ConnectionHandlerUpgrErr::Timeout => self - .pending_events - .push_back(RequestResponseHandlerEvent::InboundTimeout(info)), - ConnectionHandlerUpgrErr::Upgrade(UpgradeError::Select(NegotiationError::Failed)) => { - // The local peer merely doesn't support the protocol(s) requested. - // This is no reason to close the connection, which may - // successfully communicate with other protocols already. - // An event is reported to permit user code to react to the fact that - // the local peer does not support the requested protocol(s). - self.pending_events.push_back( - RequestResponseHandlerEvent::InboundUnsupportedProtocols(info), - ); - } - _ => { - // Anything else is considered a fatal error or misbehaviour of - // the remote peer and results in closing the connection. - self.pending_error = Some(error); - } - } - } -} - -/// The events emitted by the [`RequestResponseHandler`]. -#[doc(hidden)] -pub enum RequestResponseHandlerEvent -where - TCodec: RequestResponseCodec, - R: AsyncRead + Send, -{ - /// A request has been received. - Request { - request_id: RequestId, - request: TCodec::Request, - sender: oneshot::Sender>, - }, - /// A response has been received. - Response { - request_id: RequestId, - response: TCodec::Response, - }, - /// A response to an inbound request has been sent. - ResponseSent(RequestId), - /// A response to an inbound request was omitted as a result - /// of dropping the response `sender` of an inbound `Request`. - ResponseOmission(RequestId), - /// An outbound request timed out while sending the request - /// or waiting for the response. - OutboundTimeout(RequestId), - /// An outbound request failed to negotiate a mutually supported protocol. - OutboundUnsupportedProtocols(RequestId), - /// An inbound request timed out while waiting for the request - /// or sending the response. - InboundTimeout(RequestId), - /// An inbound request failed to negotiate a mutually supported protocol. - InboundUnsupportedProtocols(RequestId), -} - -impl fmt::Debug - for RequestResponseHandlerEvent -where - R: Send, -{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - RequestResponseHandlerEvent::Request { - request_id, - request: _, - sender: _, - } => f - .debug_struct("RequestResponseHandlerEvent::Request") - .field("request_id", request_id) - .finish(), - RequestResponseHandlerEvent::Response { - request_id, - response: _, - } => f - .debug_struct("RequestResponseHandlerEvent::Response") - .field("request_id", request_id) - .finish(), - RequestResponseHandlerEvent::ResponseSent(request_id) => f - .debug_tuple("RequestResponseHandlerEvent::ResponseSent") - .field(request_id) - .finish(), - RequestResponseHandlerEvent::ResponseOmission(request_id) => f - .debug_tuple("RequestResponseHandlerEvent::ResponseOmission") - .field(request_id) - .finish(), - RequestResponseHandlerEvent::OutboundTimeout(request_id) => f - .debug_tuple("RequestResponseHandlerEvent::OutboundTimeout") - .field(request_id) - .finish(), - RequestResponseHandlerEvent::OutboundUnsupportedProtocols(request_id) => f - .debug_tuple("RequestResponseHandlerEvent::OutboundUnsupportedProtocols") - .field(request_id) - .finish(), - RequestResponseHandlerEvent::InboundTimeout(request_id) => f - .debug_tuple("RequestResponseHandlerEvent::InboundTimeout") - .field(request_id) - .finish(), - RequestResponseHandlerEvent::InboundUnsupportedProtocols(request_id) => f - .debug_tuple("RequestResponseHandlerEvent::InboundUnsupportedProtocols") - .field(request_id) - .finish(), - } - } -} - -impl ConnectionHandler for RequestResponseHandler -where - TCodec: RequestResponseCodec + Send + Clone + 'static, - R: AsyncRead + Send + 'static, -{ - type InEvent = RequestProtocol; - type OutEvent = RequestResponseHandlerEvent; - type Error = ConnectionHandlerUpgrErr; - type InboundProtocol = ResponseProtocol; - type OutboundProtocol = RequestProtocol; - type OutboundOpenInfo = RequestId; - type InboundOpenInfo = RequestId; - - fn listen_protocol(&self) -> SubstreamProtocol { - // A channel for notifying the handler when the inbound - // upgrade received the request. - let (rq_send, rq_recv) = oneshot::channel(); - - // A channel for notifying the inbound upgrade when the - // response is sent. - let (rs_send, rs_recv) = oneshot::channel(); - - let request_id = RequestId(self.inbound_request_id.fetch_add(1, Ordering::Relaxed)); - - // By keeping all I/O inside the `ResponseProtocol` and thus the - // inbound substream upgrade via above channels, we ensure that it - // is all subject to the configured timeout without extra bookkeeping - // for inbound substreams as well as their timeouts and also make the - // implementation of inbound and outbound upgrades symmetric in - // this sense. - let proto = ResponseProtocol { - protocols: self.inbound_protocols.clone(), - codec: self.codec.clone(), - request_sender: rq_send, - response_receiver: rs_recv, - request_id, - }; - - // The handler waits for the request to come in. It then emits - // `RequestResponseHandlerEvent::Request` together with a - // `ResponseChannel`. - self.inbound - .push(rq_recv.map_ok(move |rq| (rq, rs_send)).boxed()); - - SubstreamProtocol::new(proto, request_id).with_timeout(self.substream_timeout) - } - - fn on_behaviour_event(&mut self, request: Self::InEvent) { - self.keep_alive = KeepAlive::Yes; - self.outbound.push_back(request); - } - - fn connection_keep_alive(&self) -> KeepAlive { - self.keep_alive - } - - fn poll( - &mut self, - cx: &mut Context<'_>, - ) -> Poll, RequestId, Self::OutEvent, Self::Error>> - { - // Check for a pending (fatal) error. - if let Some(err) = self.pending_error.take() { - // The handler will not be polled again by the `Swarm`. - return Poll::Ready(ConnectionHandlerEvent::Close(err)); - } - - // Drain pending events. - if let Some(event) = self.pending_events.pop_front() { - return Poll::Ready(ConnectionHandlerEvent::Custom(event)); - } else if self.pending_events.capacity() > EMPTY_QUEUE_SHRINK_THRESHOLD { - self.pending_events.shrink_to_fit(); - } - - // Check for inbound requests. - while let Poll::Ready(Some(result)) = self.inbound.poll_next_unpin(cx) { - match result { - Ok(((id, rq), rs_sender)) => { - // We received an inbound request. - self.keep_alive = KeepAlive::Yes; - return Poll::Ready(ConnectionHandlerEvent::Custom( - RequestResponseHandlerEvent::Request { - request_id: id, - request: rq, - sender: rs_sender, - }, - )); - } - Err(oneshot::Canceled) => { - // The inbound upgrade has errored or timed out reading - // or waiting for the request. The handler is informed - // via `inject_listen_upgrade_error`. - } - } - } - - // Emit outbound requests. - if let Some(request) = self.outbound.pop_front() { - let info = request.request_id; - return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { - protocol: SubstreamProtocol::new(request, info) - .with_timeout(self.substream_timeout), - }); - } - - debug_assert!(self.outbound.is_empty()); - - if self.outbound.capacity() > EMPTY_QUEUE_SHRINK_THRESHOLD { - self.outbound.shrink_to_fit(); - } - - if self.inbound.is_empty() && self.keep_alive.is_yes() { - // No new inbound or outbound requests. However, we may just have - // started the latest inbound or outbound upgrade(s), so make sure - // the keep-alive timeout is preceded by the substream timeout. - let until = Instant::now() + self.substream_timeout + self.keep_alive_timeout; - self.keep_alive = KeepAlive::Until(until); - } - - Poll::Pending - } - - fn on_connection_event( - &mut self, - event: ConnectionEvent< - Self::InboundProtocol, - Self::OutboundProtocol, - Self::InboundOpenInfo, - Self::OutboundOpenInfo, - >, - ) { - match event { - ConnectionEvent::FullyNegotiatedInbound(fully_negotiated_inbound) => { - self.on_fully_negotiated_inbound(fully_negotiated_inbound) - } - ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { - protocol: response, - info: request_id, - }) => { - self.pending_events - .push_back(RequestResponseHandlerEvent::Response { - request_id, - response, - }); - } - ConnectionEvent::DialUpgradeError(dial_upgrade_error) => { - self.on_dial_upgrade_error(dial_upgrade_error) - } - ConnectionEvent::ListenUpgradeError(listen_upgrade_error) => { - self.on_listen_upgrade_error(listen_upgrade_error) - } - ConnectionEvent::AddressChange(_) => {} - } - } -} diff --git a/exchange-protocol/src/handler/protocol.rs b/exchange-protocol/src/handler/protocol.rs deleted file mode 100644 index e7be4f37..00000000 --- a/exchange-protocol/src/handler/protocol.rs +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//! The definition of a request/response protocol via inbound -//! and outbound substream upgrades. The inbound upgrade -//! receives a request and sends a response, whereas the -//! outbound upgrade send a request and receives a response. - -use crate::codec::RequestResponseCodec; -use crate::RequestId; - -use futures::{channel::oneshot, future::BoxFuture, prelude::*}; -use libp2p::core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; -use libp2p::swarm::NegotiatedSubstream; -use smallvec::SmallVec; -use std::{fmt, io}; - -/// The level of support for a particular protocol. -#[derive(Debug, Clone)] -pub enum ProtocolSupport { - /// The protocol is only supported for inbound requests. - Inbound, - /// The protocol is only supported for outbound requests. - Outbound, - /// The protocol is supported for inbound and outbound requests. - Full, -} - -impl ProtocolSupport { - /// Whether inbound requests are supported. - pub fn inbound(&self) -> bool { - match self { - ProtocolSupport::Inbound | ProtocolSupport::Full => true, - ProtocolSupport::Outbound => false, - } - } - - /// Whether outbound requests are supported. - pub fn outbound(&self) -> bool { - match self { - ProtocolSupport::Outbound | ProtocolSupport::Full => true, - ProtocolSupport::Inbound => false, - } - } -} - -/// Response substream upgrade protocol. -/// -/// Receives a request and sends a response. -#[derive(Debug)] -pub struct ResponseProtocol -where - TCodec: RequestResponseCodec, - R: AsyncRead + Send, -{ - pub(crate) codec: TCodec, - pub(crate) protocols: SmallVec<[TCodec::Protocol; 2]>, - pub(crate) request_sender: oneshot::Sender<(RequestId, TCodec::Request)>, - pub(crate) response_receiver: oneshot::Receiver>, - pub(crate) request_id: RequestId, -} - -impl UpgradeInfo for ResponseProtocol -where - TCodec: RequestResponseCodec, - R: AsyncRead + Send, -{ - type Info = TCodec::Protocol; - type InfoIter = smallvec::IntoIter<[Self::Info; 2]>; - - fn protocol_info(&self) -> Self::InfoIter { - self.protocols.clone().into_iter() - } -} - -impl InboundUpgrade for ResponseProtocol -where - TCodec: RequestResponseCodec + Send + 'static, - R: AsyncRead + Send + 'static, -{ - type Output = bool; - type Error = io::Error; - type Future = BoxFuture<'static, Result>; - - fn upgrade_inbound(mut self, io: NegotiatedSubstream, protocol: Self::Info) -> Self::Future { - let (reader, mut writer) = io.split(); - async move { - let read = self.codec.read_request(&protocol, reader); - let request = read.await?; - match self.request_sender.send((self.request_id, request)) { - Ok(()) => {}, - Err(_) => panic!( - "Expect request receiver to be alive i.e. protocol handler to be alive.", - ), - } - - if let Ok(response) = self.response_receiver.await { - let write = self.codec.write_response(&protocol, &mut writer, response); - write.await?; - - writer.close().await?; - // Response was sent. Indicate to handler to emit a `ResponseSent` event. - Ok(true) - } else { - writer.close().await?; - // No response was sent. Indicate to handler to emit a `ResponseOmission` event. - Ok(false) - } - }.boxed() - } -} - -/// Request substream upgrade protocol. -/// -/// Sends a request and receives a response. -pub struct RequestProtocol -where - TCodec: RequestResponseCodec, -{ - pub(crate) codec: TCodec, - pub(crate) protocols: SmallVec<[TCodec::Protocol; 2]>, - pub(crate) request_id: RequestId, - pub(crate) request: TCodec::Request, -} - -impl fmt::Debug for RequestProtocol -where - TCodec: RequestResponseCodec, -{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("RequestProtocol") - .field("request_id", &self.request_id) - .finish() - } -} - -impl UpgradeInfo for RequestProtocol -where - TCodec: RequestResponseCodec, -{ - type Info = TCodec::Protocol; - type InfoIter = smallvec::IntoIter<[Self::Info; 2]>; - - fn protocol_info(&self) -> Self::InfoIter { - self.protocols.clone().into_iter() - } -} - -impl OutboundUpgrade for RequestProtocol -where - TCodec: RequestResponseCodec + Send + 'static, -{ - type Output = TCodec::Response; - type Error = io::Error; - type Future = BoxFuture<'static, Result>; - - fn upgrade_outbound( - mut self, - mut io: NegotiatedSubstream, - protocol: Self::Info, - ) -> Self::Future { - async move { - let write = self.codec.write_request(&protocol, &mut io, self.request); - write.await?; - io.close().await?; - let read = self.codec.read_response(&protocol, io); - let response = read.await?; - Ok(response) - } - .boxed() - } -} diff --git a/exchange-protocol/src/lib.rs b/exchange-protocol/src/lib.rs deleted file mode 100644 index dd06d91e..00000000 --- a/exchange-protocol/src/lib.rs +++ /dev/null @@ -1,952 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//! Generic request/response protocols. -//! -//! ## General Usage -//! -//! [`RequestResponse`] is a `NetworkBehaviour` that implements a generic -//! request/response protocol or protocol family, whereby each request is -//! sent over a new substream on a connection. `RequestResponse` is generic -//! over the actual messages being sent, which are defined in terms of a -//! [`RequestResponseCodec`]. Creating a request/response protocol thus amounts -//! to providing an implementation of this trait which can then be -//! given to [`RequestResponse::new`]. Further configuration options are -//! available via the [`RequestResponseConfig`]. -//! -//! Requests are sent using [`RequestResponse::send_request`] and the -//! responses received as [`RequestResponseMessage::Response`] via -//! [`RequestResponseEvent::Message`]. -//! -//! Responses are sent using [`RequestResponse::send_response`] upon -//! receiving a [`RequestResponseMessage::Request`] via -//! [`RequestResponseEvent::Message`]. -//! -//! ## Protocol Families -//! -//! A single [`RequestResponse`] instance can be used with an entire -//! protocol family that share the same request and response types. -//! For that purpose, [`RequestResponseCodec::Protocol`] is typically -//! instantiated with a sum type. -//! -//! ## Limited Protocol Support -//! -//! It is possible to only support inbound or outbound requests for -//! a particular protocol. This is achieved by instantiating `RequestResponse` -//! with protocols using [`ProtocolSupport::Inbound`] or -//! [`ProtocolSupport::Outbound`]. Any subset of protocols of a protocol -//! family can be configured in this way. Such protocols will not be -//! advertised during inbound respectively outbound protocol negotiation -//! on the substreams. - -#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] - -pub mod codec; -pub mod handler; - -pub use codec::{ProtocolName, RequestResponseCodec}; -pub use handler::ProtocolSupport; - -use futures::channel::oneshot; -use futures::io::AsyncRead; -use handler::{RequestProtocol, RequestResponseHandler, RequestResponseHandlerEvent}; -use libp2p::core::{connection::ConnectionId, ConnectedPoint, Multiaddr, PeerId}; -use libp2p::swarm::{ - behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}, - dial_opts::DialOpts, - IntoConnectionHandler, NegotiatedSubstream, NetworkBehaviour, NetworkBehaviourAction, - NotifyHandler, PollParameters, -}; -use smallvec::SmallVec; -use std::{ - collections::{HashMap, HashSet, VecDeque}, - fmt, - sync::{atomic::AtomicU64, Arc}, - task::{Context, Poll}, - time::Duration, -}; - -/// An inbound request or response. -#[derive(Debug)] -pub enum RequestResponseMessage { - /// A request message. - Request { - /// The ID of this request. - request_id: RequestId, - /// The request message. - request: TRequest, - /// The channel waiting for the response. - /// - /// If this channel is dropped instead of being used to send a response - /// via [`RequestResponse::send_response`], a [`RequestResponseEvent::InboundFailure`] - /// with [`InboundFailure::ResponseOmission`] is emitted. - channel: ResponseChannel, - }, - /// A response message. - Response { - /// The ID of the request that produced this response. - /// - /// See [`RequestResponse::send_request`]. - request_id: RequestId, - /// The response message. - response: TResponse, - }, -} - -/// The events emitted by a [`RequestResponse`] protocol. -#[derive(Debug)] -pub enum RequestResponseEvent { - /// An incoming message (request or response). - Message { - /// The peer who sent the message. - peer: PeerId, - /// The incoming message. - message: RequestResponseMessage, - }, - /// An outbound request failed. - OutboundFailure { - /// The peer to whom the request was sent. - peer: PeerId, - /// The (local) ID of the failed request. - request_id: RequestId, - /// The error that occurred. - error: OutboundFailure, - }, - /// An inbound request failed. - InboundFailure { - /// The peer from whom the request was received. - peer: PeerId, - /// The ID of the failed inbound request. - request_id: RequestId, - /// The error that occurred. - error: InboundFailure, - }, - /// A response to an inbound request has been sent. - /// - /// When this event is received, the response has been flushed on - /// the underlying transport connection. - ResponseSent { - /// The peer to whom the response was sent. - peer: PeerId, - /// The ID of the inbound request whose response was sent. - request_id: RequestId, - }, -} - -/// Possible failures occurring in the context of sending -/// an outbound request and receiving the response. -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum OutboundFailure { - /// The request could not be sent because a dialing attempt failed. - DialFailure, - /// The request timed out before a response was received. - /// - /// It is not known whether the request may have been - /// received (and processed) by the remote peer. - Timeout, - /// The connection closed before a response was received. - /// - /// It is not known whether the request may have been - /// received (and processed) by the remote peer. - ConnectionClosed, - /// The remote supports none of the requested protocols. - UnsupportedProtocols, -} - -impl fmt::Display for OutboundFailure { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - OutboundFailure::DialFailure => write!(f, "Failed to dial the requested peer"), - OutboundFailure::Timeout => write!(f, "Timeout while waiting for a response"), - OutboundFailure::ConnectionClosed => { - write!(f, "Connection was closed before a response was received") - } - OutboundFailure::UnsupportedProtocols => { - write!(f, "The remote supports none of the requested protocols") - } - } - } -} - -impl std::error::Error for OutboundFailure {} - -/// Possible failures occurring in the context of receiving an -/// inbound request and sending a response. -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum InboundFailure { - /// The inbound request timed out, either while reading the - /// incoming request or before a response is sent, e.g. if - /// [`RequestResponse::send_response`] is not called in a - /// timely manner. - Timeout, - /// The connection closed before a response could be send. - ConnectionClosed, - /// The local peer supports none of the protocols requested - /// by the remote. - UnsupportedProtocols, - /// The local peer failed to respond to an inbound request - /// due to the [`ResponseChannel`] being dropped instead of - /// being passed to [`RequestResponse::send_response`]. - ResponseOmission, -} - -impl fmt::Display for InboundFailure { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - InboundFailure::Timeout => { - write!(f, "Timeout while receiving request or sending response") - } - InboundFailure::ConnectionClosed => { - write!(f, "Connection was closed before a response could be sent") - } - InboundFailure::UnsupportedProtocols => write!( - f, - "The local peer supports none of the protocols requested by the remote" - ), - InboundFailure::ResponseOmission => write!( - f, - "The response channel was dropped without sending a response to the remote" - ), - } - } -} - -impl std::error::Error for InboundFailure {} - -/// A channel for sending a response to an inbound request. -/// -/// See [`RequestResponse::send_response`]. -#[derive(Debug)] -pub struct ResponseChannel { - sender: oneshot::Sender, -} - -impl ResponseChannel { - /// Checks whether the response channel is still open, i.e. - /// the `RequestResponse` behaviour is still waiting for a - /// a response to be sent via [`RequestResponse::send_response`] - /// and this response channel. - /// - /// If the response channel is no longer open then the inbound - /// request timed out waiting for the response. - pub fn is_open(&self) -> bool { - !self.sender.is_canceled() - } -} - -/// The ID of an inbound or outbound request. -/// -/// Note: [`RequestId`]'s uniqueness is only guaranteed between two -/// inbound and likewise between two outbound requests. There is no -/// uniqueness guarantee in a set of both inbound and outbound -/// [`RequestId`]s nor in a set of inbound or outbound requests -/// originating from different [`RequestResponse`] behaviours. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub struct RequestId(u64); - -impl fmt::Display for RequestId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0) - } -} - -/// The configuration for a `RequestResponse` protocol. -#[derive(Debug, Clone)] -pub struct RequestResponseConfig { - request_timeout: Duration, - connection_keep_alive: Duration, -} - -impl Default for RequestResponseConfig { - fn default() -> Self { - Self { - connection_keep_alive: Duration::from_secs(10), - request_timeout: Duration::from_secs(10), - } - } -} - -impl RequestResponseConfig { - /// Sets the keep-alive timeout of idle connections. - pub fn set_connection_keep_alive(&mut self, v: Duration) -> &mut Self { - self.connection_keep_alive = v; - self - } - - /// Sets the timeout for inbound and outbound requests. - pub fn set_request_timeout(&mut self, v: Duration) -> &mut Self { - self.request_timeout = v; - self - } -} - -/// A request/response protocol for some message codec. -pub struct RequestResponse -where - TCodec: RequestResponseCodec + Clone + Send + 'static, - R: AsyncRead + Send + 'static, -{ - /// The supported inbound protocols. - inbound_protocols: SmallVec<[TCodec::Protocol; 2]>, - /// The supported outbound protocols. - outbound_protocols: SmallVec<[TCodec::Protocol; 2]>, - /// The next (local) request ID. - next_request_id: RequestId, - /// The next (inbound) request ID. - next_inbound_id: Arc, - /// The protocol configuration. - config: RequestResponseConfig, - /// The protocol codec for reading and writing requests and responses. - codec: TCodec, - /// Pending events to return from `poll`. - pending_events: VecDeque< - NetworkBehaviourAction< - RequestResponseEvent< - TCodec::Request, - TCodec::Response, - TCodec::Response, - >, - RequestResponseHandler, - >, - >, - /// The currently connected peers, their pending outbound and inbound responses and their known, - /// reachable addresses, if any. - connected: HashMap>, - /// Externally managed addresses via `add_address` and `remove_address`. - addresses: HashMap>, - /// Requests that have not yet been sent and are waiting for a connection - /// to be established. - pending_outbound_requests: HashMap; 10]>>, -} - -impl RequestResponse -where - TCodec: RequestResponseCodec + Clone + Send + 'static, - R: AsyncRead + Send + 'static, -{ - /// Creates a new `RequestResponse` behaviour for the given - /// protocols, codec and configuration. - pub fn new(codec: TCodec, protocols: I, cfg: RequestResponseConfig) -> Self - where - I: IntoIterator, - { - let mut inbound_protocols = SmallVec::new(); - let mut outbound_protocols = SmallVec::new(); - for (p, s) in protocols { - if s.inbound() { - inbound_protocols.push(p.clone()); - } - if s.outbound() { - outbound_protocols.push(p.clone()); - } - } - RequestResponse { - inbound_protocols, - outbound_protocols, - next_request_id: RequestId(1), - next_inbound_id: Arc::new(AtomicU64::new(1)), - config: cfg, - codec, - pending_events: VecDeque::new(), - connected: HashMap::new(), - pending_outbound_requests: HashMap::new(), - addresses: HashMap::new(), - } - } - - /// Initiates sending a request. - /// - /// If the targeted peer is currently not connected, a dialing - /// attempt is initiated and the request is sent as soon as a - /// connection is established. - /// - /// > **Note**: In order for such a dialing attempt to succeed, - /// > the `RequestResonse` protocol must either be embedded - /// > in another `NetworkBehaviour` that provides peer and - /// > address discovery, or known addresses of peers must be - /// > managed via [`RequestResponse::add_address`] and - /// > [`RequestResponse::remove_address`]. - pub fn send_request(&mut self, peer: &PeerId, request: TCodec::Request) -> RequestId { - let request_id = self.next_request_id(); - let request = RequestProtocol { - request_id, - codec: self.codec.clone(), - protocols: self.outbound_protocols.clone(), - request, - }; - - if let Some(request) = self.try_send_request(peer, request) { - let handler = self.new_handler(); - self.pending_events.push_back(NetworkBehaviourAction::Dial { - opts: DialOpts::peer_id(*peer).build(), - handler, - }); - self.pending_outbound_requests - .entry(*peer) - .or_default() - .push(request); - } - - request_id - } - - /// Initiates sending a response to an inbound request. - /// - /// If the [`ResponseChannel`] is already closed due to a timeout or the - /// connection being closed, the response is returned as an `Err` for - /// further handling. Once the response has been successfully sent on the - /// corresponding connection, [`RequestResponseEvent::ResponseSent`] is - /// emitted. In all other cases [`RequestResponseEvent::InboundFailure`] - /// will be or has been emitted. - /// - /// The provided `ResponseChannel` is obtained from an inbound - /// [`RequestResponseMessage::Request`]. - pub fn send_response( - &mut self, - ch: ResponseChannel>, - rs: TCodec::Response, - ) -> Result<(), TCodec::Response> { - ch.sender.send(rs) - } - - /// Adds a known address for a peer that can be used for - /// dialing attempts by the `Swarm`, i.e. is returned - /// by [`NetworkBehaviour::addresses_of_peer`]. - /// - /// Addresses added in this way are only removed by `remove_address`. - pub fn add_address(&mut self, peer: &PeerId, address: Multiaddr) { - self.addresses.entry(*peer).or_default().push(address); - } - - /// Removes an address of a peer previously added via `add_address`. - pub fn remove_address(&mut self, peer: &PeerId, address: &Multiaddr) { - let mut last = false; - if let Some(addresses) = self.addresses.get_mut(peer) { - addresses.retain(|a| a != address); - last = addresses.is_empty(); - } - if last { - self.addresses.remove(peer); - } - } - - /// Checks whether a peer is currently connected. - pub fn is_connected(&self, peer: &PeerId) -> bool { - if let Some(connections) = self.connected.get(peer) { - !connections.is_empty() - } else { - false - } - } - - /// Checks whether an outbound request to the peer with the provided - /// [`PeerId`] initiated by [`RequestResponse::send_request`] is still - /// pending, i.e. waiting for a response. - pub fn is_pending_outbound(&self, peer: &PeerId, request_id: &RequestId) -> bool { - // Check if request is already sent on established connection. - let est_conn = self - .connected - .get(peer) - .map(|cs| { - cs.iter() - .any(|c| c.pending_inbound_responses.contains(request_id)) - }) - .unwrap_or(false); - // Check if request is still pending to be sent. - let pen_conn = self - .pending_outbound_requests - .get(peer) - .map(|rps| rps.iter().any(|rp| rp.request_id == *request_id)) - .unwrap_or(false); - - est_conn || pen_conn - } - - /// Checks whether an inbound request from the peer with the provided - /// [`PeerId`] is still pending, i.e. waiting for a response by the local - /// node through [`RequestResponse::send_response`]. - pub fn is_pending_inbound(&self, peer: &PeerId, request_id: &RequestId) -> bool { - self.connected - .get(peer) - .map(|cs| { - cs.iter() - .any(|c| c.pending_outbound_responses.contains(request_id)) - }) - .unwrap_or(false) - } - - /// Returns the next request ID. - fn next_request_id(&mut self) -> RequestId { - let request_id = self.next_request_id; - self.next_request_id.0 += 1; - request_id - } - - /// Tries to send a request by queueing an appropriate event to be - /// emitted to the `Swarm`. If the peer is not currently connected, - /// the given request is return unchanged. - fn try_send_request( - &mut self, - peer: &PeerId, - request: RequestProtocol, - ) -> Option> { - if let Some(connections) = self.connected.get_mut(peer) { - if connections.is_empty() { - return Some(request); - } - let ix = (request.request_id.0 as usize) % connections.len(); - let conn = &mut connections[ix]; - conn.pending_inbound_responses.insert(request.request_id); - self.pending_events - .push_back(NetworkBehaviourAction::NotifyHandler { - peer_id: *peer, - handler: NotifyHandler::One(conn.id), - event: request, - }); - None - } else { - Some(request) - } - } - - /// Remove pending outbound response for the given peer and connection. - /// - /// Returns `true` if the provided connection to the given peer is still - /// alive and the [`RequestId`] was previously present and is now removed. - /// Returns `false` otherwise. - fn remove_pending_outbound_response( - &mut self, - peer: &PeerId, - connection: ConnectionId, - request: RequestId, - ) -> bool { - self.get_connection_mut(peer, connection) - .map(|c| c.pending_outbound_responses.remove(&request)) - .unwrap_or(false) - } - - /// Remove pending inbound response for the given peer and connection. - /// - /// Returns `true` if the provided connection to the given peer is still - /// alive and the [`RequestId`] was previously present and is now removed. - /// Returns `false` otherwise. - fn remove_pending_inbound_response( - &mut self, - peer: &PeerId, - connection: ConnectionId, - request: &RequestId, - ) -> bool { - self.get_connection_mut(peer, connection) - .map(|c| c.pending_inbound_responses.remove(request)) - .unwrap_or(false) - } - - /// Returns a mutable reference to the connection in `self.connected` - /// corresponding to the given [`PeerId`] and [`ConnectionId`]. - fn get_connection_mut( - &mut self, - peer: &PeerId, - connection: ConnectionId, - ) -> Option<&mut Connection> { - self.connected - .get_mut(peer) - .and_then(|connections| connections.iter_mut().find(|c| c.id == connection)) - } - - fn on_address_change( - &mut self, - AddressChange { - peer_id, - connection_id, - new, - .. - }: AddressChange, - ) { - let new_address = match new { - ConnectedPoint::Dialer { address, .. } => Some(address.clone()), - ConnectedPoint::Listener { .. } => None, - }; - let connections = self - .connected - .get_mut(&peer_id) - .expect("Address change can only happen on an established connection."); - - let connection = connections - .iter_mut() - .find(|c| c.id == connection_id) - .expect("Address change can only happen on an established connection."); - connection.address = new_address; - } - - fn on_connection_established( - &mut self, - ConnectionEstablished { - peer_id, - connection_id, - endpoint, - other_established, - .. - }: ConnectionEstablished, - ) { - let address = match endpoint { - ConnectedPoint::Dialer { address, .. } => Some(address.clone()), - ConnectedPoint::Listener { .. } => None, - }; - self.connected - .entry(peer_id) - .or_default() - .push(Connection::new(connection_id, address)); - - if other_established == 0 { - if let Some(pending) = self.pending_outbound_requests.remove(&peer_id) { - for request in pending { - let request = self.try_send_request(&peer_id, request); - assert!(request.is_none()); - } - } - } - } - - fn on_connection_closed( - &mut self, - ConnectionClosed { - peer_id, - connection_id, - remaining_established, - .. - }: ConnectionClosed<::ConnectionHandler>, - ) { - let connections = self - .connected - .get_mut(&peer_id) - .expect("Expected some established connection to peer before closing."); - - let connection = connections - .iter() - .position(|c| c.id == connection_id) - .map(|p: usize| connections.remove(p)) - .expect("Expected connection to be established before closing."); - - debug_assert_eq!(connections.is_empty(), remaining_established == 0); - if connections.is_empty() { - self.connected.remove(&peer_id); - } - - for request_id in connection.pending_outbound_responses { - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::InboundFailure { - peer: peer_id, - request_id, - error: InboundFailure::ConnectionClosed, - }, - )); - } - - for request_id in connection.pending_inbound_responses { - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::OutboundFailure { - peer: peer_id, - request_id, - error: OutboundFailure::ConnectionClosed, - }, - )); - } - } - - fn on_dial_failure( - &mut self, - DialFailure { peer_id, .. }: DialFailure<::ConnectionHandler>, - ) { - if let Some(peer) = peer_id { - // If there are pending outgoing requests when a dial failure occurs, - // it is implied that we are not connected to the peer, since pending - // outgoing requests are drained when a connection is established and - // only created when a peer is not connected when a request is made. - // Thus these requests must be considered failed, even if there is - // another, concurrent dialing attempt ongoing. - if let Some(pending) = self.pending_outbound_requests.remove(&peer) { - for request in pending { - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::OutboundFailure { - peer, - request_id: request.request_id, - error: OutboundFailure::DialFailure, - }, - )); - } - } - } - } -} - -impl NetworkBehaviour for RequestResponse -where - TCodec: RequestResponseCodec + Send + Clone + 'static, - R: AsyncRead + Send + 'static, -{ - type ConnectionHandler = RequestResponseHandler; - type OutEvent = RequestResponseEvent< - TCodec::Request, - TCodec::Response, - TCodec::Response, - >; - - fn new_handler(&mut self) -> Self::ConnectionHandler { - RequestResponseHandler::new( - self.inbound_protocols.clone(), - self.codec.clone(), - self.config.connection_keep_alive, - self.config.request_timeout, - self.next_inbound_id.clone(), - ) - } - - fn addresses_of_peer(&mut self, peer: &PeerId) -> Vec { - let mut addresses = Vec::new(); - if let Some(connections) = self.connected.get(peer) { - addresses.extend(connections.iter().filter_map(|c| c.address.clone())) - } - if let Some(more) = self.addresses.get(peer) { - addresses.extend(more.into_iter().cloned()); - } - addresses - } - - fn on_swarm_event(&mut self, event: FromSwarm) { - match event { - FromSwarm::ConnectionEstablished(connection_established) => { - self.on_connection_established(connection_established) - } - FromSwarm::ConnectionClosed(connection_closed) => { - self.on_connection_closed(connection_closed) - } - FromSwarm::AddressChange(address_change) => self.on_address_change(address_change), - FromSwarm::DialFailure(dial_failure) => self.on_dial_failure(dial_failure), - FromSwarm::ListenFailure(_) => {} - FromSwarm::NewListener(_) => {} - FromSwarm::NewListenAddr(_) => {} - FromSwarm::ExpiredListenAddr(_) => {} - FromSwarm::ListenerError(_) => {} - FromSwarm::ListenerClosed(_) => {} - FromSwarm::NewExternalAddr(_) => {} - FromSwarm::ExpiredExternalAddr(_) => {} - } - } - - fn on_connection_handler_event( - &mut self, - peer: PeerId, - connection: ConnectionId, - event: <::Handler as - libp2p::swarm::ConnectionHandler>::OutEvent, - ) { - match event { - RequestResponseHandlerEvent::Response { - request_id, - response, - } => { - let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); - debug_assert!( - removed, - "Expect request_id to be pending before receiving response.", - ); - - let message = RequestResponseMessage::Response { - request_id, - response, - }; - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::Message { peer, message }, - )); - } - RequestResponseHandlerEvent::Request { - request_id, - request, - sender, - } => { - let channel = ResponseChannel { sender }; - let message = RequestResponseMessage::Request { - request_id, - request, - channel, - }; - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::Message { peer, message }, - )); - - match self.get_connection_mut(&peer, connection) { - Some(connection) => { - let inserted = connection.pending_outbound_responses.insert(request_id); - debug_assert!(inserted, "Expect id of new request to be unknown."); - } - // Connection closed after `RequestResponseEvent::Request` has been emitted. - None => { - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::InboundFailure { - peer, - request_id, - error: InboundFailure::ConnectionClosed, - }, - )); - } - } - } - RequestResponseHandlerEvent::ResponseSent(request_id) => { - let removed = self.remove_pending_outbound_response(&peer, connection, request_id); - debug_assert!( - removed, - "Expect request_id to be pending before response is sent." - ); - - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::ResponseSent { peer, request_id }, - )); - } - RequestResponseHandlerEvent::ResponseOmission(request_id) => { - let removed = self.remove_pending_outbound_response(&peer, connection, request_id); - debug_assert!( - removed, - "Expect request_id to be pending before response is omitted.", - ); - - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::InboundFailure { - peer, - request_id, - error: InboundFailure::ResponseOmission, - }, - )); - } - RequestResponseHandlerEvent::OutboundTimeout(request_id) => { - let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); - debug_assert!( - removed, - "Expect request_id to be pending before request times out." - ); - - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::OutboundFailure { - peer, - request_id, - error: OutboundFailure::Timeout, - }, - )); - } - RequestResponseHandlerEvent::InboundTimeout(request_id) => { - // Note: `RequestResponseHandlerEvent::InboundTimeout` is emitted both for timing - // out to receive the request and for timing out sending the response. In the former - // case the request is never added to `pending_outbound_responses` and thus one can - // not assert the request_id to be present before removing it. - self.remove_pending_outbound_response(&peer, connection, request_id); - - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::InboundFailure { - peer, - request_id, - error: InboundFailure::Timeout, - }, - )); - } - RequestResponseHandlerEvent::OutboundUnsupportedProtocols(request_id) => { - let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); - debug_assert!( - removed, - "Expect request_id to be pending before failing to connect.", - ); - - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::OutboundFailure { - peer, - request_id, - error: OutboundFailure::UnsupportedProtocols, - }, - )); - } - RequestResponseHandlerEvent::InboundUnsupportedProtocols(request_id) => { - // Note: No need to call `self.remove_pending_outbound_response`, - // `RequestResponseHandlerEvent::Request` was never emitted for this request and - // thus request was never added to `pending_outbound_responses`. - self.pending_events - .push_back(NetworkBehaviourAction::GenerateEvent( - RequestResponseEvent::InboundFailure { - peer, - request_id, - error: InboundFailure::UnsupportedProtocols, - }, - )); - } - } - } - - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll> { - if let Some(ev) = self.pending_events.pop_front() { - return Poll::Ready(ev); - } else if self.pending_events.capacity() > EMPTY_QUEUE_SHRINK_THRESHOLD { - self.pending_events.shrink_to_fit(); - } - - Poll::Pending - } -} - -/// Internal threshold for when to shrink the capacity -/// of empty queues. If the capacity of an empty queue -/// exceeds this threshold, the associated memory is -/// released. -const EMPTY_QUEUE_SHRINK_THRESHOLD: usize = 100; - -/// Internal information tracked for an established connection. -struct Connection { - id: ConnectionId, - address: Option, - /// Pending outbound responses where corresponding inbound requests have - /// been received on this connection and emitted via `poll` but have not yet - /// been answered. - pending_outbound_responses: HashSet, - /// Pending inbound responses for previously sent requests on this - /// connection. - pending_inbound_responses: HashSet, -} - -impl Connection { - fn new(id: ConnectionId, address: Option) -> Self { - Self { - id, - address, - pending_outbound_responses: Default::default(), - pending_inbound_responses: Default::default(), - } - } -} diff --git a/exchange-protocol/tests/ping.rs b/exchange-protocol/tests/ping.rs deleted file mode 100644 index 44bdaf05..00000000 --- a/exchange-protocol/tests/ping.rs +++ /dev/null @@ -1,388 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//! Integration tests for the `RequestResponse` network behaviour. - -use async_trait::async_trait; -use futures::{channel::mpsc, prelude::*, AsyncWriteExt}; -use libp2p::core::{ - identity, - muxing::StreamMuxerBox, - transport, - upgrade::{self, read_length_prefixed, write_length_prefixed}, - Multiaddr, PeerId, -}; -use libp2p::noise::NoiseAuthenticated; -use libp2p::request_response::*; -use libp2p::swarm::{Swarm, SwarmEvent}; -use libp2p::tcp; -use libp2p::core::Transport; -use rand::{self, Rng}; -use std::{io, iter}; - -#[test] -fn is_response_outbound() { - let _ = env_logger::try_init(); - let ping = Ping("ping".to_string().into_bytes()); - let offline_peer = PeerId::random(); - - let protocols = iter::once((PingProtocol(), ProtocolSupport::Full)); - let cfg = RequestResponseConfig::default(); - - let (peer1_id, trans) = mk_transport(); - let ping_proto1 = RequestResponse::new(PingCodec(), protocols, cfg); - let mut swarm1 = Swarm::without_executor(trans, ping_proto1, peer1_id); - - let request_id1 = swarm1 - .behaviour_mut() - .send_request(&offline_peer, ping.clone()); - - match futures::executor::block_on(swarm1.select_next_some()) { - SwarmEvent::Behaviour(RequestResponseEvent::OutboundFailure { - peer, - request_id: req_id, - error: _error, - }) => { - assert_eq!(&offline_peer, &peer); - assert_eq!(req_id, request_id1); - } - e => panic!("Peer: Unexpected event: {:?}", e), - } - - let request_id2 = swarm1.behaviour_mut().send_request(&offline_peer, ping); - - assert!(!swarm1 - .behaviour() - .is_pending_outbound(&offline_peer, &request_id1)); - assert!(swarm1 - .behaviour() - .is_pending_outbound(&offline_peer, &request_id2)); -} - -/// Exercises a simple ping protocol. -#[test] -fn ping_protocol() { - let ping = Ping("ping".to_string().into_bytes()); - let pong = Pong("pong".to_string().into_bytes()); - - let protocols = iter::once((PingProtocol(), ProtocolSupport::Full)); - let cfg = RequestResponseConfig::default(); - - let (peer1_id, trans) = mk_transport(); - let ping_proto1 = RequestResponse::new(PingCodec(), protocols.clone(), cfg.clone()); - let mut swarm1 = Swarm::without_executor(trans, ping_proto1, peer1_id); - - let (peer2_id, trans) = mk_transport(); - let ping_proto2 = RequestResponse::new(PingCodec(), protocols, cfg); - let mut swarm2 = Swarm::without_executor(trans, ping_proto2, peer2_id); - - let (mut tx, mut rx) = mpsc::channel::(1); - - let addr = "/ip4/127.0.0.1/tcp/0".parse().unwrap(); - swarm1.listen_on(addr).unwrap(); - - let expected_ping = ping.clone(); - let expected_pong = pong.clone(); - - let peer1 = async move { - loop { - match swarm1.select_next_some().await { - SwarmEvent::NewListenAddr { address, .. } => tx.send(address).await.unwrap(), - SwarmEvent::Behaviour(RequestResponseEvent::Message { - peer, - message: - RequestResponseMessage::Request { - request, channel, .. - }, - }) => { - assert_eq!(&request, &expected_ping); - assert_eq!(&peer, &peer2_id); - swarm1 - .behaviour_mut() - .send_response(channel, pong.clone()) - .unwrap(); - } - SwarmEvent::Behaviour(RequestResponseEvent::ResponseSent { peer, .. }) => { - assert_eq!(&peer, &peer2_id); - } - SwarmEvent::Behaviour(e) => panic!("Peer1: Unexpected event: {:?}", e), - _ => {} - } - } - }; - - let num_pings: u8 = rand::thread_rng().gen_range(1..100); - - let peer2 = async move { - let mut count = 0; - let addr = rx.next().await.unwrap(); - swarm2.behaviour_mut().add_address(&peer1_id, addr.clone()); - let mut req_id = swarm2.behaviour_mut().send_request(&peer1_id, ping.clone()); - assert!(swarm2.behaviour().is_pending_outbound(&peer1_id, &req_id)); - - loop { - match swarm2.select_next_some().await { - SwarmEvent::Behaviour(RequestResponseEvent::Message { - peer, - message: - RequestResponseMessage::Response { - request_id, - response, - }, - }) => { - count += 1; - assert_eq!(&response, &expected_pong); - assert_eq!(&peer, &peer1_id); - assert_eq!(req_id, request_id); - if count >= num_pings { - return; - } else { - req_id = swarm2.behaviour_mut().send_request(&peer1_id, ping.clone()); - } - } - SwarmEvent::Behaviour(e) => panic!("Peer2: Unexpected event: {:?}", e), - _ => {} - } - } - }; - - async_std::task::spawn(Box::pin(peer1)); - let () = async_std::task::block_on(peer2); -} - -#[test] -fn emits_inbound_connection_closed_failure() { - let ping = Ping("ping".to_string().into_bytes()); - - let protocols = iter::once((PingProtocol(), ProtocolSupport::Full)); - let cfg = RequestResponseConfig::default(); - - let (peer1_id, trans) = mk_transport(); - let ping_proto1 = RequestResponse::new(PingCodec(), protocols.clone(), cfg.clone()); - let mut swarm1 = Swarm::without_executor(trans, ping_proto1, peer1_id); - - let (peer2_id, trans) = mk_transport(); - let ping_proto2 = RequestResponse::new(PingCodec(), protocols, cfg); - let mut swarm2 = Swarm::without_executor(trans, ping_proto2, peer2_id); - - let addr = "/ip4/127.0.0.1/tcp/0".parse().unwrap(); - swarm1.listen_on(addr).unwrap(); - - futures::executor::block_on(async move { - while swarm1.next().now_or_never().is_some() {} - let addr1 = Swarm::listeners(&swarm1).next().unwrap(); - - swarm2.behaviour_mut().add_address(&peer1_id, addr1.clone()); - swarm2.behaviour_mut().send_request(&peer1_id, ping.clone()); - - // Wait for swarm 1 to receive request by swarm 2. - let _channel = loop { - futures::select!( - event = swarm1.select_next_some() => match event { - SwarmEvent::Behaviour(RequestResponseEvent::Message { - peer, - message: RequestResponseMessage::Request { request, channel, .. } - }) => { - assert_eq!(&request, &ping); - assert_eq!(&peer, &peer2_id); - break channel; - }, - SwarmEvent::Behaviour(ev) => panic!("Peer1: Unexpected event: {:?}", ev), - _ => {} - }, - event = swarm2.select_next_some() => { - if let SwarmEvent::Behaviour(ev) = event { - panic!("Peer2: Unexpected event: {:?}", ev); - } - } - ) - }; - - // Drop swarm 2 in order for the connection between swarm 1 and 2 to close. - drop(swarm2); - - loop { - match swarm1.select_next_some().await { - SwarmEvent::Behaviour(RequestResponseEvent::InboundFailure { - error: InboundFailure::ConnectionClosed, - .. - }) => break, - SwarmEvent::Behaviour(e) => panic!("Peer1: Unexpected event: {:?}", e), - _ => {} - } - } - }); -} - -/// We expect the substream to be properly closed when response channel is dropped. -/// Since the ping protocol used here expects a response, the sender considers this -/// early close as a protocol violation which results in the connection being closed. -/// If the substream were not properly closed when dropped, the sender would instead -/// run into a timeout waiting for the response. -#[test] -fn emits_inbound_connection_closed_if_channel_is_dropped() { - let ping = Ping("ping".to_string().into_bytes()); - - let protocols = iter::once((PingProtocol(), ProtocolSupport::Full)); - let cfg = RequestResponseConfig::default(); - - let (peer1_id, trans) = mk_transport(); - let ping_proto1 = RequestResponse::new(PingCodec(), protocols.clone(), cfg.clone()); - let mut swarm1 = Swarm::without_executor(trans, ping_proto1, peer1_id); - - let (peer2_id, trans) = mk_transport(); - let ping_proto2 = RequestResponse::new(PingCodec(), protocols, cfg); - let mut swarm2 = Swarm::without_executor(trans, ping_proto2, peer2_id); - - let addr = "/ip4/127.0.0.1/tcp/0".parse().unwrap(); - swarm1.listen_on(addr).unwrap(); - - futures::executor::block_on(async move { - while swarm1.next().now_or_never().is_some() {} - let addr1 = Swarm::listeners(&swarm1).next().unwrap(); - - swarm2.behaviour_mut().add_address(&peer1_id, addr1.clone()); - swarm2.behaviour_mut().send_request(&peer1_id, ping.clone()); - - // Wait for swarm 1 to receive request by swarm 2. - let event = loop { - futures::select!( - event = swarm1.select_next_some() => { - if let SwarmEvent::Behaviour(RequestResponseEvent::Message { - peer, - message: RequestResponseMessage::Request { request, channel, .. } - }) = event { - assert_eq!(&request, &ping); - assert_eq!(&peer, &peer2_id); - - drop(channel); - continue; - } - }, - event = swarm2.select_next_some() => { - if let SwarmEvent::Behaviour(ev) = event { - break ev; - } - }, - ) - }; - - let error = match event { - RequestResponseEvent::OutboundFailure { error, .. } => error, - e => panic!("unexpected event from peer 2: {:?}", e), - }; - - assert_eq!(error, OutboundFailure::ConnectionClosed); - }); -} - -fn mk_transport() -> (PeerId, transport::Boxed<(PeerId, StreamMuxerBox)>) { - let id_keys = identity::Keypair::generate_ed25519(); - let peer_id = id_keys.public().to_peer_id(); - - ( - peer_id, - tcp::async_io::Transport::new(tcp::Config::default().nodelay(true)) - .upgrade(upgrade::Version::V1) - .authenticate(NoiseAuthenticated::xx(&id_keys).unwrap()) - .multiplex(libp2p::yamux::YamuxConfig::default()) - .boxed(), - ) -} - -// Simple Ping-Pong Protocol - -#[derive(Debug, Clone)] -struct PingProtocol(); -#[derive(Clone)] -struct PingCodec(); -#[derive(Debug, Clone, PartialEq, Eq)] -struct Ping(Vec); -#[derive(Debug, Clone, PartialEq, Eq)] -struct Pong(Vec); - -impl ProtocolName for PingProtocol { - fn protocol_name(&self) -> &[u8] { - "/ping/1".as_bytes() - } -} - -#[async_trait] -impl RequestResponseCodec for PingCodec { - type Protocol = PingProtocol; - type Request = Ping; - type Response = Pong; - - async fn read_request(&mut self, _: &PingProtocol, io: &mut T) -> io::Result - where - T: AsyncRead + Unpin + Send, - { - let vec = read_length_prefixed(io, 1024).await?; - - if vec.is_empty() { - return Err(io::ErrorKind::UnexpectedEof.into()); - } - - Ok(Ping(vec)) - } - - async fn read_response(&mut self, _: &PingProtocol, io: &mut T) -> io::Result - where - T: AsyncRead + Unpin + Send, - { - let vec = read_length_prefixed(io, 1024).await?; - - if vec.is_empty() { - return Err(io::ErrorKind::UnexpectedEof.into()); - } - - Ok(Pong(vec)) - } - - async fn write_request( - &mut self, - _: &PingProtocol, - io: &mut T, - Ping(data): Ping, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send, - { - write_length_prefixed(io, data).await?; - io.close().await?; - - Ok(()) - } - - async fn write_response( - &mut self, - _: &PingProtocol, - io: &mut T, - Pong(data): Pong, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send, - { - write_length_prefixed(io, data).await?; - io.close().await?; - - Ok(()) - } -} From 6e5592716f6a4ee154ff59da719729fc4054e84c Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 6 Apr 2023 17:12:11 +1000 Subject: [PATCH 39/48] satisfy clippy --- src/auth_guards.rs | 2 +- src/p2p/behaviour/builder.rs | 2 +- src/p2p/mod.rs | 4 +-- src/p2p/relay.rs | 51 +++++++++++++++++++++++++++++++++--- src/p2p/transport.rs | 11 +++----- src/routes/mod.rs | 2 +- src/storage/file_system.rs | 4 +-- src/storage/s3.rs | 4 +-- 8 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/auth_guards.rs b/src/auth_guards.rs index 3b6e383d..a82b006c 100644 --- a/src/auth_guards.rs +++ b/src/auth_guards.rs @@ -86,7 +86,7 @@ fn get_state(req: &Request<'_>) -> Result<(config::Config, (PeerId, Multiaddr))> config, req.rocket() .state::() - .map(|r| (r.id().clone(), multiaddr!(Memory(port)))) + .map(|r| (*r.id(), multiaddr!(Memory(port)))) .ok_or_else(|| anyhow!("Could not retrieve relay node information"))?, )) } diff --git a/src/p2p/behaviour/builder.rs b/src/p2p/behaviour/builder.rs index 4cfa437f..83d59964 100644 --- a/src/p2p/behaviour/builder.rs +++ b/src/p2p/behaviour/builder.rs @@ -91,7 +91,7 @@ impl BehaviourConfig { let peer_id = keypair.public().to_peer_id(); Ok(Behaviour { base: BaseBehaviour { - identify: Identify::new(self.identify.to_config(keypair.public())), + identify: Identify::new(self.identify.into_config(keypair.public())), ping: Ping::new(self.ping), gossipsub: Gossipsub::new( MessageAuthenticity::Signed(keypair), diff --git a/src/p2p/mod.rs b/src/p2p/mod.rs index e0711b5b..5149e47c 100644 --- a/src/p2p/mod.rs +++ b/src/p2p/mod.rs @@ -6,7 +6,7 @@ pub mod behaviour; pub mod relay; pub mod transport; -pub const PROTOCOL_VERSION: &'static str = "kepler/0.1.0"; +pub const PROTOCOL_VERSION: &str = "kepler/0.1.0"; #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct IdentifyConfig { @@ -53,7 +53,7 @@ impl Default for IdentifyConfig { } impl IdentifyConfig { - fn to_config(self, key: PublicKey) -> OIdentifyConfig { + fn into_config(self, key: PublicKey) -> OIdentifyConfig { OIdentifyConfig::new(self.protocol_version, key) .with_initial_delay(self.initial_delay) .with_interval(self.interval) diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index b86c4700..841c07d7 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -143,7 +143,7 @@ impl Config { fn build(self, pubkey: PublicKey) -> Behaviour { let peer_id = pubkey.to_peer_id(); Behaviour { - identify: Identify::new(self.identify.to_config(pubkey)), + identify: Identify::new(self.identify.into_config(pubkey)), ping: Ping::new(self.ping), relay: Relay::new(peer_id, self.relay), autonat: AutoNat::new(peer_id, self.autonat), @@ -236,7 +236,7 @@ async fn poll_swarm( }; } Message::GetAddresses(s) => s - .send(swarm.listeners().map(|a| a.clone()).collect()) + .send(swarm.listeners().cloned().collect()) .map_err(|_| SwarmError::SendError)?, Message::Dial(addr, s) => { swarm.dial(addr)?; @@ -257,7 +257,7 @@ async fn poll_swarm( #[cfg(test)] mod test { use super::*; - use crate::p2p::transport::MemoryConfig; + use crate::p2p::transport::{Both, MemoryConfig, TcpConfig}; use libp2p::build_multiaddr; #[test] @@ -273,4 +273,49 @@ mod test { assert_eq!(listened, vec![addr]); } + + #[test] + async fn can_relay() { + let mut alice = Config::default() + .launch(Keypair::generate_ed25519(), MemoryConfig) + .unwrap(); + + let mut bob = Config::default() + .launch( + Keypair::generate_ed25519(), + Both::::default(), + ) + .unwrap(); + + let mut charles = Config::default() + .launch( + Keypair::generate_ed25519(), + Both::::default(), + ) + .unwrap(); + + alice + .listen_on([build_multiaddr!(Memory(0u8))]) + .await + .unwrap(); + + bob.listen_on([build_multiaddr!(Memory(0u8))]) + .await + .unwrap(); + + charles + .listen_on([build_multiaddr!(Tcp(0u8))]) + .await + .unwrap(); + + let alice_addrs = alice.get_addresses().await.unwrap(); + let bob_addrs = bob.get_addresses().await.unwrap(); + let charles_addrs = charles.get_addresses().await.unwrap(); + + let charles_via_bob = bob_addrs[0].clone().with(Protocol::P2p(bob.id().into())); + + let charles_via_bob = charles_addrs[0].with(Protocol::P2p(bob.id().into())); + + alice.dial().await.unwrap(); + } } diff --git a/src/p2p/transport.rs b/src/p2p/transport.rs index d8ce5ba3..9246f397 100644 --- a/src/p2p/transport.rs +++ b/src/p2p/transport.rs @@ -79,16 +79,11 @@ where } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub enum DnsResolver { + #[default] System, - Custom(CustomDnsResolver), -} - -impl Default for DnsResolver { - fn default() -> Self { - Self::System - } + Custom(Box), } #[derive(Debug, Clone, PartialEq, Eq, Default)] diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 82a9452e..337ea45e 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -93,7 +93,7 @@ pub fn relay_addr(relay: &State, config: &State) -> String { multiaddr!( Ip4([127, 0, 0, 1]), Tcp(config.relay.port), - P2p(relay.id().clone()) + P2p(*relay.id()) ) .to_string() } diff --git a/src/storage/file_system.rs b/src/storage/file_system.rs index c001d8ff..31c39a59 100644 --- a/src/storage/file_system.rs +++ b/src/storage/file_system.rs @@ -100,7 +100,7 @@ impl ProviderUtils for FileSystemConfig { async fn relay_key_pair(&self) -> Result { let path = self.path.join("kp"); match read(&path).await { - Ok(mut k) => Ok(Keypair::from_protobuf_encoding(&mut k)?), + Ok(k) => Ok(Keypair::from_protobuf_encoding(&k)?), Err(e) if e.kind() == ErrorKind::NotFound => { let k = Keypair::generate_ed25519(); write(&path, k.to_protobuf_encoding()?).await?; @@ -111,7 +111,7 @@ impl ProviderUtils for FileSystemConfig { } async fn key_pair(&self, orbit: &OrbitId) -> Result, Self::Error> { match read(self.path.join(orbit.get_cid().to_string()).join("kp")).await { - Ok(mut k) => Ok(Some(Keypair::from_protobuf_encoding(&mut k)?)), + Ok(k) => Ok(Some(Keypair::from_protobuf_encoding(&k)?)), Err(e) if e.kind() == ErrorKind::NotFound => Ok(None), Err(e) => Err(e.into()), } diff --git a/src/storage/s3.rs b/src/storage/s3.rs index 3dee2d4d..8036c623 100644 --- a/src/storage/s3.rs +++ b/src/storage/s3.rs @@ -100,7 +100,7 @@ impl ProviderUtils for S3BlockConfig { .await { Ok(o) => Ok(Keypair::from_protobuf_encoding( - &mut o.body.collect().await?.into_bytes().to_vec(), + &o.body.collect().await?.into_bytes().to_vec(), )?), Err(SdkError::ServiceError { err: @@ -132,7 +132,7 @@ impl ProviderUtils for S3BlockConfig { .await { Ok(o) => Ok(Some(Keypair::from_protobuf_encoding( - &mut o.body.collect().await?.into_bytes().to_vec(), + &o.body.collect().await?.into_bytes().to_vec(), )?)), Err(SdkError::ServiceError { err: From 6f4e0b57bd60694beb5b01e54ee37c98a119fb20 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 6 Apr 2023 17:12:19 +1000 Subject: [PATCH 40/48] cargo-update --- Cargo.lock | 1706 ++++++++++++++++++++++++---------------------------- 1 file changed, 794 insertions(+), 912 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0289e016..243a5c7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,7 +14,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -23,18 +23,18 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "rand_core 0.6.4", ] [[package]] name = "aead" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c192eb8f11fc081b0fe4259ba5af04217d4e0faddd02417310a927911abd7c8" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" dependencies = [ "crypto-common", - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -67,7 +67,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "433cfd6710c9986c576a25ca913c39d66a6474107b406f34f91d4a8923395241" dependencies = [ "cfg-if", - "cipher 0.4.3", + "cipher 0.4.4", "cpufeatures", ] @@ -91,9 +91,9 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82e1366e0c69c9f927b1fa5ce2c7bf9eafc8f9268c0b9800729e8b267612447c" dependencies = [ - "aead 0.5.1", + "aead 0.5.2", "aes 0.8.2", - "cipher 0.4.3", + "cipher 0.4.4", "ctr 0.9.2", "ghash 0.5.0", "subtle", @@ -143,9 +143,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.19" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] @@ -173,9 +173,9 @@ checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" [[package]] name = "arrayref" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] name = "arrayvec" @@ -202,7 +202,7 @@ dependencies = [ "num-traits", "rusticata-macros", "thiserror", - "time 0.3.16", + "time 0.3.20", ] [[package]] @@ -218,7 +218,7 @@ dependencies = [ "num-traits", "rusticata-macros", "thiserror", - "time 0.3.16", + "time 0.3.20", ] [[package]] @@ -229,7 +229,7 @@ checksum = "db8b7511298d5b7784b40b092d9e9dcd3a627a5707e4b5e507931ab0d44eeebf" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "synstructure", ] @@ -241,7 +241,7 @@ checksum = "726535892e8eae7e70657b4c8ea93d26b8553afb1ce617caee529ef96d7dee6c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "synstructure", ] @@ -253,15 +253,9 @@ checksum = "2777730b2039ac0f95f093556e61b6d26cebed5393ca6f152717777cec3a42ed" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] -[[package]] -name = "asn1_der" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" - [[package]] name = "async-attributes" version = "1.1.2" @@ -269,14 +263,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "async-channel" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14485364214912d3b19cc3435dde4df66065127f05fa0d75c712f36f12c2f28" +checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" dependencies = [ "concurrent-queue", "event-listener", @@ -285,15 +279,15 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b" dependencies = [ + "async-lock", "async-task", "concurrent-queue", "fastrand", "futures-lite", - "once_cell", "slab", ] @@ -314,32 +308,31 @@ dependencies = [ [[package]] name = "async-io" -version = "1.10.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8121296a9f05be7f34aa4196b1747243b3b62e048bb7906f644f3fbfc490cf7" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" dependencies = [ "async-lock", "autocfg", + "cfg-if", "concurrent-queue", "futures-lite", - "libc", "log", "parking", "polling", + "rustix 0.37.7", "slab", "socket2", "waker-fn", - "winapi", ] [[package]] name = "async-lock" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8101efe8695a6c17e02911402145357e718ac92d3ff88ae8419e84b1707b685" +checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" dependencies = [ "event-listener", - "futures-lite", ] [[package]] @@ -350,7 +343,7 @@ checksum = "d7d78656ba01f1b93024b7c3a0467f1608e4be67d725749fdcd7d2c7678fd7a2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -382,40 +375,41 @@ dependencies = [ [[package]] name = "async-stream" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" dependencies = [ "async-stream-impl", "futures-core", + "pin-project-lite 0.2.9", ] [[package]] name = "async-stream-impl" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] name = "async-task" -version = "4.3.0" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" +checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" [[package]] name = "async-trait" -version = "0.1.58" +version = "0.1.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c" +checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -448,20 +442,9 @@ dependencies = [ [[package]] name = "atomic-waker" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" - -[[package]] -name = "atty" -version = "0.2.14" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] +checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" [[package]] name = "autocfg" @@ -490,7 +473,7 @@ dependencies = [ "http", "hyper", "ring", - "time 0.3.16", + "time 0.3.20", "tokio", "tower", "tracing", @@ -654,7 +637,7 @@ dependencies = [ "percent-encoding", "regex", "ring", - "time 0.3.16", + "time 0.3.20", "tracing", ] @@ -790,7 +773,7 @@ dependencies = [ "itoa", "num-integer", "ryu", - "time 0.3.16", + "time 0.3.20", ] [[package]] @@ -850,9 +833,9 @@ checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" [[package]] name = "base64ct" -version = "1.5.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bech32" @@ -887,6 +870,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c70beb79cbb5ce9c4f8e20849978f34225931f665bb49efa6982875a4d5facb3" + [[package]] name = "bitvec" version = "0.20.4" @@ -901,11 +890,11 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.4" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "digest 0.10.5", + "digest 0.10.6", ] [[package]] @@ -916,42 +905,42 @@ checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" dependencies = [ "arrayref", "arrayvec 0.5.2", - "constant_time_eq", + "constant_time_eq 0.1.5", ] [[package]] name = "blake2b_simd" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" +checksum = "3c2f0dc9a68c6317d884f97cc36cf5a3d20ba14ce404227df55e1af708ab04bc" dependencies = [ "arrayref", "arrayvec 0.7.2", - "constant_time_eq", + "constant_time_eq 0.2.5", ] [[package]] name = "blake2s_simd" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" +checksum = "6637f448b9e61dfadbdcbae9a885fadee1f3eaffb1f8d3c1965d3ade8bdfd44f" dependencies = [ "arrayref", "arrayvec 0.7.2", - "constant_time_eq", + "constant_time_eq 0.2.5", ] [[package]] name = "blake3" -version = "1.3.1" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f" +checksum = "42ae2468a89544a466886840aa467a25b766499f4f04bf7d9fcd10ecee9fccef" dependencies = [ "arrayref", "arrayvec 0.7.2", "cc", "cfg-if", - "constant_time_eq", + "constant_time_eq 0.2.5", ] [[package]] @@ -973,16 +962,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ "block-padding 0.2.1", - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] name = "block-buffer" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -1022,16 +1011,16 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "blocking" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" +checksum = "3c67b173a56acffd6d2326fb7ab938ba0b00a71480e14902b2591c87bc5741e8" dependencies = [ "async-channel", + "async-lock", "async-task", "atomic-waker", "fastrand", "futures-lite", - "once_cell", ] [[package]] @@ -1066,9 +1055,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.11.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byte-tools" @@ -1110,19 +1099,13 @@ dependencies = [ "iri-string 0.6.0", "libipld", "serde", - "serde_with 2.0.1", + "serde_with 2.3.2", "siwe", "thiserror", - "time 0.3.16", + "time 0.3.20", "url", ] -[[package]] -name = "cache-padded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" - [[package]] name = "cached" version = "0.30.0" @@ -1161,7 +1144,7 @@ dependencies = [ "cached_proc_macro_types", "darling 0.13.4", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1197,9 +1180,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.74" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "ccm" @@ -1254,16 +1237,16 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.22" +version = "0.4.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" dependencies = [ "iana-time-zone", "js-sys", "num-integer", "num-traits", "serde", - "time 0.1.44", + "time 0.1.45", "wasm-bindgen", "winapi", ] @@ -1288,7 +1271,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -1297,14 +1280,14 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] name = "cipher" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ "crypto-common", "inout", @@ -1343,11 +1326,11 @@ checksum = "337cdbf3f1a0e643b4a7d1a2ffa39d22342fb6ee25739b5cfb997c28b3586422" [[package]] name = "concurrent-queue" -version = "1.2.4" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af4780a44ab5696ea9e28294517f1fffb421a83a25af521333c838635509db9c" +checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e" dependencies = [ - "cache-padded", + "crossbeam-utils", ] [[package]] @@ -1368,9 +1351,9 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "const-oid" -version = "0.9.0" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "722e23542a15cea1f65d4a1419c4cfd7a26706c70871a13a04238ca3f40f1661" +checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" [[package]] name = "constant_time_eq" @@ -1378,6 +1361,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "constant_time_eq" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13418e745008f7349ec7e449155f419a61b92b58a99cc3616942b926825ec76b" + [[package]] name = "contextual" version = "0.1.4" @@ -1386,19 +1375,12 @@ checksum = "4e916dad4a946c830c9f199481a03be3e8d45792d5fd228c6bde51195a34d6c7" [[package]] name = "cookie" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "344adc371239ef32293cb1c4fe519592fcf21206c79c02854320afcdf3ab4917" +checksum = "7efb37c3e1ccb1ff97164ad95ac1606e8ccd35b3fa0a7d99a304c7f4a428cc24" dependencies = [ - "aes-gcm 0.10.1", - "base64 0.13.1", - "hkdf", - "hmac 0.12.1", "percent-encoding", - "rand 0.8.5", - "sha2 0.10.6", - "subtle", - "time 0.3.16", + "time 0.3.20", "version_check 0.9.4", ] @@ -1414,9 +1396,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "core2" @@ -1429,9 +1411,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" dependencies = [ "libc", ] @@ -1477,9 +1459,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" dependencies = [ "cfg-if", "crossbeam-utils", @@ -1487,22 +1469,22 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.11" +version = "0.9.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "memoffset", + "memoffset 0.8.0", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.12" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" dependencies = [ "cfg-if", ] @@ -1519,7 +1501,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "subtle", ] @@ -1529,7 +1511,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "rand_core 0.6.4", "subtle", "zeroize", @@ -1541,7 +1523,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "rand_core 0.6.4", "typenum", ] @@ -1552,7 +1534,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "subtle", ] @@ -1572,7 +1554,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1590,7 +1572,7 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" dependencies = [ - "cipher 0.4.3", + "cipher 0.4.4", ] [[package]] @@ -1622,9 +1604,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.80" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" dependencies = [ "cc", "cxxbridge-flags", @@ -1634,9 +1616,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.80" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" dependencies = [ "cc", "codespan-reporting", @@ -1644,24 +1626,24 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 2.0.13", ] [[package]] name = "cxxbridge-flags" -version = "1.0.80" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" [[package]] name = "cxxbridge-macro" -version = "1.0.80" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -1686,12 +1668,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.14.2" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0dd3cd20dc6b5a876612a6e5accfe7f3dd883db6d07acfbf14c128f61550dfa" +checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" dependencies = [ - "darling_core 0.14.2", - "darling_macro 0.14.2", + "darling_core 0.14.4", + "darling_macro 0.14.4", ] [[package]] @@ -1705,7 +1687,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.9.3", - "syn", + "syn 1.0.109", ] [[package]] @@ -1719,21 +1701,21 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn", + "syn 1.0.109", ] [[package]] name = "darling_core" -version = "0.14.2" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a784d2ccaf7c98501746bf0be29b2022ba41fd62a2e622af997a03e9f972859f" +checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim 0.10.0", - "syn", + "syn 1.0.109", ] [[package]] @@ -1744,7 +1726,7 @@ checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ "darling_core 0.10.2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1755,25 +1737,25 @@ checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ "darling_core 0.13.4", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "darling_macro" -version = "0.14.2" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e" +checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" dependencies = [ - "darling_core 0.14.2", + "darling_core 0.14.4", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "data-encoding" -version = "2.3.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" +checksum = "23d8666cb01533c39dde32bcbab8e227b4ed6679b2c925eba05feabea39508fb" [[package]] name = "data-encoding-macro" @@ -1792,7 +1774,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5bbed42daaa95e780b60a50546aa345b8413a1e46f9a40a12907d3598f038db" dependencies = [ "data-encoding", - "syn", + "syn 1.0.109", ] [[package]] @@ -1814,11 +1796,11 @@ dependencies = [ [[package]] name = "der" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dd2ae565c0a381dde7fade45fce95984c568bdcb4700a4fdbe3175e0380b2f" +checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" dependencies = [ - "const-oid 0.9.0", + "const-oid 0.9.2", "pem-rfc7468 0.6.0", "zeroize", ] @@ -1859,7 +1841,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1872,7 +1854,7 @@ dependencies = [ "derive_builder_core 0.9.0", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1893,7 +1875,7 @@ dependencies = [ "darling 0.10.2", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1902,10 +1884,10 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4" dependencies = [ - "darling 0.14.2", + "darling 0.14.4", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1915,7 +1897,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f0314b72bed045f3a68671b3c86328386762c93f82d98c65c3cb5e5f573dd68" dependencies = [ "derive_builder_core 0.11.2", - "syn", + "syn 1.0.109", ] [[package]] @@ -1931,9 +1913,9 @@ dependencies = [ [[package]] name = "devise" -version = "0.3.1" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c7580b072f1c8476148f16e0a0d5dedddab787da98d86c5082c5e9ed8ab595" +checksum = "d6eacefd3f541c66fc61433d65e54e0e46e0a029a819a7dbbc7a7b489e8a85f8" dependencies = [ "devise_codegen", "devise_core", @@ -1941,9 +1923,9 @@ dependencies = [ [[package]] name = "devise_codegen" -version = "0.3.1" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "123c73e7a6e51b05c75fe1a1b2f4e241399ea5740ed810b0e3e6cacd9db5e7b2" +checksum = "9c8cf4b8dd484ede80fd5c547592c46c3745a617c8af278e2b72bea86b2dfed6" dependencies = [ "devise_core", "quote", @@ -1951,15 +1933,15 @@ dependencies = [ [[package]] name = "devise_core" -version = "0.3.1" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841ef46f4787d9097405cac4e70fb8644fc037b526e8c14054247c0263c400d0" +checksum = "35b50dba0afdca80b187392b24f2499a88c336d5a8493e4b4ccfb608708be56a" dependencies = [ - "bitflags", + "bitflags 2.1.0", "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -2098,16 +2080,16 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] name = "digest" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ - "block-buffer 0.10.3", + "block-buffer 0.10.4", "crypto-common", "subtle", ] @@ -2120,14 +2102,14 @@ checksum = "3bf95dc3f046b9da4f2d51833c0d3547d8564ef6910f5c1ed130306a75b92886" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "dtoa" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a6eee2d5d0d113f015688310da018bd1d864d86bd567c8fca9c266889e1bfa" +checksum = "65d09067bfacaa79114679b279d7f5885b53295b1e2cfb4e79c8e4bd3d633169" [[package]] name = "ecdsa" @@ -2135,7 +2117,7 @@ version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" dependencies = [ - "der 0.6.0", + "der 0.6.1", "elliptic-curve", "rfc6979", "signature", @@ -2143,9 +2125,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ "signature", ] @@ -2166,9 +2148,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "elliptic-curve" @@ -2178,10 +2160,10 @@ checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" dependencies = [ "base16ct", "crypto-bigint 0.4.9", - "der 0.6.0", - "digest 0.10.5", + "der 0.6.1", + "digest 0.10.6", "ff", - "generic-array 0.14.6", + "generic-array 0.14.7", "group", "hkdf", "pem-rfc7468 0.6.0", @@ -2194,9 +2176,9 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.31" +version = "0.8.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" dependencies = [ "cfg-if", ] @@ -2210,31 +2192,18 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", -] - -[[package]] -name = "env_logger" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", + "syn 1.0.109", ] [[package]] name = "errno" -version = "0.2.8" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" dependencies = [ "errno-dragonfly", "libc", - "winapi", + "windows-sys 0.45.0", ] [[package]] @@ -2253,23 +2222,6 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" -[[package]] -name = "exchange-protocol" -version = "0.1.0" -dependencies = [ - "async-std", - "async-trait", - "bytes", - "env_logger", - "futures", - "instant", - "libp2p 0.50.1", - "log", - "rand 0.8.5", - "smallvec", - "unsigned-varint", -] - [[package]] name = "fake-simd" version = "0.1.2" @@ -2278,9 +2230,9 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" [[package]] name = "fastrand" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" dependencies = [ "instant", ] @@ -2297,9 +2249,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ace6ec7cc19c8ed33a32eaa9ea692d7faea05006b5356b9e2b668ec4bc3955" +checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" [[package]] name = "figment" @@ -2324,17 +2276,11 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - [[package]] name = "flate2" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" dependencies = [ "crc32fast", "libz-sys", @@ -2389,9 +2335,9 @@ checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" [[package]] name = "futures" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" dependencies = [ "futures-channel", "futures-core", @@ -2404,9 +2350,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", "futures-sink", @@ -2414,15 +2360,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" [[package]] name = "futures-executor" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" dependencies = [ "futures-core", "futures-task", @@ -2432,9 +2378,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" [[package]] name = "futures-lite" @@ -2453,13 +2399,13 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -2469,21 +2415,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2411eed028cdf8c8034eaf21f9915f956b6c3abec4d4c7949ee67f0721127bd" dependencies = [ "futures-io", - "rustls 0.20.7", + "rustls 0.20.8", "webpki 0.22.0", ] [[package]] name = "futures-sink" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" [[package]] name = "futures-task" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" [[package]] name = "futures-timer" @@ -2493,9 +2439,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ "futures-channel", "futures-core", @@ -2520,15 +2466,15 @@ dependencies = [ [[package]] name = "generator" -version = "0.7.1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc184cace1cea8335047a471cc1da80f18acf8a76f3bab2028d499e328948ec7" +checksum = "33a20a288a94683f5f4da0adecdbe095c94a77c295e514cc6484e9394dd8376e" dependencies = [ "cc", "libc", "log", "rustversion", - "windows 0.32.0", + "windows 0.44.0", ] [[package]] @@ -2542,9 +2488,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check 0.9.4", @@ -2598,15 +2544,15 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "gloo-timers" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" dependencies = [ "futures-channel", "futures-core", @@ -2639,9 +2585,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" +checksum = "5be7b54589b581f624f566bf5d8eb2bab1db736c51528720b6bd36b96b55924d" dependencies = [ "bytes", "fnv", @@ -2687,7 +2633,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" dependencies = [ "base64 0.13.1", - "bitflags", + "bitflags 1.3.2", "bytes", "headers-core", "http", @@ -2707,19 +2653,25 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hex" version = "0.4.3" @@ -2757,7 +2709,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.5", + "digest 0.10.6", ] [[package]] @@ -2773,9 +2725,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ "bytes", "fnv", @@ -2805,17 +2757,11 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" -version = "0.14.22" +version = "0.14.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064" +checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899" dependencies = [ "bytes", "futures-channel", @@ -2854,13 +2800,13 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.23.0" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac" +checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" dependencies = [ "http", "hyper", - "rustls 0.20.7", + "rustls 0.20.8", "tokio", "tokio-rustls 0.23.4", ] @@ -2880,16 +2826,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.53" +version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi", + "windows 0.48.0", ] [[package]] @@ -2941,9 +2887,9 @@ dependencies = [ [[package]] name = "if-watch" -version = "3.0.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba7abdbb86e485125dad06c2691e1e393bf3b08c7b743b43aa162a00fd39062e" +checksum = "a9465340214b296cd17a0009acdb890d6160010b8adf8f78a00d0d7ab270f79f" dependencies = [ "async-io", "core-foundation", @@ -2960,9 +2906,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.1" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", @@ -2981,7 +2927,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -3020,27 +2966,32 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "0.7.5" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" +checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys 0.48.0", +] [[package]] name = "ipconfig" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723519edce41262b05d4143ceb95050e4c614f483e78e9fd9e39a8275a84ad98" +checksum = "bd302af1b90f2463a98fa5ad469fc212c8e3175a41c3068601bfa2727591c5be" dependencies = [ "socket2", "widestring", "winapi", - "winreg 0.7.0", + "winreg", ] [[package]] name = "ipnet" -version = "2.5.0" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" [[package]] name = "iref" @@ -3070,6 +3021,18 @@ dependencies = [ "serde", ] +[[package]] +name = "is-terminal" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix 0.37.7", + "windows-sys 0.45.0", +] + [[package]] name = "itertools" version = "0.10.5" @@ -3081,9 +3044,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "js-sys" @@ -3237,9 +3200,9 @@ dependencies = [ [[package]] name = "json-patch" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f995a3c8f2bc3dd52a18a583e90f9ec109c047fa1603a853e46bcda14d2e279d" +checksum = "eb3fa5a61630976fc4c353c70297f2e93f1930e3ccee574d59d618ccbd5154ce" dependencies = [ "serde", "serde_json", @@ -3280,9 +3243,12 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" +checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +dependencies = [ + "cpufeatures", +] [[package]] name = "keccak-hash" @@ -3312,7 +3278,6 @@ dependencies = [ "cached 0.40.0", "derive_builder 0.11.2", "either", - "exchange-protocol", "futures", "hex", "hyper", @@ -3320,7 +3285,7 @@ dependencies = [ "kepler-lib", "lazy_static", "libipld", - "libp2p 0.51.1", + "libp2p", "opentelemetry", "opentelemetry-jaeger", "percent-encoding", @@ -3335,7 +3300,7 @@ dependencies = [ "sled", "tempfile", "thiserror", - "time 0.3.16", + "time 0.3.20", "tokio", "tokio-stream", "tokio-util", @@ -3388,7 +3353,7 @@ dependencies = [ "serde_json", "serde_with 1.14.0", "thiserror", - "time 0.3.16", + "time 0.3.20", "tokio", "tracing", ] @@ -3405,7 +3370,7 @@ dependencies = [ "serde", "serde_json", "serde_with 1.14.0", - "time 0.3.16", + "time 0.3.20", "wasm-bindgen", "wasm-bindgen-futures", ] @@ -3509,9 +3474,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.140" +version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] name = "libipld" @@ -3553,7 +3518,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "synstructure", ] @@ -3601,42 +3566,25 @@ checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" [[package]] name = "libm" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" - -[[package]] -name = "libp2p" -version = "0.50.1" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7b0104790be871edcf97db9bd2356604984e623a08d825c3f27852290266b8" -dependencies = [ - "bytes", - "futures", - "futures-timer", - "getrandom 0.2.8", - "instant", - "libp2p-core 0.38.0", - "libp2p-swarm 0.41.1", - "multiaddr 0.16.0", - "parking_lot 0.12.1", - "pin-project", - "smallvec", -] +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" [[package]] name = "libp2p" -version = "0.51.1" +version = "0.51.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e068bb83ef4e0bed45de5ca4a4118018ac1f70ea3ecb1f4878742d08a97473" +checksum = "ab78d6d2201578bb3a33dff33c540af6b8f0bdcd751b4028e798e868c2ca0722" dependencies = [ "bytes", "futures", "futures-timer", "getrandom 0.2.8", "instant", + "libp2p-allow-block-list", "libp2p-autonat", - "libp2p-core 0.39.1", + "libp2p-connection-limits", + "libp2p-core", "libp2p-dcutr", "libp2p-dns", "libp2p-gossipsub", @@ -3650,16 +3598,28 @@ dependencies = [ "libp2p-ping", "libp2p-quic", "libp2p-relay", - "libp2p-swarm 0.42.0", + "libp2p-swarm", "libp2p-tcp", "libp2p-wasm-ext", "libp2p-webrtc", "libp2p-websocket", "libp2p-yamux", - "multiaddr 0.17.0", + "multiaddr", "pin-project", ] +[[package]] +name = "libp2p-allow-block-list" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c54073648b20bb47335164544a4e5694434f44530f47a4f6618f5f585f3ff5" +dependencies = [ + "libp2p-core", + "libp2p-identity", + "libp2p-swarm", + "void", +] + [[package]] name = "libp2p-autonat" version = "0.10.1" @@ -3670,47 +3630,25 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-identity", "libp2p-request-response", - "libp2p-swarm 0.42.0", + "libp2p-swarm", "log", "quick-protobuf", "rand 0.8.5", ] [[package]] -name = "libp2p-core" -version = "0.38.0" +name = "libp2p-connection-limits" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6a8fcd392ff67af6cc3f03b1426c41f7f26b6b9aff2dc632c1c56dd649e571f" +checksum = "4caa33f1d26ed664c4fe2cca81a08c8e07d4c1c04f2f4ac7655c2dd85467fda0" dependencies = [ - "asn1_der", - "bs58", - "ed25519-dalek", - "either", - "fnv", - "futures", - "futures-timer", - "instant", - "log", - "multiaddr 0.16.0", - "multihash 0.16.3", - "multistream-select", - "once_cell", - "parking_lot 0.12.1", - "pin-project", - "prost", - "prost-build", - "rand 0.8.5", - "rw-stream-sink", - "sec1", - "sha2 0.10.6", - "smallvec", - "thiserror", - "unsigned-varint", + "libp2p-core", + "libp2p-identity", + "libp2p-swarm", "void", - "zeroize", ] [[package]] @@ -3726,7 +3664,7 @@ dependencies = [ "instant", "libp2p-identity", "log", - "multiaddr 0.17.0", + "multiaddr", "multihash 0.17.0", "multistream-select", "once_cell", @@ -3752,9 +3690,9 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.0", + "libp2p-swarm", "log", "quick-protobuf", "quick-protobuf-codec", @@ -3769,7 +3707,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "146ff7034daae62077c415c2376b8057368042df6ab95f5432ad5e88568b1554" dependencies = [ "futures", - "libp2p-core 0.39.1", + "libp2p-core", "log", "parking_lot 0.12.1", "smallvec", @@ -3778,9 +3716,9 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" -version = "0.44.1" +version = "0.44.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "708235886ca7c8f3792a8683ef81f9b7fb0a952bbd15fe5038b7610689a88390" +checksum = "38c95818acf1d0d917712dd3bf4e73c4839e6fca6329d70ba9968cecc6bbb7e4" dependencies = [ "asynchronous-codec", "base64 0.21.0", @@ -3790,9 +3728,9 @@ dependencies = [ "futures", "hex_fmt", "instant", - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.0", + "libp2p-swarm", "log", "prometheus-client", "quick-protobuf", @@ -3816,9 +3754,9 @@ dependencies = [ "either", "futures", "futures-timer", - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.0", + "libp2p-swarm", "log", "lru", "quick-protobuf", @@ -3830,17 +3768,16 @@ dependencies = [ [[package]] name = "libp2p-identity" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff6c9cb71e2333d31f18e7556b9a5f1d0a2e013effc9325e36f436be65fe7bd2" +checksum = "8a8ea433ae0cea7e3315354305237b9897afe45278b2118a7a57ca744e70fd27" dependencies = [ "bs58", "ed25519-dalek", "log", - "multiaddr 0.17.0", + "multiaddr", "multihash 0.17.0", "prost", - "prost-build", "quick-protobuf", "rand 0.8.5", "thiserror", @@ -3861,9 +3798,9 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.0", + "libp2p-swarm", "log", "quick-protobuf", "rand 0.8.5", @@ -3877,15 +3814,16 @@ dependencies = [ [[package]] name = "libp2p-mdns" -version = "0.43.0" +version = "0.43.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "687a0b54ee8f7106be36f012b32bd30faceeb4cd857ebad96e512566886ffea5" +checksum = "19983e1f949f979a928f2c603de1cf180cc0dc23e4ac93a62651ccb18341460b" dependencies = [ "data-encoding", "futures", "if-watch", - "libp2p-core 0.39.1", - "libp2p-swarm 0.42.0", + "libp2p-core", + "libp2p-identity", + "libp2p-swarm", "log", "rand 0.8.5", "smallvec", @@ -3901,14 +3839,14 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a42ec91e227d7d0dafa4ce88b333cdf5f277253873ab087555c92798db2ddd46" dependencies = [ - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", "libp2p-kad", "libp2p-ping", "libp2p-relay", - "libp2p-swarm 0.42.0", + "libp2p-swarm", "prometheus-client", ] @@ -3921,7 +3859,7 @@ dependencies = [ "asynchronous-codec", "bytes", "futures", - "libp2p-core 0.39.1", + "libp2p-core", "log", "nohash-hasher", "parking_lot 0.12.1", @@ -3939,7 +3877,7 @@ dependencies = [ "bytes", "curve25519-dalek 3.2.0", "futures", - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-identity", "log", "once_cell", @@ -3963,8 +3901,8 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.39.1", - "libp2p-swarm 0.42.0", + "libp2p-core", + "libp2p-swarm", "log", "rand 0.8.5", "void", @@ -3980,14 +3918,14 @@ dependencies = [ "futures", "futures-timer", "if-watch", - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-identity", "libp2p-tls", "log", "parking_lot 0.12.1", "quinn-proto", "rand 0.8.5", - "rustls 0.20.7", + "rustls 0.20.8", "thiserror", "tokio", ] @@ -4004,9 +3942,9 @@ dependencies = [ "futures", "futures-timer", "instant", - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-identity", - "libp2p-swarm 0.42.0", + "libp2p-swarm", "log", "quick-protobuf", "quick-protobuf-codec", @@ -4026,8 +3964,8 @@ dependencies = [ "bytes", "futures", "instant", - "libp2p-core 0.39.1", - "libp2p-swarm 0.42.0", + "libp2p-core", + "libp2p-swarm", "log", "rand 0.8.5", "smallvec", @@ -4036,42 +3974,21 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.41.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2a35472fe3276b3855c00f1c032ea8413615e030256429ad5349cdf67c6e1a0" -dependencies = [ - "either", - "fnv", - "futures", - "futures-timer", - "instant", - "libp2p-core 0.38.0", - "log", - "pin-project", - "rand 0.8.5", - "smallvec", - "thiserror", - "void", -] - -[[package]] -name = "libp2p-swarm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92c22a83d70703d140092c969c1ca06ecdffff8ca7ce8ac2fd3b7eb2c1f0da86" +checksum = "bd1e223f02fcd7e3790f9b954e2e81791810e3512daeb27fa97df7652e946bc2" dependencies = [ "either", "fnv", "futures", "futures-timer", "instant", - "libp2p-core 0.39.1", + "libp2p-core", + "libp2p-identity", "libp2p-swarm-derive", "log", - "pin-project", "rand 0.8.5", "smallvec", - "thiserror", "tokio", "void", ] @@ -4084,7 +4001,7 @@ checksum = "0fba456131824ab6acd4c7bf61e9c0f0a3014b5fc9868ccb8e10d344594cdc4f" dependencies = [ "heck", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4097,7 +4014,7 @@ dependencies = [ "futures-timer", "if-watch", "libc", - "libp2p-core 0.39.1", + "libp2p-core", "log", "socket2", "tokio", @@ -4111,11 +4028,11 @@ checksum = "ff08d13d0dc66e5e9ba6279c1de417b84fa0d0adc3b03e5732928c180ec02781" dependencies = [ "futures", "futures-rustls", - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-identity", "rcgen 0.10.0", "ring", - "rustls 0.20.7", + "rustls 0.20.8", "thiserror", "webpki 0.22.0", "x509-parser 0.14.0", @@ -4130,7 +4047,7 @@ checksum = "77dff9d32353a5887adb86c8afc1de1a94d9e8c3bc6df8b2201d7cdf5c848f43" dependencies = [ "futures", "js-sys", - "libp2p-core 0.39.1", + "libp2p-core", "parity-send-wrapper", "wasm-bindgen", "wasm-bindgen-futures", @@ -4138,9 +4055,9 @@ dependencies = [ [[package]] name = "libp2p-webrtc" -version = "0.4.0-alpha.3" +version = "0.4.0-alpha.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffd0c3af5921e3bdd5fecdf3eef3be5a197def64c1d23cd3ea79abcadbd461f7" +checksum = "dba48592edbc2f60b4bc7c10d65445b0c3964c07df26fdf493b6880d33be36f8" dependencies = [ "async-trait", "asynchronous-codec", @@ -4149,7 +4066,7 @@ dependencies = [ "futures-timer", "hex", "if-watch", - "libp2p-core 0.39.1", + "libp2p-core", "libp2p-identity", "libp2p-noise", "log", @@ -4176,7 +4093,7 @@ dependencies = [ "either", "futures", "futures-rustls", - "libp2p-core 0.39.1", + "libp2p-core", "log", "parking_lot 0.12.1", "quicksink", @@ -4193,7 +4110,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d048cd82f72c8800655aa1ee9b808ea8c9d523a649d3579b3ef0cfe23952d7fd" dependencies = [ "futures", - "libp2p-core 0.39.1", + "libp2p-core", "log", "parking_lot 0.12.1", "thiserror", @@ -4213,9 +4130,9 @@ dependencies = [ [[package]] name = "link-cplusplus" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" dependencies = [ "cc", ] @@ -4228,9 +4145,15 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" -version = "0.0.46" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + +[[package]] +name = "linux-raw-sys" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" +checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" [[package]] name = "lock_api" @@ -4261,7 +4184,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4324,9 +4247,9 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" [[package]] name = "md-5" @@ -4345,7 +4268,7 @@ version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" dependencies = [ - "digest 0.10.5", + "digest 0.10.6", ] [[package]] @@ -4364,10 +4287,19 @@ dependencies = [ ] [[package]] -name = "mime" -version = "0.3.16" +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "mime" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "minimal-lexical" @@ -4377,23 +4309,23 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.5.4" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" dependencies = [ "adler", ] [[package]] name = "mio" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -4404,9 +4336,9 @@ checksum = "e7627d8bbeb17edbf1c3f74b21488e4af680040da89713b4217d0010e9cbd97e" [[package]] name = "multer" -version = "2.0.4" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ed4198ce7a4cbd2a57af78d28c6fbb57d81ac5f1d6ad79ac6c5587419cbdf22" +checksum = "01acbdc23469fd8fe07ab135923371d5f5a422fbf9c522158677c8eb15bc51c2" dependencies = [ "bytes", "encoding_rs", @@ -4416,7 +4348,7 @@ dependencies = [ "log", "memchr", "mime", - "spin 0.9.4", + "spin 0.9.8", "tokio", "tokio-util", "version_check 0.9.4", @@ -4424,31 +4356,14 @@ dependencies = [ [[package]] name = "multiaddr" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aebdb21e90f81d13ed01dc84123320838e53963c2ca94b60b305d3fa64f31e" -dependencies = [ - "arrayref", - "byteorder", - "data-encoding", - "multibase 0.9.1", - "multihash 0.16.3", - "percent-encoding", - "serde", - "static_assertions", - "unsigned-varint", - "url", -] - -[[package]] -name = "multiaddr" -version = "0.17.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b53e0cc5907a5c216ba6584bf74be8ab47d6d6289f72793b2dddbf15dc3bf8c" +checksum = "2b36f567c7099511fa8612bbbb52dda2419ce0bdbacf31714e3a5ffdb766d3bd" dependencies = [ "arrayref", "byteorder", "data-encoding", + "log", "multibase 0.9.1", "multihash 0.17.0", "percent-encoding", @@ -4486,11 +4401,11 @@ version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c346cf9999c631f002d8f977c4eaeaa0e6386f16007202308d0b3757522c2cc" dependencies = [ - "blake2b_simd 1.0.0", + "blake2b_simd 1.0.1", "blake2s_simd", "blake3", "core2", - "digest 0.10.5", + "digest 0.10.6", "multihash-derive", "serde", "serde-big-array", @@ -4506,7 +4421,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835d6ff01d610179fbce3de1694d007e500bf33a7f29689838941d6bf783ae40" dependencies = [ "core2", - "digest 0.10.5", + "digest 0.10.6", "multihash-derive", "sha2 0.10.6", "unsigned-varint", @@ -4514,24 +4429,18 @@ dependencies = [ [[package]] name = "multihash-derive" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" +checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" dependencies = [ "proc-macro-crate", "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "synstructure", ] -[[package]] -name = "multimap" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" - [[package]] name = "multistream-select" version = "0.12.1" @@ -4583,7 +4492,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9ea4302b9759a7a88242299225ea3688e63c85ea136371bb6cf94fd674efaab" dependencies = [ "anyhow", - "bitflags", + "bitflags 1.3.2", "byteorder", "libc", "netlink-packet-core", @@ -4592,9 +4501,9 @@ dependencies = [ [[package]] name = "netlink-packet-utils" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e" +checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34" dependencies = [ "anyhow", "byteorder", @@ -4619,9 +4528,9 @@ dependencies = [ [[package]] name = "netlink-sys" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92b654097027250401127914afb37cb1f311df6610a9891ff07a757e94199027" +checksum = "6471bf08e7ac0135876a9581bf3217ef0333c191c128d34878079f42ee150411" dependencies = [ "bytes", "futures", @@ -4632,14 +4541,14 @@ dependencies = [ [[package]] name = "nix" -version = "0.24.2" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "libc", - "memoffset", + "memoffset 0.6.5", ] [[package]] @@ -4691,13 +4600,13 @@ dependencies = [ [[package]] name = "num-bigint-dig" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "566d173b2f9406afbc5510a90925d5a2cd80cae4605631f1212303df265de011" +checksum = "2399c9463abc5f909349d8aa9ba080e0b88b3ce2885389b60b993f39b1a56905" dependencies = [ "byteorder", "lazy_static", - "libm 0.2.5", + "libm 0.2.6", "num-integer", "num-iter", "num-traits", @@ -4715,7 +4624,7 @@ checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4746,25 +4655,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", - "libm 0.2.5", + "libm 0.2.6", ] [[package]] name = "num_cpus" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "num_threads" -version = "0.1.6" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ + "hermit-abi 0.2.6", "libc", ] @@ -4806,11 +4706,11 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.42" +version = "0.10.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" +checksum = "4d2f106ab837a24e03672c59b1239669a0596406ff657c3c0835b6b7f0f35a33" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "foreign-types", "libc", @@ -4821,13 +4721,13 @@ dependencies = [ [[package]] name = "openssl-macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -4838,20 +4738,19 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "111.24.0+1.1.1s" +version = "111.25.2+1.1.1t" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3498f259dab01178c6228c6b00dcef0ed2a2d5e20d648c017861227773ea4abd" +checksum = "320708a054ad9b3bf314688b5db87cf4d6683d64cfc835e2337924ae62bf4431" dependencies = [ "cc", ] [[package]] name = "openssl-sys" -version = "0.9.77" +version = "0.9.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" +checksum = "3a20eace9dc2d82904039cb76dcf50fb1a0bba071cfd1629720b5d6f1ddba0fa" dependencies = [ - "autocfg", "cc", "libc", "openssl-src", @@ -4988,7 +4887,7 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core 0.8.5", + "parking_lot_core 0.8.6", ] [[package]] @@ -4998,53 +4897,56 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.4", + "parking_lot_core 0.9.7", ] [[package]] name = "parking_lot_core" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" dependencies = [ "cfg-if", "instant", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "smallvec", "winapi", ] [[package]] name = "parking_lot_core" -version = "0.9.4" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "smallvec", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] name = "paste" -version = "1.0.9" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" +checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" [[package]] name = "pct-str" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1240e3e7bfdde5660ba0fc3e9e3565d3b30c2ae1973e218e93b869da771ff2e9" +checksum = "77d207ec8d182c2fef45f028b9b9507770df19e89b3e14827ccd95d4a23f6003" +dependencies = [ + "utf8-decode", +] [[package]] name = "pear" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e44241c5e4c868e3eaa78b7c1848cadd6344ed4f54d029832d32b415a58702" +checksum = "0ec95680a7087503575284e5063e14b694b7a9c0b065e5dceec661e0497127e8" dependencies = [ "inlinable_string", "pear_codegen", @@ -5053,14 +4955,14 @@ dependencies = [ [[package]] name = "pear_codegen" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a5ca643c2303ecb740d506539deba189e16f2754040a42901cd8105d0282d0" +checksum = "9661a3a53f93f09f2ea882018e4d7c88f6ff2956d809a276060476fd8c879d3c" dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -5102,16 +5004,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b687ff7b5da449d39e418ad391e5e08da53ec334903ddbb921db208908fc372c" -[[package]] -name = "petgraph" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143" -dependencies = [ - "fixedbitset", - "indexmap", -] - [[package]] name = "pgp" version = "0.8.0" @@ -5138,7 +5030,7 @@ dependencies = [ "digest 0.9.0", "ed25519-dalek", "flate2", - "generic-array 0.14.6", + "generic-array 0.14.7", "hex", "lazy_static", "log", @@ -5178,7 +5070,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -5227,7 +5119,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" dependencies = [ - "der 0.6.0", + "der 0.6.1", "spki 0.6.0", ] @@ -5245,16 +5137,18 @@ checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" [[package]] name = "polling" -version = "2.4.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab4609a838d88b73d8238967b60dd115cc08d38e2bbaf51ee1e4b695f89122e2" +checksum = "7e1f879b2998099c2d69ab9605d145d5b661195627eccc680002c4918a7fb6fa" dependencies = [ "autocfg", + "bitflags 1.3.2", "cfg-if", + "concurrent-queue", "libc", "log", - "wepoll-ffi", - "winapi", + "pin-project-lite 0.2.9", + "windows-sys 0.45.0", ] [[package]] @@ -5294,9 +5188,9 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "pretty_dtoa" @@ -5319,11 +5213,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.2.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" dependencies = [ - "once_cell", "thiserror", "toml", ] @@ -5337,7 +5230,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "version_check 0.9.4", ] @@ -5354,37 +5247,37 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] [[package]] name = "proc-macro2-diagnostics" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada" +checksum = "606c4ba35817e2922a308af55ad51bab3645b59eae5c570d4a6cf07e36bd493b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", "version_check 0.9.4", "yansi", ] [[package]] name = "procfs" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfb6451c91904606a1abe93e83a8ec851f45827fa84273f256ade45dc095818" +checksum = "b1de8dacb0873f77e6aefc6d71e044761fcc68060290f5b1089fcdf84626bb69" dependencies = [ - "bitflags", + "bitflags 1.3.2", "byteorder", "hex", "lazy_static", - "rustix", + "rustix 0.36.12", ] [[package]] @@ -5424,60 +5317,30 @@ checksum = "72b6a5217beb0ad503ee7fa752d451c905113d70721b937126158f3106a48cc1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "prost" -version = "0.11.0" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399c3c31cdec40583bb68f0b18403400d01ec4289c383aa047560439952c4dd7" +checksum = "e48e50df39172a3e7eb17e14642445da64996989bc212b583015435d39a58537" dependencies = [ "bytes", "prost-derive", ] -[[package]] -name = "prost-build" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f835c582e6bd972ba8347313300219fed5bfa52caf175298d860b61ff6069bb" -dependencies = [ - "bytes", - "heck", - "itertools", - "lazy_static", - "log", - "multimap", - "petgraph", - "prost", - "prost-types", - "regex", - "tempfile", - "which", -] - [[package]] name = "prost-derive" -version = "0.11.0" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7345d5f0e08c0536d7ac7229952590239e77abf0a0100a1b1d890add6ea96364" +checksum = "4ea9b0f8cbe5e15a8a042d030bd96668db28ecb567ec37d691971ff5731d2b1b" dependencies = [ "anyhow", "itertools", "proc-macro2", "quote", - "syn", -] - -[[package]] -name = "prost-types" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dfaa718ad76a44b3415e6c4d53b17c8f99160dcb3a99b10470fce8ad43f6e3e" -dependencies = [ - "bytes", - "prost", + "syn 1.0.109", ] [[package]] @@ -5527,15 +5390,15 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72ef4ced82a24bb281af338b9e8f94429b6eca01b4e66d899f40031f074e74c9" +checksum = "67c10f662eee9c94ddd7135043e544f3c82fa839a1e7b865911331961b53186c" dependencies = [ "bytes", "rand 0.8.5", "ring", "rustc-hash", - "rustls 0.20.7", + "rustls 0.20.8", "slab", "thiserror", "tinyvec", @@ -5545,9 +5408,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.21" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -5637,7 +5500,7 @@ checksum = "6413f3de1edee53342e6138e75b56d32e7bc6e332b3bd62d497b1929d4cfbcdd" dependencies = [ "pem", "ring", - "time 0.3.16", + "time 0.3.20", "x509-parser 0.13.2", "yasna", ] @@ -5650,7 +5513,7 @@ checksum = "ffbe84efe2f38dea12e9bfc1f65377fdf03e53a18cb3b995faedf7934c7e785b" dependencies = [ "pem", "ring", - "time 0.3.16", + "time 0.3.20", "yasna", ] @@ -5673,34 +5536,43 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags 1.3.2", ] [[package]] name = "ref-cast" -version = "1.0.13" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b15debb4f9d60d767cd8ca9ef7abb2452922f3214671ff052defc7f3502c44" +checksum = "f43faa91b1c8b36841ee70e97188a869d37ae21759da6846d4be66de5bf7b12c" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.13" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abfa8511e9e94fd3de6585a3d3cd00e01ed556dc9814829280af0e8dc72a8f36" +checksum = "8d2275aab483050ab2a7364c1a46604865ee7d6906684e08db0f090acf74f9e7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] name = "regex" -version = "1.6.0" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "aho-corasick", "memchr", @@ -5718,26 +5590,17 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.27" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" - -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "reqwest" -version = "0.11.12" +version = "0.11.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" +checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" dependencies = [ - "base64 0.13.1", + "base64 0.21.0", "bytes", "encoding_rs", "futures-core", @@ -5746,7 +5609,7 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-rustls 0.23.0", + "hyper-rustls 0.23.2", "hyper-tls", "ipnet", "js-sys", @@ -5756,7 +5619,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite 0.2.9", - "rustls 0.20.7", + "rustls 0.20.8", "rustls-pemfile", "serde", "serde_json", @@ -5771,7 +5634,7 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "webpki-roots", - "winreg 0.10.1", + "winreg", ] [[package]] @@ -5786,9 +5649,9 @@ dependencies = [ [[package]] name = "rfc6979" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88c86280f057430a52f4861551b092a01b419b8eacefc7c995eacb9dc132fe32" +checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" dependencies = [ "crypto-bigint 0.4.9", "hmac 0.12.1", @@ -5823,20 +5686,20 @@ dependencies = [ [[package]] name = "rocket" -version = "0.5.0-rc.2" +version = "0.5.0-rc.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98ead083fce4a405feb349cf09abdf64471c6077f14e0ce59364aa90d4b99317" +checksum = "58734f7401ae5cfd129685b48f61182331745b357b96f2367f01aebaf1cc9cc9" dependencies = [ "async-stream", "async-trait", "atomic", - "atty", "binascii", "bytes", "either", "figment", "futures", "indexmap", + "is-terminal", "log", "memchr", "multer", @@ -5851,7 +5714,7 @@ dependencies = [ "serde_json", "state", "tempfile", - "time 0.3.16", + "time 0.3.20", "tokio", "tokio-stream", "tokio-util", @@ -5862,9 +5725,9 @@ dependencies = [ [[package]] name = "rocket_codegen" -version = "0.5.0-rc.2" +version = "0.5.0-rc.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6aeb6bb9c61e9cd2c00d70ea267bf36f76a4cc615e5908b349c2f9d93999b47" +checksum = "7093353f14228c744982e409259fb54878ba9563d08214f2d880d59ff2fc508b" dependencies = [ "devise", "glob", @@ -5872,15 +5735,15 @@ dependencies = [ "proc-macro2", "quote", "rocket_http", - "syn", + "syn 2.0.13", "unicode-xid", ] [[package]] name = "rocket_http" -version = "0.5.0-rc.2" +version = "0.5.0-rc.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ded65d127954de3c12471630bf4b81a2792f065984461e65b91d0fdaafc17a2" +checksum = "936012c99162a03a67f37f9836d5f938f662e26f2717809761a9ac46432090f4" dependencies = [ "cookie", "either", @@ -5898,7 +5761,7 @@ dependencies = [ "smallvec", "stable-pattern", "state", - "time 0.3.16", + "time 0.3.20", "tokio", "uncased", ] @@ -5910,7 +5773,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cf22754c49613d2b3b119f0e5d46e34a2c628a937e3024b8762de4e7d8c710b" dependencies = [ "byteorder", - "digest 0.10.5", + "digest 0.10.6", "num-bigint-dig", "num-integer", "num-iter", @@ -5989,16 +5852,30 @@ dependencies = [ [[package]] name = "rustix" -version = "0.35.13" +version = "0.36.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" +checksum = "e0af200a3324fa5bcd922e84e9b55a298ea9f431a489f01961acdebc6e908f25" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", - "linux-raw-sys", - "windows-sys 0.42.0", + "linux-raw-sys 0.1.4", + "windows-sys 0.45.0", +] + +[[package]] +name = "rustix" +version = "0.37.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.1", + "windows-sys 0.45.0", ] [[package]] @@ -6016,9 +5893,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.7" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" dependencies = [ "log", "ring", @@ -6040,18 +5917,18 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" +checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" dependencies = [ - "base64 0.13.1", + "base64 0.21.0", ] [[package]] name = "rustversion" -version = "1.0.9" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" +checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" [[package]] name = "rw-stream-sink" @@ -6066,9 +5943,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" [[package]] name = "ryu-js" @@ -6090,12 +5967,11 @@ checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" [[package]] name = "schannel" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" dependencies = [ - "lazy_static", - "windows-sys 0.36.1", + "windows-sys 0.42.0", ] [[package]] @@ -6112,9 +5988,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "scratch" -version = "1.0.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" +checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" [[package]] name = "sct" @@ -6155,8 +6031,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" dependencies = [ "base16ct", - "der 0.6.0", - "generic-array 0.14.6", + "der 0.6.1", + "generic-array 0.14.7", "pkcs8 0.9.0", "subtle", "zeroize", @@ -6164,11 +6040,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.7.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -6177,9 +6053,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" dependencies = [ "core-foundation-sys", "libc", @@ -6187,15 +6063,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.14" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] name = "serde" -version = "1.0.147" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" dependencies = [ "serde_derive", ] @@ -6211,22 +6087,22 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.7" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfc50e8183eeeb6178dcb167ae34a8051d63535023ae38b5d8d12beae193d37b" +checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.147" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -6242,9 +6118,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.87" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" +checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" dependencies = [ "itoa", "ryu", @@ -6277,9 +6153,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "2.0.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368f2d60d049ea019a84dcd6687b0d1e0030fe663ae105039bdf967ed5e6a9a7" +checksum = "331bb8c3bf9b92457ab7abecf07078c13f7d270ba490103e84e8b014490cd0b0" dependencies = [ "base64 0.13.1", "chrono", @@ -6287,8 +6163,8 @@ dependencies = [ "indexmap", "serde", "serde_json", - "serde_with_macros 2.0.1", - "time 0.3.16", + "serde_with_macros 2.3.2", + "time 0.3.20", ] [[package]] @@ -6300,19 +6176,19 @@ dependencies = [ "darling 0.13.4", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "serde_with_macros" -version = "2.0.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ccadfacf6cf10faad22bbadf55986bdd0856edfb5d9210aa1dcf1f516e84e93" +checksum = "859011bddcc11f289f07f467cc1fe01c7a941daa4d8f6c40d4d1c92eb6d9319c" dependencies = [ - "darling 0.14.2", + "darling 0.14.4", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -6336,7 +6212,7 @@ checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.5", + "digest 0.10.6", ] [[package]] @@ -6372,7 +6248,7 @@ checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.5", + "digest 0.10.6", ] [[package]] @@ -6393,7 +6269,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" dependencies = [ - "digest 0.10.5", + "digest 0.10.6", "keccak", ] @@ -6408,9 +6284,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ "libc", ] @@ -6421,7 +6297,7 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" dependencies = [ - "digest 0.10.5", + "digest 0.10.6", "rand_core 0.6.4", ] @@ -6450,7 +6326,7 @@ dependencies = [ "rand 0.8.5", "sha3 0.10.6", "thiserror", - "time 0.3.16", + "time 0.3.20", ] [[package]] @@ -6469,9 +6345,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ "autocfg", ] @@ -6526,9 +6402,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" dependencies = [ "libc", "winapi", @@ -6558,9 +6434,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.4" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "spki" @@ -6579,7 +6455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" dependencies = [ "base64ct", - "der 0.6.0", + "der 0.6.1", ] [[package]] @@ -6688,9 +6564,9 @@ dependencies = [ [[package]] name = "ssi-json-ld" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01f5f3d1fe13108148d89e54df870664f35b69e5c6d263b370521da4951a3854" +checksum = "b90b3723421b79dcefdbe65ee92d6f7a9d74b6d42de57afeca7d8286424faa14" dependencies = [ "async-std", "combination", @@ -6975,9 +6851,20 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.103" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" dependencies = [ "proc-macro2", "quote", @@ -6992,7 +6879,7 @@ checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "unicode-xid", ] @@ -7002,7 +6889,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75182f12f490e953596550b65ee31bda7c8e043d9386174b353bda50838c3fd" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "system-configuration-sys", ] @@ -7025,53 +6912,53 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.3.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ "cfg-if", "fastrand", - "libc", - "redox_syscall", - "remove_dir_all", - "winapi", + "redox_syscall 0.3.5", + "rustix 0.37.7", + "windows-sys 0.45.0", ] [[package]] name = "termcolor" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] [[package]] name = "thiserror" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] name = "thread_local" -version = "1.1.4" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" dependencies = [ + "cfg-if", "once_cell", ] @@ -7099,9 +6986,9 @@ dependencies = [ [[package]] name = "time" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", @@ -7110,14 +6997,12 @@ dependencies = [ [[package]] name = "time" -version = "0.3.16" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fab5c8b9980850e06d92ddbe3ab839c062c801f3927c0fb8abd6fc8e918fbca" +checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" dependencies = [ "itoa", "js-sys", - "libc", - "num_threads", "serde", "time-core", "time-macros", @@ -7131,9 +7016,9 @@ checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" [[package]] name = "time-macros" -version = "0.2.5" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bb801831d812c562ae7d2bfb531f26e66e4e1f6b17307ba4149c5064710e5b" +checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36" dependencies = [ "time-core", ] @@ -7168,20 +7053,19 @@ dependencies = [ [[package]] name = "tinyvec_macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.21.2" +version = "1.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" dependencies = [ "autocfg", "bytes", "libc", - "memchr", "mio", "num_cpus", "parking_lot 0.12.1", @@ -7189,25 +7073,25 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "winapi", + "windows-sys 0.45.0", ] [[package]] name = "tokio-macros" -version = "1.8.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] name = "tokio-native-tls" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ "native-tls", "tokio", @@ -7230,7 +7114,7 @@ version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" dependencies = [ - "rustls 0.20.7", + "rustls 0.20.8", "tokio", "webpki 0.22.0", ] @@ -7249,9 +7133,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" +checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313" dependencies = [ "futures-core", "pin-project-lite 0.2.9", @@ -7260,9 +7144,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" dependencies = [ "bytes", "futures-core", @@ -7275,9 +7159,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] @@ -7331,7 +7215,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -7457,9 +7341,9 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "turn" @@ -7493,9 +7377,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "ubyte" @@ -7508,9 +7392,9 @@ dependencies = [ [[package]] name = "uint" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a45526d29728d135c2900b0d30573fe3ee79fceb12ef534c7bb30e810a91b601" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" dependencies = [ "byteorder", "crunchy", @@ -7530,15 +7414,15 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unicode-normalization" @@ -7567,7 +7451,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "subtle", ] @@ -7616,11 +7500,17 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" +[[package]] +name = "utf8-decode" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca61eb27fa339aa08826a29f03e87b99b4d8f0fc2255306fd266bb1b6a9de498" + [[package]] name = "uuid" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" dependencies = [ "getrandom 0.2.8", "wasm-bindgen", @@ -7730,7 +7620,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -7764,7 +7654,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -7792,9 +7682,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" dependencies = [ "js-sys", "wasm-bindgen", @@ -7822,9 +7712,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.5" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" dependencies = [ "webpki 0.22.0", ] @@ -7855,7 +7745,7 @@ dependencies = [ "sha2 0.10.6", "stun", "thiserror", - "time 0.3.16", + "time 0.3.20", "tokio", "turn", "url", @@ -8027,7 +7917,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f1db1727772c05cf7a2cfece52c3aca8045ca1e176cd517d323489aa3c6d87" dependencies = [ "async-trait", - "bitflags", + "bitflags 1.3.2", "bytes", "cc", "ipnet", @@ -8041,26 +7931,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "wepoll-ffi" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" -dependencies = [ - "cc", -] - -[[package]] -name = "which" -version = "4.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" -dependencies = [ - "either", - "libc", - "once_cell", -] - [[package]] name = "widestring" version = "0.5.1" @@ -8098,19 +7968,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbedf6db9096bc2364adce0ae0aa636dcd89f3c3f2cd67947062aaf0ca2a10ec" -dependencies = [ - "windows_aarch64_msvc 0.32.0", - "windows_i686_gnu 0.32.0", - "windows_i686_msvc 0.32.0", - "windows_x86_64_gnu 0.32.0", - "windows_x86_64_msvc 0.32.0", -] - [[package]] name = "windows" version = "0.34.0" @@ -8125,16 +7982,21 @@ dependencies = [ ] [[package]] -name = "windows-sys" -version = "0.36.1" +name = "windows" +version = "0.44.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +checksum = "9e745dab35a0c4c77aa3ce42d595e13d2003d6902d6b08c9ef5fc326d08da12b" dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", + "windows-targets 0.42.2", +] + +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.0", ] [[package]] @@ -8143,26 +8005,74 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.0", - "windows_i686_gnu 0.42.0", - "windows_i686_msvc 0.42.0", - "windows_x86_64_gnu 0.42.0", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.0", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] -name = "windows_aarch64_msvc" -version = "0.32.0" +name = "windows_aarch64_gnullvm" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_msvc" @@ -8172,21 +8082,15 @@ checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" [[package]] name = "windows_aarch64_msvc" -version = "0.36.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_aarch64_msvc" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" - -[[package]] -name = "windows_i686_gnu" -version = "0.32.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_i686_gnu" @@ -8196,21 +8100,15 @@ checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" [[package]] name = "windows_i686_gnu" -version = "0.36.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_gnu" -version = "0.42.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" - -[[package]] -name = "windows_i686_msvc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_msvc" @@ -8220,21 +8118,15 @@ checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" [[package]] name = "windows_i686_msvc" -version = "0.36.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_i686_msvc" -version = "0.42.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_x86_64_gnu" @@ -8244,27 +8136,27 @@ checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" [[package]] name = "windows_x86_64_gnu" -version = "0.36.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] -name = "windows_x86_64_msvc" -version = "0.32.0" +name = "windows_x86_64_gnullvm" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_msvc" @@ -8274,24 +8166,15 @@ checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" [[package]] name = "windows_x86_64_msvc" -version = "0.36.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "windows_x86_64_msvc" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" - -[[package]] -name = "winreg" -version = "0.7.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" -dependencies = [ - "winapi", -] +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winreg" @@ -8346,7 +8229,7 @@ dependencies = [ "ring", "rusticata-macros", "thiserror", - "time 0.3.16", + "time 0.3.20", ] [[package]] @@ -8364,7 +8247,7 @@ dependencies = [ "oid-registry 0.6.1", "rusticata-macros", "thiserror", - "time 0.3.16", + "time 0.3.20", ] [[package]] @@ -8395,30 +8278,29 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "yasna" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aed2e7a52e3744ab4d0c05c20aa065258e84c49fd4226f5191b2ed29712710b4" +checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd" dependencies = [ - "time 0.3.16", + "time 0.3.20", ] [[package]] name = "zeroize" -version = "1.5.7" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.3.2" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn", - "synstructure", + "syn 2.0.13", ] From 622e92f275ff642d7272be045f865e27eb5313db Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 6 Apr 2023 20:25:10 +1000 Subject: [PATCH 41/48] satisfy clippy again --- src/p2p/relay.rs | 45 -------------------------------------------- src/storage/s3.rs | 4 ++-- src/storage/utils.rs | 1 - 3 files changed, 2 insertions(+), 48 deletions(-) diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index 841c07d7..ae4b3da0 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -273,49 +273,4 @@ mod test { assert_eq!(listened, vec![addr]); } - - #[test] - async fn can_relay() { - let mut alice = Config::default() - .launch(Keypair::generate_ed25519(), MemoryConfig) - .unwrap(); - - let mut bob = Config::default() - .launch( - Keypair::generate_ed25519(), - Both::::default(), - ) - .unwrap(); - - let mut charles = Config::default() - .launch( - Keypair::generate_ed25519(), - Both::::default(), - ) - .unwrap(); - - alice - .listen_on([build_multiaddr!(Memory(0u8))]) - .await - .unwrap(); - - bob.listen_on([build_multiaddr!(Memory(0u8))]) - .await - .unwrap(); - - charles - .listen_on([build_multiaddr!(Tcp(0u8))]) - .await - .unwrap(); - - let alice_addrs = alice.get_addresses().await.unwrap(); - let bob_addrs = bob.get_addresses().await.unwrap(); - let charles_addrs = charles.get_addresses().await.unwrap(); - - let charles_via_bob = bob_addrs[0].clone().with(Protocol::P2p(bob.id().into())); - - let charles_via_bob = charles_addrs[0].with(Protocol::P2p(bob.id().into())); - - alice.dial().await.unwrap(); - } } diff --git a/src/storage/s3.rs b/src/storage/s3.rs index 8036c623..d4374b5c 100644 --- a/src/storage/s3.rs +++ b/src/storage/s3.rs @@ -100,7 +100,7 @@ impl ProviderUtils for S3BlockConfig { .await { Ok(o) => Ok(Keypair::from_protobuf_encoding( - &o.body.collect().await?.into_bytes().to_vec(), + &o.body.collect().await?.into_bytes(), )?), Err(SdkError::ServiceError { err: @@ -132,7 +132,7 @@ impl ProviderUtils for S3BlockConfig { .await { Ok(o) => Ok(Some(Keypair::from_protobuf_encoding( - &o.body.collect().await?.into_bytes().to_vec(), + &o.body.collect().await?.into_bytes(), )?)), Err(SdkError::ServiceError { err: diff --git a/src/storage/utils.rs b/src/storage/utils.rs index d40560e9..800d20f5 100644 --- a/src/storage/utils.rs +++ b/src/storage/utils.rs @@ -53,7 +53,6 @@ macro_rules! write_with_multihash { let (mut h, b) = hb.into_inner(); Ok((Code::$hashes.wrap(h.finalize())?, b)) },)* - _ => Err(MultihashError::UnsupportedCode($code.into())), } }; } From 4fd7cba0f027b0df38a178dec169537d70e0a3bc Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 6 Apr 2023 20:25:43 +1000 Subject: [PATCH 42/48] relay test --- src/p2p/relay.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/p2p/relay.rs b/src/p2p/relay.rs index ae4b3da0..841c07d7 100644 --- a/src/p2p/relay.rs +++ b/src/p2p/relay.rs @@ -273,4 +273,49 @@ mod test { assert_eq!(listened, vec![addr]); } + + #[test] + async fn can_relay() { + let mut alice = Config::default() + .launch(Keypair::generate_ed25519(), MemoryConfig) + .unwrap(); + + let mut bob = Config::default() + .launch( + Keypair::generate_ed25519(), + Both::::default(), + ) + .unwrap(); + + let mut charles = Config::default() + .launch( + Keypair::generate_ed25519(), + Both::::default(), + ) + .unwrap(); + + alice + .listen_on([build_multiaddr!(Memory(0u8))]) + .await + .unwrap(); + + bob.listen_on([build_multiaddr!(Memory(0u8))]) + .await + .unwrap(); + + charles + .listen_on([build_multiaddr!(Tcp(0u8))]) + .await + .unwrap(); + + let alice_addrs = alice.get_addresses().await.unwrap(); + let bob_addrs = bob.get_addresses().await.unwrap(); + let charles_addrs = charles.get_addresses().await.unwrap(); + + let charles_via_bob = bob_addrs[0].clone().with(Protocol::P2p(bob.id().into())); + + let charles_via_bob = charles_addrs[0].with(Protocol::P2p(bob.id().into())); + + alice.dial().await.unwrap(); + } } From 9faea0f6fe2b77590cce5249fb37b8eab03af841 Mon Sep 17 00:00:00 2001 From: chunningham Date: Wed, 26 Apr 2023 17:18:48 +0200 Subject: [PATCH 43/48] config relay with any multiaddr --- README.md | 17 ++++++++--------- kepler.toml | 3 +-- src/auth_guards.rs | 3 +-- src/config.rs | 7 +++---- src/lib.rs | 5 +---- src/routes/mod.rs | 14 +++++++------- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 7997bdca..ac02f73f 100644 --- a/README.md +++ b/README.md @@ -40,14 +40,13 @@ Kepler instances are configured by the [kepler.toml](kepler.toml) configuration The following common options are available: -| Option | env var | description | -|:---------------------|:----------------------------|:---------------------------------------------------------------| -| log_level | KEPLER_LOG_LEVEL | Set the level of logging output, options are "normal", "debug" | -| address | KEPLER_ADDRESS | Set the listening address of the kepler instance | -| port | KEPLER_PORT | Set the listening TCP port for the kepler instance | -| storage.blocks.type | KEPLER_STORAGE_BLOCKS_TYPE | Set the mode of block storage, options are "Local" and "S3" | -| storage.indexes.type | KEPLER_STORAGE_INDEXES_TYPE | Set the type of the index store, options are "Local" and "DynamoDB" | -| orbits.allowlist | KEPLER_ORBITS_ALLOWLIST | Set the URL of an allowlist service for gating the creation of Orbit Peers | +| Option | env var | description | +|:---------------------|:----------------------------|:---------------------------------------------------------------------------| +| log_level | KEPLER_LOG_LEVEL | Set the level of logging output, options are "normal", "debug" | +| address | KEPLER_ADDRESS | Set the listening multi-address of the kepler instance | +| storage.blocks.type | KEPLER_STORAGE_BLOCKS_TYPE | Set the mode of block storage, options are "Local" and "S3" | +| storage.indexes.type | KEPLER_STORAGE_INDEXES_TYPE | Set the type of the index store, options are "Local" and "DynamoDB" | +| orbits.allowlist | KEPLER_ORBITS_ALLOWLIST | Set the URL of an allowlist service for gating the creation of Orbit Peers | ### Storage Config @@ -82,7 +81,7 @@ Additionally, the following environment variables must be present: `AWS_ACCESS_K Kepler instances can be started via command line, e.g.: ``` sh -KEPLER_PORT=8001 kepler +KEPLER_ADDRESS=/ip4/127.0.0.1/tcp/8001 kepler ``` If the Kepler instance is not able to find or establish a connection to the configured storage, the instance will terminate. diff --git a/kepler.toml b/kepler.toml index b4104af3..e3ab4aa4 100644 --- a/kepler.toml +++ b/kepler.toml @@ -1,7 +1,6 @@ [global] # log_level = "normal" -# address = "127.0.0.1" -# port = 8000 +# address = "/ip4/127.0.0.1/tcp/8081" # cors = true ## Example of nest config variable: KEPLER_DATABASE_PATH diff --git a/src/auth_guards.rs b/src/auth_guards.rs index a82b006c..ffc92d01 100644 --- a/src/auth_guards.rs +++ b/src/auth_guards.rs @@ -81,12 +81,11 @@ fn get_state(req: &Request<'_>) -> Result<(config::Config, (PeerId, Multiaddr))> .state::() .cloned() .ok_or_else(|| anyhow!("Could not retrieve config"))?; - let port = config.relay.port; Ok(( config, req.rocket() .state::() - .map(|r| (*r.id(), multiaddr!(Memory(port)))) + .map(|r| (*r.id(), multiaddr!(Memory(1u8)))) .ok_or_else(|| anyhow!("Could not retrieve relay node information"))?, )) } diff --git a/src/config.rs b/src/config.rs index c02f32db..51d0d6d7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,6 +3,7 @@ use crate::{ storage::{file_system::FileSystemConfig, s3::S3BlockConfig}, BlockConfig, }; +use libp2p::{build_multiaddr, Multiaddr}; use rocket::http::hyper::Uri; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr, FromInto}; @@ -81,8 +82,7 @@ pub struct DynamoStorage { #[derive(Serialize, Deserialize, Debug, Clone, Hash, PartialEq, Eq)] pub struct Relay { - pub address: String, - pub port: u16, + pub address: Multiaddr, } #[derive(Serialize, Deserialize, Debug, Clone, Hash, PartialEq, Eq)] @@ -122,8 +122,7 @@ impl Default for LocalIndexStorage { impl Default for Relay { fn default() -> Self { Self { - address: "127.0.0.1".into(), - port: 8081, + address: build_multiaddr!(Ip4([127, 0, 0, 1]), Tcp(8081u16)), } } } diff --git a/src/lib.rs b/src/lib.rs index 456b3b42..94d741c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,10 +80,7 @@ pub async fn app(config: &Figment) -> Result> { )?; relay_node - .listen_on([ - build_multiaddr!(Memory(kepler_config.relay.port)), - build_multiaddr!(Ip4([127, 0, 0, 1]), Tcp(kepler_config.relay.port)), - ]) + .listen_on([build_multiaddr!(Memory(1u64)), kepler_config.relay.address]) .await?; let routes = routes![ diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 337ea45e..4cd3b97b 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -4,7 +4,7 @@ use kepler_lib::{ authorization::{EncodingError, HeaderEncode}, libipld::Cid, }; -use libp2p::{identity::Keypair, multiaddr::multiaddr, PeerId}; +use libp2p::{identity::Keypair, multiaddr::Protocol, PeerId}; use rocket::{ data::{Data, ToByteUnit}, http::{Header, Status}, @@ -90,12 +90,12 @@ pub mod util_routes { #[get("/peer/relay")] pub fn relay_addr(relay: &State, config: &State) -> String { - multiaddr!( - Ip4([127, 0, 0, 1]), - Tcp(config.relay.port), - P2p(*relay.id()) - ) - .to_string() + config + .relay + .address + .clone() + .with(Protocol::P2p(*relay.id().as_ref())) + .to_string() } #[get("/peer/generate")] From 5253b8967d804716161853b2be287ffb407138af Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 27 Apr 2023 11:59:50 +0200 Subject: [PATCH 44/48] fix rocket config, add .toml relay config comments --- README.md | 4 +++- kepler.toml | 6 +++++- src/config.rs | 4 ++-- src/lib.rs | 9 ++++++++- src/routes/mod.rs | 10 ++++++---- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ac02f73f..47cadd7f 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,12 @@ The following common options are available: | Option | env var | description | |:---------------------|:----------------------------|:---------------------------------------------------------------------------| | log_level | KEPLER_LOG_LEVEL | Set the level of logging output, options are "normal", "debug" | -| address | KEPLER_ADDRESS | Set the listening multi-address of the kepler instance | +| address | KEPLER_ADDRESS | Set the listening address of the kepler instance | +| port | KEPLER_PORT | Set the listening TCP port for the kepler instance | | storage.blocks.type | KEPLER_STORAGE_BLOCKS_TYPE | Set the mode of block storage, options are "Local" and "S3" | | storage.indexes.type | KEPLER_STORAGE_INDEXES_TYPE | Set the type of the index store, options are "Local" and "DynamoDB" | | orbits.allowlist | KEPLER_ORBITS_ALLOWLIST | Set the URL of an allowlist service for gating the creation of Orbit Peers | +| relay.addresses | KEPLER_RELAY_ADDRESSES | Set the listening multiaddresses for the relay node | ### Storage Config diff --git a/kepler.toml b/kepler.toml index e3ab4aa4..65fef329 100644 --- a/kepler.toml +++ b/kepler.toml @@ -1,6 +1,7 @@ [global] # log_level = "normal" -# address = "/ip4/127.0.0.1/tcp/8081" +# address = "127.0.0.1" +# port = 8000 # cors = true ## Example of nest config variable: KEPLER_DATABASE_PATH @@ -16,3 +17,6 @@ [global.orbits] ## Orbit allow list api endpoint # allowlist = "http://localhost:10000" + +[global.relay] +# addresses = ["/ip4/127.0.0.1/tcp/8081"] diff --git a/src/config.rs b/src/config.rs index 51d0d6d7..f33b17d3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -82,7 +82,7 @@ pub struct DynamoStorage { #[derive(Serialize, Deserialize, Debug, Clone, Hash, PartialEq, Eq)] pub struct Relay { - pub address: Multiaddr, + pub addresses: Vec, } #[derive(Serialize, Deserialize, Debug, Clone, Hash, PartialEq, Eq)] @@ -122,7 +122,7 @@ impl Default for LocalIndexStorage { impl Default for Relay { fn default() -> Self { Self { - address: build_multiaddr!(Ip4([127, 0, 0, 1]), Tcp(8081u16)), + addresses: vec![build_multiaddr!(Ip4([127, 0, 0, 1]), Tcp(8081u16))], } } } diff --git a/src/lib.rs b/src/lib.rs index 94d741c5..fe3322cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,7 +80,14 @@ pub async fn app(config: &Figment) -> Result> { )?; relay_node - .listen_on([build_multiaddr!(Memory(1u64)), kepler_config.relay.address]) + .listen_on( + kepler_config + .relay + .addresses + .iter() + .cloned() + .chain([build_multiaddr!(Memory(1u64))]), + ) .await?; let routes = routes![ diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 4cd3b97b..e8207f3a 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -92,10 +92,12 @@ pub mod util_routes { pub fn relay_addr(relay: &State, config: &State) -> String { config .relay - .address - .clone() - .with(Protocol::P2p(*relay.id().as_ref())) - .to_string() + .addresses + .iter() + .cloned() + .map(|a| a.with(Protocol::P2p(*relay.id().as_ref())).to_string()) + .collect::>() + .join(", ") } #[get("/peer/generate")] From c3cc2a6a6ace9b42ab3b8072f3cb21b22d2bd50b Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 27 Apr 2023 12:01:55 +0200 Subject: [PATCH 45/48] fix readme example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47cadd7f..47a19a86 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Additionally, the following environment variables must be present: `AWS_ACCESS_K Kepler instances can be started via command line, e.g.: ``` sh -KEPLER_ADDRESS=/ip4/127.0.0.1/tcp/8001 kepler +KEPLER_PORT=8001 kepler ``` If the Kepler instance is not able to find or establish a connection to the configured storage, the instance will terminate. From 4645b00ce04d035c1c7126bc9a314cf4a5675812 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 27 Apr 2023 12:07:31 +0200 Subject: [PATCH 46/48] update docker relay config --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 2da5fadc..1d3ddad0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/kepler /usr/lo USER kepler COPY ./kepler.toml ./ ENV ROCKET_ADDRESS=0.0.0.0 +ENV KEPLER_RELAY_ADDRESSES=[\"/ip4/0.0.0.0/tcp/8081\"] EXPOSE 8000 EXPOSE 8001 EXPOSE 8081 From d3e55c85dd9c96fd80394236665c344e51c35c63 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 27 Apr 2023 12:16:33 +0200 Subject: [PATCH 47/48] fix readme log config example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47a19a86..e66b9826 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ The following common options are available: | Option | env var | description | |:---------------------|:----------------------------|:---------------------------------------------------------------------------| -| log_level | KEPLER_LOG_LEVEL | Set the level of logging output, options are "normal", "debug" | +| log_level | RUST_LOG | Set the level of logging output, options are "normal", "debug" | | address | KEPLER_ADDRESS | Set the listening address of the kepler instance | | port | KEPLER_PORT | Set the listening TCP port for the kepler instance | | storage.blocks.type | KEPLER_STORAGE_BLOCKS_TYPE | Set the mode of block storage, options are "Local" and "S3" | From 9985cc6bce4a59b03be9c75d626636b414c2e389 Mon Sep 17 00:00:00 2001 From: chunningham Date: Thu, 27 Apr 2023 13:31:14 +0200 Subject: [PATCH 48/48] unfix log readme example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e66b9826..47a19a86 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ The following common options are available: | Option | env var | description | |:---------------------|:----------------------------|:---------------------------------------------------------------------------| -| log_level | RUST_LOG | Set the level of logging output, options are "normal", "debug" | +| log_level | KEPLER_LOG_LEVEL | Set the level of logging output, options are "normal", "debug" | | address | KEPLER_ADDRESS | Set the listening address of the kepler instance | | port | KEPLER_PORT | Set the listening TCP port for the kepler instance | | storage.blocks.type | KEPLER_STORAGE_BLOCKS_TYPE | Set the mode of block storage, options are "Local" and "S3" |