diff --git a/.github/workflows/cache-factory.yml b/.github/workflows/cache-factory.yml index f4ef3cc8591..07e2bb1f7cf 100644 --- a/.github/workflows/cache-factory.yml +++ b/.github/workflows/cache-factory.yml @@ -22,7 +22,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: shared-key: stable-cache diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf786abaa2f..5bdaaef88de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: shared-key: stable-cache save-if: false @@ -141,7 +141,7 @@ jobs: - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: key: ${{ matrix.target }} save-if: ${{ github.ref == 'refs/heads/master' }} @@ -166,7 +166,7 @@ jobs: - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: save-if: ${{ github.ref == 'refs/heads/master' }} @@ -187,7 +187,7 @@ jobs: - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: key: ${{ matrix.features }} save-if: ${{ github.ref == 'refs/heads/master' }} @@ -204,7 +204,7 @@ jobs: - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: save-if: ${{ github.ref == 'refs/heads/master' }} @@ -231,7 +231,7 @@ jobs: - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: save-if: ${{ github.ref == 'refs/heads/master' }} @@ -247,7 +247,7 @@ jobs: - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: save-if: ${{ github.ref == 'refs/heads/master' }} @@ -266,7 +266,7 @@ jobs: - uses: r7kamura/rust-problem-matchers@2c2f1016021a7455a6b5b4bbae31145f3b3cd83a #v1.4.0 - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 with: shared-key: stable-cache save-if: false @@ -342,7 +342,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - run: cargo install --version 0.10.0 pb-rs --locked @@ -368,7 +368,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0 + - uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 - run: cargo metadata --locked --format-version=1 > /dev/null cargo-deny: diff --git a/Cargo.lock b/Cargo.lock index e187aa97735..9ef1c930dc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,16 +130,15 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstream" -version = "0.3.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", "utf8parse", ] @@ -169,9 +168,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "1.0.1" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", "windows-sys", @@ -395,7 +394,7 @@ dependencies = [ "log", "memchr", "once_cell", - "pin-project-lite 0.2.12", + "pin-project-lite", "pin-utils", "slab", "wasm-bindgen-futures", @@ -412,7 +411,7 @@ dependencies = [ "futures-io", "futures-util", "pin-utils", - "socket2 0.5.4", + "socket2 0.5.5", "trust-dns-resolver", ] @@ -424,9 +423,9 @@ checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", @@ -443,7 +442,7 @@ dependencies = [ "futures-sink", "futures-util", "memchr", - "pin-project-lite 0.2.12", + "pin-project-lite", ] [[package]] @@ -499,7 +498,7 @@ dependencies = [ "memchr", "mime", "percent-encoding", - "pin-project-lite 0.2.12", + "pin-project-lite", "rustversion", "serde", "serde_json", @@ -859,20 +858,19 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.23" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03aef18ddf7d879c15ce20f04826ef8418101c7e528014c3eeea13321047dca3" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ "clap_builder", "clap_derive", - "once_cell", ] [[package]] name = "clap_builder" -version = "4.3.23" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ce6fffb678c9b80a70b6b6de0aad31df727623a70fd9a842c30cd573e2fa98" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ "anstream", "anstyle", @@ -882,9 +880,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.3.12" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" dependencies = [ "heck", "proc-macro2", @@ -913,7 +911,7 @@ dependencies = [ "bytes", "futures-core", "memchr", - "pin-project-lite 0.2.12", + "pin-project-lite", "tokio", "tokio-util", ] @@ -1531,9 +1529,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "miniz_oxide", @@ -1638,7 +1636,7 @@ dependencies = [ "futures-io", "memchr", "parking", - "pin-project-lite 0.2.12", + "pin-project-lite", "waker-fn", ] @@ -1709,7 +1707,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.12", + "pin-project-lite", "pin-utils", "slab", ] @@ -1969,7 +1967,7 @@ checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", "http", - "pin-project-lite 0.2.12", + "pin-project-lite", ] [[package]] @@ -2012,7 +2010,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project-lite 0.2.12", + "pin-project-lite", "socket2 0.4.9", "tokio", "tower-service", @@ -2232,7 +2230,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" dependencies = [ - "socket2 0.5.4", + "socket2 0.5.5", "widestring", "windows-sys", "winreg", @@ -2711,7 +2709,7 @@ dependencies = [ "log", "rand 0.8.5", "smallvec", - "socket2 0.5.4", + "socket2 0.5.5", "tokio", "trust-dns-proto", "void", @@ -2926,7 +2924,7 @@ dependencies = [ "rand 0.8.5", "ring", "rustls 0.21.7", - "socket2 0.5.4", + "socket2 0.5.5", "thiserror", "tokio", ] @@ -3110,7 +3108,7 @@ dependencies = [ "libp2p-core", "libp2p-identity", "log", - "socket2 0.5.4", + "socket2 0.5.5", "tokio", ] @@ -3126,7 +3124,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "libp2p-yamux", - "rcgen 0.10.0", + "rcgen", "ring", "rustls 0.21.7", "rustls-webpki", @@ -3181,7 +3179,7 @@ dependencies = [ "multihash", "quickcheck", "rand 0.8.5", - "rcgen 0.11.1", + "rcgen", "serde", "stun", "thiserror", @@ -3254,8 +3252,8 @@ dependencies = [ "libp2p-tcp", "log", "parking_lot", - "quicksink", - "rcgen 0.10.0", + "pin-project-lite", + "rcgen", "rw-stream-sink", "soketto", "url", @@ -3927,15 +3925,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "pem" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" -dependencies = [ - "base64 0.13.1", -] - [[package]] name = "pem" version = "2.0.1" @@ -3993,15 +3982,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" - -[[package]] -name = "pin-project-lite" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -4081,7 +4064,7 @@ dependencies = [ "concurrent-queue", "libc", "log", - "pin-project-lite 0.2.12", + "pin-project-lite", "windows-sys", ] @@ -4247,17 +4230,6 @@ dependencies = [ "quickcheck", ] -[[package]] -name = "quicksink" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77de3c815e5a160b1539c6592796801df2043ae35e123b46d73380cfa57af858" -dependencies = [ - "futures-core", - "futures-sink", - "pin-project-lite 0.1.12", -] - [[package]] name = "quinn" version = "0.10.2" @@ -4268,7 +4240,7 @@ dependencies = [ "async-std", "bytes", "futures-io", - "pin-project-lite 0.2.12", + "pin-project-lite", "quinn-proto", "quinn-udp", "rustc-hash", @@ -4303,7 +4275,7 @@ checksum = "6df19e284d93757a9fb91d63672f7741b129246a669db09d1c0063071debc0c0" dependencies = [ "bytes", "libc", - "socket2 0.5.4", + "socket2 0.5.5", "tracing", "windows-sys", ] @@ -4410,18 +4382,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "rcgen" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffbe84efe2f38dea12e9bfc1f65377fdf03e53a18cb3b995faedf7934c7e785b" -dependencies = [ - "pem 1.1.1", - "ring", - "time", - "yasna", -] - [[package]] name = "rcgen" version = "0.11.1" @@ -4447,7 +4407,7 @@ dependencies = [ "futures-util", "itoa", "percent-encoding", - "pin-project-lite 0.2.12", + "pin-project-lite", "ryu", "tokio", "tokio-util", @@ -4575,7 +4535,7 @@ dependencies = [ "native-tls", "once_cell", "percent-encoding", - "pin-project-lite 0.2.12", + "pin-project-lite", "serde", "serde_json", "serde_urlencoded", @@ -5225,9 +5185,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", "windows-sys", @@ -5457,18 +5417,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", @@ -5549,9 +5509,9 @@ dependencies = [ "mio", "num_cpus", "parking_lot", - "pin-project-lite 0.2.12", + "pin-project-lite", "signal-hook-registry", - "socket2 0.5.4", + "socket2 0.5.5", "tokio-macros", "windows-sys", ] @@ -5608,7 +5568,7 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "pin-project-lite 0.2.12", + "pin-project-lite", "tokio", "tracing", ] @@ -5622,7 +5582,7 @@ dependencies = [ "futures-core", "futures-util", "pin-project", - "pin-project-lite 0.2.12", + "pin-project-lite", "tokio", "tower-layer", "tower-service", @@ -5646,7 +5606,7 @@ dependencies = [ "mime", "mime_guess", "percent-encoding", - "pin-project-lite 0.2.12", + "pin-project-lite", "tokio", "tokio-util", "tower-layer", @@ -5668,12 +5628,12 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.39" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2ef2af84856a50c1d430afce2fdded0a4ec7eda868db86409b4543df0797f9" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", - "pin-project-lite 0.2.12", + "pin-project-lite", "tracing-attributes", "tracing-core", ] @@ -5752,7 +5712,7 @@ dependencies = [ "rustls-pemfile", "rustls-webpki", "smallvec", - "socket2 0.5.4", + "socket2 0.5.5", "thiserror", "tinyvec", "tokio", @@ -6195,7 +6155,7 @@ dependencies = [ "log", "pem 3.0.2", "rand 0.8.5", - "rcgen 0.11.1", + "rcgen", "regex", "ring", "rtcp", @@ -6259,7 +6219,7 @@ dependencies = [ "pem 3.0.2", "rand 0.8.5", "rand_core 0.6.4", - "rcgen 0.11.1", + "rcgen", "ring", "rustls 0.21.7", "sec1", @@ -6305,7 +6265,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62bebbd40e7f8b630a0f1a74783dbfff1edfc0ccaae891c4689891156a8c4d8c" dependencies = [ "log", - "socket2 0.5.4", + "socket2 0.5.5", "thiserror", "tokio", "webrtc-util", diff --git a/Cargo.toml b/Cargo.toml index ca60d469595..347ccb74c39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ members = [ resolver = "2" [workspace.package] -rust-version = "1.65.0" +rust-version = "1.73.0" [workspace.dependencies] futures-bounded = { version = "0.1.0", path = "misc/futures-bounded" } diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 76cffdfcedd..007e00e7710 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.41.0 - unreleased +- Remove blanket-impl of `{In,Out}boundUpgrade` for `{In,Out}boundConnectionUpgrade`. + See [PR 4695](https://github.com/libp2p/rust-libp2p/pull/4695). ## 0.40.1 diff --git a/core/src/upgrade.rs b/core/src/upgrade.rs index 7db1853b56c..777443822b7 100644 --- a/core/src/upgrade.rs +++ b/core/src/upgrade.rs @@ -157,31 +157,3 @@ pub trait OutboundConnectionUpgrade: UpgradeInfo { /// The `info` is the identifier of the protocol, as produced by `protocol_info`. fn upgrade_outbound(self, socket: T, info: Self::Info) -> Self::Future; } - -// Blanket implementation for InboundConnectionUpgrade based on InboundUpgrade for backwards compatibility -impl InboundConnectionUpgrade for U -where - U: InboundUpgrade, -{ - type Output = >::Output; - type Error = >::Error; - type Future = >::Future; - - fn upgrade_inbound(self, socket: T, info: Self::Info) -> Self::Future { - self.upgrade_inbound(socket, info) - } -} - -// Blanket implementation for OutboundConnectionUpgrade based on OutboundUpgrade for backwards compatibility -impl OutboundConnectionUpgrade for U -where - U: OutboundUpgrade, -{ - type Output = >::Output; - type Error = >::Error; - type Future = >::Future; - - fn upgrade_outbound(self, socket: T, info: Self::Info) -> Self::Future { - self.upgrade_outbound(socket, info) - } -} diff --git a/core/tests/transport_upgrade.rs b/core/tests/transport_upgrade.rs index 193ee73cbc8..8f151c886c7 100644 --- a/core/tests/transport_upgrade.rs +++ b/core/tests/transport_upgrade.rs @@ -20,7 +20,9 @@ use futures::prelude::*; use libp2p_core::transport::{ListenerId, MemoryTransport, Transport}; -use libp2p_core::upgrade::{self, InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::upgrade::{ + self, InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeInfo, +}; use libp2p_identity as identity; use libp2p_mplex::MplexConfig; use libp2p_noise as noise; @@ -40,7 +42,7 @@ impl UpgradeInfo for HelloUpgrade { } } -impl InboundUpgrade for HelloUpgrade +impl InboundConnectionUpgrade for HelloUpgrade where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { @@ -58,7 +60,7 @@ where } } -impl OutboundUpgrade for HelloUpgrade +impl OutboundConnectionUpgrade for HelloUpgrade where C: AsyncWrite + AsyncRead + Send + Unpin + 'static, { diff --git a/examples/autonat/Cargo.toml b/examples/autonat/Cargo.toml index e61a31bcd85..f347fa7a1fd 100644 --- a/examples/autonat/Cargo.toml +++ b/examples/autonat/Cargo.toml @@ -10,7 +10,7 @@ release = false [dependencies] tokio = { version = "1.33", features = ["full"] } -clap = { version = "4.3.23", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["tokio", "tcp", "noise", "yamux", "autonat", "identify", "macros"] } diff --git a/examples/dcutr/Cargo.toml b/examples/dcutr/Cargo.toml index 56a0ef1eca1..325189d3cec 100644 --- a/examples/dcutr/Cargo.toml +++ b/examples/dcutr/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" release = false [dependencies] -clap = { version = "4.3.23", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" futures-timer = "3.0" diff --git a/examples/file-sharing/Cargo.toml b/examples/file-sharing/Cargo.toml index f64fc504700..dd3c731ef72 100644 --- a/examples/file-sharing/Cargo.toml +++ b/examples/file-sharing/Cargo.toml @@ -11,7 +11,7 @@ release = false [dependencies] serde = { version = "1.0", features = ["derive"] } async-std = { version = "1.12", features = ["attributes"] } -clap = { version = "4.3.23", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive"] } either = "1.9" env_logger = "0.10" futures = "0.3.28" diff --git a/examples/ipfs-kad/Cargo.toml b/examples/ipfs-kad/Cargo.toml index e619a72a551..24fb249c14b 100644 --- a/examples/ipfs-kad/Cargo.toml +++ b/examples/ipfs-kad/Cargo.toml @@ -11,7 +11,7 @@ release = false [dependencies] tokio = { version = "1.33", features = ["rt-multi-thread", "macros"] } async-trait = "0.1" -clap = { version = "4.3.23", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive"] } env_logger = "0.10" futures = "0.3.28" anyhow = "1.0.75" diff --git a/examples/relay-server/Cargo.toml b/examples/relay-server/Cargo.toml index 275038f75df..41b22aee5c0 100644 --- a/examples/relay-server/Cargo.toml +++ b/examples/relay-server/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" release = false [dependencies] -clap = { version = "4.3.23", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive"] } async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" env_logger = "0.10.0" diff --git a/interop-tests/Dockerfile.chromium b/interop-tests/Dockerfile.chromium index ab720c4d317..5ec46e313aa 100644 --- a/interop-tests/Dockerfile.chromium +++ b/interop-tests/Dockerfile.chromium @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.5-labs -FROM rust:1.67.0 as chef +FROM rust:1.73.0 as chef RUN rustup target add wasm32-unknown-unknown RUN wget -q -O- https://github.com/rustwasm/wasm-pack/releases/download/v0.12.1/wasm-pack-v0.12.1-x86_64-unknown-linux-musl.tar.gz | tar -zx -C /usr/local/bin --strip-components 1 --wildcards "wasm-pack-*/wasm-pack" RUN wget -q -O- https://github.com/WebAssembly/binaryen/releases/download/version_115/binaryen-version_115-x86_64-linux.tar.gz | tar -zx -C /usr/local/bin --strip-components 2 --wildcards "binaryen-version_*/bin/wasm-opt" @@ -14,13 +14,13 @@ FROM chef AS builder COPY --from=planner /app/recipe.json recipe.json # Build dependencies - this is the caching Docker layer! RUN cargo chef cook --release --package interop-tests --target wasm32-unknown-unknown --recipe-path recipe.json -RUN cargo chef cook --release --package interop-tests --bin wasm_ping --recipe-path recipe.json +RUN RUSTFLAGS='-C target-feature=+crt-static' cargo chef cook --release --package interop-tests --target x86_64-unknown-linux-gnu --bin wasm_ping --recipe-path recipe.json # Build application COPY . . RUN wasm-pack build --target web interop-tests -RUN cargo build --release --package interop-tests --bin wasm_ping +RUN RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --package interop-tests --target x86_64-unknown-linux-gnu --bin wasm_ping FROM selenium/standalone-chrome:115.0 -COPY --from=builder /app/target/release/wasm_ping /usr/local/bin/testplan +COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/wasm_ping /usr/local/bin/testplan ENV RUST_BACKTRACE=1 ENTRYPOINT ["testplan"] diff --git a/interop-tests/Dockerfile.native b/interop-tests/Dockerfile.native index df5eb9a1240..047194b7135 100644 --- a/interop-tests/Dockerfile.native +++ b/interop-tests/Dockerfile.native @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.5-labs -FROM rust:1.67.0 as chef +FROM rust:1.73.0 as chef RUN wget -q -O- https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-gnu.tar.gz | tar -zx -C /usr/local/bin WORKDIR /app @@ -10,12 +10,12 @@ RUN cargo chef prepare --recipe-path recipe.json FROM chef AS builder COPY --from=planner /app/recipe.json recipe.json # Build dependencies - this is the caching Docker layer! -RUN cargo chef cook --release --package interop-tests --bin native_ping --recipe-path recipe.json +RUN RUSTFLAGS='-C target-feature=+crt-static' cargo chef cook --release --package interop-tests --target x86_64-unknown-linux-gnu --bin native_ping --recipe-path recipe.json # Build application COPY . . -RUN cargo build --release --package interop-tests --bin native_ping +RUN RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --package interop-tests --target x86_64-unknown-linux-gnu --bin native_ping -FROM gcr.io/distroless/cc -COPY --from=builder /app/target/release/native_ping /usr/local/bin/testplan +FROM scratch +COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/native_ping /usr/local/bin/testplan ENV RUST_BACKTRACE=1 ENTRYPOINT ["testplan"] diff --git a/libp2p/CHANGELOG.md b/libp2p/CHANGELOG.md index ee0e07e7449..245fb83c85b 100644 --- a/libp2p/CHANGELOG.md +++ b/libp2p/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.53.0 - unreleased +- Raise MSRV to 1.73. + See [PR 4692](https://github.com/libp2p/rust-libp2p/pull/4692). - Remove deprecated `libp2p-wasm-ext`. Users should use `libp2p-websocket-websys` instead. See [PR 4694](https://github.com/libp2p/rust-libp2p/pull/4694). diff --git a/libp2p/src/builder.rs b/libp2p/src/builder.rs index 0dbeaa7e2ee..60b977f4397 100644 --- a/libp2p/src/builder.rs +++ b/libp2p/src/builder.rs @@ -1,6 +1,7 @@ use std::marker::PhantomData; mod phase; +mod select_muxer; mod select_security; /// Build a [`Swarm`](libp2p_swarm::Swarm) by combining an identity, a set of @@ -52,6 +53,10 @@ mod select_security; /// libp2p_yamux::Config::default, /// )? /// .with_behaviour(|_key, relay| MyBehaviour { relay })? +/// .with_swarm_config(|cfg| { +/// // Edit cfg here. +/// cfg +/// }) /// .build(); /// # /// # Ok(()) diff --git a/libp2p/src/builder/phase.rs b/libp2p/src/builder/phase.rs index dbf9eb883ae..4871adf65ca 100644 --- a/libp2p/src/builder/phase.rs +++ b/libp2p/src/builder/phase.rs @@ -25,10 +25,11 @@ use swarm::*; use tcp::*; use websocket::*; +use super::select_muxer::SelectMuxerUpgrade; use super::select_security::SelectSecurityUpgrade; use super::SwarmBuilder; -use libp2p_core::{muxing::StreamMuxerBox, upgrade::SelectUpgrade, Transport}; +use libp2p_core::{muxing::StreamMuxerBox, Transport}; use libp2p_identity::Keypair; pub trait IntoSecurityUpgrade { @@ -94,7 +95,7 @@ where U1: IntoMultiplexerUpgrade, U2: IntoMultiplexerUpgrade, { - type Upgrade = SelectUpgrade; + type Upgrade = SelectMuxerUpgrade; fn into_multiplexer_upgrade(self) -> Self::Upgrade { let (f1, f2) = self; @@ -102,7 +103,7 @@ where let u1 = f1.into_multiplexer_upgrade(); let u2 = f2.into_multiplexer_upgrade(); - SelectUpgrade::new(u1, u2) + SelectMuxerUpgrade::new(u1, u2) } } diff --git a/libp2p/src/builder/phase/other_transport.rs b/libp2p/src/builder/phase/other_transport.rs index 1453d2d097b..946b696323c 100644 --- a/libp2p/src/builder/phase/other_transport.rs +++ b/libp2p/src/builder/phase/other_transport.rs @@ -2,9 +2,10 @@ use std::convert::Infallible; use std::marker::PhantomData; use std::sync::Arc; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; use libp2p_core::Transport; #[cfg(feature = "relay")] -use libp2p_core::{InboundUpgrade, Negotiated, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::{Negotiated, UpgradeInfo}; #[cfg(feature = "relay")] use libp2p_identity::PeerId; @@ -119,9 +120,9 @@ impl SecStream: futures::AsyncRead + futures::AsyncWrite + Unpin + Send + 'static, SecError: std::error::Error + Send + Sync + 'static, SecUpgrade: IntoSecurityUpgrade, - SecUpgrade::Upgrade: InboundUpgrade, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + SecUpgrade::Upgrade: InboundConnectionUpgrade, Output = (PeerId, SecStream), Error = SecError> + OutboundConnectionUpgrade, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -129,9 +130,9 @@ impl MuxStream::Substream: Send + 'static, MuxStream::Error: Send + Sync + 'static, MuxUpgrade: IntoMultiplexerUpgrade, - MuxUpgrade::Upgrade: InboundUpgrade, Output = MuxStream, Error = MuxError> + OutboundUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + MuxUpgrade::Upgrade: InboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + OutboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, MuxError: std::error::Error + Send + Sync + 'static, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, diff --git a/libp2p/src/builder/phase/quic.rs b/libp2p/src/builder/phase/quic.rs index 47eec66b8d2..ae8d9400c25 100644 --- a/libp2p/src/builder/phase/quic.rs +++ b/libp2p/src/builder/phase/quic.rs @@ -2,6 +2,7 @@ use super::*; use crate::SwarmBuilder; #[cfg(all(not(target_arch = "wasm32"), feature = "websocket"))] use libp2p_core::muxing::StreamMuxer; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; #[cfg(any( feature = "relay", all(not(target_arch = "wasm32"), feature = "websocket") @@ -90,9 +91,9 @@ impl SwarmBuilder, - SecUpgrade::Upgrade: InboundUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + OutboundUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + SecUpgrade::Upgrade: InboundConnectionUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + OutboundConnectionUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -100,9 +101,9 @@ impl SwarmBuilder, - MuxUpgrade::Upgrade: InboundUpgrade, Output = MuxStream, Error = MuxError> + OutboundUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + MuxUpgrade::Upgrade: InboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + OutboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, MuxError: std::error::Error + Send + Sync + 'static, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -207,9 +208,9 @@ macro_rules! impl_quic_phase_with_websocket { SecStream: futures::AsyncRead + futures::AsyncWrite + Unpin + Send + 'static, SecError: std::error::Error + Send + Sync + 'static, SecUpgrade: IntoSecurityUpgrade<$websocketStream>, - SecUpgrade::Upgrade: InboundUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + OutboundUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + SecUpgrade::Upgrade: InboundConnectionUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + OutboundConnectionUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -217,9 +218,9 @@ macro_rules! impl_quic_phase_with_websocket { MuxStream::Substream: Send + 'static, MuxStream::Error: Send + Sync + 'static, MuxUpgrade: IntoMultiplexerUpgrade, - MuxUpgrade::Upgrade: InboundUpgrade, Output = MuxStream, Error = MuxError> + OutboundUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + MuxUpgrade::Upgrade: InboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + OutboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, MuxError: std::error::Error + Send + Sync + 'static, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, diff --git a/libp2p/src/builder/phase/relay.rs b/libp2p/src/builder/phase/relay.rs index 3062e828e07..2d47810ca9e 100644 --- a/libp2p/src/builder/phase/relay.rs +++ b/libp2p/src/builder/phase/relay.rs @@ -2,6 +2,7 @@ use std::marker::PhantomData; #[cfg(feature = "relay")] use libp2p_core::muxing::StreamMuxerBox; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; #[cfg(feature = "relay")] use libp2p_core::Transport; #[cfg(any(feature = "relay", feature = "websocket"))] @@ -59,9 +60,9 @@ impl SwarmBuilder, - SecUpgrade::Upgrade: InboundUpgrade, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + SecUpgrade::Upgrade: InboundConnectionUpgrade, Output = (PeerId, SecStream), Error = SecError> + OutboundConnectionUpgrade, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -69,9 +70,9 @@ impl SwarmBuilder, - MuxUpgrade::Upgrade: InboundUpgrade, Output = MuxStream, Error = MuxError> + OutboundUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + MuxUpgrade::Upgrade: InboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + OutboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, MuxError: std::error::Error + Send + Sync + 'static, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, diff --git a/libp2p/src/builder/phase/tcp.rs b/libp2p/src/builder/phase/tcp.rs index aee786c869d..5db7315d472 100644 --- a/libp2p/src/builder/phase/tcp.rs +++ b/libp2p/src/builder/phase/tcp.rs @@ -11,7 +11,9 @@ use libp2p_core::Transport; not(target_arch = "wasm32"), any(feature = "tcp", feature = "websocket") ))] -use libp2p_core::{InboundUpgrade, Negotiated, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::{ + upgrade::InboundConnectionUpgrade, upgrade::OutboundConnectionUpgrade, Negotiated, UpgradeInfo, +}; use std::marker::PhantomData; pub struct TcpPhase {} @@ -58,9 +60,9 @@ macro_rules! impl_tcp_builder { SecStream: futures::AsyncRead + futures::AsyncWrite + Unpin + Send + 'static, SecError: std::error::Error + Send + Sync + 'static, SecUpgrade: IntoSecurityUpgrade, - SecUpgrade::Upgrade: InboundUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + OutboundUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + SecUpgrade::Upgrade: InboundConnectionUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + OutboundConnectionUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -68,9 +70,9 @@ macro_rules! impl_tcp_builder { MuxStream::Substream: Send + 'static, MuxStream::Error: Send + Sync + 'static, MuxUpgrade: IntoMultiplexerUpgrade, - MuxUpgrade::Upgrade: InboundUpgrade, Output = MuxStream, Error = MuxError> + OutboundUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + MuxUpgrade::Upgrade: InboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + OutboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, MuxError: std::error::Error + Send + Sync + 'static, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -184,9 +186,9 @@ macro_rules! impl_tcp_phase_with_websocket { SecStream: futures::AsyncRead + futures::AsyncWrite + Unpin + Send + 'static, SecError: std::error::Error + Send + Sync + 'static, SecUpgrade: IntoSecurityUpgrade<$websocketStream>, - SecUpgrade::Upgrade: InboundUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + OutboundUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + SecUpgrade::Upgrade: InboundConnectionUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + OutboundConnectionUpgrade, Output = (libp2p_identity::PeerId, SecStream), Error = SecError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -194,9 +196,9 @@ macro_rules! impl_tcp_phase_with_websocket { MuxStream::Substream: Send + 'static, MuxStream::Error: Send + Sync + 'static, MuxUpgrade: IntoMultiplexerUpgrade, - MuxUpgrade::Upgrade: InboundUpgrade, Output = MuxStream, Error = MuxError> + OutboundUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + MuxUpgrade::Upgrade: InboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + OutboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, MuxError: std::error::Error + Send + Sync + 'static, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, diff --git a/libp2p/src/builder/phase/websocket.rs b/libp2p/src/builder/phase/websocket.rs index 0415b3a3b4d..aeb6236a026 100644 --- a/libp2p/src/builder/phase/websocket.rs +++ b/libp2p/src/builder/phase/websocket.rs @@ -2,6 +2,7 @@ use super::*; use crate::SwarmBuilder; #[cfg(all(not(target_arch = "wasm32"), feature = "websocket"))] use libp2p_core::muxing::{StreamMuxer, StreamMuxerBox}; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; #[cfg(all(not(target_arch = "wasm32"), feature = "websocket"))] use libp2p_core::Transport; #[cfg(any( @@ -70,9 +71,9 @@ macro_rules! impl_websocket_builder { SecStream: futures::AsyncRead + futures::AsyncWrite + Unpin + Send + 'static, SecError: std::error::Error + Send + Sync + 'static, SecUpgrade: IntoSecurityUpgrade<$websocketStream>, - SecUpgrade::Upgrade: InboundUpgrade, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + SecUpgrade::Upgrade: InboundConnectionUpgrade, Output = (PeerId, SecStream), Error = SecError> + OutboundConnectionUpgrade, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -80,9 +81,9 @@ macro_rules! impl_websocket_builder { MuxStream::Substream: Send + 'static, MuxStream::Error: Send + Sync + 'static, MuxUpgrade: IntoMultiplexerUpgrade, - MuxUpgrade::Upgrade: InboundUpgrade, Output = MuxStream, Error = MuxError> + OutboundUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + MuxUpgrade::Upgrade: InboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + OutboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, MuxError: std::error::Error + Send + Sync + 'static, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -164,9 +165,9 @@ impl SwarmBuilder, - SecUpgrade::Upgrade: InboundUpgrade, Output = (PeerId, SecStream), Error = SecError> + OutboundUpgrade, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + SecUpgrade::Upgrade: InboundConnectionUpgrade, Output = (PeerId, SecStream), Error = SecError> + OutboundConnectionUpgrade, Output = (PeerId, SecStream), Error = SecError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, @@ -174,9 +175,9 @@ impl SwarmBuilder, - MuxUpgrade::Upgrade: InboundUpgrade, Output = MuxStream, Error = MuxError> + OutboundUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, - >>::Future: Send, - >>::Future: Send, + MuxUpgrade::Upgrade: InboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + OutboundConnectionUpgrade, Output = MuxStream, Error = MuxError> + Clone + Send + 'static, + >>::Future: Send, + >>::Future: Send, MuxError: std::error::Error + Send + Sync + 'static, <<>::Upgrade as UpgradeInfo>::InfoIter as IntoIterator>::IntoIter: Send, <>::Upgrade as UpgradeInfo>::Info: Send, diff --git a/libp2p/src/builder/select_muxer.rs b/libp2p/src/builder/select_muxer.rs new file mode 100644 index 00000000000..5a2bdbf0864 --- /dev/null +++ b/libp2p/src/builder/select_muxer.rs @@ -0,0 +1,96 @@ +// Copyright 2018 Parity Technologies (UK) Ltd. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +use either::Either; +use futures::future; +use libp2p_core::either::EitherFuture; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; +use libp2p_core::UpgradeInfo; +use std::iter::{Chain, Map}; + +#[derive(Debug, Clone)] +pub struct SelectMuxerUpgrade(A, B); + +impl SelectMuxerUpgrade { + pub fn new(a: A, b: B) -> Self { + SelectMuxerUpgrade(a, b) + } +} + +impl UpgradeInfo for SelectMuxerUpgrade +where + A: UpgradeInfo, + B: UpgradeInfo, +{ + type Info = Either; + type InfoIter = Chain< + Map<::IntoIter, fn(A::Info) -> Self::Info>, + Map<::IntoIter, fn(B::Info) -> Self::Info>, + >; + + fn protocol_info(&self) -> Self::InfoIter { + let a = self + .0 + .protocol_info() + .into_iter() + .map(Either::Left as fn(A::Info) -> _); + let b = self + .1 + .protocol_info() + .into_iter() + .map(Either::Right as fn(B::Info) -> _); + + a.chain(b) + } +} + +impl InboundConnectionUpgrade for SelectMuxerUpgrade +where + A: InboundConnectionUpgrade, + B: InboundConnectionUpgrade, +{ + type Output = future::Either; + type Error = Either; + type Future = EitherFuture; + + fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future { + match info { + Either::Left(info) => EitherFuture::First(self.0.upgrade_inbound(sock, info)), + Either::Right(info) => EitherFuture::Second(self.1.upgrade_inbound(sock, info)), + } + } +} + +impl OutboundConnectionUpgrade for SelectMuxerUpgrade +where + A: OutboundConnectionUpgrade, + B: OutboundConnectionUpgrade, +{ + type Output = future::Either; + type Error = Either; + type Future = EitherFuture; + + fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future { + match info { + Either::Left(info) => EitherFuture::First(self.0.upgrade_outbound(sock, info)), + Either::Right(info) => EitherFuture::Second(self.1.upgrade_outbound(sock, info)), + } + } +} diff --git a/libp2p/src/builder/select_security.rs b/libp2p/src/builder/select_security.rs index 91dbae869c6..4bae959b28b 100644 --- a/libp2p/src/builder/select_security.rs +++ b/libp2p/src/builder/select_security.rs @@ -23,7 +23,7 @@ use either::Either; use futures::future::MapOk; use futures::{future, TryFutureExt}; use libp2p_core::either::EitherFuture; -use libp2p_core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeInfo}; use libp2p_identity::PeerId; use std::iter::{Chain, Map}; @@ -70,10 +70,10 @@ where } } -impl InboundUpgrade for SelectSecurityUpgrade +impl InboundConnectionUpgrade for SelectSecurityUpgrade where - A: InboundUpgrade, - B: InboundUpgrade, + A: InboundConnectionUpgrade, + B: InboundConnectionUpgrade, { type Output = (PeerId, future::Either); type Error = Either; @@ -91,10 +91,10 @@ where } } -impl OutboundUpgrade for SelectSecurityUpgrade +impl OutboundConnectionUpgrade for SelectSecurityUpgrade where - A: OutboundUpgrade, - B: OutboundUpgrade, + A: OutboundConnectionUpgrade, + B: OutboundConnectionUpgrade, { type Output = (PeerId, future::Either); type Error = Either; diff --git a/misc/allow-block-list/src/lib.rs b/misc/allow-block-list/src/lib.rs index 1950c47f28b..8f8892b7810 100644 --- a/misc/allow-block-list/src/lib.rs +++ b/misc/allow-block-list/src/lib.rs @@ -64,8 +64,8 @@ use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ - dummy, CloseConnection, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, - PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + dummy, CloseConnection, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::collections::{HashSet, VecDeque}; use std::fmt; @@ -261,7 +261,6 @@ where fn poll( &mut self, cx: &mut Context<'_>, - _: &mut impl PollParameters, ) -> Poll>> { if let Some(peer) = self.close_connections.pop_front() { return Poll::Ready(ToSwarm::CloseConnection { diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index 472d12f93b6..f58e880cf91 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -22,8 +22,8 @@ use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ behaviour::{ConnectionEstablished, DialFailure, ListenFailure}, - dummy, ConnectionClosed, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, - PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + dummy, ConnectionClosed, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::collections::{HashMap, HashSet}; use std::fmt; @@ -364,11 +364,7 @@ impl NetworkBehaviour for Behaviour { void::unreachable(event) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { Poll::Pending } } @@ -600,8 +596,7 @@ mod tests { fn poll( &mut self, - _cx: &mut Context<'_>, - _params: &mut impl PollParameters, + _: &mut Context<'_>, ) -> Poll>> { Poll::Pending } diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index 91092d9920e..028a0cf3478 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -13,7 +13,7 @@ publish = false release = false [dependencies] -clap = { version = "4.3.23", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive"] } zeroize = "1" serde = { version = "1.0.189", features = ["derive"] } serde_json = "1.0.107" diff --git a/misc/memory-connection-limits/src/lib.rs b/misc/memory-connection-limits/src/lib.rs index 36f0d1648d7..b1e68d80083 100644 --- a/misc/memory-connection-limits/src/lib.rs +++ b/misc/memory-connection-limits/src/lib.rs @@ -21,8 +21,8 @@ use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ - dummy, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, PollParameters, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + dummy, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use void::Void; @@ -192,11 +192,7 @@ impl NetworkBehaviour for Behaviour { void::unreachable(event) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { Poll::Pending } } diff --git a/misc/memory-connection-limits/tests/util.rs b/misc/memory-connection-limits/tests/util.rs index a2fd7c20fed..8d9d73af187 100644 --- a/misc/memory-connection-limits/tests/util.rs +++ b/misc/memory-connection-limits/tests/util.rs @@ -23,8 +23,8 @@ use std::task::{Context, Poll}; use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ - dummy, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, PollParameters, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + dummy, ConnectionDenied, ConnectionId, FromSwarm, NetworkBehaviour, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use void::Void; @@ -118,11 +118,7 @@ impl NetworkBehaviour void::unreachable(event) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { Poll::Pending } } diff --git a/misc/server/Cargo.toml b/misc/server/Cargo.toml index a0e3883f1b5..4450be60217 100644 --- a/misc/server/Cargo.toml +++ b/misc/server/Cargo.toml @@ -12,7 +12,7 @@ license = "MIT" [dependencies] base64 = "0.21" -clap = { version = "4.3.12", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive"] } env_logger = "0.10.0" futures = "0.3" futures-timer = "3" diff --git a/misc/server/Dockerfile b/misc/server/Dockerfile index 90e504f4b11..9d2742f97e8 100644 --- a/misc/server/Dockerfile +++ b/misc/server/Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.5-labs -FROM rust:1.67.0 as chef +FROM rust:1.73.0 as chef RUN wget -q -O- https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-gnu.tar.gz | tar -zx -C /usr/local/bin RUN cargo install --locked --root /usr/local libp2p-lookup --version 0.6.4 WORKDIR /app diff --git a/misc/webrtc-utils/src/noise.rs b/misc/webrtc-utils/src/noise.rs index 023766bc1df..ac2e58c9163 100644 --- a/misc/webrtc-utils/src/noise.rs +++ b/misc/webrtc-utils/src/noise.rs @@ -19,7 +19,8 @@ // DEALINGS IN THE SOFTWARE. use futures::{AsyncRead, AsyncWrite, AsyncWriteExt}; -use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; +use libp2p_core::UpgradeInfo; use libp2p_identity as identity; use libp2p_identity::PeerId; use libp2p_noise as noise; diff --git a/muxers/mplex/CHANGELOG.md b/muxers/mplex/CHANGELOG.md index 8cee61ced6e..1e50042e08a 100644 --- a/muxers/mplex/CHANGELOG.md +++ b/muxers/mplex/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.41.0 - unreleased +- Migrate to `{In,Out}boundConnectionUpgrade` traits. + See [PR 4695](https://github.com/libp2p/rust-libp2p/pull/4695). ## 0.40.0 diff --git a/muxers/mplex/src/lib.rs b/muxers/mplex/src/lib.rs index 81c5147af69..c67e0e3baec 100644 --- a/muxers/mplex/src/lib.rs +++ b/muxers/mplex/src/lib.rs @@ -32,7 +32,7 @@ use bytes::Bytes; use codec::LocalStreamId; use futures::{future, prelude::*, ready}; use libp2p_core::muxing::{StreamMuxer, StreamMuxerEvent}; -use libp2p_core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeInfo}; use parking_lot::Mutex; use std::{cmp, iter, pin::Pin, sync::Arc, task::Context, task::Poll}; @@ -45,7 +45,7 @@ impl UpgradeInfo for MplexConfig { } } -impl InboundUpgrade for MplexConfig +impl InboundConnectionUpgrade for MplexConfig where C: AsyncRead + AsyncWrite + Unpin, { @@ -61,7 +61,7 @@ where } } -impl OutboundUpgrade for MplexConfig +impl OutboundConnectionUpgrade for MplexConfig where C: AsyncRead + AsyncWrite + Unpin, { diff --git a/muxers/test-harness/src/lib.rs b/muxers/test-harness/src/lib.rs index 544e057c108..233fe3a478c 100644 --- a/muxers/test-harness/src/lib.rs +++ b/muxers/test-harness/src/lib.rs @@ -3,7 +3,8 @@ use futures::{future, AsyncRead, AsyncWrite}; use futures::{AsyncReadExt, Stream}; use futures::{AsyncWriteExt, StreamExt}; use libp2p_core::muxing::StreamMuxerExt; -use libp2p_core::{InboundUpgrade, OutboundUpgrade, StreamMuxer, UpgradeInfo}; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; +use libp2p_core::{StreamMuxer, UpgradeInfo}; use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; @@ -12,15 +13,15 @@ use std::{fmt, mem}; pub async fn connected_muxers_on_memory_ring_buffer() -> (M, M) where - MC: InboundUpgrade - + OutboundUpgrade + MC: InboundConnectionUpgrade + + OutboundConnectionUpgrade + Send + 'static + Default, ::Info: Send, <::InfoIter as IntoIterator>::IntoIter: Send, - >::Future: Send, - >::Future: Send, + >::Future: Send, + >::Future: Send, E: std::error::Error + Send + Sync + 'static, { let (alice, bob) = futures_ringbuf::Endpoint::pair(100, 100); diff --git a/muxers/yamux/CHANGELOG.md b/muxers/yamux/CHANGELOG.md index af761d76fe0..d9925596bad 100644 --- a/muxers/yamux/CHANGELOG.md +++ b/muxers/yamux/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.45.0 - unreleased +- Migrate to `{In,Out}boundConnectionUpgrade` traits. + See [PR 4695](https://github.com/libp2p/rust-libp2p/pull/4695). ## 0.44.1 diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index 12e5dd8c1ff..073a5723d2e 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -24,7 +24,7 @@ use futures::{future, prelude::*, ready}; use libp2p_core::muxing::{StreamMuxer, StreamMuxerEvent}; -use libp2p_core::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade, UpgradeInfo}; use std::collections::VecDeque; use std::io::{IoSlice, IoSliceMut}; use std::task::Waker; @@ -311,7 +311,7 @@ impl UpgradeInfo for Config { } } -impl InboundUpgrade for Config +impl InboundConnectionUpgrade for Config where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { @@ -325,7 +325,7 @@ where } } -impl OutboundUpgrade for Config +impl OutboundConnectionUpgrade for Config where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { diff --git a/protocols/autonat/src/behaviour.rs b/protocols/autonat/src/behaviour.rs index 439543f8318..e0e311e3666 100644 --- a/protocols/autonat/src/behaviour.rs +++ b/protocols/autonat/src/behaviour.rs @@ -40,7 +40,7 @@ use libp2p_swarm::{ ExternalAddrExpired, FromSwarm, }, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, NewExternalAddrCandidate, - PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::{ collections::{HashMap, HashSet, VecDeque}, @@ -435,13 +435,16 @@ impl NetworkBehaviour for Behaviour { as NetworkBehaviour>::ConnectionHandler; type ToSwarm = Event; - fn poll(&mut self, cx: &mut Context<'_>, params: &mut impl PollParameters) -> Poll { + fn poll( + &mut self, + cx: &mut Context<'_>, + ) -> Poll>> { loop { if let Some(event) = self.pending_actions.pop_front() { return Poll::Ready(event); } - match self.inner.poll(cx, params) { + match self.inner.poll(cx) { Poll::Ready(ToSwarm::GenerateEvent(event)) => { let actions = match event { request_response::Event::Message { @@ -449,14 +452,14 @@ impl NetworkBehaviour for Behaviour { .. } | request_response::Event::OutboundFailure { .. } => { - self.as_client().handle_event(params, event) + self.as_client().handle_event(event) } request_response::Event::Message { message: request_response::Message::Request { .. }, .. } | request_response::Event::InboundFailure { .. } => { - self.as_server().handle_event(params, event) + self.as_server().handle_event(event) } request_response::Event::ResponseSent { .. } => VecDeque::new(), }; @@ -609,7 +612,6 @@ type Action = ToSwarm<::ToSwarm, THandlerInEvent< trait HandleInnerEvent { fn handle_event( &mut self, - params: &mut impl PollParameters, event: request_response::Event, ) -> VecDeque; } diff --git a/protocols/autonat/src/behaviour/as_client.rs b/protocols/autonat/src/behaviour/as_client.rs index e57523afaf8..45608ea98fd 100644 --- a/protocols/autonat/src/behaviour/as_client.rs +++ b/protocols/autonat/src/behaviour/as_client.rs @@ -30,7 +30,7 @@ use instant::Instant; use libp2p_core::Multiaddr; use libp2p_identity::PeerId; use libp2p_request_response::{self as request_response, OutboundFailure, RequestId}; -use libp2p_swarm::{ConnectionId, ListenAddresses, PollParameters, ToSwarm}; +use libp2p_swarm::{ConnectionId, ListenAddresses, ToSwarm}; use rand::{seq::SliceRandom, thread_rng}; use std::{ collections::{HashMap, HashSet, VecDeque}, @@ -101,7 +101,6 @@ pub(crate) struct AsClient<'a> { impl<'a> HandleInnerEvent for AsClient<'a> { fn handle_event( &mut self, - _: &mut impl PollParameters, event: request_response::Event, ) -> VecDeque { match event { diff --git a/protocols/autonat/src/behaviour/as_server.rs b/protocols/autonat/src/behaviour/as_server.rs index 09c70a27e93..b4c67a6a350 100644 --- a/protocols/autonat/src/behaviour/as_server.rs +++ b/protocols/autonat/src/behaviour/as_server.rs @@ -30,7 +30,7 @@ use libp2p_request_response::{ }; use libp2p_swarm::{ dial_opts::{DialOpts, PeerCondition}, - ConnectionId, DialError, PollParameters, ToSwarm, + ConnectionId, DialError, ToSwarm, }; use std::{ collections::{HashMap, HashSet, VecDeque}, @@ -95,7 +95,6 @@ pub(crate) struct AsServer<'a> { impl<'a> HandleInnerEvent for AsServer<'a> { fn handle_event( &mut self, - _params: &mut impl PollParameters, event: request_response::Event, ) -> VecDeque { match event { diff --git a/protocols/autonat/tests/test_server.rs b/protocols/autonat/tests/test_server.rs index 1bb5f624793..c952179d42c 100644 --- a/protocols/autonat/tests/test_server.rs +++ b/protocols/autonat/tests/test_server.rs @@ -305,7 +305,7 @@ async fn test_dial_multiple_addr() { let dial_errors = concurrent_dial_errors.unwrap(); // The concurrent dial might not be fast enough to produce a dial error. - if let Some((addr, _)) = dial_errors.get(0) { + if let Some((addr, _)) = dial_errors.first() { assert_eq!(addr, &dial_addresses[0]); } diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index 1cd82ca1b60..737d8aede70 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -27,7 +27,7 @@ void = "1" [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } -clap = { version = "4.3.23", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive"] } env_logger = "0.10.0" libp2p-dns = { workspace = true, features = ["async-std"] } libp2p-identify = { workspace = true } diff --git a/protocols/dcutr/src/behaviour_impl.rs b/protocols/dcutr/src/behaviour_impl.rs index b420bff81cc..84ed18276d2 100644 --- a/protocols/dcutr/src/behaviour_impl.rs +++ b/protocols/dcutr/src/behaviour_impl.rs @@ -32,8 +32,8 @@ use libp2p_swarm::{ dummy, ConnectionDenied, ConnectionHandler, ConnectionId, THandler, THandlerOutEvent, }; use libp2p_swarm::{ - ExternalAddresses, NetworkBehaviour, NotifyHandler, PollParameters, StreamUpgradeError, - THandlerInEvent, ToSwarm, + ExternalAddresses, NetworkBehaviour, NotifyHandler, StreamUpgradeError, THandlerInEvent, + ToSwarm, }; use std::collections::{HashMap, HashSet, VecDeque}; use std::task::{Context, Poll}; @@ -351,11 +351,7 @@ impl NetworkBehaviour for Behaviour { }; } - fn poll( - &mut self, - _cx: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(event) = self.queued_events.pop_front() { return Poll::Ready(event); } diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index ace2c5cbaf8..522188e92fd 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.1" -thiserror = "1.0.49" +thiserror = "1.0.50" # 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..5f80f63c38e 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -30,8 +30,8 @@ use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm}; use libp2p_swarm::{ - dial_opts::DialOpts, ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, - OneShotHandler, PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + dial_opts::DialOpts, CloseConnection, ConnectionDenied, ConnectionId, NetworkBehaviour, + NotifyHandler, OneShotHandler, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use log::warn; use smallvec::SmallVec; @@ -354,13 +354,21 @@ impl NetworkBehaviour for Floodsub { fn on_connection_handler_event( &mut self, propagation_source: PeerId, - _connection_id: ConnectionId, + connection_id: ConnectionId, event: THandlerOutEvent, ) { // We ignore successful sends or timeouts. let event = match event { - InnerMessage::Rx(event) => event, - InnerMessage::Sent => return, + Ok(InnerMessage::Rx(event)) => event, + Ok(InnerMessage::Sent) => return, + Err(e) => { + log::debug!("Failed to send floodsub message: {e}"); + self.events.push_back(ToSwarm::CloseConnection { + peer_id: propagation_source, + connection: CloseConnection::One(connection_id), + }); + return; + } }; // Update connected peers topics @@ -466,11 +474,7 @@ impl NetworkBehaviour for Floodsub { } } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(event); } diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 69fa36b002f..5c5260b4b13 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -42,8 +42,8 @@ use libp2p_identity::PeerId; use libp2p_swarm::{ behaviour::{AddressChange, ConnectionClosed, ConnectionEstablished, FromSwarm}, dial_opts::DialOpts, - ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, PollParameters, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionId, NetworkBehaviour, NotifyHandler, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use crate::backoff::BackoffStorage; @@ -3416,7 +3416,6 @@ where fn poll( &mut self, cx: &mut Context<'_>, - _: &mut impl PollParameters, ) -> Poll>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(event); @@ -3516,7 +3515,7 @@ fn peer_removed_from_mesh( .get(&peer_id) .expect("To be connected to peer.") .connections - .get(0) + .first() .expect("There should be at least one connection to a peer."); if let Some(topics) = known_topics { diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index 46415288d9b..47410d890ce 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -1413,7 +1413,7 @@ fn test_explicit_peer_reconnects() { .gs_config(config) .create_network(); - let peer = others.get(0).unwrap(); + let peer = others.first().unwrap(); //add peer as explicit peer gs.add_explicit_peer(peer); @@ -1464,7 +1464,7 @@ fn test_handle_graft_explicit_peer() { .explicit(1) .create_network(); - let peer = peers.get(0).unwrap(); + let peer = peers.first().unwrap(); gs.handle_graft(peer, topic_hashes.clone()); diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index c97456826fe..8a3e545a229 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -26,7 +26,7 @@ use libp2p_identity::PublicKey; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}; use libp2p_swarm::{ ConnectionDenied, DialError, ExternalAddresses, ListenAddresses, NetworkBehaviour, - NotifyHandler, PollParameters, StreamUpgradeError, THandlerInEvent, ToSwarm, + NotifyHandler, StreamUpgradeError, THandlerInEvent, ToSwarm, }; use libp2p_swarm::{ConnectionId, THandler, THandlerOutEvent}; use lru::LruCache; @@ -312,11 +312,7 @@ impl NetworkBehaviour for Behaviour { } } - fn poll( - &mut self, - _cx: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(event); } diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index c4b268901f9..4a7829d592a 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, ConnectionHandler, ConnectionId, DialError, ExternalAddresses, - ListenAddresses, NetworkBehaviour, NotifyHandler, PollParameters, StreamProtocol, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + ListenAddresses, NetworkBehaviour, NotifyHandler, StreamProtocol, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use log::{debug, info, warn}; use smallvec::SmallVec; @@ -2406,7 +2406,6 @@ where fn poll( &mut self, cx: &mut Context<'_>, - _: &mut impl PollParameters, ) -> Poll>> { let now = Instant::now(); diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index a8b6a7da1b9..065e878b258 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -22,7 +22,7 @@ libp2p-identity = { workspace = true } log = "0.4.20" rand = "0.8.3" smallvec = "1.11.1" -socket2 = { version = "0.5.4", features = ["all"] } +socket2 = { version = "0.5.5", features = ["all"] } tokio = { version = "1.33", default-features = false, features = ["net", "time"], optional = true} trust-dns-proto = { version = "0.23.0", default-features = false, features = ["mdns"] } void = "1.0.2" diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index 9e937272e8c..bda0910c45c 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -32,8 +32,8 @@ use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::behaviour::FromSwarm; use libp2p_swarm::{ - dummy, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, PollParameters, - THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + dummy, ConnectionDenied, ConnectionId, ListenAddresses, NetworkBehaviour, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use smallvec::SmallVec; use std::collections::hash_map::{Entry, HashMap}; @@ -285,7 +285,6 @@ where fn poll( &mut self, cx: &mut Context<'_>, - _: &mut impl PollParameters, ) -> Poll>> { // Poll ifwatch. while let Poll::Ready(Some(event)) = Pin::new(&mut self.if_watch).poll_next(cx) { diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index 3a40b0de25d..ddf95a33867 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] anyhow = "1" async-trait = "0.1" -clap = { version = "4.3.23", features = ["derive"] } +clap = { version = "4.4.6", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" instant = "0.1.12" diff --git a/protocols/perf/src/client.rs b/protocols/perf/src/client.rs index 6ef671a429a..52388820be4 100644 --- a/protocols/perf/src/client.rs +++ b/protocols/perf/src/client.rs @@ -30,7 +30,7 @@ use libp2p_identity::PeerId; use libp2p_request_response as request_response; use libp2p_swarm::{ derive_prelude::ConnectionEstablished, ConnectionClosed, ConnectionId, FromSwarm, - NetworkBehaviour, PollParameters, THandlerInEvent, THandlerOutEvent, ToSwarm, + NetworkBehaviour, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use crate::{protocol::Response, RunDuration, RunParams}; @@ -199,9 +199,8 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { - self.request_response.poll(cx, params).map(|to_swarm| { + self.request_response.poll(cx).map(|to_swarm| { to_swarm.map_out(|m| match m { request_response::Event::Message { peer: _, diff --git a/protocols/perf/src/server.rs b/protocols/perf/src/server.rs index ea361755ec3..60fa252de1a 100644 --- a/protocols/perf/src/server.rs +++ b/protocols/perf/src/server.rs @@ -25,8 +25,7 @@ use libp2p_core::Multiaddr; use libp2p_identity::PeerId; use libp2p_request_response as request_response; use libp2p_swarm::{ - ConnectionId, FromSwarm, NetworkBehaviour, PollParameters, THandlerInEvent, THandlerOutEvent, - ToSwarm, + ConnectionId, FromSwarm, NetworkBehaviour, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use crate::protocol::Response; @@ -134,9 +133,8 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { - self.request_response.poll(cx, params).map(|to_swarm| { + self.request_response.poll(cx).map(|to_swarm| { to_swarm.map_out(|m| match m { request_response::Event::Message { peer: _, diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index d1c4a2facaf..b25adad9e4e 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -54,8 +54,8 @@ use handler::Handler; use libp2p_core::{Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ - behaviour::FromSwarm, ConnectionDenied, ConnectionId, NetworkBehaviour, PollParameters, - THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + behaviour::FromSwarm, ConnectionDenied, ConnectionId, NetworkBehaviour, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::time::Duration; use std::{ @@ -141,11 +141,7 @@ impl NetworkBehaviour for Behaviour { }) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(e) = self.events.pop_back() { Poll::Ready(ToSwarm::GenerateEvent(e)) } else { diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 9e49b9cea08..7de9cfced88 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -34,7 +34,7 @@ use libp2p_identity::PeerId; use libp2p_swarm::behaviour::{ConnectionClosed, FromSwarm}; use libp2p_swarm::{ dummy, ConnectionDenied, ConnectionId, ExternalAddresses, NetworkBehaviour, NotifyHandler, - PollParameters, StreamUpgradeError, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + StreamUpgradeError, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::collections::{hash_map, HashMap, HashSet, VecDeque}; use std::num::NonZeroU32; @@ -689,11 +689,7 @@ impl NetworkBehaviour for Behaviour { } } - fn poll( - &mut self, - _cx: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(to_swarm) = self.queued_actions.pop_front() { return Poll::Ready(to_swarm); } diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index d4f0c07cae3..770f552cb79 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -40,8 +40,8 @@ use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, FromSwarm use libp2p_swarm::dial_opts::DialOpts; use libp2p_swarm::{ dummy, ConnectionDenied, ConnectionHandler, ConnectionId, DialFailure, NetworkBehaviour, - NotifyHandler, PollParameters, Stream, StreamUpgradeError, THandler, THandlerInEvent, - THandlerOutEvent, ToSwarm, + NotifyHandler, Stream, StreamUpgradeError, THandler, THandlerInEvent, THandlerOutEvent, + ToSwarm, }; use std::collections::{hash_map, HashMap, VecDeque}; use std::io::{Error, ErrorKind, IoSlice}; @@ -287,7 +287,6 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - _poll_parameters: &mut impl PollParameters, ) -> Poll>> { if let Some(action) = self.queued_actions.pop_front() { return Poll::Ready(action); @@ -302,7 +301,7 @@ impl NetworkBehaviour for Behaviour { match self .directly_connected_peers .get(&relay_peer_id) - .and_then(|cs| cs.get(0)) + .and_then(|cs| cs.first()) { Some(connection_id) => ToSwarm::NotifyHandler { peer_id: relay_peer_id, @@ -332,7 +331,7 @@ impl NetworkBehaviour for Behaviour { match self .directly_connected_peers .get(&relay_peer_id) - .and_then(|cs| cs.get(0)) + .and_then(|cs| cs.first()) { Some(connection_id) => ToSwarm::NotifyHandler { peer_id: relay_peer_id, diff --git a/protocols/rendezvous/src/client.rs b/protocols/rendezvous/src/client.rs index 8459dc21c7e..876ced1ee96 100644 --- a/protocols/rendezvous/src/client.rs +++ b/protocols/rendezvous/src/client.rs @@ -28,8 +28,8 @@ use libp2p_core::{Endpoint, Multiaddr, PeerRecord}; use libp2p_identity::{Keypair, PeerId, SigningError}; use libp2p_request_response::{ProtocolSupport, RequestId}; use libp2p_swarm::{ - ConnectionDenied, ConnectionId, ExternalAddresses, FromSwarm, NetworkBehaviour, PollParameters, - THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionId, ExternalAddresses, FromSwarm, NetworkBehaviour, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use std::collections::HashMap; use std::iter; @@ -241,12 +241,11 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { use libp2p_request_response as req_res; loop { - match self.inner.poll(cx, params) { + match self.inner.poll(cx) { Poll::Ready(ToSwarm::GenerateEvent(req_res::Event::Message { message: req_res::Message::Response { diff --git a/protocols/rendezvous/src/server.rs b/protocols/rendezvous/src/server.rs index 44f2f97a6a0..2e2e4c0ee1d 100644 --- a/protocols/rendezvous/src/server.rs +++ b/protocols/rendezvous/src/server.rs @@ -29,8 +29,8 @@ use libp2p_identity::PeerId; use libp2p_request_response::ProtocolSupport; use libp2p_swarm::behaviour::FromSwarm; use libp2p_swarm::{ - ConnectionDenied, ConnectionId, NetworkBehaviour, PollParameters, THandler, THandlerInEvent, - THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionId, NetworkBehaviour, THandler, THandlerInEvent, THandlerOutEvent, + ToSwarm, }; use std::collections::{HashMap, HashSet}; use std::iter; @@ -158,7 +158,6 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { if let Poll::Ready(ExpiredRegistration(registration)) = self.registrations.poll(cx) { return Poll::Ready(ToSwarm::GenerateEvent(Event::RegistrationExpired( @@ -167,7 +166,7 @@ impl NetworkBehaviour for Behaviour { } loop { - if let Poll::Ready(to_swarm) = self.inner.poll(cx, params) { + if let Poll::Ready(to_swarm) = self.inner.poll(cx) { match to_swarm { ToSwarm::GenerateEvent(libp2p_request_response::Event::Message { peer: peer_id, diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 6503460f672..db6859dd244 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -84,8 +84,8 @@ use libp2p_identity::PeerId; use libp2p_swarm::{ behaviour::{AddressChange, ConnectionClosed, DialFailure, FromSwarm}, dial_opts::DialOpts, - ConnectionDenied, ConnectionHandler, ConnectionId, NetworkBehaviour, NotifyHandler, - PollParameters, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionHandler, ConnectionId, NetworkBehaviour, NotifyHandler, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use smallvec::SmallVec; use std::{ @@ -897,11 +897,7 @@ where } } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(ev) = self.pending_events.pop_front() { return Poll::Ready(ev); } else if self.pending_events.capacity() > EMPTY_QUEUE_SHRINK_THRESHOLD { diff --git a/protocols/upnp/src/behaviour.rs b/protocols/upnp/src/behaviour.rs index 45b82edc562..cd153020f63 100644 --- a/protocols/upnp/src/behaviour.rs +++ b/protocols/upnp/src/behaviour.rs @@ -39,7 +39,7 @@ use igd_next::PortMappingProtocol; use libp2p_core::{multiaddr, transport::ListenerId, Endpoint, Multiaddr}; use libp2p_swarm::{ derive_prelude::PeerId, dummy, ConnectionDenied, ConnectionId, ExpiredListenAddr, FromSwarm, - NetworkBehaviour, NewListenAddr, PollParameters, ToSwarm, + NetworkBehaviour, NewListenAddr, ToSwarm, }; /// The duration in seconds of a port mapping on the gateway. @@ -370,7 +370,6 @@ impl NetworkBehaviour for Behaviour { fn poll( &mut self, cx: &mut Context<'_>, - _params: &mut impl PollParameters, ) -> Poll>> { // If there are pending addresses to be emitted we emit them. if let Some(event) = self.pending_events.pop_front() { diff --git a/swarm-derive/src/lib.rs b/swarm-derive/src/lib.rs index e54cd058daf..02f2df037c0 100644 --- a/swarm-derive/src/lib.rs +++ b/swarm-derive/src/lib.rs @@ -72,7 +72,6 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result syn::Result { return std::task::Poll::Ready(#network_behaviour_action::Dial { opts }); @@ -836,7 +835,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> syn::Result std::task::Poll<#network_behaviour_action>> { + fn poll(&mut self, cx: &mut std::task::Context) -> std::task::Poll<#network_behaviour_action>> { use #prelude_path::futures::*; #(#poll_stmts)* std::task::Poll::Pending diff --git a/swarm-test/Cargo.toml b/swarm-test/Cargo.toml index cad7c98affd..df2444827b9 100644 --- a/swarm-test/Cargo.toml +++ b/swarm-test/Cargo.toml @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -async-trait = "0.1.73" +async-trait = "0.1.74" libp2p-core = { workspace = true } libp2p-identity = { workspace = true, features = ["rand"] } libp2p-plaintext = { workspace = true } diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 53a6220f8d4..36c76bcdc2b 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,11 +1,16 @@ ## 0.44.0 - unreleased +- Remove deprecated `PollParameters` from `NetworkBehaviour::poll` function. + See [PR 4490](https://github.com/libp2p/rust-libp2p/pull/4490). - Add `PeerCondition::DisconnectedAndNotDialing` variant, combining pre-existing conditions. This is the new default. A new dialing attempt is iniated _only if_ the peer is both considered disconnected and there is currently no ongoing dialing attempt. See [PR 4225](https://github.com/libp2p/rust-libp2p/pull/4225). - Remove deprecated `keep_alive_timeout` in `OneShotHandlerConfig`. See [PR 4677](https://github.com/libp2p/rust-libp2p/pull/4677). +- Don't close entire connection upon `DialUpgradeError`s within `OneShotHandler`. + Instead, the error is reported as `Err(e)` via `ConnectionHandler::ToBehaviour`. + See [PR 4715](https://github.com/libp2p/rust-libp2p/pull/4715). ## 0.43.6 diff --git a/swarm/src/behaviour.rs b/swarm/src/behaviour.rs index 3662bf5c48d..4866b9cc29e 100644 --- a/swarm/src/behaviour.rs +++ b/swarm/src/behaviour.rs @@ -209,28 +209,8 @@ pub trait NetworkBehaviour: 'static { /// /// This API mimics the API of the `Stream` trait. The method may register the current task in /// order to wake it up at a later point in time. - fn poll( - &mut self, - cx: &mut Context<'_>, - params: &mut impl PollParameters, - ) -> Poll>>; -} - -/// Parameters passed to `poll()`, that the `NetworkBehaviour` has access to. -pub trait PollParameters { - /// Iterator returned by [`supported_protocols`](PollParameters::supported_protocols). - type SupportedProtocolsIter: ExactSizeIterator>; - - /// Returns the list of protocol the behaviour supports when a remote negotiates a protocol on - /// an inbound substream. - /// - /// The iterator's elements are the ASCII names as reported on the wire. - /// - /// Note that the list is computed once at initialization and never refreshed. - #[deprecated( - note = "Use `libp2p_swarm::SupportedProtocols` in your `ConnectionHandler` instead." - )] - fn supported_protocols(&self) -> Self::SupportedProtocolsIter; + fn poll(&mut self, cx: &mut Context<'_>) + -> Poll>>; } /// A command issued from a [`NetworkBehaviour`] for the [`Swarm`]. diff --git a/swarm/src/behaviour/either.rs b/swarm/src/behaviour/either.rs index c6e0870d11c..0e92c54aaf6 100644 --- a/swarm/src/behaviour/either.rs +++ b/swarm/src/behaviour/either.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::behaviour::{self, NetworkBehaviour, PollParameters, ToSwarm}; +use crate::behaviour::{self, NetworkBehaviour, ToSwarm}; use crate::connection::ConnectionId; use crate::{ConnectionDenied, THandler, THandlerInEvent, THandlerOutEvent}; use either::Either; @@ -155,13 +155,12 @@ where fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { let event = match self { - Either::Left(behaviour) => futures::ready!(behaviour.poll(cx, params)) + Either::Left(behaviour) => futures::ready!(behaviour.poll(cx)) .map_out(Either::Left) .map_in(Either::Left), - Either::Right(behaviour) => futures::ready!(behaviour.poll(cx, params)) + Either::Right(behaviour) => futures::ready!(behaviour.poll(cx)) .map_out(Either::Right) .map_in(Either::Right), }; diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index 92bd8963502..4f4f9585f0e 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -27,8 +27,7 @@ use crate::handler::{ }; use crate::upgrade::SendWrapper; use crate::{ - ConnectionDenied, NetworkBehaviour, PollParameters, THandler, THandlerInEvent, - THandlerOutEvent, ToSwarm, + ConnectionDenied, NetworkBehaviour, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, }; use either::Either; use futures::future; @@ -181,10 +180,9 @@ where fn poll( &mut self, cx: &mut Context<'_>, - params: &mut impl PollParameters, ) -> Poll>> { if let Some(inner) = self.inner.as_mut() { - inner.poll(cx, params) + inner.poll(cx) } else { Poll::Pending } diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index 6810abec591..067c9788e4d 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -1,4 +1,4 @@ -use crate::behaviour::{FromSwarm, NetworkBehaviour, PollParameters, ToSwarm}; +use crate::behaviour::{FromSwarm, NetworkBehaviour, ToSwarm}; use crate::connection::ConnectionId; use crate::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, @@ -50,11 +50,7 @@ impl NetworkBehaviour for Behaviour { void::unreachable(event) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { Poll::Pending } diff --git a/swarm/src/handler/one_shot.rs b/swarm/src/handler/one_shot.rs index 7f422cfa7d0..68854bdcaa3 100644 --- a/swarm/src/handler/one_shot.rs +++ b/swarm/src/handler/one_shot.rs @@ -20,10 +20,10 @@ use crate::handler::{ ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent, DialUpgradeError, - FullyNegotiatedInbound, FullyNegotiatedOutbound, KeepAlive, StreamUpgradeError, - SubstreamProtocol, + FullyNegotiatedInbound, FullyNegotiatedOutbound, KeepAlive, SubstreamProtocol, }; use crate::upgrade::{InboundUpgradeSend, OutboundUpgradeSend}; +use crate::StreamUpgradeError; use smallvec::SmallVec; use std::{error, fmt::Debug, task::Context, task::Poll, time::Duration}; @@ -35,10 +35,8 @@ where { /// The upgrade for inbound substreams. listen_protocol: SubstreamProtocol, - /// If `Some`, something bad happened and we should shut down the handler with an error. - pending_error: Option::Error>>, /// Queue of events to produce in `poll()`. - events_out: SmallVec<[TEvent; 4]>, + events_out: SmallVec<[Result>; 4]>, /// Queue of outbound substreams to open. dial_queue: SmallVec<[TOutbound; 4]>, /// Current number of concurrent outbound substreams being opened. @@ -60,7 +58,6 @@ where ) -> Self { OneShotHandler { listen_protocol, - pending_error: None, events_out: SmallVec::new(), dial_queue: SmallVec::new(), dial_negotiated: 0, @@ -121,8 +118,8 @@ where TEvent: Debug + Send + 'static, { type FromBehaviour = TOutbound; - type ToBehaviour = TEvent; - type Error = StreamUpgradeError<::Error>; + type ToBehaviour = Result>; + type Error = void::Void; type InboundProtocol = TInbound; type OutboundProtocol = TOutbound; type OutboundOpenInfo = (); @@ -151,10 +148,6 @@ where Self::Error, >, > { - if let Some(err) = self.pending_error.take() { - return Poll::Ready(ConnectionHandlerEvent::Close(err)); - } - if !self.events_out.is_empty() { return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour( self.events_out.remove(0), @@ -197,20 +190,17 @@ where protocol: out, .. }) => { - self.events_out.push(out.into()); + self.events_out.push(Ok(out.into())); } ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { protocol: out, .. }) => { self.dial_negotiated -= 1; - self.events_out.push(out.into()); + self.events_out.push(Ok(out.into())); } ConnectionEvent::DialUpgradeError(DialUpgradeError { error, .. }) => { - if self.pending_error.is_none() { - log::debug!("DialUpgradeError: {error}"); - self.keep_alive = KeepAlive::No; - } + self.events_out.push(Err(error)); } ConnectionEvent::AddressChange(_) | ConnectionEvent::ListenUpgradeError(_) diff --git a/swarm/src/keep_alive.rs b/swarm/src/keep_alive.rs index 05cbcdf7b8c..deae4bf9bb3 100644 --- a/swarm/src/keep_alive.rs +++ b/swarm/src/keep_alive.rs @@ -1,4 +1,4 @@ -use crate::behaviour::{FromSwarm, NetworkBehaviour, PollParameters, ToSwarm}; +use crate::behaviour::{FromSwarm, NetworkBehaviour, ToSwarm}; use crate::connection::ConnectionId; use crate::handler::{ ConnectionEvent, ConnectionHandlerEvent, FullyNegotiatedInbound, FullyNegotiatedOutbound, @@ -53,11 +53,7 @@ impl NetworkBehaviour for Behaviour { void::unreachable(event) } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { Poll::Pending } diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index e0bcfccfa56..08d981eaf9a 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -96,7 +96,6 @@ pub mod derive_prelude { pub use crate::ConnectionHandlerSelect; pub use crate::DialError; pub use crate::NetworkBehaviour; - pub use crate::PollParameters; pub use crate::THandler; pub use crate::THandlerInEvent; pub use crate::THandlerOutEvent; @@ -114,7 +113,7 @@ pub use behaviour::{ AddressChange, CloseConnection, ConnectionClosed, DialFailure, ExpiredListenAddr, ExternalAddrExpired, ExternalAddresses, FromSwarm, ListenAddresses, ListenFailure, ListenerClosed, ListenerError, NetworkBehaviour, NewExternalAddrCandidate, NewListenAddr, - NotifyHandler, PollParameters, ToSwarm, + NotifyHandler, ToSwarm, }; pub use connection::pool::ConnectionCounters; pub use connection::{ConnectionError, ConnectionId, SupportedProtocols}; @@ -1192,26 +1191,16 @@ where } }, // No pending event. Allow the [`NetworkBehaviour`] to make progress. - None => { - let behaviour_poll = { - let mut parameters = SwarmPollParameters { - supported_protocols: &this.supported_protocols, - }; - this.behaviour.poll(cx, &mut parameters) - }; - - match behaviour_poll { - Poll::Pending => {} - Poll::Ready(behaviour_event) => { - if let Some(swarm_event) = this.handle_behaviour_event(behaviour_event) - { - return Poll::Ready(swarm_event); - } - - continue; + None => match this.behaviour.poll(cx) { + Poll::Pending => {} + Poll::Ready(behaviour_event) => { + if let Some(swarm_event) = this.handle_behaviour_event(behaviour_event) { + return Poll::Ready(swarm_event); } + + continue; } - } + }, } // Poll the known peers. @@ -1357,20 +1346,6 @@ where } } -/// Parameters passed to `poll()`, that the `NetworkBehaviour` has access to. -// TODO: #[derive(Debug)] -pub struct SwarmPollParameters<'a> { - supported_protocols: &'a [Vec], -} - -impl<'a> PollParameters for SwarmPollParameters<'a> { - type SupportedProtocolsIter = std::iter::Cloned>>; - - fn supported_protocols(&self) -> Self::SupportedProtocolsIter { - self.supported_protocols.iter().cloned() - } -} - pub struct Config { pool_config: PoolConfig, } diff --git a/swarm/src/test.rs b/swarm/src/test.rs index 6f39d56da91..a4520545998 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -23,8 +23,8 @@ use crate::behaviour::{ FromSwarm, ListenerClosed, ListenerError, NewExternalAddrCandidate, NewListenAddr, NewListener, }; use crate::{ - ConnectionDenied, ConnectionHandler, ConnectionId, NetworkBehaviour, PollParameters, THandler, - THandlerInEvent, THandlerOutEvent, ToSwarm, + ConnectionDenied, ConnectionHandler, ConnectionId, NetworkBehaviour, THandler, THandlerInEvent, + THandlerOutEvent, ToSwarm, }; use libp2p_core::{multiaddr::Multiaddr, transport::ListenerId, ConnectedPoint, Endpoint}; use libp2p_identity::PeerId; @@ -110,11 +110,7 @@ where Ok(self.addresses.get(&p).map_or(Vec::new(), |v| v.clone())) } - fn poll( - &mut self, - _: &mut Context, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { self.next_action.take().map_or(Poll::Pending, Poll::Ready) } @@ -559,10 +555,9 @@ where fn poll( &mut self, - cx: &mut Context, - args: &mut impl PollParameters, + cx: &mut Context<'_>, ) -> Poll>> { self.poll += 1; - self.inner.poll(cx, args) + self.inner.poll(cx) } } diff --git a/swarm/tests/listener.rs b/swarm/tests/listener.rs index 71d92cb0e1f..6faee330ab1 100644 --- a/swarm/tests/listener.rs +++ b/swarm/tests/listener.rs @@ -7,8 +7,8 @@ use libp2p_core::{multiaddr::Protocol, transport::ListenerId, Endpoint, Multiadd use libp2p_identity::PeerId; use libp2p_swarm::{ derive_prelude::NewListener, dummy, ConnectionDenied, ConnectionId, FromSwarm, ListenOpts, - ListenerClosed, ListenerError, NetworkBehaviour, NewListenAddr, PollParameters, Swarm, - SwarmEvent, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm, + ListenerClosed, ListenerError, NetworkBehaviour, NewListenAddr, Swarm, SwarmEvent, THandler, + THandlerInEvent, THandlerOutEvent, ToSwarm, }; use libp2p_swarm_test::SwarmExt; @@ -129,11 +129,7 @@ impl NetworkBehaviour for Behaviour { } } - fn poll( - &mut self, - _: &mut Context<'_>, - _: &mut impl PollParameters, - ) -> Poll>> { + fn poll(&mut self, _: &mut Context<'_>) -> Poll>> { if let Some(event) = self.events.pop_front() { return Poll::Ready(event); } diff --git a/swarm/tests/swarm_derive.rs b/swarm/tests/swarm_derive.rs index d0680591621..5782d0a92b3 100644 --- a/swarm/tests/swarm_derive.rs +++ b/swarm/tests/swarm_derive.rs @@ -457,7 +457,7 @@ fn multiple_behaviour_attributes() { #[test] fn custom_out_event_no_type_parameters() { use libp2p_identity::PeerId; - use libp2p_swarm::{ConnectionId, PollParameters, ToSwarm}; + use libp2p_swarm::{ConnectionId, ToSwarm}; use std::task::Context; use std::task::Poll; @@ -500,8 +500,7 @@ fn custom_out_event_no_type_parameters() { fn poll( &mut self, - _ctx: &mut Context, - _: &mut impl PollParameters, + _: &mut Context<'_>, ) -> Poll>> { Poll::Pending } diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index 535cc240503..1a5ce33e033 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -async-trait = "0.1.72" +async-trait = "0.1.74" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } log = "0.4.20" diff --git a/transports/noise/CHANGELOG.md b/transports/noise/CHANGELOG.md index c7f0308754a..e53d3a1077e 100644 --- a/transports/noise/CHANGELOG.md +++ b/transports/noise/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.44.0 - unreleased +- Migrate to `{In,Out}boundConnectionUpgrade` traits. + See [PR 4695](https://github.com/libp2p/rust-libp2p/pull/4695). ## 0.43.2 diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index 6c20d72213e..82ba697edcf 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.8" static_assertions = "1" -thiserror = "1.0.49" +thiserror = "1.0.50" x25519-dalek = "2" zeroize = "1" diff --git a/transports/noise/src/lib.rs b/transports/noise/src/lib.rs index be73ea3f7f9..485f5d68155 100644 --- a/transports/noise/src/lib.rs +++ b/transports/noise/src/lib.rs @@ -65,7 +65,8 @@ use crate::handshake::State; use crate::io::handshake; use crate::protocol::{noise_params_into_builder, AuthenticKeypair, Keypair, PARAMS_XX}; use futures::prelude::*; -use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; +use libp2p_core::UpgradeInfo; use libp2p_identity as identity; use libp2p_identity::PeerId; use multiaddr::Protocol; @@ -171,7 +172,7 @@ impl UpgradeInfo for Config { } } -impl InboundUpgrade for Config +impl InboundConnectionUpgrade for Config where T: AsyncRead + AsyncWrite + Unpin + Send + 'static, { @@ -195,7 +196,7 @@ where } } -impl OutboundUpgrade for Config +impl OutboundConnectionUpgrade for Config where T: AsyncRead + AsyncWrite + Unpin + Send + 'static, { diff --git a/transports/noise/tests/smoke.rs b/transports/noise/tests/smoke.rs index 6d1723ec7d6..ffcf7934ac0 100644 --- a/transports/noise/tests/smoke.rs +++ b/transports/noise/tests/smoke.rs @@ -20,7 +20,8 @@ use futures::prelude::*; use libp2p_core::transport::{MemoryTransport, Transport}; -use libp2p_core::{upgrade, InboundUpgrade, OutboundUpgrade}; +use libp2p_core::upgrade; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; use libp2p_identity as identity; use libp2p_noise as noise; use log::info; diff --git a/transports/noise/tests/webtransport_certhashes.rs b/transports/noise/tests/webtransport_certhashes.rs index 95ce0bf58db..b3c924f8188 100644 --- a/transports/noise/tests/webtransport_certhashes.rs +++ b/transports/noise/tests/webtransport_certhashes.rs @@ -1,4 +1,4 @@ -use libp2p_core::{InboundUpgrade, OutboundUpgrade}; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; use libp2p_identity as identity; use libp2p_noise as noise; use multihash::Multihash; diff --git a/transports/plaintext/CHANGELOG.md b/transports/plaintext/CHANGELOG.md index 8bb7dfd4809..d9aa850a807 100644 --- a/transports/plaintext/CHANGELOG.md +++ b/transports/plaintext/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.41.0 - unreleased +- Migrate to `{In,Out}boundConnectionUpgrade` traits. + See [PR 4695](https://github.com/libp2p/rust-libp2p/pull/4695). ## 0.40.1 diff --git a/transports/plaintext/src/lib.rs b/transports/plaintext/src/lib.rs index fa7cba6b8ff..1d771f9c143 100644 --- a/transports/plaintext/src/lib.rs +++ b/transports/plaintext/src/lib.rs @@ -27,7 +27,8 @@ use crate::error::Error; use bytes::Bytes; use futures::future::BoxFuture; use futures::prelude::*; -use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; +use libp2p_core::UpgradeInfo; use libp2p_identity as identity; use libp2p_identity::PeerId; use libp2p_identity::PublicKey; @@ -77,7 +78,7 @@ impl UpgradeInfo for Config { } } -impl InboundUpgrade for Config +impl InboundConnectionUpgrade for Config where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { @@ -90,7 +91,7 @@ where } } -impl OutboundUpgrade for Config +impl OutboundConnectionUpgrade for Config where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { diff --git a/transports/plaintext/tests/smoke.rs b/transports/plaintext/tests/smoke.rs index ed18fb44cba..fd3350fb5aa 100644 --- a/transports/plaintext/tests/smoke.rs +++ b/transports/plaintext/tests/smoke.rs @@ -19,7 +19,7 @@ // DEALINGS IN THE SOFTWARE. use futures::io::{AsyncReadExt, AsyncWriteExt}; -use libp2p_core::InboundUpgrade; +use libp2p_core::upgrade::InboundConnectionUpgrade; use libp2p_identity as identity; use libp2p_plaintext as plaintext; use log::debug; diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index ee9e8b8d965..254abf7bb81 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -22,9 +22,9 @@ 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.7", default-features = false } -thiserror = "1.0.49" +thiserror = "1.0.50" tokio = { version = "1.33.0", default-features = false, features = ["net", "rt", "time"], optional = true } -socket2 = "0.5.4" +socket2 = "0.5.5" ring = "0.16.20" [features] diff --git a/transports/quic/src/connection/connecting.rs b/transports/quic/src/connection/connecting.rs index b911eaa7dfe..141f0b5542e 100644 --- a/transports/quic/src/connection/connecting.rs +++ b/transports/quic/src/connection/connecting.rs @@ -58,7 +58,7 @@ impl Connecting { let certificates: Box> = identity.downcast().expect("we rely on rustls feature; qed"); let end_entity = certificates - .get(0) + .first() .expect("there should be exactly one certificate; qed"); let p2p_cert = libp2p_tls::certificate::parse(end_entity) .expect("the certificate was validated during TLS handshake; qed"); diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index fa6e3b73413..33ff21e8d7c 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -19,7 +19,7 @@ libc = "0.2.149" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } log = "0.4.20" -socket2 = { version = "0.5.4", features = ["all"] } +socket2 = { version = "0.5.5", features = ["all"] } tokio = { version = "1.33.0", default-features = false, features = ["net"], optional = true } [features] diff --git a/transports/tls/CHANGELOG.md b/transports/tls/CHANGELOG.md index c34b228f6c7..04793c719f0 100644 --- a/transports/tls/CHANGELOG.md +++ b/transports/tls/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.3.0 - unreleased +- Migrate to `{In,Out}boundConnectionUpgrade` traits. + See [PR 4695](https://github.com/libp2p/rust-libp2p/pull/4695). ## 0.2.1 diff --git a/transports/tls/Cargo.toml b/transports/tls/Cargo.toml index 10124f6cd56..489f12d8ac3 100644 --- a/transports/tls/Cargo.toml +++ b/transports/tls/Cargo.toml @@ -13,9 +13,9 @@ futures = { version = "0.3.28", default-features = false } futures-rustls = "0.24.0" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } -rcgen = "0.10.0" +rcgen = "0.11.0" ring = "0.16.20" -thiserror = "1.0.49" +thiserror = "1.0.50" webpki = { version = "0.101.4", package = "rustls-webpki", features = ["std"] } x509-parser = "0.15.1" yasna = "0.5.2" diff --git a/transports/tls/src/upgrade.rs b/transports/tls/src/upgrade.rs index bf64ce61505..463f2c3a323 100644 --- a/transports/tls/src/upgrade.rs +++ b/transports/tls/src/upgrade.rs @@ -24,7 +24,8 @@ use futures::future::BoxFuture; use futures::AsyncWrite; use futures::{AsyncRead, FutureExt}; use futures_rustls::TlsStream; -use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; +use libp2p_core::upgrade::{InboundConnectionUpgrade, OutboundConnectionUpgrade}; +use libp2p_core::UpgradeInfo; use libp2p_identity as identity; use libp2p_identity::PeerId; use rustls::{CommonState, ServerName}; @@ -67,7 +68,7 @@ impl UpgradeInfo for Config { } } -impl InboundUpgrade for Config +impl InboundConnectionUpgrade for Config where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { @@ -90,7 +91,7 @@ where } } -impl OutboundUpgrade for Config +impl OutboundConnectionUpgrade for Config where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { diff --git a/transports/websocket-websys/Cargo.toml b/transports/websocket-websys/Cargo.toml index 2018df1bf07..c18b03e8a59 100644 --- a/transports/websocket-websys/Cargo.toml +++ b/transports/websocket-websys/Cargo.toml @@ -18,7 +18,7 @@ libp2p-core = { workspace = true } log = "0.4.19" parking_lot = "0.12.1" send_wrapper = "0.6.0" -thiserror = "1.0.38" +thiserror = "1.0.50" wasm-bindgen = "0.2.84" web-sys = { version = "0.3.61", features = ["BinaryType", "CloseEvent", "MessageEvent", "WebSocket", "Window"] } diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 488e93dc835..cf3e9607953 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -18,7 +18,7 @@ libp2p-core = { workspace = true } libp2p-identity = { workspace = true } log = "0.4.20" parking_lot = "0.12.0" -quicksink = "0.1" +pin-project-lite = "0.2.13" rw-stream-sink = { workspace = true } soketto = "0.7.0" url = "2.4" @@ -29,7 +29,7 @@ libp2p-tcp = { workspace = true, features = ["async-io"] } libp2p-dns = { workspace = true, features = ["async-std"] } libp2p-identity = { workspace = true, features = ["rand"] } async-std = { version = "1.6.5", features = ["attributes"] } -rcgen = "0.10.0" +rcgen = "0.11.0" # 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/transports/websocket/src/framed.rs b/transports/websocket/src/framed.rs index fc3f6514f12..07013973fdc 100644 --- a/transports/websocket/src/framed.rs +++ b/transports/websocket/src/framed.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::{error::Error, tls}; +use crate::{error::Error, quicksink, tls}; use either::Either; use futures::{future::BoxFuture, prelude::*, ready, stream::BoxStream}; use futures_rustls::{client, rustls, server}; diff --git a/transports/websocket/src/lib.rs b/transports/websocket/src/lib.rs index d7dd7628888..e0b3d09ca25 100644 --- a/transports/websocket/src/lib.rs +++ b/transports/websocket/src/lib.rs @@ -24,6 +24,7 @@ pub mod error; pub mod framed; +mod quicksink; pub mod tls; use error::Error; diff --git a/transports/websocket/src/quicksink.rs b/transports/websocket/src/quicksink.rs new file mode 100644 index 00000000000..d9edb4dfe0d --- /dev/null +++ b/transports/websocket/src/quicksink.rs @@ -0,0 +1,350 @@ +// Copyright (c) 2019-2020 Parity Technologies (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 +// or the MIT +// license , at your +// option. All files in the project carrying such notice may not be copied, +// modified, or distributed except according to those terms. +// +// Forked into rust-libp2p and further distributed under the MIT license. + +// Create a [`Sink`] implementation from an initial value and a closure +// returning a [`Future`]. +// +// This is very similar to how `futures::stream::unfold` creates a `Stream` +// implementation from a seed value and a future-returning closure. +// +// # Examples +// +// ```no_run +// use async_std::io; +// use futures::prelude::*; +// use crate::quicksink::Action; +// +// crate::quicksink::make_sink(io::stdout(), |mut stdout, action| async move { +// match action { +// Action::Send(x) => stdout.write_all(x).await?, +// Action::Flush => stdout.flush().await?, +// Action::Close => stdout.close().await? +// } +// Ok::<_, io::Error>(stdout) +// }); +// ``` +// +// # Panics +// +// - If any of the [`Sink`] methods produce an error, the sink transitions +// to a failure state and none of its methods must be called afterwards or +// else a panic will occur. +// - If [`Sink::poll_close`] has been called, no other sink method must be +// called afterwards or else a panic will be caused. + +use futures::{ready, sink::Sink}; +use pin_project_lite::pin_project; +use std::{ + future::Future, + pin::Pin, + task::{Context, Poll}, +}; + +/// Returns a `Sink` impl based on the initial value and the given closure. +/// +/// The closure will be applied to the initial value and an [`Action`] that +/// informs it about the action it should perform. The returned [`Future`] +/// will resolve to another value and the process starts over using this +/// output. +pub(crate) fn make_sink(init: S, f: F) -> SinkImpl +where + F: FnMut(S, Action) -> T, + T: Future>, +{ + SinkImpl { + lambda: f, + future: None, + param: Some(init), + state: State::Empty, + _mark: std::marker::PhantomData, + } +} + +/// The command given to the closure so that it can perform appropriate action. +/// +/// Presumably the closure encapsulates a resource to perform I/O. The commands +/// correspond to methods of the [`Sink`] trait and provide the closure with +/// sufficient information to know what kind of action to perform with it. +#[derive(Clone, Debug, PartialEq, Eq)] +pub(crate) enum Action { + /// Send the given value. + /// Corresponds to [`Sink::start_send`]. + Send(A), + /// Flush the resource. + /// Corresponds to [`Sink::poll_flush`]. + Flush, + /// Close the resource. + /// Corresponds to [`Sink::poll_close`]. + Close, +} + +/// The various states the `Sink` may be in. +#[derive(Debug, PartialEq, Eq)] +enum State { + /// The `Sink` is idle. + Empty, + /// The `Sink` is sending a value. + Sending, + /// The `Sink` is flushing its resource. + Flushing, + /// The `Sink` is closing its resource. + Closing, + /// The `Sink` is closed (terminal state). + Closed, + /// The `Sink` experienced an error (terminal state). + Failed, +} + +pin_project! { + /// `SinkImpl` implements the `Sink` trait. + #[derive(Debug)] + pub(crate) struct SinkImpl { + lambda: F, + #[pin] future: Option, + param: Option, + state: State, + _mark: std::marker::PhantomData<(A, E)> + } +} + +impl Sink for SinkImpl +where + F: FnMut(S, Action) -> T, + T: Future>, +{ + type Error = E; + + fn poll_ready(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + let mut this = self.project(); + match this.state { + State::Sending | State::Flushing => { + match ready!(this.future.as_mut().as_pin_mut().unwrap().poll(cx)) { + Ok(p) => { + this.future.set(None); + *this.param = Some(p); + *this.state = State::Empty; + Poll::Ready(Ok(())) + } + Err(e) => { + this.future.set(None); + *this.state = State::Failed; + Poll::Ready(Err(e)) + } + } + } + State::Closing => match ready!(this.future.as_mut().as_pin_mut().unwrap().poll(cx)) { + Ok(_) => { + this.future.set(None); + *this.state = State::Closed; + panic!("SinkImpl::poll_ready called on a closing sink.") + } + Err(e) => { + this.future.set(None); + *this.state = State::Failed; + Poll::Ready(Err(e)) + } + }, + State::Empty => { + assert!(this.param.is_some()); + Poll::Ready(Ok(())) + } + State::Closed => panic!("SinkImpl::poll_ready called on a closed sink."), + State::Failed => panic!("SinkImpl::poll_ready called after error."), + } + } + + fn start_send(self: Pin<&mut Self>, item: A) -> Result<(), Self::Error> { + assert_eq!(State::Empty, self.state); + let mut this = self.project(); + let param = this.param.take().unwrap(); + let future = (this.lambda)(param, Action::Send(item)); + this.future.set(Some(future)); + *this.state = State::Sending; + Ok(()) + } + + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + loop { + let mut this = self.as_mut().project(); + match this.state { + State::Empty => { + if let Some(p) = this.param.take() { + let future = (this.lambda)(p, Action::Flush); + this.future.set(Some(future)); + *this.state = State::Flushing + } else { + return Poll::Ready(Ok(())); + } + } + State::Sending => match ready!(this.future.as_mut().as_pin_mut().unwrap().poll(cx)) + { + Ok(p) => { + this.future.set(None); + *this.param = Some(p); + *this.state = State::Empty + } + Err(e) => { + this.future.set(None); + *this.state = State::Failed; + return Poll::Ready(Err(e)); + } + }, + State::Flushing => { + match ready!(this.future.as_mut().as_pin_mut().unwrap().poll(cx)) { + Ok(p) => { + this.future.set(None); + *this.param = Some(p); + *this.state = State::Empty; + return Poll::Ready(Ok(())); + } + Err(e) => { + this.future.set(None); + *this.state = State::Failed; + return Poll::Ready(Err(e)); + } + } + } + State::Closing => match ready!(this.future.as_mut().as_pin_mut().unwrap().poll(cx)) + { + Ok(_) => { + this.future.set(None); + *this.state = State::Closed; + return Poll::Ready(Ok(())); + } + Err(e) => { + this.future.set(None); + *this.state = State::Failed; + return Poll::Ready(Err(e)); + } + }, + State::Closed => return Poll::Ready(Ok(())), + State::Failed => panic!("SinkImpl::poll_flush called after error."), + } + } + } + + fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + loop { + let mut this = self.as_mut().project(); + match this.state { + State::Empty => { + if let Some(p) = this.param.take() { + let future = (this.lambda)(p, Action::Close); + this.future.set(Some(future)); + *this.state = State::Closing; + } else { + return Poll::Ready(Ok(())); + } + } + State::Sending => match ready!(this.future.as_mut().as_pin_mut().unwrap().poll(cx)) + { + Ok(p) => { + this.future.set(None); + *this.param = Some(p); + *this.state = State::Empty + } + Err(e) => { + this.future.set(None); + *this.state = State::Failed; + return Poll::Ready(Err(e)); + } + }, + State::Flushing => { + match ready!(this.future.as_mut().as_pin_mut().unwrap().poll(cx)) { + Ok(p) => { + this.future.set(None); + *this.param = Some(p); + *this.state = State::Empty + } + Err(e) => { + this.future.set(None); + *this.state = State::Failed; + return Poll::Ready(Err(e)); + } + } + } + State::Closing => match ready!(this.future.as_mut().as_pin_mut().unwrap().poll(cx)) + { + Ok(_) => { + this.future.set(None); + *this.state = State::Closed; + return Poll::Ready(Ok(())); + } + Err(e) => { + this.future.set(None); + *this.state = State::Failed; + return Poll::Ready(Err(e)); + } + }, + State::Closed => return Poll::Ready(Ok(())), + State::Failed => panic!("SinkImpl::poll_closed called after error."), + } + } + } +} + +#[cfg(test)] +mod tests { + use crate::quicksink::{make_sink, Action}; + use async_std::{io, task}; + use futures::{channel::mpsc, prelude::*, stream}; + + #[test] + fn smoke_test() { + task::block_on(async { + let sink = make_sink(io::stdout(), |mut stdout, action| async move { + match action { + Action::Send(x) => stdout.write_all(x).await?, + Action::Flush => stdout.flush().await?, + Action::Close => stdout.close().await?, + } + Ok::<_, io::Error>(stdout) + }); + + let values = vec![Ok(&b"hello\n"[..]), Ok(&b"world\n"[..])]; + assert!(stream::iter(values).forward(sink).await.is_ok()) + }) + } + + #[test] + fn replay() { + task::block_on(async { + let (tx, rx) = mpsc::channel(5); + + let sink = make_sink(tx, |mut tx, action| async move { + tx.send(action.clone()).await?; + if action == Action::Close { + tx.close().await? + } + Ok::<_, mpsc::SendError>(tx) + }); + + futures::pin_mut!(sink); + + let expected = [ + Action::Send("hello\n"), + Action::Flush, + Action::Send("world\n"), + Action::Flush, + Action::Close, + ]; + + for &item in &["hello\n", "world\n"] { + sink.send(item).await.unwrap() + } + + sink.close().await.unwrap(); + + let actual = rx.collect::>().await; + + assert_eq!(&expected[..], &actual[..]) + }); + } +} diff --git a/transports/webtransport-websys/Cargo.toml b/transports/webtransport-websys/Cargo.toml index 9fcfd820b5d..996808d7966 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.49" +thiserror = "1.0.50" wasm-bindgen = "0.2.87" wasm-bindgen-futures = "0.4.37" web-sys = { version = "0.3.64", features = [ diff --git a/transports/webtransport-websys/src/connection.rs b/transports/webtransport-websys/src/connection.rs index 9ea1dbefd1c..982f9e5a32c 100644 --- a/transports/webtransport-websys/src/connection.rs +++ b/transports/webtransport-websys/src/connection.rs @@ -1,6 +1,7 @@ use futures::FutureExt; use libp2p_core::muxing::{StreamMuxer, StreamMuxerEvent}; -use libp2p_core::{OutboundUpgrade, UpgradeInfo}; +use libp2p_core::upgrade::OutboundConnectionUpgrade; +use libp2p_core::UpgradeInfo; use libp2p_identity::{Keypair, PeerId}; use multihash::Multihash; use send_wrapper::SendWrapper;