diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2e90b4..ec07764 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,35 +8,35 @@ jobs: fail-fast: false matrix: toolchain: - - rust: stable + - rust: stable #- rust: nightly platform: - - target: x86_64-unknown-linux-gnu - host: ubuntu-latest - cross: false - - - target: x86_64-apple-darwin - host: macos-latest - cross: false - - - target: x86_64-pc-windows-msvc - host: windows-latest - cross: false - - - target: armv7-linux-androideabi - host: ubuntu-latest - cross: true - - target: aarch64-linux-android - host: ubuntu-latest - cross: true - - - target: aarch64-apple-ios - host: macos-latest - cross: true - - # - target: wasm32-unknown-unknown - # host: ubuntu-latest - # cross: true + - target: x86_64-unknown-linux-gnu + host: ubuntu-latest + cross: false + + - target: x86_64-apple-darwin + host: macos-latest + cross: false + + - target: x86_64-pc-windows-msvc + host: windows-latest + cross: false + + - target: armv7-linux-androideabi + host: ubuntu-latest + cross: true + - target: aarch64-linux-android + host: ubuntu-latest + cross: true + + - target: aarch64-apple-ios + host: macos-latest + cross: true + + # - target: wasm32-unknown-unknown + # host: ubuntu-latest + # cross: true env: RUST_BACKTRACE: 1 CARGO_INCREMENTAL: 0 @@ -45,69 +45,108 @@ jobs: runs-on: ${{ matrix.platform.host }} steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Cache cargo folder - uses: actions/cache@v1 - with: - path: ~/.cargo - key: ${{ matrix.platform.target }}-cargo-${{ matrix.toolchain.rust }} - - - name: Install dependencies ubuntu - if: matrix.platform.host == 'ubuntu-latest' - run: sudo apt-get install llvm-dev - - - name: Install dependencies macos - if: matrix.platform.host == 'macos-latest' - run: brew install llvm - - - name: Install dependencies windows - if: matrix.platform.host == 'windows-latest' - run: choco install llvm - - - name: Install rust toolchain - uses: hecrj/setup-rust-action@v1 - with: - rust-version: ${{ matrix.toolchain.rust }} - targets: ${{ matrix.platform.target }} - - - name: Install cargo-apk - if: contains(matrix.platform.target, 'android') - run: cargo install cargo-apk - - - name: Build - if: contains(matrix.platform.target, 'android') == false - run: cargo build --all --target ${{ matrix.platform.target }} - - - name: Build android - if: contains(matrix.platform.target, 'android') - run: cargo apk --target ${{ matrix.platform.target }} build --all - - - name: Rust tests - if: matrix.platform.cross == false - run: cargo test --all + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Cache cargo folder + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ matrix.platform.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Install Protoc + uses: arduino/setup-protoc@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies ubuntu + if: matrix.platform.host == 'ubuntu-latest' + run: sudo apt-get install llvm-dev + + - name: Install dependencies macos + if: matrix.platform.host == 'macos-latest' + run: brew install llvm + + - name: Install dependencies windows + if: matrix.platform.host == 'windows-latest' + run: choco install llvm + + - name: Install rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.toolchain.rust }} + target: ${{ matrix.platform.target }} + + - name: Install cargo-apk + if: contains(matrix.platform.target, 'android') + uses: baptiste0928/cargo-install@bf6758885262d0e6f61089a9d8c8790d3ac3368f # v1.3.0 + with: + crate: cargo-apk + + - name: Build + if: contains(matrix.platform.target, 'android') == false + uses: actions-rs/cargo@v1 + with: + command: build + args: --all --target ${{ matrix.platform.target }} + + - name: Build android + if: contains(matrix.platform.target, 'android') + uses: actions-rs/cargo@v1 + with: + command: apk + args: -- build --target ${{ matrix.platform.target }} + + - name: Rust tests + if: matrix.platform.cross == false + uses: actions-rs/cargo@v1 + with: + command: test + args: --all lint-rust: runs-on: ubuntu-latest steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Cache cargo folder - uses: actions/cache@v1 - with: - path: ~/.cargo - key: lint-cargo - - - name: Install rust toolchain - uses: hecrj/setup-rust-action@v1 - with: - rust-version: stable - components: clippy, rustfmt - - - name: cargo fmt - run: cargo fmt --all -- --check - - - name: cargo clippy - run: cargo clippy --workspace --examples --tests -- -D warnings + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Cache cargo folder + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Install rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + components: clippy, rustfmt + + - name: Install Protoc + uses: arduino/setup-protoc@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - name: cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --workspace --examples --tests -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index 7f9113b..1cd8373 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,15 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - [[package]] name = "anyhow" version = "1.0.56" @@ -29,21 +20,30 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" -[[package]] -name = "atomic" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" -dependencies = [ - "autocfg", -] - [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base64ct" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" + [[package]] name = "bitflags" version = "1.3.2" @@ -74,12 +74,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" -[[package]] -name = "bumpalo" -version = "3.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" - [[package]] name = "byteorder" version = "1.4.3" @@ -92,18 +86,18 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" -[[package]] -name = "cc" -version = "1.0.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "const-oid" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cec318a675afcb6a1ea1d4340e2d377e56e47c266f28043ceccbf4412ddfdd3b" + [[package]] name = "core2" version = "0.4.0" @@ -134,9 +128,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "3.2.1" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ "byteorder", "digest 0.9.0", @@ -151,6 +145,36 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" +[[package]] +name = "data-encoding-macro" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86927b7cd2fe88fa698b87404b287ab98d1a0063a34071d92e575b72d3029aca" +dependencies = [ + "data-encoding", + "data-encoding-macro-internal", +] + +[[package]] +name = "data-encoding-macro-internal" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5bbed42daaa95e780b60a50546aa345b8413a1e46f9a40a12907d3598f038db" +dependencies = [ + "data-encoding", + "syn", +] + +[[package]] +name = "der" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dd2ae565c0a381dde7fade45fce95984c568bdcb4700a4fdbe3175e0380b2f" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "digest" version = "0.9.0" @@ -366,12 +390,9 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] name = "heck" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" @@ -421,15 +442,6 @@ dependencies = [ "either", ] -[[package]] -name = "js-sys" -version = "0.3.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" -dependencies = [ - "wasm-bindgen", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -444,30 +456,26 @@ checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" [[package]] name = "libp2p" -version = "0.43.0" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e8570e25fa03d4385405dbeaf540ba00e3ee50942f03d84e1a8928a029f35f9" +checksum = "2e0a0d2f693675f49ded13c5d510c48b78069e23cbd9108d7ccd59f6dc568819" dependencies = [ - "atomic", "bytes", "futures", "futures-timer", "getrandom 0.2.5", "instant", - "lazy_static", "libp2p-core", "libp2p-swarm", - "libp2p-swarm-derive", "multiaddr", "parking_lot", - "pin-project 1.0.10", - "rand 0.7.3", + "pin-project", "smallvec", ] [[package]] name = "libp2p-broadcast" -version = "0.9.1" +version = "0.12.0" dependencies = [ "fnv", "futures", @@ -476,9 +484,9 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.32.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9164ec41455856e8187addc870bb4fe1ea2ee28e1a9244831d449a2429b32c1a" +checksum = "b6a8fcd392ff67af6cc3f03b1426c41f7f26b6b9aff2dc632c1c56dd649e571f" dependencies = [ "asn1_der", "bs58", @@ -488,18 +496,18 @@ dependencies = [ "futures", "futures-timer", "instant", - "lazy_static", "log", "multiaddr", "multihash", "multistream-select", + "once_cell", "parking_lot", - "pin-project 1.0.10", + "pin-project", "prost", "prost-build", "rand 0.8.5", - "ring", "rw-stream-sink", + "sec1", "sha2 0.10.2", "smallvec", "thiserror", @@ -510,9 +518,9 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.34.0" +version = "0.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53ab2d4eb8ef2966b10fdf859245cdd231026df76d3c6ed2cf9e418a8f688ec9" +checksum = "b2a35472fe3276b3855c00f1c032ea8413615e030256429ad5349cdf67c6e1a0" dependencies = [ "either", "fnv", @@ -521,23 +529,13 @@ dependencies = [ "instant", "libp2p-core", "log", - "pin-project 1.0.10", - "rand 0.7.3", + "pin-project", + "rand 0.8.5", "smallvec", "thiserror", "void", ] -[[package]] -name = "libp2p-swarm-derive" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf2fe8c80b43561355f4d51875273b5b6dfbac37952e8f64b1270769305c9d7" -dependencies = [ - "quote", - "syn", -] - [[package]] name = "lock_api" version = "0.4.6" @@ -570,14 +568,14 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "multiaddr" -version = "0.14.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c580bfdd8803cce319b047d239559a22f809094aaea4ac13902a1fdcfcd4261" +checksum = "a4aebdb21e90f81d13ed01dc84123320838e53963c2ca94b60b305d3fa64f31e" dependencies = [ "arrayref", - "bs58", "byteorder", "data-encoding", + "multibase", "multihash", "percent-encoding", "serde", @@ -586,6 +584,17 @@ dependencies = [ "url", ] +[[package]] +name = "multibase" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" +dependencies = [ + "base-x", + "data-encoding", + "data-encoding-macro", +] + [[package]] name = "multihash" version = "0.16.1" @@ -621,14 +630,14 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "multistream-select" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "363a84be6453a70e63513660f4894ef815daf88e3356bffcda9ca27d810ce83b" +checksum = "c8552ab875c1313b97b8d20cb857b9fd63e2d1d6a0a1b53ce9821e575405f27a" dependencies = [ "bytes", "futures", "log", - "pin-project 1.0.10", + "pin-project", "smallvec", "unsigned-varint", ] @@ -645,9 +654,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.10.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "opaque-debug" @@ -694,33 +703,13 @@ dependencies = [ "indexmap", ] -[[package]] -name = "pin-project" -version = "0.4.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9615c18d31137579e9ff063499264ddc1278e7b1982757ebc111028c4d1dc909" -dependencies = [ - "pin-project-internal 0.4.29", -] - [[package]] name = "pin-project" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" dependencies = [ - "pin-project-internal 1.0.10", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "044964427019eed9d49d9d5bbce6047ef18f37100ea400912a9fa4a3523ab12a" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "pin-project-internal", ] [[package]] @@ -746,6 +735,16 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs8" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +dependencies = [ + "der", + "spki", +] + [[package]] name = "ppv-lite86" version = "0.2.16" @@ -797,9 +796,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.9.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" +checksum = "399c3c31cdec40583bb68f0b18403400d01ec4289c383aa047560439952c4dd7" dependencies = [ "bytes", "prost-derive", @@ -807,9 +806,9 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.9.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" +checksum = "7f835c582e6bd972ba8347313300219fed5bfa52caf175298d860b61ff6069bb" dependencies = [ "bytes", "heck", @@ -827,9 +826,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.9.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" +checksum = "7345d5f0e08c0536d7ac7229952590239e77abf0a0100a1b1d890add6ea96364" dependencies = [ "anyhow", "itertools", @@ -840,9 +839,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.9.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534b7a0e836e3c482d2693070f982e39e7611da9695d4d1f5a4b186b51faef0a" +checksum = "4dfaa718ad76a44b3415e6c4d53b17c8f99160dcb3a99b10470fce8ad43f6e3e" dependencies = [ "bytes", "prost", @@ -943,8 +942,6 @@ version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" dependencies = [ - "aho-corasick", - "memchr", "regex-syntax", ] @@ -963,29 +960,14 @@ dependencies = [ "winapi", ] -[[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin", - "untrusted", - "web-sys", - "winapi", -] - [[package]] name = "rw-stream-sink" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4da5fcb054c46f5a5dff833b129285a93d3f0179531735e6c866e8cc307d2020" +checksum = "26338f5e09bb721b85b135ea05af7767c90b52f6de4f087d4f4a3a9d64e7dc04" dependencies = [ "futures", - "pin-project 0.4.29", + "pin-project", "static_assertions", ] @@ -995,6 +977,19 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sec1" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "zeroize", +] + [[package]] name = "serde" version = "1.0.136" @@ -1044,10 +1039,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] -name = "spin" -version = "0.5.2" +name = "spki" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" +dependencies = [ + "base64ct", + "der", +] [[package]] name = "static_assertions" @@ -1163,12 +1162,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" - [[package]] name = "unicode-xid" version = "0.2.2" @@ -1181,12 +1174,6 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86a8dc7f45e4c1b0d30e43038c38f274e77af056aa5f74b93c2cf9eb3c1c836" -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - [[package]] name = "url" version = "2.2.2" @@ -1223,70 +1210,6 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" -[[package]] -name = "wasm-bindgen" -version = "0.2.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" - -[[package]] -name = "web-sys" -version = "0.3.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "which" version = "4.2.5" @@ -1365,9 +1288,9 @@ checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" [[package]] name = "zeroize" -version = "1.3.0" +version = "1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" dependencies = [ "zeroize_derive", ] diff --git a/Cargo.toml b/Cargo.toml index bae4028..d51cc77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-broadcast" -version = "0.9.1" +version = "0.12.0" authors = ["David Craven ", "Actyx AG"] edition = "2018" license = "MIT OR Apache-2.0" @@ -10,4 +10,4 @@ repository = "https://github.com/ipfs-rust/libp2p-broadcast" [dependencies] fnv = "1.0.7" futures = "0.3.21" -libp2p = { version = "0.43.0", default-features = false } +libp2p = { version = "0.50.0" } diff --git a/src/lib.rs b/src/lib.rs index 9276d99..9680cb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ use std::task::{Context, Poll}; mod protocol; +use libp2p::swarm::derive_prelude::FromSwarm; pub use protocol::{BroadcastConfig, Topic}; #[derive(Clone, Debug, Eq, PartialEq)] @@ -139,33 +140,23 @@ impl NetworkBehaviour for Broadcast { Vec::new() } - fn inject_connection_established( - &mut self, - peer: &PeerId, - _connection_id: &ConnectionId, - _endpoint: &libp2p::core::ConnectedPoint, - _failed_addresses: Option<&Vec>, - other_established: usize, - ) { - if other_established == 0 { - self.inject_connected(peer) - } - } - - fn inject_connection_closed( - &mut self, - peer: &PeerId, - _: &ConnectionId, - _: &libp2p::core::ConnectedPoint, - _: ::Handler, - remaining_established: usize, - ) { - if remaining_established == 0 { - self.inject_disconnected(peer) + fn on_swarm_event(&mut self, event: FromSwarm) { + match event { + FromSwarm::ConnectionEstablished(c) => { + if c.other_established == 0 { + self.inject_connected(&c.peer_id); + } + } + FromSwarm::ConnectionClosed(c) => { + if c.remaining_established == 0 { + self.inject_disconnected(&c.peer_id); + } + } + _ => {} } } - fn inject_event(&mut self, peer: PeerId, _: ConnectionId, msg: HandlerEvent) { + fn on_connection_handler_event(&mut self, peer: PeerId, _: ConnectionId, msg: HandlerEvent) { use HandlerEvent::*; use Message::*; let ev = match msg { @@ -278,7 +269,7 @@ mod tests { }) => { if let Some(other) = self.connections.get(&peer_id) { let mut other = other.lock().unwrap(); - other.inject_event( + other.on_connection_handler_event( *self.peer_id(), ConnectionId::new(0), HandlerEvent::Rx(event), diff --git a/src/protocol.rs b/src/protocol.rs index 45b4cd0..e6dcee0 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -39,7 +39,7 @@ impl AsRef<[u8]> for Topic { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum Message { Subscribe(Topic), Broadcast(Topic, Arc<[u8]>),