diff --git a/.cargo/config.toml b/.cargo/config.toml index e55adcc9ed1..8c1349f4bc0 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,3 @@ [alias] # Temporary solution to have clippy config in a single place until https://github.com/rust-lang/rust-clippy/blob/master/doc/roadmap-2021.md#lintstoml-configuration is shipped. -custom-clippy = "clippy --workspace --all-features --all-targets -- -A clippy::type_complexity -A clippy::pedantic -W clippy::used_underscore_binding -W unreachable_pub -D warnings" +custom-clippy = "clippy --workspace --all-features --all-targets -- -A clippy::type_complexity -A clippy::pedantic -W clippy::used_underscore_binding -W unreachable_pub" diff --git a/.github/actions/cargo-semver-checks/action.yml b/.github/actions/cargo-semver-checks/action.yml deleted file mode 100644 index e9e6844f49c..00000000000 --- a/.github/actions/cargo-semver-checks/action.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: "Run cargo semver-checks" -description: "Install and run the cargo semver-checks tool" -inputs: - crate: - required: true - description: "The crate to run `cargo semver-checks` on." -runs: - using: "composite" - steps: - - run: wget -q -O- https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.22.1/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/.cargo/bin - shell: bash - - - name: Get released version - shell: bash - id: get-released-version - run: | - MAX_STABLE_VERSION=$(curl https://crates.io/api/v1/crates/${{ inputs.crate }} --silent | jq '.crate.max_stable_version') - echo "version=${MAX_STABLE_VERSION}" >> $GITHUB_OUTPUT - - - shell: bash - run: | - rustc --version | tee .rustc-version - cargo semver-checks --version | tee .semver-checks-version - - - uses: actions/cache@v3 - with: - path: ${{ github.workspace }}/target/semver-checks/cache - key: semver-checks-cache-${{ hashFiles('.rustc-version') }}-${{ hashFiles('.semver-checks-version') }}-${{ inputs.crate }}-${{ steps.get-released-version.outputs.version }} - - - run: cargo semver-checks check-release --package ${{ inputs.crate }} --verbose - shell: bash - env: - CARGO_TERM_VERBOSE: "true" - # debugging https://github.com/libp2p/rust-libp2p/pull/3782#issuecomment-1523346255 - CARGO_HTTP_DEBUG: "true" - CARGO_LOG: "cargo::ops::registry=debug" diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0bfe5069ae0..59915a71b6c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,6 +8,11 @@ updates: commit-message: prefix: "deps" rebase-strategy: "disabled" + groups: + trust-dns: + patterns: + - "trust-dns-*" + - "async-std-resolver" - package-ecosystem: "github-actions" directory: "/" schedule: diff --git a/.github/workflows/cache-factory.yml b/.github/workflows/cache-factory.yml index 860f0a0de2c..3f4abfbce93 100644 --- a/.github/workflows/cache-factory.yml +++ b/.github/workflows/cache-factory.yml @@ -18,11 +18,11 @@ jobs: make_stable_rust_cache: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 with: shared-key: stable-cache diff --git a/.github/workflows/cargo-audit.yml b/.github/workflows/cargo-audit.yml index 2b5abe19292..65c5de03f22 100644 --- a/.github/workflows/cargo-audit.yml +++ b/.github/workflows/cargo-audit.yml @@ -7,7 +7,7 @@ jobs: audit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions-rs/audit-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92f7b449fde..6e8dc32c7b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,7 @@ concurrency: env: SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2 # Fail cache download after 2 minutes. + RUSTFLAGS: '-Dwarnings' # Never tolerate warnings. jobs: test: @@ -31,13 +32,13 @@ jobs: env: CRATE: ${{ matrix.crate }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 with: shared-key: stable-cache save-if: false @@ -48,20 +49,6 @@ jobs: - name: Check if we compile without any features activated run: cargo build --package "$CRATE" --no-default-features - - run: cargo clean - - - name: Check if crate has been released - id: check-released - run: | - RESPONSE_CODE=$(curl https://crates.io/api/v1/crates/"$CRATE" --silent --write-out "%{http_code}" --output /dev/null) - echo "code=${RESPONSE_CODE}" - echo "code=${RESPONSE_CODE}" >> $GITHUB_OUTPUT - - - uses: ./.github/actions/cargo-semver-checks - if: steps.check-released.outputs.code == 200 && !contains(fromJSON('["libp2p-swarm-derive"]'), env.CRATE) # Workaround until https://github.com/obi1kenobi/cargo-semver-check/issues/146 is shipped. - with: - crate: ${{ env.CRATE }} - - name: Enforce no dependency on meta crate if: env.CRATE != 'libp2p-server' run: | @@ -89,7 +76,7 @@ jobs: env: CHROMEDRIVER_VERSION: '114.0.5735.90' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: @@ -129,7 +116,7 @@ jobs: os: windows-latest runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: @@ -137,7 +124,7 @@ jobs: - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 with: key: ${{ matrix.target }} save-if: ${{ github.ref == 'refs/heads/master' }} @@ -148,7 +135,7 @@ jobs: name: Compile with MSRV runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Extract MSRV from workspace manifest shell: bash @@ -162,7 +149,7 @@ jobs: - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 with: save-if: ${{ github.ref == 'refs/heads/master' }} @@ -177,13 +164,13 @@ jobs: - features: "mdns tcp dns tokio" - features: "mdns tcp dns async-std" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 with: key: ${{ matrix.features }} save-if: ${{ github.ref == 'refs/heads/master' }} @@ -194,13 +181,13 @@ jobs: name: Check rustdoc intra-doc links runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 with: save-if: ${{ github.ref == 'refs/heads/master' }} @@ -213,11 +200,11 @@ jobs: fail-fast: false matrix: rust-version: [ - 1.71.0, # current stable + 1.72.0, # current stable beta ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: @@ -226,7 +213,7 @@ jobs: - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 with: save-if: ${{ github.ref == 'refs/heads/master' }} @@ -237,13 +224,13 @@ jobs: name: IPFS Integration tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 with: save-if: ${{ github.ref == 'refs/heads/master' }} @@ -253,13 +240,13 @@ jobs: examples: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 with: shared-key: stable-cache save-if: false @@ -272,10 +259,18 @@ jobs: cargo check --manifest-path "$toml"; done + semver: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: wget -q -O- https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.23.0/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/.cargo/bin + shell: bash + - uses: obi1kenobi/cargo-semver-checks-action@v2 + rustfmt: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: @@ -289,7 +284,7 @@ jobs: manifest_lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -312,7 +307,7 @@ jobs: outputs: members: ${{ steps.cargo-metadata.outputs.members }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -325,9 +320,9 @@ jobs: name: Check for changes in proto files runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - run: cargo install --version 0.10.0 pb-rs --locked @@ -352,19 +347,14 @@ jobs: name: Ensure that `Cargo.lock` is up-to-date runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: Swatinem/rust-cache@578b235f6e5f613f7727f1c17bd3305b4d4d4e1f # v2.6.1 + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - run: cargo metadata --locked --format-version=1 > /dev/null cargo-deny: runs-on: ubuntu-latest - strategy: - matrix: - checks: - - advisories - - bans licenses sources steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: EmbarkStudios/cargo-deny-action@v1 with: - command: check ${{ matrix.checks }} + command: check advisories bans licenses sources diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 45a4db14385..7bde2040e2d 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -11,7 +11,7 @@ jobs: server: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: docker/login-action@v2 with: @@ -27,7 +27,7 @@ jobs: run: echo ::set-output name=ref::${GITHUB_REF#refs/*/} - name: Build and push - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v4 with: context: . file: ./misc/server/Dockerfile diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8513493b41a..bffcc60d2ea 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install nightly toolchain run: rustup toolchain install nightly - name: Build Documentation diff --git a/.github/workflows/interop-test.yml b/.github/workflows/interop-test.yml index 4d63a76c811..5bda0622a72 100644 --- a/.github/workflows/interop-test.yml +++ b/.github/workflows/interop-test.yml @@ -17,7 +17,7 @@ jobs: matrix: flavour: [chromium, native] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: docker/setup-buildx-action@v2 - name: Build ${{ matrix.flavour }} image run: docker buildx build --load -t ${{ matrix.flavour }}-rust-libp2p-head . -f interop-tests/Dockerfile.${{ matrix.flavour }} diff --git a/Cargo.lock b/Cargo.lock index 8ae14bea796..e49ec51f6ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -463,16 +463,16 @@ dependencies = [ [[package]] name = "async-std-resolver" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba50e24d9ee0a8950d3d03fc6d0dd10aa14b5de3b101949b4e160f7fee7c723" +checksum = "0354a68a52265a3bde76005ddd2726624ef8624614f7f58871301de205a58a59" dependencies = [ "async-std", "async-trait", "futures-io", "futures-util", "pin-utils", - "socket2 0.4.9", + "socket2 0.5.3", "trust-dns-resolver", ] @@ -490,7 +490,7 @@ checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -619,9 +619,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.2" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53" [[package]] name = "base64ct" @@ -746,9 +746,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" dependencies = [ "serde", ] @@ -920,7 +920,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -1249,7 +1249,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -1435,7 +1435,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -1564,14 +1564,14 @@ dependencies = [ [[package]] name = "enum-as-inner" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116" +checksum = "5ffccbb6966c05b32ef8fbac435df276c4ae4d3dc55a8cd0eb9745e6c12f546a" dependencies = [ "heck", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.31", ] [[package]] @@ -1819,18 +1819,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", -] - -[[package]] -name = "futures-rustls" -version = "0.22.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2411eed028cdf8c8034eaf21f9915f956b6c3abec4d4c7949ee67f0721127bd" -dependencies = [ - "futures-io", - "rustls 0.20.8", - "webpki 0.22.0", + "syn 2.0.31", ] [[package]] @@ -1840,7 +1829,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35bd3cf68c183738046838e300353e4716c674dc5e56890de4826801a6622a28" dependencies = [ "futures-io", - "rustls 0.21.6", + "rustls 0.21.7", ] [[package]] @@ -2210,7 +2199,7 @@ dependencies = [ "rustls 0.20.8", "rustls-native-certs", "tokio", - "tokio-rustls", + "tokio-rustls 0.23.4", ] [[package]] @@ -2242,17 +2231,6 @@ dependencies = [ "libp2p", ] -[[package]] -name = "idna" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "0.4.0" @@ -2406,7 +2384,7 @@ dependencies = [ "socket2 0.5.3", "widestring", "windows-sys", - "winreg 0.50.0", + "winreg", ] [[package]] @@ -2486,7 +2464,7 @@ dependencies = [ name = "keygen" version = "0.1.0" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "clap", "libp2p-core", "libp2p-identity", @@ -2618,7 +2596,7 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.40.0" +version = "0.40.1" dependencies = [ "async-std", "either", @@ -2699,6 +2677,7 @@ version = "0.40.0" dependencies = [ "async-std", "async-std-resolver", + "async-trait", "env_logger 0.10.0", "futures", "libp2p-core", @@ -2735,7 +2714,7 @@ version = "0.45.1" dependencies = [ "async-std", "asynchronous-codec", - "base64 0.21.2", + "base64 0.21.3", "byteorder", "bytes", "either", @@ -2795,7 +2774,7 @@ name = "libp2p-identity" version = "0.2.3" dependencies = [ "asn1_der", - "base64 0.21.2", + "base64 0.21.3", "bs58", "criterion", "ed25519-dalek", @@ -3006,7 +2985,7 @@ dependencies = [ [[package]] name = "libp2p-ping" -version = "0.43.0" +version = "0.43.1" dependencies = [ "async-std", "either", @@ -3085,7 +3064,7 @@ dependencies = [ "quickcheck", "quinn", "rand 0.8.5", - "rustls 0.21.6", + "rustls 0.21.7", "socket2 0.5.3", "thiserror", "tokio", @@ -3176,9 +3155,9 @@ dependencies = [ [[package]] name = "libp2p-server" -version = "0.12.1" +version = "0.12.3" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "clap", "env_logger 0.10.0", "futures", @@ -3196,7 +3175,7 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.43.3" +version = "0.43.4" dependencies = [ "async-std", "either", @@ -3235,7 +3214,7 @@ dependencies = [ "proc-macro-warning", "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -3275,10 +3254,10 @@ dependencies = [ [[package]] name = "libp2p-tls" -version = "0.2.0" +version = "0.2.1" dependencies = [ "futures", - "futures-rustls 0.24.0", + "futures-rustls", "hex", "hex-literal", "libp2p-core", @@ -3287,10 +3266,10 @@ dependencies = [ "libp2p-yamux", "rcgen 0.10.0", "ring", - "rustls 0.21.6", + "rustls 0.21.7", + "rustls-webpki", "thiserror", "tokio", - "webpki 0.22.0", "x509-parser 0.15.1", "yasna", ] @@ -3359,12 +3338,12 @@ dependencies = [ [[package]] name = "libp2p-websocket" -version = "0.42.0" +version = "0.42.1" dependencies = [ "async-std", "either", "futures", - "futures-rustls 0.22.2", + "futures-rustls", "libp2p-core", "libp2p-dns", "libp2p-identity", @@ -3376,7 +3355,7 @@ dependencies = [ "rw-stream-sink", "soketto", "url", - "webpki-roots 0.25.2", + "webpki-roots", ] [[package]] @@ -3530,12 +3509,6 @@ dependencies = [ "regex-automata 0.1.10", ] -[[package]] -name = "matches" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" - [[package]] name = "matchit" version = "0.7.1" @@ -3553,9 +3526,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" [[package]] name = "memoffset" @@ -3672,9 +3645,9 @@ dependencies = [ [[package]] name = "multihash" -version = "0.19.0" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd59dcc2bbe70baabeac52cd22ae52c55eefe6c38ff11a9439f16a350a939f2" +checksum = "076d548d76a0e2a0d4ab471d0b1c36c577786dfc4471242035d97a12a735c492" dependencies = [ "arbitrary", "core2", @@ -3942,7 +3915,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -4088,7 +4061,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -4271,13 +4244,13 @@ dependencies = [ [[package]] name = "proc-macro-warning" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70550716265d1ec349c41f70dd4f964b4fd88394efe4405f0c1da679c4799a07" +checksum = "3d1eaa7fa0aa1929ffdf7eeb6eac234dde6268914a14ad44d23521ab6a9b258e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -4382,7 +4355,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls 0.21.6", + "rustls 0.21.7", "thiserror", "tokio", "tracing", @@ -4398,7 +4371,7 @@ dependencies = [ "rand 0.8.5", "ring", "rustc-hash", - "rustls 0.21.6", + "rustls 0.21.7", "slab", "thiserror", "tinyvec", @@ -4420,9 +4393,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -4547,9 +4520,9 @@ dependencies = [ [[package]] name = "redis" -version = "0.23.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffd6543a7bc6428396845f6854ccf3d1ae8823816592e2cbe74f20f50f209d02" +checksum = "4f49cdc0bb3f412bf8e7d1bd90fe1d9eb10bc5c399ba90973c14662a27b3f8ba" dependencies = [ "async-trait", "bytes", @@ -4575,14 +4548,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.3" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" +checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.6", - "regex-syntax 0.7.4", + "regex-automata 0.3.8", + "regex-syntax 0.7.5", ] [[package]] @@ -4596,13 +4569,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" +checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.4", + "regex-syntax 0.7.5", ] [[package]] @@ -4613,9 +4586,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "relay-server-example" @@ -4644,11 +4617,11 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.18" +version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "bytes", "encoding_rs", "futures-core", @@ -4676,7 +4649,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg 0.10.1", + "winreg", ] [[package]] @@ -4798,9 +4771,9 @@ dependencies = [ [[package]] name = "rust-embed" -version = "6.8.1" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a36224c3276f8c4ebc8c20f158eca7ca4359c8db89991c4925132aaaf6702661" +checksum = "b1e7d90385b59f0a6bf3d3b757f3ca4ece2048265d70db20a2016043d4509a40" dependencies = [ "rust-embed-impl", "rust-embed-utils", @@ -4809,22 +4782,22 @@ dependencies = [ [[package]] name = "rust-embed-impl" -version = "6.8.1" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b94b81e5b2c284684141a2fb9e2a31be90638caf040bf9afbc5a0416afe1ac" +checksum = "3c3d8c6fd84090ae348e63a84336b112b5c3918b3bf0493a581f7bd8ee623c29" dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.29", + "syn 2.0.31", "walkdir", ] [[package]] name = "rust-embed-utils" -version = "7.8.1" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d38ff6bf570dc3bb7100fce9f7b60c33fa71d80e88da3f2580df4ff2bdded74" +checksum = "873feff8cb7bf86fdf0a71bb21c95159f4e4a37dd7a4bd1855a940909b583ada" dependencies = [ "sha2 0.10.7", "walkdir", @@ -4914,9 +4887,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.6" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", "ring", @@ -4942,14 +4915,14 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", ] [[package]] name = "rustls-webpki" -version = "0.101.2" +version = "0.101.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "513722fd73ad80a71f72b61009ea1b584bcfa1483ca93949c8f290298837fa59" +checksum = "7d93931baf2d282fff8d3a532bbfd7653f734643161b87e3e01e59a04439bf0d" dependencies = [ "ring", "untrusted", @@ -5122,29 +5095,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.185" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be9b6f69f1dfd54c3b568ffa45c310d6973a5e5148fd40cf515acaf38cf5bc31" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.185" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc59dfdcbad1437773485e0367fea4b090a2e0a16d9ffc46af47764536a298ec" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] name = "serde_json" -version = "1.0.105" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" +checksum = "2cc66a619ed80bf7a0f6b17dd063a84b88f6dea1813737cf469aef1d081142c2" dependencies = [ "indexmap 2.0.0", "itoa", @@ -5170,7 +5143,7 @@ checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -5478,9 +5451,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.29" +version = "2.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398" dependencies = [ "proc-macro2", "quote", @@ -5507,9 +5480,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.29.8" +version = "0.29.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d10ed79c22663a35a255d289a7fdcb43559fc77ff15df5ce6c341809e7867528" +checksum = "0a18d114d420ada3a891e6bc8e96a2023402203296a47cdd65083377dad18ba5" dependencies = [ "cfg-if 1.0.0", "core-foundation-sys", @@ -5570,7 +5543,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf0fe180d5f1f7dd32bb5f1a8d19231bb63dc9bbb1985e1dbb6f07163b6a8578" dependencies = [ "async-trait", - "base64 0.21.2", + "base64 0.21.3", "cookie", "fantoccini", "futures", @@ -5603,22 +5576,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.44" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" +checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.44" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" +checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -5710,7 +5683,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -5734,6 +5707,16 @@ dependencies = [ "webpki 0.22.0", ] +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls 0.21.7", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.8" @@ -5767,9 +5750,9 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ae70283aba8d2a8b411c695c437fe25b8b5e44e23e780662002fc72fb47a82" +checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" dependencies = [ "bitflags 2.3.3", "bytes", @@ -5823,7 +5806,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] [[package]] @@ -5867,9 +5850,9 @@ dependencies = [ [[package]] name = "trust-dns-proto" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f7f83d1e4a0e4358ac54c5c3681e5d7da5efc5a7a632c90bb6d6669ddd9bc26" +checksum = "0dc775440033cb114085f6f2437682b194fa7546466024b1037e82a48a052a69" dependencies = [ "async-trait", "bytes", @@ -5881,45 +5864,46 @@ dependencies = [ "futures-util", "h2", "http", - "idna 0.2.3", + "idna", "ipnet", - "lazy_static", + "once_cell", "rand 0.8.5", - "rustls 0.20.8", + "rustls 0.21.7", "rustls-pemfile", + "rustls-webpki", "smallvec", - "socket2 0.4.9", + "socket2 0.5.3", "thiserror", "tinyvec", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tracing", "url", - "webpki 0.22.0", - "webpki-roots 0.22.6", + "webpki-roots", ] [[package]] name = "trust-dns-resolver" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aff21aa4dcefb0a1afbfac26deb0adc93888c7d295fb63ab273ef276ba2b7cfe" +checksum = "2dff7aed33ef3e8bf2c9966fccdfed93f93d46f432282ea875cd66faabc6ef2f" dependencies = [ "cfg-if 1.0.0", "futures-util", "ipconfig", - "lazy_static", "lru-cache", + "once_cell", "parking_lot", + "rand 0.8.5", "resolv-conf", - "rustls 0.20.8", + "rustls 0.21.7", "smallvec", "thiserror", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tracing", "trust-dns-proto", - "webpki-roots 0.22.6", + "webpki-roots", ] [[package]] @@ -5930,9 +5914,9 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "trybuild" -version = "1.0.83" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6df60d81823ed9c520ee897489573da4b1d79ffbe006b8134f46de1a1aa03555" +checksum = "a5c89fd17b7536f2cf66c97cff6e811e89e728ca0ed13caeed610c779360d8b4" dependencies = [ "basic-toml", "glob", @@ -6044,9 +6028,9 @@ dependencies = [ [[package]] name = "unsigned-varint" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86a8dc7f45e4c1b0d30e43038c38f274e77af056aa5f74b93c2cf9eb3c1c836" +checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" dependencies = [ "asynchronous-codec", "bytes", @@ -6060,12 +6044,12 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", - "idna 0.4.0", + "idna", "percent-encoding", ] @@ -6181,7 +6165,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", "wasm-bindgen-shared", ] @@ -6215,7 +6199,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -6310,15 +6294,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "webpki-roots" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" -dependencies = [ - "webpki 0.22.0", -] - [[package]] name = "webpki-roots" version = "0.25.2" @@ -6701,15 +6676,6 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - [[package]] name = "winreg" version = "0.50.0" @@ -6837,5 +6803,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.31", ] diff --git a/Cargo.toml b/Cargo.toml index 979365d1131..55258267fec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,10 +64,11 @@ resolver = "2" rust-version = "1.65.0" [workspace.dependencies] +libp2p = { version = "0.52.3", path = "libp2p" } libp2p-allow-block-list = { version = "0.2.0", path = "misc/allow-block-list" } libp2p-autonat = { version = "0.11.0", path = "protocols/autonat" } libp2p-connection-limits = { version = "0.2.1", path = "misc/connection-limits" } -libp2p-core = { version = "0.40.0", path = "core" } +libp2p-core = { version = "0.40.1", path = "core" } libp2p-dcutr = { version = "0.10.0", path = "protocols/dcutr" } libp2p-deflate = { version = "0.40.0", path = "transports/deflate" } libp2p-dns = { version = "0.40.0", path = "transports/dns" } @@ -83,23 +84,23 @@ libp2p-mplex = { version = "0.40.0", path = "muxers/mplex" } libp2p-muxer-test-harness = { path = "muxers/test-harness" } libp2p-noise = { version = "0.43.1", path = "transports/noise" } libp2p-perf = { version = "0.2.0", path = "protocols/perf" } -libp2p-ping = { version = "0.43.0", path = "protocols/ping" } +libp2p-ping = { version = "0.43.1", path = "protocols/ping" } libp2p-plaintext = { version = "0.40.0", path = "transports/plaintext" } libp2p-pnet = { version = "0.23.0", path = "transports/pnet" } libp2p-quic = { version = "0.9.2", path = "transports/quic" } libp2p-relay = { version = "0.16.1", path = "protocols/relay" } libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.25.1", path = "protocols/request-response" } -libp2p-server = { version = "0.12.1", path = "misc/server" } -libp2p-swarm = { version = "0.43.3", path = "swarm" } +libp2p-server = { version = "0.12.3", path = "misc/server" } +libp2p-swarm = { version = "0.43.4", path = "swarm" } libp2p-swarm-derive = { version = "0.33.0", path = "swarm-derive" } libp2p-swarm-test = { version = "0.2.0", path = "swarm-test" } libp2p-tcp = { version = "0.40.0", path = "transports/tcp" } -libp2p-tls = { version = "0.2.0", path = "transports/tls" } +libp2p-tls = { version = "0.2.1", path = "transports/tls" } libp2p-uds = { version = "0.39.0", path = "transports/uds" } libp2p-wasm-ext = { version = "0.40.0", path = "transports/wasm-ext" } libp2p-webrtc = { version = "0.6.0-alpha", path = "transports/webrtc" } -libp2p-websocket = { version = "0.42.0", path = "transports/websocket" } +libp2p-websocket = { version = "0.42.1", path = "transports/websocket" } libp2p-webtransport-websys = { version = "0.1.0", path = "transports/webtransport-websys" } libp2p-yamux = { version = "0.44.1", path = "muxers/yamux" } multistream-select = { version = "0.13.0", path = "misc/multistream-select" } @@ -107,7 +108,7 @@ quick-protobuf-codec = { version = "0.2.0", path = "misc/quick-protobuf-codec" } quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" } rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" } multiaddr = "0.18.0" -multihash = "0.19.0" +multihash = "0.19.1" [patch.crates-io] diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index ecc1eff2d7a..2d5c47a1633 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,4 +1,11 @@ -## 0.40.0 +## 0.40.1 - unreleased + +- Implement `Debug` for `StreamMuxerEvent`. + See [PR 4426]. + +[PR 4426]: https://github.com/libp2p/rust-libp2p/pull/4426 + +## 0.40.0 - Allow `ListenerId` to be user-controlled, i.e. to be provided on `Transport::listen_on`. See [PR 3567]. diff --git a/core/Cargo.toml b/core/Cargo.toml index e71c4d0f243..a3912f0f5e4 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-core" edition = "2021" rust-version = { workspace = true } description = "Core traits and structs of libp2p" -version = "0.40.0" +version = "0.40.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/core/src/muxing.rs b/core/src/muxing.rs index 13b826ba840..477e1608073 100644 --- a/core/src/muxing.rs +++ b/core/src/muxing.rs @@ -112,6 +112,7 @@ pub trait StreamMuxer { } /// An event produced by a [`StreamMuxer`]. +#[derive(Debug)] pub enum StreamMuxerEvent { /// The address of the remote has changed. AddressChange(Multiaddr), diff --git a/examples/dcutr/README.md b/examples/dcutr/README.md index 52ce991e4b9..5c7a9c38f82 100644 --- a/examples/dcutr/README.md +++ b/examples/dcutr/README.md @@ -18,12 +18,12 @@ To run the example, follow these steps: - Example usage in client-listen mode: ```sh - cargo run -- --mode listen --secret-key-seed 42 --relay-address /ip4/127.0.0.1/tcp/12345 + cargo run -- --mode listen --secret-key-seed 42 --relay-address /ip4/$RELAY_IP/tcp/$PORT/p2p/$RELAY_PEERID ``` - Example usage in client-dial mode: ```sh - cargo run -- --mode dial --secret-key-seed 42 --relay-address /ip4/127.0.0.1/tcp/12345 --remote-peer-id + cargo run -- --mode dial --secret-key-seed 42 --relay-address /ip4/$RELAY_IP/tcp/$PORT/p2p/$RELAY_PEERID --remote-peer-id ``` For this example to work, it is also necessary to turn on a relay server (you will find the related instructions in the example in the `examples/relay-server` folder). diff --git a/identity/Cargo.toml b/identity/Cargo.toml index ed74c5e9836..e5da8595ebf 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -17,7 +17,7 @@ bs58 = { version = "0.5.0", optional = true } ed25519-dalek = { version = "2.0", optional = true, features = ["rand_core"] } libsecp256k1 = { version = "0.7.0", optional = true } log = "0.4" -multihash = { version = "0.19.0", optional = true } +multihash = { version = "0.19.1", optional = true } p256 = { version = "0.13", default-features = false, features = ["ecdsa", "std", "pem"], optional = true } quick-protobuf = "0.8.1" rand = { version = "0.8", optional = true } @@ -40,7 +40,7 @@ peerid = [ "dep:multihash", "dep:bs58", "dep:rand", "dep:thiserror", "dep:sha2" [dev-dependencies] quickcheck = { workspace = true } -base64 = "0.21.2" +base64 = "0.21.3" serde_json = "1.0" rmp-serde = "1.1" criterion = "0.5" diff --git a/identity/src/ed25519.rs b/identity/src/ed25519.rs index 23d11932425..06708ce6371 100644 --- a/identity/src/ed25519.rs +++ b/identity/src/ed25519.rs @@ -128,7 +128,7 @@ impl hash::Hash for PublicKey { impl cmp::PartialOrd for PublicKey { fn partial_cmp(&self, other: &Self) -> Option { - self.0.as_bytes().partial_cmp(other.0.as_bytes()) + Some(self.cmp(other)) } } diff --git a/identity/src/error.rs b/identity/src/error.rs index 4580c4422a1..71cd78fe1ea 100644 --- a/identity/src/error.rs +++ b/identity/src/error.rs @@ -77,11 +77,7 @@ impl DecodingError { } } - #[cfg(any( - all(feature = "rsa", not(target_arch = "wasm32")), - feature = "secp256k1", - feature = "ecdsa" - ))] + #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] pub(crate) fn encoding_unsupported(key_type: &'static str) -> Self { Self { msg: format!("encoding {key_type} key to Protobuf is unsupported"), @@ -111,7 +107,7 @@ pub struct SigningError { /// An error during encoding of key material. impl SigningError { - #[cfg(any(feature = "secp256k1", feature = "rsa"))] + #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] pub(crate) fn new(msg: S) -> Self { Self { msg: msg.to_string(), @@ -119,7 +115,7 @@ impl SigningError { } } - #[cfg(feature = "rsa")] + #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] pub(crate) fn source(self, source: impl Error + Send + Sync + 'static) -> Self { Self { source: Some(Box::new(source)), diff --git a/identity/src/secp256k1.rs b/identity/src/secp256k1.rs index a32a64e7b37..94b9b917787 100644 --- a/identity/src/secp256k1.rs +++ b/identity/src/secp256k1.rs @@ -178,7 +178,7 @@ impl hash::Hash for PublicKey { impl cmp::PartialOrd for PublicKey { fn partial_cmp(&self, other: &Self) -> Option { - self.to_bytes().partial_cmp(&other.to_bytes()) + Some(self.cmp(other)) } } diff --git a/interop-tests/Cargo.toml b/interop-tests/Cargo.toml index fb12812c229..d3a2e00647f 100644 --- a/interop-tests/Cargo.toml +++ b/interop-tests/Cargo.toml @@ -23,8 +23,8 @@ libp2p = { path = "../libp2p", features = ["ping", "noise", "tls", "rsa", "macro libp2p-webrtc = { workspace = true, features = ["tokio"] } libp2p-mplex = { path = "../muxers/mplex" } mime_guess = "2.0" -redis = { version = "0.23.2", default-features = false, features = ["tokio-comp"] } -rust-embed = "6.8" +redis = { version = "0.23.3", default-features = false, features = ["tokio-comp"] } +rust-embed = "8.0" serde_json = "1" thirtyfour = "=0.32.0-rc.8" # https://github.com/stevepryde/thirtyfour/issues/169 tokio = { version = "1.32.0", features = ["full"] } diff --git a/interop-tests/Dockerfile.chromium b/interop-tests/Dockerfile.chromium index ebe66850197..61ebb0424e6 100644 --- a/interop-tests/Dockerfile.chromium +++ b/interop-tests/Dockerfile.chromium @@ -23,7 +23,7 @@ RUN --mount=type=cache,target=./target \ RUN --mount=type=cache,target=./target \ mv ./target/release/wasm_ping /usr/local/bin/testplan -FROM selenium/standalone-chrome:112.0 +FROM selenium/standalone-chrome:115.0 COPY --from=builder /usr/local/bin/testplan /usr/local/bin/testplan ENV RUST_BACKTRACE=1 diff --git a/interop-tests/src/bin/wasm_ping.rs b/interop-tests/src/bin/wasm_ping.rs index 20350170d59..83ed3c37465 100644 --- a/interop-tests/src/bin/wasm_ping.rs +++ b/interop-tests/src/bin/wasm_ping.rs @@ -103,7 +103,12 @@ async fn open_in_browser() -> Result<(Child, WebDriver)> { // start a webdriver process // currently only the chromedriver is supported as firefox doesn't // have support yet for the certhashes - let mut chrome = tokio::process::Command::new("chromedriver") + let chromedriver = if cfg!(windows) { + "chromedriver.cmd" + } else { + "chromedriver" + }; + let mut chrome = tokio::process::Command::new(chromedriver) .arg("--port=45782") .stdout(Stdio::piped()) .spawn()?; diff --git a/libp2p/CHANGELOG.md b/libp2p/CHANGELOG.md index 642d4103729..414c11058cb 100644 --- a/libp2p/CHANGELOG.md +++ b/libp2p/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.52.3 - unreleased +## 0.52.3 - Add `libp2p-quic` stable release. diff --git a/libp2p/src/tutorials/hole_punching.rs b/libp2p/src/tutorials/hole_punching.rs index 161a2feeec4..c184274bbb0 100644 --- a/libp2p/src/tutorials/hole_punching.rs +++ b/libp2p/src/tutorials/hole_punching.rs @@ -54,16 +54,16 @@ //! //! ``` bash //! ## Inside the rust-libp2p repository. -//! cargo build --example relay_v2 -p libp2p-relay +//! cargo build --bin relay-server-example //! ``` //! -//! You can find the binary at `target/debug/examples/relay_v2`. In case you built it locally, copy +//! You can find the binary at `target/debug/relay-server-example`. In case you built it locally, copy //! it to your server. //! //! On your server, start the relay server binary: //! //! ``` bash -//! ./relay_v2 --port 4001 --secret-key-seed 0 +//! ./relay-server-example --port 4001 --secret-key-seed 0 //! ``` //! //! Now let's make sure that the server is public, in other words let's make sure one can reach it @@ -122,16 +122,16 @@ //! //! ``` bash //! ## Inside the rust-libp2p repository. -//! cargo build --example client -p libp2p-dcutr +//! cargo build --bin dcutr //! ``` //! -//! You can find the binary at `target/debug/examples/client`. In case you built it locally, copy +//! You can find the binary at `target/debug/dcutr`. In case you built it locally, copy //! it to your listening client machine. //! //! On the listening client machine: //! //! ``` bash -//! RUST_LOG=info ./client --secret-key-seed 1 --mode listen --relay-address /ip4/$RELAY_SERVER_IP/tcp/4001/p2p/12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN +//! RUST_LOG=info ./dcutr --secret-key-seed 1 --mode listen --relay-address /ip4/$RELAY_SERVER_IP/tcp/4001/p2p/12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN //! //! [2022-05-11T10:38:52Z INFO client] Local peer id: PeerId("XXX") //! [2022-05-11T10:38:52Z INFO client] Listening on "/ip4/127.0.0.1/tcp/44703" @@ -153,7 +153,7 @@ //! ## Connecting to the listening client from the dialing client //! //! ``` bash -//! RUST_LOG=info ./client --secret-key-seed 2 --mode dial --relay-address /ip4/$RELAY_SERVER_IP/tcp/4001/p2p/12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN --remote-peer-id 12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X +//! RUST_LOG=info ./dcutr --secret-key-seed 2 --mode dial --relay-address /ip4/$RELAY_SERVER_IP/tcp/4001/p2p/12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN --remote-peer-id 12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X //! ``` //! //! You should see the following logs appear: diff --git a/misc/allow-block-list/src/lib.rs b/misc/allow-block-list/src/lib.rs index eed79d740a1..516e2ee0d07 100644 --- a/misc/allow-block-list/src/lib.rs +++ b/misc/allow-block-list/src/lib.rs @@ -233,19 +233,20 @@ where fn on_swarm_event(&mut self, event: FromSwarm) { match event { - FromSwarm::ConnectionClosed(_) => {} - FromSwarm::ConnectionEstablished(_) => {} - FromSwarm::AddressChange(_) => {} - FromSwarm::DialFailure(_) => {} - FromSwarm::ListenFailure(_) => {} - FromSwarm::NewListener(_) => {} - FromSwarm::NewListenAddr(_) => {} - FromSwarm::ExpiredListenAddr(_) => {} - FromSwarm::ListenerError(_) => {} - FromSwarm::ListenerClosed(_) => {} - FromSwarm::NewExternalAddrCandidate(_) => {} - FromSwarm::ExternalAddrExpired(_) => {} - FromSwarm::ExternalAddrConfirmed(_) => {} + FromSwarm::ConnectionClosed(_) + | FromSwarm::ConnectionEstablished(_) + | FromSwarm::AddressChange(_) + | FromSwarm::DialFailure(_) + | FromSwarm::ListenFailure(_) + | FromSwarm::NewListener(_) + | FromSwarm::NewListenAddr(_) + | FromSwarm::ExpiredListenAddr(_) + | FromSwarm::ListenerError(_) + | FromSwarm::ListenerClosed(_) + | FromSwarm::NewExternalAddrCandidate(_) + | FromSwarm::ExternalAddrExpired(_) + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index e4723dd95c6..f7860b60071 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -344,14 +344,15 @@ impl NetworkBehaviour for Behaviour { FromSwarm::ListenFailure(ListenFailure { connection_id, .. }) => { self.pending_inbound_connections.remove(&connection_id); } - FromSwarm::NewListener(_) => {} - FromSwarm::NewListenAddr(_) => {} - FromSwarm::ExpiredListenAddr(_) => {} - FromSwarm::ListenerError(_) => {} - FromSwarm::ListenerClosed(_) => {} - FromSwarm::NewExternalAddrCandidate(_) => {} - FromSwarm::ExternalAddrExpired(_) => {} - FromSwarm::ExternalAddrConfirmed(_) => {} + FromSwarm::NewListener(_) + | FromSwarm::NewListenAddr(_) + | FromSwarm::ExpiredListenAddr(_) + | FromSwarm::ListenerError(_) + | FromSwarm::ListenerClosed(_) + | FromSwarm::NewExternalAddrCandidate(_) + | FromSwarm::ExternalAddrExpired(_) + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index ec898dbae3f..a24a7fa83a8 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -12,8 +12,8 @@ publish = false [dependencies] clap = { version = "4.3.23", features = ["derive"] } zeroize = "1" -serde = { version = "1.0.185", features = ["derive"] } -serde_json = "1.0.105" +serde = { version = "1.0.188", features = ["derive"] } +serde_json = "1.0.106" libp2p-core = { workspace = true } -base64 = "0.21.2" +base64 = "0.21.3" libp2p-identity = { workspace = true } diff --git a/misc/server/CHANGELOG.md b/misc/server/CHANGELOG.md index f419bb7cebd..d7c8f71d033 100644 --- a/misc/server/CHANGELOG.md +++ b/misc/server/CHANGELOG.md @@ -4,8 +4,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [0.12.1] - unreleased +## [0.12.3] - unreleased +### Changed +- Add libp2p-lookup to Dockerfile to enable healthchecks. + +## [0.12.2] +### Fixed +- Adhere to `--metrics-path` flag and listen on `0.0.0.0:8888` (default IPFS metrics port). + [PR 4392] + +[PR 4392]: https://github.com/libp2p/rust-libp2p/pull/4392 +## [0.12.1] ### Changed - Move to tokio and hyper. See [PR 4311]. diff --git a/misc/server/Cargo.toml b/misc/server/Cargo.toml index baf5fbab13c..aa259ce8214 100644 --- a/misc/server/Cargo.toml +++ b/misc/server/Cargo.toml @@ -1,8 +1,9 @@ [package] name = "libp2p-server" -version = "0.12.1" +version = "0.12.3" authors = ["Max Inden "] edition = "2021" +repository = "https://github.com/libp2p/rust-libp2p" rust-version = { workspace = true } description = "A rust-libp2p server binary." license = "MIT" @@ -16,10 +17,10 @@ env_logger = "0.10.0" futures = "0.3" futures-timer = "3" hyper = { version = "0.14", features = ["server", "tcp", "http1"] } -libp2p = { path = "../../libp2p", features = ["autonat", "dns", "tokio", "noise", "tcp", "yamux", "identify", "kad", "ping", "relay", "metrics", "rsa", "macros", "quic"] } +libp2p = { workspace = true, features = ["autonat", "dns", "tokio", "noise", "tcp", "yamux", "identify", "kad", "ping", "relay", "metrics", "rsa", "macros", "quic"] } log = "0.4" prometheus-client = "0.21.2" -serde = "1.0.183" +serde = "1.0.188" serde_derive = "1.0.125" serde_json = "1.0" tokio = { version = "1", features = ["rt-multi-thread", "macros"] } diff --git a/misc/server/Dockerfile b/misc/server/Dockerfile index 34f0c7d0bf9..72641cc3b2e 100644 --- a/misc/server/Dockerfile +++ b/misc/server/Dockerfile @@ -1,8 +1,12 @@ -FROM rust:1.66-bullseye as builder +FROM rust:1.72-bullseye as builder WORKDIR /usr/src/rust-libp2p-server # Run with access to the target cache to speed up builds WORKDIR /workspace + +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + cargo install --locked --root /usr/local libp2p-lookup --version 0.6.4 + ADD . . RUN --mount=type=cache,target=./target \ --mount=type=cache,target=/usr/local/cargo/registry \ @@ -12,5 +16,5 @@ RUN --mount=type=cache,target=./target \ mv ./target/release/libp2p-server /usr/local/bin/libp2p-server FROM gcr.io/distroless/cc -COPY --from=builder /usr/local/bin/libp2p-server /usr/local/bin/libp2p-server +COPY --from=builder /usr/local/bin/libp2p-server /usr/local/bin/libp2p-lookup /usr/local/bin/ CMD ["libp2p-server"] diff --git a/misc/server/README.md b/misc/server/README.md index ec4012562a2..0da1bd8abd9 100644 --- a/misc/server/README.md +++ b/misc/server/README.md @@ -33,3 +33,9 @@ Local peer id: PeerId("12D3KooWSa1YEeQVSwvoqAMhwjKQ6kqZQckhWPb3RWEGV3sZGU6Z") Listening on "/ip4/127.0.0.1/udp/4001/quic" [...] ``` + +The Docker container includes [libp2-lookup](https://github.com/mxinden/libp2p-lookup/) to enable adding a proper healthcheck for container startup, e.g. + +``` shell +docker run --health-cmd 'libp2p-lookup direct --address /ip4/127.0.0.1/tcp/4001/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa' /home/ipfs/.ipfs:/ipfs ghcr.io/libp2p/rust-libp2p-server --config /ipfs/config +``` diff --git a/misc/server/src/http_service.rs b/misc/server/src/http_service.rs index 46cb7aacb84..8b5779f3cef 100644 --- a/misc/server/src/http_service.rs +++ b/misc/server/src/http_service.rs @@ -31,15 +31,23 @@ use std::task::{Context, Poll}; const METRICS_CONTENT_TYPE: &str = "application/openmetrics-text;charset=utf-8;version=1.0.0"; -pub(crate) async fn metrics_server(registry: Registry) -> Result<(), std::io::Error> { +pub(crate) async fn metrics_server( + registry: Registry, + metrics_path: String, +) -> Result<(), std::io::Error> { // Serve on localhost. - let addr = ([127, 0, 0, 1], 8080).into(); + let addr = ([0, 0, 0, 0], 8888).into(); // Use the tokio runtime to run the hyper server. let rt = tokio::runtime::Runtime::new()?; rt.block_on(async { - let server = Server::bind(&addr).serve(MakeMetricService::new(registry)); - info!("Metrics server on http://{}/metrics", server.local_addr()); + let server = + Server::bind(&addr).serve(MakeMetricService::new(registry, metrics_path.clone())); + info!( + "Metrics server on http://{}{}", + server.local_addr(), + metrics_path + ); if let Err(e) = server.await { error!("server error: {}", e); } @@ -49,6 +57,7 @@ pub(crate) async fn metrics_server(registry: Registry) -> Result<(), std::io::Er pub(crate) struct MetricService { reg: Arc>, + metrics_path: String, } type SharedRegistry = Arc>; @@ -75,7 +84,10 @@ impl MetricService { fn respond_with_404_not_found(&mut self) -> Response { Response::builder() .status(StatusCode::NOT_FOUND) - .body("Not found try localhost:[port]/metrics".to_string()) + .body(format!( + "Not found try localhost:[port]/{}", + self.metrics_path + )) .unwrap() } } @@ -92,7 +104,7 @@ impl Service> for MetricService { fn call(&mut self, req: Request) -> Self::Future { let req_path = req.uri().path(); let req_method = req.method(); - let resp = if (req_method == Method::GET) && (req_path == "/metrics") { + let resp = if (req_method == Method::GET) && (req_path == self.metrics_path) { // Encode and serve metrics from registry. self.respond_with_metrics() } else { @@ -104,12 +116,14 @@ impl Service> for MetricService { pub(crate) struct MakeMetricService { reg: SharedRegistry, + metrics_path: String, } impl MakeMetricService { - pub(crate) fn new(registry: Registry) -> MakeMetricService { + pub(crate) fn new(registry: Registry, metrics_path: String) -> MakeMetricService { MakeMetricService { reg: Arc::new(Mutex::new(registry)), + metrics_path, } } } @@ -125,7 +139,8 @@ impl Service for MakeMetricService { fn call(&mut self, _: T) -> Self::Future { let reg = self.reg.clone(); - let fut = async move { Ok(MetricService { reg }) }; + let metrics_path = self.metrics_path.clone(); + let fut = async move { Ok(MetricService { reg, metrics_path }) }; Box::pin(fut) } } diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index c2dff1f9228..67abb5b2549 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -18,7 +18,7 @@ use libp2p::swarm::{SwarmBuilder, SwarmEvent}; use libp2p::tcp; use libp2p::yamux; use libp2p::Transport; -use log::{debug, info}; +use log::{debug, info, warn}; use prometheus_client::metrics::info::Info; use prometheus_client::registry::Registry; use std::error::Error; @@ -79,7 +79,7 @@ async fn main() -> Result<(), Box> { (peer_id, keypair) }; - println!("Local peer id: {local_peer_id}"); + info!("Local peer id: {local_peer_id}"); let transport = { let tcp_transport = @@ -115,24 +115,24 @@ async fn main() -> Result<(), Box> { let mut swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build(); if config.addresses.swarm.is_empty() { - log::warn!("No listen addresses configured."); + warn!("No listen addresses configured."); } for address in &config.addresses.swarm { match swarm.listen_on(address.clone()) { Ok(_) => {} Err(e @ libp2p::TransportError::MultiaddrNotSupported(_)) => { - log::warn!("Failed to listen on {address}, continuing anyways, {e}") + warn!("Failed to listen on {address}, continuing anyways, {e}") } Err(e) => return Err(e.into()), } } if config.addresses.append_announce.is_empty() { - log::warn!("No external addresses configured."); + warn!("No external addresses configured."); } for address in &config.addresses.append_announce { swarm.add_external_address(address.clone()) } - log::info!( + info!( "External addresses: {:?}", swarm.external_addresses().collect::>() ); @@ -145,7 +145,12 @@ async fn main() -> Result<(), Box> { "A metric with a constant '1' value labeled by version", build_info, ); - thread::spawn(move || block_on(http_service::metrics_server(metric_registry))); + thread::spawn(move || { + block_on(http_service::metrics_server( + metric_registry, + opt.metrics_path, + )) + }); let mut bootstrap_timer = Delay::new(BOOTSTRAP_INTERVAL); @@ -205,7 +210,7 @@ async fn main() -> Result<(), Box> { // metrics.record(&e) } SwarmEvent::NewListenAddr { address, .. } => { - println!("Listening on {address:?}"); + info!("Listening on {address:?}"); } _ => {} } diff --git a/muxers/mplex/src/io.rs b/muxers/mplex/src/io.rs index 85b58820823..8002ad383d6 100644 --- a/muxers/mplex/src/io.rs +++ b/muxers/mplex/src/io.rs @@ -143,7 +143,7 @@ where } /// Flushes the underlying I/O stream. - pub(crate) fn poll_flush(&mut self, cx: &mut Context<'_>) -> Poll> { + pub(crate) fn poll_flush(&mut self, cx: &Context<'_>) -> Poll> { match &self.status { Status::Closed => return Poll::Ready(Ok(())), Status::Err(e) => return Poll::Ready(Err(io::Error::new(e.kind(), e.to_string()))), @@ -169,7 +169,7 @@ where /// > **Note**: No `Close` or `Reset` frames are sent on open substreams /// > before closing the underlying connection. However, the connection /// > close implies a flush of any frames already sent. - pub(crate) fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll> { + pub(crate) fn poll_close(&mut self, cx: &Context<'_>) -> Poll> { match &self.status { Status::Closed => return Poll::Ready(Ok(())), Status::Err(e) => return Poll::Ready(Err(io::Error::new(e.kind(), e.to_string()))), @@ -208,10 +208,7 @@ where /// [`MaxBufferBehaviour::Block`] is used, this method is blocked /// (i.e. `Pending`) on some task reading from the substream whose /// buffer is full. - pub(crate) fn poll_next_stream( - &mut self, - cx: &mut Context<'_>, - ) -> Poll> { + pub(crate) fn poll_next_stream(&mut self, cx: &Context<'_>) -> Poll> { self.guard_open()?; // Try to read from the buffer first. @@ -252,10 +249,7 @@ where } /// Creates a new (outbound) substream, returning the allocated stream ID. - pub(crate) fn poll_open_stream( - &mut self, - cx: &mut Context<'_>, - ) -> Poll> { + pub(crate) fn poll_open_stream(&mut self, cx: &Context<'_>) -> Poll> { self.guard_open()?; // Check the stream limits. @@ -374,7 +368,7 @@ where /// Writes data to a substream. pub(crate) fn poll_write_stream( &mut self, - cx: &mut Context<'_>, + cx: &Context<'_>, id: LocalStreamId, buf: &[u8], ) -> Poll> { @@ -424,7 +418,7 @@ where /// Inbound substreams received in excess of that limit are immediately reset. pub(crate) fn poll_read_stream( &mut self, - cx: &mut Context<'_>, + cx: &Context<'_>, id: LocalStreamId, ) -> Poll>> { self.guard_open()?; @@ -516,7 +510,7 @@ where /// > the underlying I/O stream is already closed. pub(crate) fn poll_flush_stream( &mut self, - cx: &mut Context<'_>, + cx: &Context<'_>, id: LocalStreamId, ) -> Poll> { self.guard_open()?; @@ -532,7 +526,7 @@ where /// > **Note**: As opposed to `poll_close()`, a flush it not implied. pub(crate) fn poll_close_stream( &mut self, - cx: &mut Context<'_>, + cx: &Context<'_>, id: LocalStreamId, ) -> Poll> { self.guard_open()?; @@ -587,7 +581,7 @@ where /// /// The frame is only constructed if the underlying sink is ready to /// send another frame. - fn poll_send_frame(&mut self, cx: &mut Context<'_>, frame: F) -> Poll> + fn poll_send_frame(&mut self, cx: &Context<'_>, frame: F) -> Poll> where F: FnOnce() -> Frame, { @@ -613,7 +607,7 @@ where /// frames for any substream. fn poll_read_frame( &mut self, - cx: &mut Context<'_>, + cx: &Context<'_>, stream_id: Option, ) -> Poll>> { // Try to send pending frames, if there are any, without blocking, @@ -822,7 +816,7 @@ where } /// Sends pending frames, without flushing. - fn send_pending_frames(&mut self, cx: &mut Context<'_>) -> Poll> { + fn send_pending_frames(&mut self, cx: &Context<'_>) -> Poll> { while let Some(frame) = self.pending_frames.pop_back() { if self.poll_send_frame(cx, || frame.clone())?.is_pending() { self.pending_frames.push_back(frame); diff --git a/protocols/autonat/src/behaviour.rs b/protocols/autonat/src/behaviour.rs index 439543f8318..0eba2d43418 100644 --- a/protocols/autonat/src/behaviour.rs +++ b/protocols/autonat/src/behaviour.rs @@ -37,7 +37,7 @@ use libp2p_request_response::{ use libp2p_swarm::{ behaviour::{ AddressChange, ConnectionClosed, ConnectionEstablished, DialFailure, ExpiredListenAddr, - ExternalAddrExpired, FromSwarm, + ExternalAddrExpired, FromSwarm, NewExternalAddrOfPeer, }, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, NewExternalAddrCandidate, PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, @@ -589,6 +589,12 @@ impl NetworkBehaviour for Behaviour { self.inner.on_swarm_event(listener_closed) } confirmed @ FromSwarm::ExternalAddrConfirmed(_) => self.inner.on_swarm_event(confirmed), + FromSwarm::NewExternalAddrOfPeer(NewExternalAddrOfPeer { + addr: _addr, + peer_id: _peer_id, + }) => { + todo!(); + } } } diff --git a/protocols/dcutr/src/behaviour_impl.rs b/protocols/dcutr/src/behaviour_impl.rs index 4993da655d3..5b2e813df06 100644 --- a/protocols/dcutr/src/behaviour_impl.rs +++ b/protocols/dcutr/src/behaviour_impl.rs @@ -375,7 +375,8 @@ impl NetworkBehaviour for Behaviour { | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } } diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index d79ae5bc719..8dd3c80d95e 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -23,7 +23,7 @@ quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } rand = "0.8" smallvec = "1.11.0" -thiserror = "1.0.44" +thiserror = "1.0.48" # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index 29fe8ba250f..a4874d8a259 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -496,7 +496,8 @@ impl NetworkBehaviour for Floodsub { | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } } diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index acbab0c82e9..813924ecc81 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -15,9 +15,9 @@ wasm-bindgen = ["getrandom/js", "instant/wasm-bindgen"] [dependencies] asynchronous-codec = "0.6" -base64 = "0.21.2" +base64 = "0.21.3" byteorder = "1.3.4" -bytes = "1.4" +bytes = "1.5" either = "1.9" fnv = "1.0.7" futures = "0.3.28" @@ -32,11 +32,11 @@ log = "0.4.20" quick-protobuf = "0.8" quick-protobuf-codec = { workspace = true } rand = "0.8" -regex = "1.9.3" +regex = "1.9.5" serde = { version = "1", optional = true, features = ["derive"] } sha2 = "0.10.7" smallvec = "1.11.0" -unsigned-varint = { version = "0.7.0", features = ["asynchronous_codec"] } +unsigned-varint = { version = "0.7.2", features = ["asynchronous_codec"] } void = "1.0.2" # Metrics dependencies diff --git a/protocols/gossipsub/src/backoff.rs b/protocols/gossipsub/src/backoff.rs index 3021e841eae..b4a40b91a74 100644 --- a/protocols/gossipsub/src/backoff.rs +++ b/protocols/gossipsub/src/backoff.rs @@ -86,12 +86,7 @@ impl BackoffStorage { backoffs_by_heartbeat[index].insert(pair); HeartbeatIndex(index) }; - match self - .backoffs - .entry(topic.clone()) - .or_insert_with(HashMap::new) - .entry(*peer) - { + match self.backoffs.entry(topic.clone()).or_default().entry(*peer) { Entry::Occupied(mut o) => { let (backoff, index) = o.get(); if backoff < &instant { diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 7ca9f6df9da..98981acf992 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -1020,10 +1020,7 @@ where "JOIN: Inserting {:?} random peers into the mesh", new_peers.len() ); - let mesh_peers = self - .mesh - .entry(topic_hash.clone()) - .or_insert_with(Default::default); + let mesh_peers = self.mesh.entry(topic_hash.clone()).or_default(); mesh_peers.extend(new_peers); } @@ -1962,10 +1959,7 @@ where for subscription in filtered_topics { // get the peers from the mapping, or insert empty lists if the topic doesn't exist let topic_hash = &subscription.topic_hash; - let peer_list = self - .topic_peers - .entry(topic_hash.clone()) - .or_insert_with(Default::default); + let peer_list = self.topic_peers.entry(topic_hash.clone()).or_default(); match subscription.action { SubscriptionAction::Subscribe => { @@ -2874,10 +2868,7 @@ where peer: PeerId, control: ControlAction, ) { - control_pool - .entry(peer) - .or_insert_with(Vec::new) - .push(control); + control_pool.entry(peer).or_default().push(control); } /// Takes each control action mapping and turns it into a message @@ -3507,7 +3498,8 @@ where | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } } diff --git a/protocols/gossipsub/src/gossip_promises.rs b/protocols/gossipsub/src/gossip_promises.rs index e1418032903..827206afe8d 100644 --- a/protocols/gossipsub/src/gossip_promises.rs +++ b/protocols/gossipsub/src/gossip_promises.rs @@ -48,7 +48,7 @@ impl GossipPromises { // If a promise for this message id and peer already exists we don't update the expiry! self.promises .entry(message_id.clone()) - .or_insert_with(HashMap::new) + .or_default() .entry(peer) .or_insert(expires); } diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index ab92d536aba..c6c918d6b2a 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -454,10 +454,7 @@ impl PeerScore { // Insert the ip peer_stats.known_ips.insert(ip); - self.peer_ips - .entry(ip) - .or_insert_with(HashSet::new) - .insert(*peer_id); + self.peer_ips.entry(ip).or_default().insert(*peer_id); } /// Removes an ip from a peer @@ -570,9 +567,7 @@ impl PeerScore { topic_hash: &TopicHash, ) { // adds an empty record with the message id - self.deliveries - .entry(msg_id.clone()) - .or_insert_with(DeliveryRecord::default); + self.deliveries.entry(msg_id.clone()).or_default(); if let Some(callback) = self.message_delivery_time_callback { if self @@ -595,10 +590,7 @@ impl PeerScore { ) { self.mark_first_message_delivery(from, topic_hash); - let record = self - .deliveries - .entry(msg_id.clone()) - .or_insert_with(DeliveryRecord::default); + let record = self.deliveries.entry(msg_id.clone()).or_default(); // this should be the first delivery trace if record.status != DeliveryStatus::Unknown { @@ -649,10 +641,7 @@ impl PeerScore { } let peers: Vec<_> = { - let record = self - .deliveries - .entry(msg_id.clone()) - .or_insert_with(DeliveryRecord::default); + let record = self.deliveries.entry(msg_id.clone()).or_default(); // Multiple peers can now reject the same message as we track which peers send us the // message. If we have already updated the status, return. @@ -686,10 +675,7 @@ impl PeerScore { msg_id: &MessageId, topic_hash: &TopicHash, ) { - let record = self - .deliveries - .entry(msg_id.clone()) - .or_insert_with(DeliveryRecord::default); + let record = self.deliveries.entry(msg_id.clone()).or_default(); if record.peers.get(from).is_some() { // we have already seen this duplicate! diff --git a/protocols/gossipsub/src/time_cache.rs b/protocols/gossipsub/src/time_cache.rs index ed0956caa60..ffc95a474f4 100644 --- a/protocols/gossipsub/src/time_cache.rs +++ b/protocols/gossipsub/src/time_cache.rs @@ -99,6 +99,15 @@ where Entry::Vacant(entry) => entry.insert(default()), } } + pub(crate) fn or_default(self) -> &'a mut V + where + V: Default, + { + match self { + Entry::Occupied(entry) => entry.into_mut(), + Entry::Vacant(entry) => entry.insert(V::default()), + } + } } impl TimeCache diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index f572b937d38..2d03ac2fcc1 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -395,6 +395,7 @@ impl NetworkBehaviour for Behaviour { } } } + FromSwarm::NewExternalAddrOfPeer(_addr) => todo!(), FromSwarm::NewListenAddr(_) | FromSwarm::ExpiredListenAddr(_) | FromSwarm::AddressChange(_) diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 340fefb276a..90142f52cf6 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -44,8 +44,8 @@ use libp2p_swarm::behaviour::{ use libp2p_swarm::{ dial_opts::{self, DialOpts}, ConnectionDenied, ConnectionId, DialError, ExternalAddresses, ListenAddresses, - NetworkBehaviour, NotifyHandler, PollParameters, StreamProtocol, THandler, THandlerInEvent, - THandlerOutEvent, ToSwarm, + NetworkBehaviour, NewExternalAddrOfPeer, NotifyHandler, PollParameters, StreamProtocol, + THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use log::{debug, info, warn}; use smallvec::SmallVec; @@ -1993,6 +1993,38 @@ where } } + fn on_new_address_event( + &mut self, + NewExternalAddrOfPeer { addr, peer_id }: NewExternalAddrOfPeer, + ) { + let key = kbucket::Key::from(peer_id.clone()); + + match self.kbuckets.entry(&key) { + kbucket::Entry::Present(mut entry, _node_status) => { + if entry.value().insert(addr.clone()) { + self.queued_events.push_back(ToSwarm::GenerateEvent( + KademliaEvent::RoutingUpdated { + peer: *peer_id, + is_new_peer: false, + addresses: entry.value().clone(), + old_peer: None, + bucket_range: self + .kbuckets + .bucket(&key) + .map(|b| b.range()) + .expect("Not kbucket::Entry::SelfEntry."), + }, + )) + } + } + kbucket::Entry::Pending(mut entry, _node_status) => { + entry.value().insert(addr.clone()); + () + } + kbucket::Entry::Absent(_) | kbucket::Entry::SelfEntry => {} + } + } + fn on_dial_failure(&mut self, DialFailure { peer_id, error, .. }: DialFailure) { let peer_id = match peer_id { Some(id) => id, @@ -2551,6 +2583,7 @@ where } FromSwarm::DialFailure(dial_failure) => self.on_dial_failure(dial_failure), FromSwarm::AddressChange(address_change) => self.on_address_change(address_change), + FromSwarm::NewExternalAddrOfPeer(addr) => self.on_new_address_event(addr), FromSwarm::ExpiredListenAddr(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::NewListenAddr(_) diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index cd4337e9094..ade1bc8ddf7 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -1378,6 +1378,89 @@ fn network_behaviour_on_address_change() { ); } +#[test] +fn network_behaviour_on_new_external_address_of_peer_for_present_entry() { + let local_peer_id = PeerId::random(); + + let remote_peer_id = PeerId::random(); + let connection_id = ConnectionId::new_unchecked(0); + let address: Multiaddr = Protocol::Memory(1).into(); + let discovered_address: Multiaddr = Protocol::Memory(2).into(); + + let mut kademlia = Kademlia::new(local_peer_id, MemoryStore::new(local_peer_id)); + + let endpoint = ConnectedPoint::Dialer { + address: address.clone(), + role_override: Endpoint::Dialer, + }; + + // Mimick a connection being established. + kademlia.on_swarm_event(FromSwarm::ConnectionEstablished(ConnectionEstablished { + peer_id: remote_peer_id, + connection_id, + endpoint: &endpoint, + failed_addresses: &[], + other_established: 0, + })); + + // At this point the remote is not yet known to support the + // configured protocol name, so the peer is not yet in the + // local routing table and hence no addresses are known. + assert!(kademlia + .handle_pending_outbound_connection( + connection_id, + Some(remote_peer_id), + &[], + Endpoint::Dialer + ) + .unwrap() + .is_empty()); + + // Mimick the connection handler confirming the protocol for + // the test connection, so that the peer is added to the routing table. + kademlia.on_connection_handler_event( + remote_peer_id, + connection_id, + KademliaHandlerEvent::ProtocolConfirmed { endpoint }, + ); + + let key = kbucket::Key::from(remote_peer_id); + + assert!(matches!( + kademlia.kbuckets.entry(&key), + kbucket::Entry::Present(_, _) + )); + + assert_eq!( + vec![address.clone()], + kademlia + .handle_pending_outbound_connection( + connection_id, + Some(remote_peer_id), + &[], + Endpoint::Dialer + ) + .unwrap(), + ); + + kademlia.on_new_address_event(NewExternalAddrOfPeer { + addr: &discovered_address, + peer_id: &remote_peer_id, + }); + + assert_eq!( + vec![address, discovered_address], + kademlia + .handle_pending_outbound_connection( + connection_id, + Some(remote_peer_id), + &[], + Endpoint::Dialer + ) + .unwrap(), + ); +} + #[test] fn get_providers_single() { fn prop(key: record_priv::Key) { diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 41f5d9af428..01a30741914 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -23,7 +23,7 @@ rand = "0.8.3" smallvec = "1.11.0" socket2 = { version = "0.5.3", features = ["all"] } tokio = { version = "1.32", default-features = false, features = ["net", "time"], optional = true} -trust-dns-proto = { version = "0.22.0", default-features = false, features = ["mdns", "tokio-runtime"] } +trust-dns-proto = { version = "0.23.0", default-features = false, features = ["mdns"] } void = "1.0.2" [features] diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index bc102f832df..d8ea2541f94 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -245,7 +245,8 @@ where | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } diff --git a/protocols/perf/src/client.rs b/protocols/perf/src/client.rs index 93c2086a49e..49d3e273cac 100644 --- a/protocols/perf/src/client.rs +++ b/protocols/perf/src/client.rs @@ -181,7 +181,8 @@ impl NetworkBehaviour for Behaviour { | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrConfirmed(_) - | FromSwarm::ExternalAddrExpired(_) => {} + | FromSwarm::ExternalAddrExpired(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} }; self.request_response.on_swarm_event(event); diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index fd0c0824ef0..7b46cdc3626 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.43.1 - unreleased + +- Honor ping interval in case of errors. + Previously, we would immediately open another ping stream if the current one failed. + See [PR 4423]. + +[PR 4423]: https://github.com/libp2p/rust-libp2p/pull/4423 + ## 0.43.0 - Raise MSRV to 1.65. diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index f66222efff7..29cf5985b76 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-ping" edition = "2021" rust-version = { workspace = true } description = "Ping protocol for libp2p" -version = "0.43.0" +version = "0.43.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 0cf5c6e5f07..522663196e6 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -303,6 +303,7 @@ impl ConnectionHandler for Handler { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(Ok(rtt))); } Poll::Ready(Err(e)) => { + self.interval.reset(self.config.interval); self.pending_errors.push_front(e); } }, @@ -321,13 +322,16 @@ impl ConnectionHandler for Handler { self.outbound = Some(OutboundState::OpenStream); break; } - None => { - self.outbound = Some(OutboundState::OpenStream); - let protocol = SubstreamProtocol::new(ReadyUpgrade::new(PROTOCOL_NAME), ()); - return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { - protocol, - }); - } + None => match self.interval.poll_unpin(cx) { + Poll::Pending => break, + Poll::Ready(()) => { + self.outbound = Some(OutboundState::OpenStream); + let protocol = SubstreamProtocol::new(ReadyUpgrade::new(PROTOCOL_NAME), ()); + return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { + protocol, + }); + } + }, } } diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index d1c4a2facaf..951482f12d8 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -167,7 +167,8 @@ impl NetworkBehaviour for Behaviour { | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } } diff --git a/protocols/ping/src/protocol.rs b/protocols/ping/src/protocol.rs index 59e583a8b3b..28549e1c198 100644 --- a/protocols/ping/src/protocol.rs +++ b/protocols/ping/src/protocol.rs @@ -35,8 +35,7 @@ pub const PROTOCOL_NAME: StreamProtocol = StreamProtocol::new("/ipfs/ping/1.0.0" /// /// At most a single inbound and outbound substream is kept open at /// any time. In case of a ping timeout or another error on a substream, the -/// substream is dropped. If a configurable number of consecutive -/// outbound pings fail, the connection is closed. +/// substream is dropped. /// /// Successful pings report the round-trip time. /// diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 8fcfa103c4f..921401bc384 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -353,7 +353,8 @@ impl NetworkBehaviour for Behaviour { | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index c3c80c5b504..276234cfb93 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -231,7 +231,8 @@ impl NetworkBehaviour for Behaviour { | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 505635efda8..4fb8ddbd03d 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -274,7 +274,8 @@ impl NetworkBehaviour for Behaviour { | ToSwarm::Dial { .. } | ToSwarm::CloseConnection { .. } | ToSwarm::ListenOn { .. } - | ToSwarm::RemoveListener { .. }), + | ToSwarm::RemoveListener { .. } + | ToSwarm::NewExternalAddrOfPeer { .. }), ) => { let new_to_swarm = other.map_out(|_| unreachable!("we manually map `GenerateEvent` variants")); diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 44f2f97a6a0..8ded3724752 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -218,6 +218,7 @@ impl NetworkBehaviour for Behaviour { | ToSwarm::NewExternalAddrCandidate(_) | ToSwarm::ExternalAddrConfirmed(_) | ToSwarm::ExternalAddrExpired(_) + | ToSwarm::NewExternalAddrOfPeer { .. } | ToSwarm::CloseConnection { .. } => { let new_to_swarm = to_swarm .map_out(|_| unreachable!("we manually map `GenerateEvent` variants")); diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 0db687592f7..33df77f0a13 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -20,7 +20,7 @@ libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } rand = "0.8" serde = { version = "1.0", optional = true} -serde_json = { version = "1.0.105", optional = true } +serde_json = { version = "1.0.106", optional = true } smallvec = "1.11.0" void = "1.0.2" log = "0.4.20" diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 7b1a8088443..249702bedbf 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -775,15 +775,16 @@ where } 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::NewExternalAddrCandidate(_) => {} - FromSwarm::ExternalAddrExpired(_) => {} - FromSwarm::ExternalAddrConfirmed(_) => {} + FromSwarm::ListenFailure(_) + | FromSwarm::NewListener(_) + | FromSwarm::NewListenAddr(_) + | FromSwarm::ExpiredListenAddr(_) + | FromSwarm::ListenerError(_) + | FromSwarm::ListenerClosed(_) + | FromSwarm::NewExternalAddrCandidate(_) + | FromSwarm::ExternalAddrExpired(_) + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } diff --git a/swarm-derive/Cargo.toml b/swarm-derive/Cargo.toml index d8d4b83d033..ab8c4a80ee7 100644 --- a/swarm-derive/Cargo.toml +++ b/swarm-derive/Cargo.toml @@ -16,8 +16,8 @@ proc-macro = true [dependencies] heck = "0.4" quote = "1.0" -syn = { version = "2.0.29", default-features = false, features = ["clone-impls", "derive", "parsing", "printing", "proc-macro"] } -proc-macro-warning = "0.4.0" +syn = { version = "2.0.31", default-features = false, features = ["clone-impls", "derive", "parsing", "printing", "proc-macro"] } +proc-macro-warning = "0.4.2" proc-macro2 = "1.0" # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index e54cd058daf..b0113182f53 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -83,6 +83,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result syn::Result quote! { + self.#i.on_swarm_event(#from_swarm::NewExternalAddrOfPeer(#new_external_addr_of_peer { + addr, peer_id + })); + }, + None => quote! { + self.#field_n.on_swarm_event(#from_swarm::NewExternalAddrOfPeer(#new_external_addr_of_peer { + addr, peer_id + })); + }, + }) + }; + // Build the list of statements to put in the body of `on_swarm_event()` // for the `FromSwarm::ExternalAddrExpired` variant. let on_external_addr_expired_stmts = { @@ -757,6 +779,9 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result { return std::task::Poll::Ready(#network_behaviour_action::CloseConnection { peer_id, connection }); } + std::task::Poll::Ready(#network_behaviour_action::NewExternalAddrOfPeer{addr, peer_id}) => { + return std::task::Poll::Ready(#network_behaviour_action::NewExternalAddrOfPeer{addr, peer_id}); + } std::task::Poll::Pending => {}, } } @@ -883,6 +908,9 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result { #(#on_listener_closed_stmts)* } + #from_swarm::NewExternalAddrOfPeer( + #new_external_addr_of_peer {addr, peer_id}) + => { #(#on_new_external_addr_of_peer_stmts)* } _ => {} } } diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 37a5cbc6157..77ddf3458d1 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,14 @@ +## 0.43.4 - unreleased + +- Implement `Debug` for event structs. + See [PR 4426]. + +- Improve error message when `DialPeerCondition` prevents a dial. + See [PR 4409]. + +[PR 4426]: https://github.com/libp2p/rust-libp2p/pull/4426 +[PR 4409]: https://github.com/libp2p/rust-libp2p/pull/4409 + ## 0.43.3 - Implement `Display` for `ConnectionId`. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index c2b959eea01..ca49d92031f 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm" edition = "2021" rust-version = { workspace = true } description = "The libp2p swarm" -version = "0.43.3" +version = "0.43.4" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -54,7 +54,7 @@ libp2p-yamux = { path = "../muxers/yamux" } # Using `path` here because this is quickcheck = { workspace = true } void = "1" once_cell = "1.18.0" -trybuild = "1.0.83" +trybuild = "1.0.84" [[test]] name = "swarm_derive" diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index 0ecdf7b31f0..aae14a6ad44 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -320,6 +320,10 @@ pub enum ToSwarm { /// Whether to close a specific or all connections to the given peer. connection: CloseConnection, }, + + /// TODO: more documentation needed + /// Reports external address of a remote peer to other `NetworkBehaviours` + NewExternalAddrOfPeer { addr: Multiaddr, peer_id: PeerId }, } impl ToSwarm { @@ -352,6 +356,9 @@ impl ToSwarm { ToSwarm::NewExternalAddrCandidate(addr) => ToSwarm::NewExternalAddrCandidate(addr), ToSwarm::ExternalAddrConfirmed(addr) => ToSwarm::ExternalAddrConfirmed(addr), ToSwarm::ExternalAddrExpired(addr) => ToSwarm::ExternalAddrExpired(addr), + ToSwarm::NewExternalAddrOfPeer { addr, peer_id } => { + ToSwarm::NewExternalAddrOfPeer { addr, peer_id } + } } } } @@ -383,6 +390,9 @@ impl ToSwarm { peer_id, connection, }, + ToSwarm::NewExternalAddrOfPeer { addr, peer_id } => { + ToSwarm::NewExternalAddrOfPeer { addr, peer_id } + } } } } @@ -408,6 +418,7 @@ pub enum CloseConnection { /// Enumeration with the list of the possible events /// to pass to [`on_swarm_event`](NetworkBehaviour::on_swarm_event). +#[derive(Debug)] pub enum FromSwarm<'a, Handler> { /// Informs the behaviour about a newly established connection to a peer. ConnectionEstablished(ConnectionEstablished<'a>), @@ -447,10 +458,12 @@ pub enum FromSwarm<'a, Handler> { ExternalAddrConfirmed(ExternalAddrConfirmed<'a>), /// Informs the behaviour that an external address of the local node expired, i.e. is no-longer confirmed. ExternalAddrExpired(ExternalAddrExpired<'a>), + /// TODO: document it + NewExternalAddrOfPeer(NewExternalAddrOfPeer<'a>), } /// [`FromSwarm`] variant that informs the behaviour about a newly established connection to a peer. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ConnectionEstablished<'a> { pub peer_id: PeerId, pub connection_id: ConnectionId, @@ -464,6 +477,7 @@ pub struct ConnectionEstablished<'a> { /// This event is always paired with an earlier /// [`FromSwarm::ConnectionEstablished`] with the same peer ID, connection ID /// and endpoint. +#[derive(Debug)] pub struct ConnectionClosed<'a, Handler> { pub peer_id: PeerId, pub connection_id: ConnectionId, @@ -474,7 +488,7 @@ pub struct ConnectionClosed<'a, Handler> { /// [`FromSwarm`] variant that informs the behaviour that the [`ConnectedPoint`] of an existing /// connection has changed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct AddressChange<'a> { pub peer_id: PeerId, pub connection_id: ConnectionId, @@ -484,7 +498,7 @@ pub struct AddressChange<'a> { /// [`FromSwarm`] variant that informs the behaviour that the dial to a known /// or unknown node failed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct DialFailure<'a> { pub peer_id: Option, pub error: &'a DialError, @@ -496,7 +510,7 @@ pub struct DialFailure<'a> { /// /// This can include, for example, an error during the handshake of the encryption layer, or the /// connection unexpectedly closed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ListenFailure<'a> { pub local_addr: &'a Multiaddr, pub send_back_addr: &'a Multiaddr, @@ -505,14 +519,14 @@ pub struct ListenFailure<'a> { } /// [`FromSwarm`] variant that informs the behaviour that a new listener was created. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct NewListener { pub listener_id: ListenerId, } /// [`FromSwarm`] variant that informs the behaviour /// that we have started listening on a new multiaddr. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct NewListenAddr<'a> { pub listener_id: ListenerId, pub addr: &'a Multiaddr, @@ -521,44 +535,51 @@ pub struct NewListenAddr<'a> { /// [`FromSwarm`] variant that informs the behaviour that a multiaddr /// we were listening on has expired, /// which means that we are no longer listening on it. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ExpiredListenAddr<'a> { pub listener_id: ListenerId, pub addr: &'a Multiaddr, } /// [`FromSwarm`] variant that informs the behaviour that a listener experienced an error. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ListenerError<'a> { pub listener_id: ListenerId, pub err: &'a (dyn std::error::Error + 'static), } /// [`FromSwarm`] variant that informs the behaviour that a listener closed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ListenerClosed<'a> { pub listener_id: ListenerId, pub reason: Result<(), &'a std::io::Error>, } /// [`FromSwarm`] variant that informs the behaviour about a new candidate for an external address for us. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct NewExternalAddrCandidate<'a> { pub addr: &'a Multiaddr, } /// [`FromSwarm`] variant that informs the behaviour that an external address was confirmed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ExternalAddrConfirmed<'a> { pub addr: &'a Multiaddr, } /// [`FromSwarm`] variant that informs the behaviour that an external address was removed. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct ExternalAddrExpired<'a> { pub addr: &'a Multiaddr, } +/// [`FromSwarm`] variant that informs the behaviour that a new external address was detected. +#[derive(Clone, Copy, Debug)] +pub struct NewExternalAddrOfPeer<'a> { + pub addr: &'a Multiaddr, + pub peer_id: &'a PeerId, +} + impl<'a, Handler> FromSwarm<'a, Handler> { fn map_handler( self, @@ -658,6 +679,7 @@ impl<'a, Handler> FromSwarm<'a, Handler> { FromSwarm::NewExternalAddrCandidate(e) => Some(FromSwarm::NewExternalAddrCandidate(e)), FromSwarm::ExternalAddrExpired(e) => Some(FromSwarm::ExternalAddrExpired(e)), FromSwarm::ExternalAddrConfirmed(e) => Some(FromSwarm::ExternalAddrConfirmed(e)), + FromSwarm::NewExternalAddrOfPeer(e) => Some(FromSwarm::NewExternalAddrOfPeer(e)), } } } diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index 6810abec591..0d1bccbd5cf 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -72,7 +72,8 @@ impl NetworkBehaviour for Behaviour { | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } } diff --git a/swarm/src/handler.rs b/swarm/src/handler.rs index dcc7ab1c09d..9374903f9b7 100644 --- a/swarm/src/handler.rs +++ b/swarm/src/handler.rs @@ -222,6 +222,42 @@ pub enum ConnectionEvent<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IO RemoteProtocolsChange(ProtocolsChange<'a>), } +impl<'a, IP, OP, IOI, OOI> fmt::Debug for ConnectionEvent<'a, IP, OP, IOI, OOI> +where + IP: InboundUpgradeSend + fmt::Debug, + IP::Output: fmt::Debug, + IP::Error: fmt::Debug, + OP: OutboundUpgradeSend + fmt::Debug, + OP::Output: fmt::Debug, + OP::Error: fmt::Debug, + IOI: fmt::Debug, + OOI: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ConnectionEvent::FullyNegotiatedInbound(v) => { + f.debug_tuple("FullyNegotiatedInbound").field(v).finish() + } + ConnectionEvent::FullyNegotiatedOutbound(v) => { + f.debug_tuple("FullyNegotiatedOutbound").field(v).finish() + } + ConnectionEvent::AddressChange(v) => f.debug_tuple("AddressChange").field(v).finish(), + ConnectionEvent::DialUpgradeError(v) => { + f.debug_tuple("DialUpgradeError").field(v).finish() + } + ConnectionEvent::ListenUpgradeError(v) => { + f.debug_tuple("ListenUpgradeError").field(v).finish() + } + ConnectionEvent::LocalProtocolsChange(v) => { + f.debug_tuple("LocalProtocolsChange").field(v).finish() + } + ConnectionEvent::RemoteProtocolsChange(v) => { + f.debug_tuple("RemoteProtocolsChange").field(v).finish() + } + } + } +} + impl<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> ConnectionEvent<'a, IP, OP, IOI, OOI> { @@ -262,6 +298,7 @@ impl<'a, IP: InboundUpgradeSend, OP: OutboundUpgradeSend, IOI, OOI> /// of simultaneously open negotiated inbound substreams. In other words it is up to the /// [`ConnectionHandler`] implementation to stop a malicious remote node to open and keep alive /// an excessive amount of inbound substreams. +#[derive(Debug)] pub struct FullyNegotiatedInbound { pub protocol: IP::Output, pub info: IOI, @@ -271,18 +308,20 @@ pub struct FullyNegotiatedInbound { /// /// The `protocol` field is the information that was previously passed to /// [`ConnectionHandlerEvent::OutboundSubstreamRequest`]. +#[derive(Debug)] pub struct FullyNegotiatedOutbound { pub protocol: OP::Output, pub info: OOI, } /// [`ConnectionEvent`] variant that informs the handler about a change in the address of the remote. +#[derive(Debug)] pub struct AddressChange<'a> { pub new_address: &'a Multiaddr, } /// [`ConnectionEvent`] variant that informs the handler about a change in the protocols supported on the connection. -#[derive(Clone)] +#[derive(Debug, Clone)] pub enum ProtocolsChange<'a> { Added(ProtocolsAdded<'a>), Removed(ProtocolsRemoved<'a>), @@ -352,7 +391,7 @@ impl<'a> ProtocolsChange<'a> { } /// An [`Iterator`] over all protocols that have been added. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct ProtocolsAdded<'a> { protocols: Peekable>, } @@ -366,7 +405,7 @@ impl<'a> ProtocolsAdded<'a> { } /// An [`Iterator`] over all protocols that have been removed. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct ProtocolsRemoved<'a> { protocols: Either< Peekable>, @@ -399,6 +438,7 @@ impl<'a> Iterator for ProtocolsRemoved<'a> { /// [`ConnectionEvent`] variant that informs the handler /// that upgrading an outbound substream to the given protocol has failed. +#[derive(Debug)] pub struct DialUpgradeError { pub info: OOI, pub error: StreamUpgradeError, @@ -406,6 +446,7 @@ pub struct DialUpgradeError { /// [`ConnectionEvent`] variant that informs the handler /// that upgrading an inbound substream to the given protocol has failed. +#[derive(Debug)] pub struct ListenUpgradeError { pub info: IOI, pub error: IP::Error, diff --git a/swarm/src/handler/map_in.rs b/swarm/src/handler/map_in.rs index af828999b03..82cb12a183d 100644 --- a/swarm/src/handler/map_in.rs +++ b/swarm/src/handler/map_in.rs @@ -24,6 +24,7 @@ use crate::handler::{ use std::{fmt::Debug, marker::PhantomData, task::Context, task::Poll}; /// Wrapper around a protocol handler that turns the input event into something else. +#[derive(Debug)] pub struct MapInEvent { inner: TConnectionHandler, map: TMap, diff --git a/swarm/src/handler/map_out.rs b/swarm/src/handler/map_out.rs index e92d1403ce6..8528b563ece 100644 --- a/swarm/src/handler/map_out.rs +++ b/swarm/src/handler/map_out.rs @@ -25,6 +25,7 @@ use std::fmt::Debug; use std::task::{Context, Poll}; /// Wrapper around a protocol handler that turns the output event into something else. +#[derive(Debug)] pub struct MapOutEvent { inner: TConnectionHandler, map: TMap, diff --git a/swarm/src/keep_alive.rs b/swarm/src/keep_alive.rs index 05cbcdf7b8c..7cc1cb99ec9 100644 --- a/swarm/src/keep_alive.rs +++ b/swarm/src/keep_alive.rs @@ -75,7 +75,8 @@ impl NetworkBehaviour for Behaviour { | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 867e49410c5..c5c499bcf13 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -85,6 +85,7 @@ pub mod derive_prelude { pub use crate::behaviour::ListenerClosed; pub use crate::behaviour::ListenerError; pub use crate::behaviour::NewExternalAddrCandidate; + pub use crate::behaviour::NewExternalAddrOfPeer; pub use crate::behaviour::NewListenAddr; pub use crate::behaviour::NewListener; pub use crate::connection::ConnectionId; @@ -110,8 +111,8 @@ pub mod derive_prelude { pub use behaviour::{ AddressChange, CloseConnection, ConnectionClosed, DialFailure, ExpiredListenAddr, ExternalAddrExpired, ExternalAddresses, FromSwarm, ListenAddresses, ListenFailure, - ListenerClosed, ListenerError, NetworkBehaviour, NewExternalAddrCandidate, NewListenAddr, - NotifyHandler, PollParameters, ToSwarm, + ListenerClosed, ListenerError, NetworkBehaviour, NewExternalAddrCandidate, + NewExternalAddrOfPeer, NewListenAddr, NotifyHandler, PollParameters, ToSwarm, }; pub use connection::pool::ConnectionCounters; pub use connection::{ConnectionError, ConnectionId, SupportedProtocols}; @@ -1112,6 +1113,13 @@ where self.pool.disconnect(peer_id); } }, + ToSwarm::NewExternalAddrOfPeer { addr, peer_id } => { + self.behaviour + .on_swarm_event(FromSwarm::NewExternalAddrOfPeer(NewExternalAddrOfPeer { + addr: &addr, + peer_id: &peer_id, + })) + } } None diff --git a/swarm/src/test.rs b/swarm/src/test.rs index 6f39d56da91..55a944f5fdb 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -132,7 +132,8 @@ where | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } diff --git a/swarm/tests/swarm_derive.rs b/swarm/tests/swarm_derive.rs index fa3f6c69dd0..fc48260c732 100644 --- a/swarm/tests/swarm_derive.rs +++ b/swarm/tests/swarm_derive.rs @@ -520,7 +520,8 @@ fn custom_out_event_no_type_parameters() { | FromSwarm::ListenerClosed(_) | FromSwarm::NewExternalAddrCandidate(_) | FromSwarm::ExternalAddrExpired(_) - | FromSwarm::ExternalAddrConfirmed(_) => {} + | FromSwarm::ExternalAddrConfirmed(_) + | FromSwarm::NewExternalAddrOfPeer(_) => {} } } } diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index a85307aad32..77c8e57e3ff 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -11,13 +11,14 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] +async-trait = "0.1.72" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } log = "0.4.20" futures = "0.3.28" -async-std-resolver = { version = "0.22", optional = true } +async-std-resolver = { version = "0.23", optional = true } parking_lot = "0.12.0" -trust-dns-resolver = { version = "0.22", default-features = false, features = ["system-config"] } +trust-dns-resolver = { version = "0.23", default-features = false, features = ["system-config"] } smallvec = "1.11.0" [dev-dependencies] diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index 771c7dbc94a..61d1f4fed91 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -58,7 +58,8 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #[cfg(feature = "async-std")] -use async_std_resolver::{AsyncStdConnection, AsyncStdConnectionProvider}; +use async_std_resolver::AsyncStdResolver; +use async_trait::async_trait; use futures::{future::BoxFuture, prelude::*}; use libp2p_core::{ connection::Endpoint, @@ -69,10 +70,10 @@ use libp2p_core::{ use parking_lot::Mutex; use smallvec::SmallVec; use std::io; +use std::net::{Ipv4Addr, Ipv6Addr}; use std::{ convert::TryFrom, error, fmt, iter, - net::IpAddr, ops::DerefMut, pin::Pin, str, @@ -81,12 +82,15 @@ use std::{ }; #[cfg(any(feature = "async-std", feature = "tokio"))] use trust_dns_resolver::system_conf; -use trust_dns_resolver::{proto::xfer::dns_handle::DnsHandle, AsyncResolver, ConnectionProvider}; #[cfg(feature = "tokio")] -use trust_dns_resolver::{TokioAsyncResolver, TokioConnection, TokioConnectionProvider}; +use trust_dns_resolver::TokioAsyncResolver; pub use trust_dns_resolver::config::{ResolverConfig, ResolverOpts}; pub use trust_dns_resolver::error::{ResolveError, ResolveErrorKind}; +use trust_dns_resolver::lookup::{Ipv4Lookup, Ipv6Lookup, TxtLookup}; +use trust_dns_resolver::lookup_ip::LookupIp; +use trust_dns_resolver::name_server::ConnectionProvider; +use trust_dns_resolver::AsyncResolver; /// The prefix for `dnsaddr` protocol TXT record lookups. const DNSADDR_PREFIX: &str = "_dnsaddr."; @@ -109,23 +113,20 @@ const MAX_TXT_RECORDS: usize = 16; /// A `Transport` wrapper for performing DNS lookups when dialing `Multiaddr`esses /// using `async-std` for all async I/O. #[cfg(feature = "async-std")] -pub type DnsConfig = GenDnsConfig; +pub type DnsConfig = GenDnsConfig; /// A `Transport` wrapper for performing DNS lookups when dialing `Multiaddr`esses /// using `tokio` for all async I/O. #[cfg(feature = "tokio")] -pub type TokioDnsConfig = GenDnsConfig; +pub type TokioDnsConfig = GenDnsConfig; /// A `Transport` wrapper for performing DNS lookups when dialing `Multiaddr`esses. -pub struct GenDnsConfig -where - C: DnsHandle, - P: ConnectionProvider, -{ +#[derive(Debug)] +pub struct GenDnsConfig { /// The underlying transport. inner: Arc>, /// The DNS resolver used when dialing addresses with DNS components. - resolver: AsyncResolver, + resolver: R, } #[cfg(feature = "async-std")] @@ -145,9 +146,10 @@ where cfg: ResolverConfig, opts: ResolverOpts, ) -> Result, io::Error> { + // TODO: Make infallible in next breaking release. Or deprecation? Ok(DnsConfig { inner: Arc::new(Mutex::new(inner)), - resolver: async_std_resolver::resolver(cfg, opts).await?, + resolver: async_std_resolver::resolver(cfg, opts).await, }) } } @@ -170,31 +172,20 @@ where cfg: ResolverConfig, opts: ResolverOpts, ) -> Result, io::Error> { + // TODO: Make infallible in next breaking release. Or deprecation? Ok(TokioDnsConfig { inner: Arc::new(Mutex::new(inner)), - resolver: TokioAsyncResolver::tokio(cfg, opts)?, + resolver: TokioAsyncResolver::tokio(cfg, opts), }) } } -impl fmt::Debug for GenDnsConfig -where - C: DnsHandle, - P: ConnectionProvider, - T: fmt::Debug, -{ - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.debug_tuple("GenDnsConfig").field(&self.inner).finish() - } -} - -impl Transport for GenDnsConfig +impl Transport for GenDnsConfig where T: Transport + Send + Unpin + 'static, T::Error: Send, T::Dial: Send, - C: DnsHandle, - P: ConnectionProvider, + R: Clone + Send + Sync + Resolver + 'static, { type Output = T::Output; type Error = DnsErr; @@ -247,13 +238,12 @@ where } } -impl GenDnsConfig +impl GenDnsConfig where T: Transport + Send + Unpin + 'static, T::Error: Send, T::Dial: Send, - C: DnsHandle, - P: ConnectionProvider, + R: Clone + Send + Sync + Resolver + 'static, { fn do_dial( &mut self, @@ -460,14 +450,10 @@ enum Resolved<'a> { /// Asynchronously resolves the domain name of a `Dns`, `Dns4`, `Dns6` or `Dnsaddr` protocol /// component. If the given protocol is of a different type, it is returned unchanged as a /// [`Resolved::One`]. -fn resolve<'a, E: 'a + Send, C, P>( +fn resolve<'a, E: 'a + Send, R: Resolver>( proto: &Protocol<'a>, - resolver: &'a AsyncResolver, -) -> BoxFuture<'a, Result, DnsErr>> -where - C: DnsHandle, - P: ConnectionProvider, -{ + resolver: &'a R, +) -> BoxFuture<'a, Result, DnsErr>> { match proto { Protocol::Dns(ref name) => resolver .lookup_ip(name.clone().into_owned()) @@ -505,12 +491,12 @@ where iter::once(one) .chain(iter::once(two)) .chain(ips) - .map(IpAddr::from) + .map(Ipv4Addr::from) .map(Protocol::from) .collect(), )) } else { - Ok(Resolved::One(Protocol::from(IpAddr::from(one)))) + Ok(Resolved::One(Protocol::from(Ipv4Addr::from(one)))) } } Err(e) => Err(DnsErr::ResolveError(e)), @@ -529,12 +515,12 @@ where iter::once(one) .chain(iter::once(two)) .chain(ips) - .map(IpAddr::from) + .map(Ipv6Addr::from) .map(Protocol::from) .collect(), )) } else { - Ok(Resolved::One(Protocol::from(IpAddr::from(one)))) + Ok(Resolved::One(Protocol::from(Ipv6Addr::from(one)))) } } Err(e) => Err(DnsErr::ResolveError(e)), @@ -583,6 +569,37 @@ fn invalid_data(e: impl Into>) -> io::E io::Error::new(io::ErrorKind::InvalidData, e) } +#[async_trait::async_trait] +#[doc(hidden)] +pub trait Resolver { + async fn lookup_ip(&self, name: String) -> Result; + async fn ipv4_lookup(&self, name: String) -> Result; + async fn ipv6_lookup(&self, name: String) -> Result; + async fn txt_lookup(&self, name: String) -> Result; +} + +#[async_trait] +impl Resolver for AsyncResolver +where + C: ConnectionProvider, +{ + async fn lookup_ip(&self, name: String) -> Result { + self.lookup_ip(name).await + } + + async fn ipv4_lookup(&self, name: String) -> Result { + self.ipv4_lookup(name).await + } + + async fn ipv6_lookup(&self, name: String) -> Result { + self.ipv6_lookup(name).await + } + + async fn txt_lookup(&self, name: String) -> Result { + self.txt_lookup(name).await + } +} + #[cfg(all(test, any(feature = "tokio", feature = "async-std")))] mod tests { use super::*; @@ -647,13 +664,12 @@ mod tests { } } - async fn run(mut transport: GenDnsConfig) + async fn run(mut transport: GenDnsConfig) where - C: DnsHandle, - P: ConnectionProvider, T: Transport + Clone + Send + Unpin + 'static, T::Error: Send, T::Dial: Send, + R: Clone + Send + Sync + Resolver + 'static, { // Success due to existing A record for example.com. let _ = transport diff --git a/transports/noise/CHANGELOG.md b/transports/noise/CHANGELOG.md index 8567b8727cd..2a0c31c96a8 100644 --- a/transports/noise/CHANGELOG.md +++ b/transports/noise/CHANGELOG.md @@ -1,8 +1,8 @@ -## 0.43.1 - unreleased +## 0.43.1 - Update dependencies. -## 0.43.0 +## 0.43.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index d957d4fdc59..04aae5fba59 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -22,7 +22,7 @@ quick-protobuf = "0.8" rand = "0.8.3" sha2 = "0.10.7" static_assertions = "1" -thiserror = "1.0.44" +thiserror = "1.0.48" x25519-dalek = "1.1.0" zeroize = "1" diff --git a/transports/quic/CHANGELOG.md b/transports/quic/CHANGELOG.md index c7da2895b58..7cf54e89b66 100644 --- a/transports/quic/CHANGELOG.md +++ b/transports/quic/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.9.2 - unreleased +## 0.9.2 - Cut stable release. diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 99ac616fa34..b0c445a8efc 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -10,7 +10,7 @@ license = "MIT" [dependencies] async-std = { version = "1.12.0", optional = true } -bytes = "1.4.0" +bytes = "1.5.0" futures = "0.3.28" futures-timer = "3.0.2" if-watch = "3.0.1" @@ -21,8 +21,8 @@ log = "0.4" parking_lot = "0.12.0" quinn = { version = "0.10.2", default-features = false, features = ["tls-rustls", "futures-io"] } rand = "0.8.5" -rustls = { version = "0.21.6", default-features = false } -thiserror = "1.0.44" +rustls = { version = "0.21.7", default-features = false } +thiserror = "1.0.48" tokio = { version = "1.32.0", default-features = false, features = ["net", "rt", "time"], optional = true } socket2 = "0.5.3" diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index a0c43b9ebdd..5581ceb744c 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -730,6 +730,7 @@ async fn open_outbound_streams( } /// Helper function for driving two transports until they established a connection. +#[allow(unknown_lints, clippy::needless_pass_by_ref_mut)] // False positive. async fn connect( listener: &mut Boxed<(PeerId, StreamMuxerBox)>, dialer: &mut Boxed<(PeerId, StreamMuxerBox)>, diff --git a/transports/tls/CHANGELOG.md b/transports/tls/CHANGELOG.md index 9d014accbd3..4c85ccf578c 100644 --- a/transports/tls/CHANGELOG.md +++ b/transports/tls/CHANGELOG.md @@ -1,4 +1,13 @@ -## 0.2.0 +## 0.2.1 + +- Switch from webpki to rustls-webpki. + This is a part of the resolution of the [RUSTSEC-2023-0052]. + See [PR 4381]. + +[PR 4381]: https://github.com/libp2p/rust-libp2p/pull/4381 +[RUSTSEC-2023-0052]: https://rustsec.org/advisories/RUSTSEC-2023-0052.html + +## 0.2.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/transports/tls/Cargo.toml b/transports/tls/Cargo.toml index 7e6288fe054..ba60164cd3e 100644 --- a/transports/tls/Cargo.toml +++ b/transports/tls/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-tls" -version = "0.2.0" +version = "0.2.1" edition = "2021" rust-version = { workspace = true } description = "TLS configuration based on libp2p TLS specs." @@ -15,14 +15,14 @@ libp2p-core = { workspace = true } libp2p-identity = { workspace = true } rcgen = "0.10.0" ring = "0.16.20" -thiserror = "1.0.44" -webpki = { version = "0.22.0", features = ["std"] } +thiserror = "1.0.48" +webpki = { version = "0.101.4", package = "rustls-webpki", features = ["std"] } x509-parser = "0.15.1" yasna = "0.5.2" # Exposed dependencies. Breaking changes to these are breaking changes to us. [dependencies.rustls] -version = "0.21.6" +version = "0.21.7" default-features = false features = ["dangerous_configuration"] # Must enable this to allow for custom verification code. diff --git a/transports/webrtc/src/lib.rs b/transports/webrtc/src/lib.rs index 012796a6b69..f89d946228c 100644 --- a/transports/webrtc/src/lib.rs +++ b/transports/webrtc/src/lib.rs @@ -83,6 +83,7 @@ mod proto { #![allow(unreachable_pub)] include!("generated/mod.rs"); + #[cfg(feature = "tokio")] pub(crate) use self::webrtc::pb::{mod_Message::Flag, Message}; } diff --git a/transports/websocket/CHANGELOG.md b/transports/websocket/CHANGELOG.md index 5ae250a5fe6..a93b1484946 100644 --- a/transports/websocket/CHANGELOG.md +++ b/transports/websocket/CHANGELOG.md @@ -1,4 +1,13 @@ -## 0.42.0 +## 0.42.1 + +- Bump `futures-rustls` to `0.24.0`. + This is a part of the resolution of the [RUSTSEC-2023-0052]. + See [PR 4378]. + +[PR 4378]: https://github.com/libp2p/rust-libp2p/pull/4378 +[RUSTSEC-2023-0052]: https://rustsec.org/advisories/RUSTSEC-2023-0052.html + +## 0.42.0 - Raise MSRV to 1.65. See [PR 3715]. diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index b33af22fe45..f3ebf5af000 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-websocket" edition = "2021" rust-version = { workspace = true } description = "WebSocket transport for libp2p" -version = "0.42.0" +version = "0.42.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,7 +11,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -futures-rustls = "0.22" +futures-rustls = "0.24.0" either = "1.9.0" futures = "0.3.28" libp2p-core = { workspace = true } @@ -21,7 +21,7 @@ parking_lot = "0.12.0" quicksink = "0.1" rw-stream-sink = { workspace = true } soketto = "0.7.0" -url = "2.1" +url = "2.4" webpki-roots = "0.25" [dev-dependencies] diff --git a/transports/websocket/src/tls.rs b/transports/websocket/src/tls.rs index 63379db65cc..5bff818f34c 100644 --- a/transports/websocket/src/tls.rs +++ b/transports/websocket/src/tls.rs @@ -92,7 +92,7 @@ impl Config { /// Setup the rustls client configuration. fn client_root_store() -> rustls::RootCertStore { let mut client_root_store = rustls::RootCertStore::empty(); - client_root_store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.iter().map(|ta| { + client_root_store.add_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.iter().map(|ta| { rustls::OwnedTrustAnchor::from_subject_spki_name_constraints( ta.subject, ta.spki, diff --git a/transports/webtransport-websys/Cargo.toml b/transports/webtransport-websys/Cargo.toml index 695a62f4cde..7825f64a8ab 100644 --- a/transports/webtransport-websys/Cargo.toml +++ b/transports/webtransport-websys/Cargo.toml @@ -23,7 +23,7 @@ log = "0.4.20" multiaddr = { workspace = true } multihash = { workspace = true } send_wrapper = { version = "0.6.0", features = ["futures"] } -thiserror = "1.0.44" +thiserror = "1.0.48" wasm-bindgen = "0.2.87" wasm-bindgen-futures = "0.4.37" web-sys = { version = "0.3.64", features = [ diff --git a/wasm-tests/webtransport-tests/src/lib.rs b/wasm-tests/webtransport-tests/src/lib.rs index 0ec2f0bcb03..1f420cd6671 100644 --- a/wasm-tests/webtransport-tests/src/lib.rs +++ b/wasm-tests/webtransport-tests/src/lib.rs @@ -338,12 +338,14 @@ async fn fetch_server_addr() -> Multiaddr { .unwrap() } +#[allow(unknown_lints, clippy::needless_pass_by_ref_mut)] // False positive. async fn create_stream(conn: &mut Connection) -> Stream { poll_fn(|cx| Pin::new(&mut *conn).poll_outbound(cx)) .await .unwrap() } +#[allow(unknown_lints, clippy::needless_pass_by_ref_mut)] // False positive. async fn incoming_stream(conn: &mut Connection) -> Stream { let mut stream = poll_fn(|cx| Pin::new(&mut *conn).poll_inbound(cx)) .await