From ac4c62dce709379f66861d5a80f585a19d6aff27 Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Fri, 9 Feb 2024 15:56:49 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20Port=20to=20zbus=204=20?= =?UTF-8?q?API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also implies bumping required versions of shared depdendencies, like event-listener and tokio. --- Cargo.lock | 604 +++++++++++++++++++++++------------------- Cargo.toml | 20 +- src/bus/mod.rs | 163 +++++++----- src/fdo/dbus.rs | 26 +- src/fdo/mod.rs | 5 +- src/fdo/monitoring.rs | 4 +- src/match_rules.rs | 17 +- src/peer/mod.rs | 12 +- src/peer/monitor.rs | 3 +- src/peer/stream.rs | 54 ++-- src/peers.rs | 47 ++-- tests/fdo.rs | 13 +- tests/greet.rs | 12 +- tests/monitor.rs | 9 +- 14 files changed, 526 insertions(+), 463 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e09a89a..6dfc76f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" @@ -34,13 +43,14 @@ checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" [[package]] name = "async-broadcast" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b19760fa2b7301cf235360ffd6d3558b1ed4249edd16d6cca8d690cee265b95" +checksum = "258b52a1aa741b9f09783b2d86cf0aeeb617bbf847f6933340a39644227acbdb" dependencies = [ - "event-listener", + "event-listener 5.0.0", + "event-listener-strategy 0.5.0", "futures-core", - "parking_lot", + "pin-project-lite", ] [[package]] @@ -50,28 +60,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" dependencies = [ "concurrent-queue", - "event-listener", + "event-listener 2.5.3", "futures-core", ] +[[package]] +name = "async-channel" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca33f4bc4ed1babef42cad36cc1f51fa88be00420404e5b1e80ab1b18f7678c" +dependencies = [ + "concurrent-queue", + "event-listener 4.0.3", + "event-listener-strategy 0.4.0", + "futures-core", + "pin-project-lite", +] + [[package]] name = "async-io" -version = "1.13.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +checksum = "8f97ab0c5b00a7cdbe5a371b9a782ee7be1316095885c8a4ea1daf490eb0ef65" dependencies = [ - "async-lock", - "autocfg", + "async-lock 3.3.0", "cfg-if", "concurrent-queue", - "futures-lite", - "log", + "futures-io", + "futures-lite 2.2.0", "parking", "polling", "rustix", "slab", - "socket2", - "waker-fn", + "tracing", + "windows-sys 0.52.0", ] [[package]] @@ -80,25 +102,36 @@ version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" dependencies = [ - "event-listener", + "event-listener 2.5.3", +] + +[[package]] +name = "async-lock" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d034b430882f8381900d3fe6f0aaa3ad94f2cb4ac519b429692a1bc2dda4ae7b" +dependencies = [ + "event-listener 4.0.3", + "event-listener-strategy 0.4.0", + "pin-project-lite", ] [[package]] name = "async-process" -version = "1.7.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a9d28b1d97e08915212e2e45310d47854eafa69600756fc735fb788f75199c9" +checksum = "15c1cd5d253ecac3d3cf15e390fd96bd92a13b1d14497d81abf077304794fb04" dependencies = [ + "async-channel 2.1.1", "async-io", - "async-lock", - "autocfg", + "async-lock 3.3.0", + "async-signal", "blocking", "cfg-if", - "event-listener", - "futures-lite", + "event-listener 4.0.3", + "futures-lite 2.2.0", "rustix", - "signal-hook", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -112,6 +145,24 @@ dependencies = [ "syn 1.0.103", ] +[[package]] +name = "async-signal" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e47d90f65a225c4527103a8d747001fc56e375203592b25ad103e1ca13124c5" +dependencies = [ + "async-io", + "async-lock 2.7.0", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix", + "signal-hook-registry", + "slab", + "windows-sys 0.48.0", +] + [[package]] name = "async-stream" version = "0.3.3" @@ -162,7 +213,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi", "libc", "winapi", ] @@ -181,7 +232,7 @@ checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" dependencies = [ "async-trait", "axum-core", - "bitflags", + "bitflags 1.3.2", "bytes", "futures-util", "http", @@ -218,6 +269,21 @@ dependencies = [ "tower-service", ] +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide 0.7.1", + "object", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.1" @@ -230,6 +296,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + [[package]] name = "block-buffer" version = "0.10.3" @@ -245,12 +317,12 @@ version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" dependencies = [ - "async-channel", - "async-lock", + "async-channel 1.8.0", + "async-lock 2.7.0", "async-task", "atomic-waker", - "fastrand", - "futures-lite", + "fastrand 1.8.0", + "futures-lite 1.13.0", "log", ] @@ -262,10 +334,10 @@ dependencies = [ "clap", "console-subscriber", "enumflags2", - "event-listener", + "event-listener 5.0.0", "futures-util", "hex", - "nix", + "nix 0.26.2", "ntest", "rand", "serde", @@ -290,9 +362,12 @@ checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -307,7 +382,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_derive", "clap_lex", "once_cell", @@ -456,6 +531,12 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "endi" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf" + [[package]] name = "enumflags2" version = "0.7.7" @@ -479,30 +560,61 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.1" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ - "errno-dragonfly", "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] -name = "errno-dragonfly" -version = "0.1.2" +name = "event-listener" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b215c49b2b248c855fb73579eb1f4f26c38ffdc12973e20e07b91d78d5646e" dependencies = [ - "cc", - "libc", + "concurrent-queue", + "parking", + "pin-project-lite", ] [[package]] name = "event-listener" -version = "2.5.3" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +checksum = "b72557800024fabbaa2449dd4bf24e37b93702d457a4d4f2b0dd1f0f039f20c1" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" +dependencies = [ + "event-listener 4.0.3", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feedafcaa9b749175d5ac357452a9d41ea2911da598fde46ce1fe02c37751291" +dependencies = [ + "event-listener 5.0.0", + "pin-project-lite", +] [[package]] name = "fastrand" @@ -513,6 +625,12 @@ dependencies = [ "instant", ] +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "flate2" version = "1.0.25" @@ -520,7 +638,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" dependencies = [ "crc32fast", - "miniz_oxide", + "miniz_oxide 0.6.2", ] [[package]] @@ -555,15 +673,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.25" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-io" -version = "0.3.25" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-lite" @@ -571,7 +689,7 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" dependencies = [ - "fastrand", + "fastrand 1.8.0", "futures-core", "futures-io", "memchr", @@ -580,6 +698,19 @@ dependencies = [ "waker-fn", ] +[[package]] +name = "futures-lite" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445ba825b27408685aaecefd65178908c36c6e96aaf6d8599419d46e624192ba" +dependencies = [ + "fastrand 2.0.1", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + [[package]] name = "futures-macro" version = "0.3.25" @@ -639,6 +770,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + [[package]] name = "h2" version = "0.3.15" @@ -692,12 +829,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" - [[package]] name = "hex" version = "0.4.3" @@ -767,7 +898,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.4", "tokio", "tower-service", "tracing", @@ -805,17 +936,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "io-lifetimes" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" -dependencies = [ - "hermit-abi 0.3.1", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "itertools" version = "0.10.5" @@ -839,25 +959,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.137" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - -[[package]] -name = "lock_api" -version = "0.4.7" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" -dependencies = [ - "autocfg", - "scopeguard", -] +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "log" @@ -898,6 +1008,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.16" @@ -919,16 +1038,24 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + [[package]] name = "mio" -version = "0.8.4" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", - "log", "wasi", - "windows-sys 0.36.1", + "windows-sys 0.48.0", ] [[package]] @@ -937,14 +1064,26 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "libc", - "memoffset", + "memoffset 0.7.1", "pin-utils", "static_assertions", ] +[[package]] +name = "nix" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +dependencies = [ + "bitflags 2.4.2", + "cfg-if", + "libc", + "memoffset 0.9.0", +] + [[package]] name = "nom" version = "7.1.1" @@ -1003,10 +1142,19 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi", "libc", ] +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.17.2" @@ -1031,32 +1179,9 @@ checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" [[package]] name = "parking" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys 0.36.1", -] +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" [[package]] name = "percent-encoding" @@ -1086,9 +1211,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1098,18 +1223,16 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "polling" -version = "2.8.0" +version = "3.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +checksum = "545c980a3880efd47b2e262f6a4bb6daad6555cf3367aa9c4e52895f69537a41" dependencies = [ - "autocfg", - "bitflags", "cfg-if", "concurrent-queue", - "libc", - "log", "pin-project-lite", - "windows-sys 0.48.0", + "rustix", + "tracing", + "windows-sys 0.52.0", ] [[package]] @@ -1240,7 +1363,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534cfe58d6a18cc17120fbf4635d53d14691c1fe4d951064df9bd326178d7d5a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1278,18 +1401,23 @@ dependencies = [ "winapi", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustix" -version = "0.37.3" +version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b24138615de35e32031d041a09032ef3487a616d901ca4db224e7d557efae2" +checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ - "bitflags", + "bitflags 2.4.2", "errno", - "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.45.0", + "windows-sys 0.52.0", ] [[package]] @@ -1298,12 +1426,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "serde" version = "1.0.140" @@ -1366,16 +1488,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "signal-hook" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" -dependencies = [ - "libc", - "signal-hook-registry", -] - [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1387,19 +1499,13 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] -[[package]] -name = "smallvec" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" - [[package]] name = "socket2" version = "0.4.4" @@ -1410,6 +1516,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -1457,7 +1573,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ "cfg-if", - "fastrand", + "fastrand 1.8.0", "libc", "redox_syscall", "remove_dir_all", @@ -1504,22 +1620,21 @@ dependencies = [ [[package]] name = "tokio" -version = "1.21.2" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ - "autocfg", + "backtrace", "bytes", "libc", - "memchr", "mio", "num_cpus", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.5", "tokio-macros", "tracing", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -1534,13 +1649,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.8.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 1.0.103", + "syn 2.0.22", ] [[package]] @@ -1635,7 +1750,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c530c8675c1dbf98facee631536fa116b5fb6382d7dd6dc1b118d970eafe3ba" dependencies = [ - "bitflags", + "bitflags 1.3.2", "bytes", "futures-core", "futures-util", @@ -1734,10 +1849,11 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "uds_windows" -version = "1.0.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce65604324d3cce9b966701489fbd0cf318cb1f7bd9dd07ac9a4ee6fb791930d" +checksum = "89daebc3e6fd160ac4aa9fc8b3bf71e1f74fbf92367ae71fb83a037e8bf164b9" dependencies = [ + "memoffset 0.9.0", "tempfile", "winapi", ] @@ -1813,28 +1929,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", -] - -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -1845,18 +1939,12 @@ dependencies = [ ] [[package]] -name = "windows-targets" -version = "0.42.2" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows-targets 0.52.0", ] [[package]] @@ -1875,10 +1963,19 @@ dependencies = [ ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" +name = "windows-targets" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", +] [[package]] name = "windows_aarch64_gnullvm" @@ -1887,16 +1984,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" +name = "windows_aarch64_gnullvm" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" [[package]] name = "windows_aarch64_msvc" @@ -1905,16 +1996,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" +name = "windows_aarch64_msvc" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" [[package]] name = "windows_i686_gnu" @@ -1923,16 +2008,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" +name = "windows_i686_gnu" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" [[package]] name = "windows_i686_msvc" @@ -1941,16 +2020,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" +name = "windows_i686_msvc" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" [[package]] name = "windows_x86_64_gnu" @@ -1959,10 +2032,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" +name = "windows_x86_64_gnu" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" [[package]] name = "windows_x86_64_gnullvm" @@ -1971,22 +2044,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" +name = "windows_x86_64_gnullvm" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "xdg-home" @@ -1994,29 +2067,27 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2769203cd13a0c6015d515be729c526d041e9cf2c0cc478d57faee85f40c6dcd" dependencies = [ - "nix", + "nix 0.26.2", "winapi", ] [[package]] name = "zbus" -version = "3.14.1" -source = "git+https://github.com/dbus2/zbus/#79ad20b0af6468c6e892d6d647750e882b81ec9d" +version = "4.0.0" +source = "git+https://github.com/dbus2/zbus/#e75e30713d3ed78fe1e53726e2a1e75fc536169f" dependencies = [ "async-broadcast", "async-process", "async-recursion", "async-trait", - "byteorder", "derivative", "enumflags2", - "event-listener", + "event-listener 5.0.0", "futures-core", "futures-sink", "futures-util", "hex", - "nix", - "once_cell", + "nix 0.27.1", "ordered-stream", "rand", "serde", @@ -2026,7 +2097,7 @@ dependencies = [ "tokio", "tracing", "uds_windows", - "winapi", + "windows-sys 0.52.0", "xdg-home", "zbus_macros", "zbus_names", @@ -2035,8 +2106,8 @@ dependencies = [ [[package]] name = "zbus_macros" -version = "3.14.1" -source = "git+https://github.com/dbus2/zbus/#79ad20b0af6468c6e892d6d647750e882b81ec9d" +version = "4.0.0" +source = "git+https://github.com/dbus2/zbus/#e75e30713d3ed78fe1e53726e2a1e75fc536169f" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2048,8 +2119,8 @@ dependencies = [ [[package]] name = "zbus_names" -version = "2.6.0" -source = "git+https://github.com/dbus2/zbus/#79ad20b0af6468c6e892d6d647750e882b81ec9d" +version = "3.0.0" +source = "git+https://github.com/dbus2/zbus/#e75e30713d3ed78fe1e53726e2a1e75fc536169f" dependencies = [ "serde", "static_assertions", @@ -2058,12 +2129,11 @@ dependencies = [ [[package]] name = "zvariant" -version = "3.15.0" -source = "git+https://github.com/dbus2/zbus/#79ad20b0af6468c6e892d6d647750e882b81ec9d" +version = "4.0.0" +source = "git+https://github.com/dbus2/zbus/#e75e30713d3ed78fe1e53726e2a1e75fc536169f" dependencies = [ - "byteorder", + "endi", "enumflags2", - "libc", "serde", "static_assertions", "zvariant_derive", @@ -2071,8 +2141,8 @@ dependencies = [ [[package]] name = "zvariant_derive" -version = "3.15.0" -source = "git+https://github.com/dbus2/zbus/#79ad20b0af6468c6e892d6d647750e882b81ec9d" +version = "4.0.0" +source = "git+https://github.com/dbus2/zbus/#e75e30713d3ed78fe1e53726e2a1e75fc536169f" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2083,8 +2153,8 @@ dependencies = [ [[package]] name = "zvariant_utils" -version = "1.0.1" -source = "git+https://github.com/dbus2/zbus/#79ad20b0af6468c6e892d6d647750e882b81ec9d" +version = "1.1.0" +source = "git+https://github.com/dbus2/zbus/#e75e30713d3ed78fe1e53726e2a1e75fc536169f" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index bb8c8a4..ddebe5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,12 +20,22 @@ name = "busd" path = "src/bin/busd.rs" [dependencies] -zbus = { git = "https://github.com/dbus2/zbus/", features = ["tokio"], default-features = false } -#zbus = { version = "3.14.1", features = ["tokio"], default-features = false } -tokio = { version = "1.19.2", features = ["macros", "rt-multi-thread", "signal", "tracing", "fs" ] } +zbus = { git = "https://github.com/dbus2/zbus/", features = ["tokio", "bus-impl"], default-features = false } +#zbus = { version = "4", features = ["tokio", "bus-impl"], default-features = false } +tokio = { version = "1.19.2", features = [ + "macros", + "rt-multi-thread", + "signal", + "tracing", + "fs", +] } clap = { version = "4.0.18", features = ["derive"] } tracing = "0.1.34" -tracing-subscriber = { version = "0.3.11", features = ["env-filter" , "fmt", "ansi"], default-features = false, optional = true } +tracing-subscriber = { version = "0.3.11", features = [ + "env-filter", + "fmt", + "ansi", +], default-features = false, optional = true } anyhow = "1.0.58" # Explicitly depend on serde to enable `rc` feature. serde = { version = "1.0.140", features = ["rc"] } @@ -36,7 +46,7 @@ console-subscriber = { version = "0.1.8", optional = true } hex = "0.4.3" xdg-home = "1.0.0" rand = "0.8.5" -event-listener = "2.5.3" +event-listener = "5" [target.'cfg(unix)'.dependencies] nix = "0.26.0" diff --git a/src/bus/mod.rs b/src/bus/mod.rs index 1c9c997..765846b 100644 --- a/src/bus/mod.rs +++ b/src/bus/mod.rs @@ -7,15 +7,18 @@ use futures_util::{ }; use std::{cell::OnceCell, str::FromStr, sync::Arc}; #[cfg(unix)] -use std::{ - env, - path::{Path, PathBuf}, -}; +use std::{env, path::Path}; #[cfg(unix)] use tokio::fs::remove_file; use tokio::{spawn, task::JoinHandle}; use tracing::{debug, info, trace, warn}; -use zbus::{Address, AuthMechanism, Connection, ConnectionBuilder, Guid, Socket, TcpAddress}; +#[cfg(unix)] +use zbus::address::transport::{Unix, UnixSocket}; +use zbus::{ + address::{transport::Tcp, Transport}, + connection::socket::BoxedSplit, + Address, AuthMechanism, Connection, ConnectionBuilder, Guid, OwnedGuid, +}; use crate::{ fdo::{self, DBus, Monitoring}, @@ -35,7 +38,7 @@ pub struct Bus { pub struct Inner { address: Address, peers: Arc, - guid: Arc, + guid: OwnedGuid, next_id: Option, auth_mechanism: AuthMechanism, self_conn: OnceCell, @@ -44,45 +47,38 @@ pub struct Inner { #[derive(Debug)] enum Listener { #[cfg(unix)] - Unix { - listener: tokio::net::UnixListener, - socket_path: PathBuf, - }, - Tcp { - listener: tokio::net::TcpListener, - }, + Unix(tokio::net::UnixListener), + Tcp(tokio::net::TcpListener), } impl Bus { pub async fn for_address(address: Option<&str>, auth_mechanism: AuthMechanism) -> Result { - let address = match address { - Some(address) => address.to_string(), - None => default_address(), + let mut address = match address { + Some(address) => Address::from_str(address)?, + None => Address::from_str(&default_address())?, }; - let address = Address::from_str(&address)?; - let listener = match &address { - #[cfg(unix)] - Address::Unix(path) => { - let path = Path::new(&path); - info!("Listening on {}.", path.display()); - - Self::unix_stream(path).await - } - Address::Tcp(address) => { - info!("Listening on `{}:{}`.", address.host(), address.port()); + let guid: OwnedGuid = match address.guid() { + Some(guid) => guid.to_owned().into(), + None => { + let guid = Guid::generate(); + address = address.set_guid(guid.clone())?; - Self::tcp_stream(address).await + guid.into() } - Address::NonceTcp { .. } => bail!("`nonce-tcp` transport is not supported (yet)."), - Address::Autolaunch(_) => bail!("`autolaunch` transport is not supported (yet)."), + }; + let listener = match address.transport() { + #[cfg(unix)] + Transport::Unix(unix) => Self::unix_stream(unix).await, + Transport::Tcp(tcp) => Self::tcp_stream(tcp).await, + #[cfg(windows)] + Transport::Autolaunch(_) => bail!("`autolaunch` transport is not supported (yet)."), _ => bail!("Unsupported address `{}`.", address), }?; - let mut bus = Self::new(address.clone(), listener, auth_mechanism).await?; + let mut bus = Self::new(address.clone(), guid.clone(), listener, auth_mechanism).await?; // Create a peer for ourselves. trace!("Creating self-dial connection."); - let guid = bus.guid().clone(); let dbus = DBus::new(bus.peers().clone(), guid.clone()); let monitoring = Monitoring::new(bus.peers().clone()); let conn_builder_fut = ConnectionBuilder::address(address)? @@ -114,17 +110,18 @@ impl Bus { // AsyncDrop would have been nice! pub async fn cleanup(self) -> Result<()> { - match self.listener { - #[cfg(unix)] - Listener::Unix { socket_path, .. } => { - remove_file(socket_path).await.map_err(Into::into) - } - Listener::Tcp { .. } => Ok(()), + match self.inner.address.transport() { + Transport::Unix(unix) => match unix.path() { + UnixSocket::File(path) => remove_file(path).await.map_err(Into::into), + _ => Ok(()), + }, + _ => Ok(()), } } async fn new( address: Address, + guid: OwnedGuid, listener: Listener, auth_mechanism: AuthMechanism, ) -> Result { @@ -142,7 +139,7 @@ impl Bus { inner: Inner { address, peers: Peers::new(), - guid: Arc::new(Guid::generate()), + guid, next_id: None, auth_mechanism, self_conn: OnceCell::new(), @@ -151,23 +148,56 @@ impl Bus { } #[cfg(unix)] - async fn unix_stream(socket_path: &Path) -> Result { - let socket_path = socket_path.to_path_buf(); - let listener = Listener::Unix { - listener: tokio::net::UnixListener::bind(&socket_path)?, - socket_path, - }; + async fn unix_stream(unix: &Unix) -> Result { + // TODO: Use tokio::net::UnixListener directly once it supports abstract sockets: + // + // https://github.com/tokio-rs/tokio/issues/4610 + + use std::os::{linux::net::SocketAddrExt, unix::net::SocketAddr}; + + let addr = match unix.path() { + UnixSocket::Abstract(name) => { + let addr = SocketAddr::from_abstract_name(name.as_encoded_bytes())?; + info!( + "Listening on abstract UNIX socket `{}`.", + name.to_string_lossy() + ); - Ok(listener) - } + addr + } + UnixSocket::File(path) => { + let addr = SocketAddr::from_pathname(path)?; + info!( + "Listening on UNIX socket file `{}`.", + path.to_string_lossy() + ); - async fn tcp_stream(address: &TcpAddress) -> Result { - let address = (address.host(), address.port()); - let listener = Listener::Tcp { - listener: tokio::net::TcpListener::bind(address).await?, + addr + } + UnixSocket::Dir(_) => bail!("`dir` transport is not supported (yet)."), + UnixSocket::TmpDir(_) => bail!("`tmpdir` transport is not supported (yet)."), + _ => bail!("Unsupported address."), }; + let std_listener = + tokio::task::spawn_blocking(move || std::os::unix::net::UnixListener::bind_addr(&addr)) + .await??; + std_listener.set_nonblocking(true)?; + tokio::net::UnixListener::from_std(std_listener) + .map(Listener::Unix) + .map_err(Into::into) + } + + async fn tcp_stream(tcp: &Tcp) -> Result { + if tcp.nonce_file().is_some() { + bail!("`nonce-tcp` transport is not supported (yet)."); + } + info!("Listening on `{}:{}`.", tcp.host(), tcp.port()); + let address = (tcp.host(), tcp.port()); - Ok(listener) + tokio::net::TcpListener::bind(address) + .await + .map(Listener::Tcp) + .map_err(Into::into) } async fn accept_next(&mut self) -> Result<()> { @@ -203,35 +233,22 @@ impl Bus { Ok(()) } - async fn accept(&mut self) -> Result> { - match &mut self.listener { + async fn accept(&mut self) -> Result { + let stream = match &mut self.listener { #[cfg(unix)] - Listener::Unix { - listener, - socket_path, - } => { - let (unix_stream, _) = listener.accept().await?; - debug!( - "Accepted connection on socket file {}", - socket_path.display() - ); - - Ok(Box::new(unix_stream)) - } - Listener::Tcp { listener } => { - let (tcp_stream, addr) = listener.accept().await?; - debug!("Accepted connection from {addr}"); + Listener::Unix(listener) => listener.accept().await.map(|(stream, _)| stream.into())?, + Listener::Tcp(listener) => listener.accept().await.map(|(stream, _)| stream.into())?, + }; + debug!("Accepted connection on address `{}`", self.inner.address); - Ok(Box::new(tcp_stream)) - } - } + Ok(stream) } pub fn peers(&self) -> &Arc { &self.inner.peers } - pub fn guid(&self) -> &Arc { + pub fn guid(&self) -> &OwnedGuid { &self.inner.guid } diff --git a/src/fdo/dbus.rs b/src/fdo/dbus.rs index 4e4cfc4..0c288e2 100644 --- a/src/fdo/dbus.rs +++ b/src/fdo/dbus.rs @@ -7,13 +7,13 @@ use enumflags2::BitFlags; use tokio::spawn; use tracing::warn; use zbus::{ - dbus_interface, fdo::{ ConnectionCredentials, Error, ReleaseNameReply, RequestNameFlags, RequestNameReply, Result, }, + interface, names::{BusName, InterfaceName, OwnedBusName, OwnedUniqueName, UniqueName, WellKnownName}, zvariant::Optional, - Guid, MessageHeader, OwnedMatchRule, ResponseDispatchNotifier, SignalContext, + MessageHeader, OwnedGuid, OwnedMatchRule, ResponseDispatchNotifier, SignalContext, }; use super::msg_sender; @@ -22,14 +22,14 @@ use crate::{peer::Peer, peers::Peers}; #[derive(Debug)] pub struct DBus { peers: Weak, - guid: Arc, + guid: OwnedGuid, } impl DBus { pub const PATH: &'static str = "/org/freedesktop/DBus"; pub const INTERFACE: &'static str = "org.freedesktop.DBus"; - pub fn new(peers: Arc, guid: Arc) -> Self { + pub fn new(peers: Arc, guid: OwnedGuid) -> Self { Self { peers: Arc::downgrade(&peers), guid, @@ -59,7 +59,7 @@ impl DBus { } } -#[dbus_interface(interface = "org.freedesktop.DBus")] +#[interface(interface = "org.freedesktop.DBus")] impl DBus { /// This is already called & handled and we only need to handle it once. async fn hello( @@ -224,7 +224,7 @@ impl DBus { } /// Returns the security context used by SELinux, in an unspecified format. - #[dbus_interface(name = "GetConnectionSELinuxSecurityContext")] + #[zbus(name = "GetConnectionSELinuxSecurityContext")] async fn get_connection_selinux_security_context( &self, bus_name: BusName<'_>, @@ -239,7 +239,7 @@ impl DBus { } /// Returns the Unix process ID of the process connected to the server. - #[dbus_interface(name = "GetConnectionUnixProcessID")] + #[zbus(name = "GetConnectionUnixProcessID")] async fn get_connection_unix_process_id(&self, bus_name: BusName<'_>) -> Result { self.get_connection_credentials(bus_name.clone()) .await @@ -264,7 +264,7 @@ impl DBus { } /// Gets the unique ID of the bus. - fn get_id(&self) -> &Guid { + fn get_id(&self) -> &OwnedGuid { &self.guid } @@ -356,7 +356,7 @@ impl DBus { /// This property lists abstract “features” provided by the message bus, and can be used by /// clients to detect the capabilities of the message bus with which they are communicating. - #[dbus_interface(property)] + #[zbus(property)] fn features(&self) -> &[&str] { &[] } @@ -373,7 +373,7 @@ impl DBus { /// `org.freedesktop.DBus` was successful. The standard `org.freedesktop.DBus.Peer` and /// `org.freedesktop.DBus.Introspectable` interfaces are not included in the value of this /// property either, because they do not indicate features of the message bus implementation. - #[dbus_interface(property)] + #[zbus(property)] fn interfaces(&self) -> &[InterfaceName<'_>] { // TODO: List `org.freedesktop.DBus.Monitoring` when we support it. &[] @@ -382,7 +382,7 @@ impl DBus { /// This signal indicates that the owner of a name has changed. /// /// It's also the signal to use to detect the appearance of new names on the bus. - #[dbus_interface(signal)] + #[zbus(signal)] pub async fn name_owner_changed( signal_ctxt: &SignalContext<'_>, name: BusName<'_>, @@ -391,11 +391,11 @@ impl DBus { ) -> zbus::Result<()>; /// This signal is sent to a specific application when it loses ownership of a name. - #[dbus_interface(signal)] + #[zbus(signal)] pub async fn name_lost(signal_ctxt: &SignalContext<'_>, name: BusName<'_>) -> zbus::Result<()>; /// This signal is sent to a specific application when it gains ownership of a name. - #[dbus_interface(signal)] + #[zbus(signal)] pub async fn name_acquired( signal_ctxt: &SignalContext<'_>, name: BusName<'_>, diff --git a/src/fdo/mod.rs b/src/fdo/mod.rs index c6d14f1..446cae7 100644 --- a/src/fdo/mod.rs +++ b/src/fdo/mod.rs @@ -9,8 +9,5 @@ pub const BUS_NAME: &str = "org.freedesktop.DBus"; /// Helper for getting the peer name from a message header. fn msg_sender<'h>(hdr: &'h MessageHeader<'h>) -> &'h UniqueName<'h> { // SAFETY: The bus (that's us!) is supposed to ensure a valid sender on the message. - hdr.sender() - .ok() - .flatten() - .expect("Missing `sender` header") + hdr.sender().expect("Missing `sender` header") } diff --git a/src/fdo/monitoring.rs b/src/fdo/monitoring.rs index 98f449f..d9cfad0 100644 --- a/src/fdo/monitoring.rs +++ b/src/fdo/monitoring.rs @@ -3,8 +3,8 @@ use std::sync::{Arc, Weak}; use tokio::spawn; use tracing::{debug, warn}; use zbus::{ - dbus_interface, fdo::{Error, Result}, + interface, zvariant::Optional, MessageHeader, ResponseDispatchNotifier, SignalContext, }; @@ -28,7 +28,7 @@ impl Monitoring { } } -#[dbus_interface(interface = "org.freedesktop.DBus.Monitoring")] +#[interface(interface = "org.freedesktop.DBus.Monitoring")] impl Monitoring { async fn become_monitor( &self, diff --git a/src/match_rules.rs b/src/match_rules.rs index 970fd69..1d7736a 100644 --- a/src/match_rules.rs +++ b/src/match_rules.rs @@ -16,7 +16,7 @@ impl MatchRules { /// /// if header, SENDER or DESTINATION is not set. pub fn matches(&self, msg: &zbus::Message, name_registry: &NameRegistry) -> bool { - let hdr = msg.header().expect("received message without header"); + let hdr = msg.header(); let ret = self.0.iter().any(|rule| { // First make use of zbus API @@ -36,25 +36,14 @@ impl MatchRules { // Unique name is already taken care of by the zbus API. BusName::Unique(_) => None, }) { - if sender - != hdr - .sender() - .expect("SENDER field unset") - .expect("SENDER field unset") - .clone() - { + if sender != hdr.sender().expect("SENDER field unset").clone() { return false; } } // The destination. if let Some(destination) = rule.destination() { - match hdr - .destination() - .expect("DESTINATION field unset") - .expect("DESTINATION field unset") - .clone() - { + match hdr.destination().expect("DESTINATION field unset").clone() { BusName::WellKnown(name) => match name_registry.lookup(name) { Some(name) if name == *destination => (), Some(_) => return false, diff --git a/src/peer/mod.rs b/src/peer/mod.rs index 28dc18f..d9ae1f1 100644 --- a/src/peer/mod.rs +++ b/src/peer/mod.rs @@ -4,13 +4,11 @@ pub use stream::*; mod monitor; pub use monitor::*; -use std::sync::Arc; - use anyhow::Result; use tracing::trace; use zbus::{ - names::OwnedUniqueName, AuthMechanism, Connection, ConnectionBuilder, Guid, OwnedMatchRule, - Socket, + connection::socket::BoxedSplit, names::OwnedUniqueName, AuthMechanism, Connection, + ConnectionBuilder, OwnedGuid, OwnedMatchRule, }; use crate::{fdo, match_rules::MatchRules, name_registry::NameRegistry}; @@ -27,9 +25,9 @@ pub struct Peer { impl Peer { pub async fn new( - guid: Arc, + guid: OwnedGuid, id: Option, - socket: Box, + socket: BoxedSplit, auth_mechanism: AuthMechanism, ) -> Result { let unique_name = match id { @@ -37,7 +35,7 @@ impl Peer { None => OwnedUniqueName::try_from(fdo::BUS_NAME).unwrap(), }; let conn = ConnectionBuilder::socket(socket) - .server(&guid) + .server(guid)? .p2p() .auth_mechanisms(&[auth_mechanism]) .build() diff --git a/src/peer/monitor.rs b/src/peer/monitor.rs index eeadcf1..7777ea6 100644 --- a/src/peer/monitor.rs +++ b/src/peer/monitor.rs @@ -33,8 +33,7 @@ impl Monitor { /// Same as [`MatchRules::matches`]. pub fn interested(&self, msg: &zbus::Message, name_registry: &NameRegistry) -> bool { if self.match_rules.is_empty() - || msg.header().unwrap().destination().unwrap() - == Some(&BusName::from(self.unique_name.clone())) + || msg.header().destination().unwrap() == &BusName::from(&self.unique_name) { return true; } diff --git a/src/peer/stream.rs b/src/peer/stream.rs index f211f0b..926ff27 100644 --- a/src/peer/stream.rs +++ b/src/peer/stream.rs @@ -1,14 +1,9 @@ -#[cfg(unix)] -use std::os::fd::AsRawFd; -use std::{pin::Pin, sync::Arc}; +use std::pin::Pin; use anyhow::{bail, Error, Result}; use futures_util::{Stream as FutureStream, TryStream, TryStreamExt}; use tracing::trace; -use zbus::{ - zvariant::Type, Message, MessageBuilder, MessageField, MessageFieldCode, MessageStream, - MessageType, -}; +use zbus::{zvariant::Type, Message, MessageBuilder, MessageStream, MessageType}; use crate::peer::Peer; @@ -22,8 +17,7 @@ pub struct Stream { stream: Pin>, } -type StreamInner = - dyn TryStream, Error = Error, Item = Result>> + Send; +type StreamInner = dyn TryStream> + Send; impl Stream { pub fn for_peer(peer: &Peer) -> Self { @@ -33,37 +27,31 @@ impl Stream { .and_then(move |msg| { let unique_name = unique_name.clone(); async move { - let fields = match msg.message_type() { - MessageType::MethodCall - | MessageType::MethodReturn - | MessageType::Error - | MessageType::Signal => msg.fields()?, - MessageType::Invalid => bail!("Invalid message"), - }; + let header = msg.header(); // Ensure destination field is present and readable for non-signals. - if msg.message_type() != MessageType::Signal { - match fields.get_field(MessageFieldCode::Destination) { - Some(MessageField::Destination(_)) => (), - Some(_) => { - bail!("failed to parse message: Invalid destination field"); - } - None => bail!("missing destination field"), - } + if msg.message_type() != MessageType::Signal && header.destination().is_none() { + bail!("missing destination field"); } // Ensure sender field is present. If it is not we add it using the unique name // of the peer. - match fields.get_field(MessageFieldCode::Sender) { - Some(MessageField::Sender(sender)) if *sender == unique_name => Ok(msg), + match header.sender() { + Some(sender) if *sender == unique_name => Ok(msg), Some(_) => bail!("failed to parse message: Invalid sender field"), None => { - let header = msg.header()?; - let signature = match header.signature()? { + let signature = match header.signature() { Some(sig) => sig.clone(), None => <()>::signature(), }; - let body_bytes = msg.body_as_bytes()?; + let body = msg.body(); + let body_bytes = body.data(); + #[cfg(unix)] + let fds = body_bytes + .fds() + .iter() + .map(|fd| fd.try_clone().map(Into::into)) + .collect::>>()?; let builder = MessageBuilder::from(header.clone()).sender(&unique_name)?; let new_msg = unsafe { @@ -71,12 +59,12 @@ impl Stream { body_bytes, signature, #[cfg(unix)] - msg.take_fds().iter().map(|fd| fd.as_raw_fd()).collect(), + fds, )? }; trace!("Added sender field to message: {:?}", new_msg); - Ok(Arc::new(new_msg)) + Ok(new_msg) } } } @@ -89,12 +77,12 @@ impl Stream { } impl FutureStream for Stream { - type Item = Result>; + type Item = Result; fn poll_next( self: Pin<&mut Self>, cx: &mut std::task::Context, - ) -> std::task::Poll>>> { + ) -> std::task::Poll>> { FutureStream::poll_next(Pin::new(&mut self.get_mut().stream), cx) } } diff --git a/src/peers.rs b/src/peers.rs index d8db73b..156682c 100644 --- a/src/peers.rs +++ b/src/peers.rs @@ -3,7 +3,6 @@ use event_listener::EventListener; use futures_util::{ future::{select, Either}, stream::StreamExt, - SinkExt, }; use std::{ collections::BTreeMap, @@ -13,9 +12,10 @@ use std::{ use tokio::{spawn, sync::RwLock}; use tracing::{debug, trace, warn}; use zbus::{ + connection::socket::BoxedSplit, names::{BusName, OwnedUniqueName, UniqueName}, zvariant::Optional, - AuthMechanism, Guid, MessageBuilder, MessageField, MessageFieldCode, MessageType, Socket, + AuthMechanism, Message, MessageType, OwnedGuid, }; use crate::{ @@ -45,9 +45,9 @@ impl Peers { pub async fn add( self: &Arc, - guid: &Arc, + guid: &OwnedGuid, id: Option, - socket: Box, + socket: BoxedSplit, auth_mechanism: AuthMechanism, ) -> Result<()> { let mut peers = self.peers_mut().await; @@ -128,7 +128,7 @@ impl Peers { let new_owner = name_owner_changed.new_owner.map(UniqueName::from); // First broadcast the name change signal. - let msg = MessageBuilder::signal(fdo::DBus::PATH, fdo::DBus::INTERFACE, "NameOwnerChanged") + let msg = Message::signal(fdo::DBus::PATH, fdo::DBus::INTERFACE, "NameOwnerChanged") .unwrap() .sender(fdo::BUS_NAME) .unwrap() @@ -137,36 +137,30 @@ impl Peers { Optional::from(old_owner.clone()), Optional::from(new_owner.clone()), ))?; - self.broadcast_msg(Arc::new(msg)).await; + self.broadcast_msg(msg).await; // Now unicast the appropriate signal to the old and new owners. if let Some(old_owner) = old_owner { - let msg = MessageBuilder::signal(fdo::DBus::PATH, fdo::DBus::INTERFACE, "NameLost") + let msg = Message::signal(fdo::DBus::PATH, fdo::DBus::INTERFACE, "NameLost") .unwrap() .sender(fdo::BUS_NAME) .unwrap() .destination(old_owner.clone()) .unwrap() .build(&name)?; - if let Err(e) = self - .send_msg_to_unique_name(Arc::new(msg), old_owner.clone()) - .await - { + if let Err(e) = self.send_msg_to_unique_name(msg, old_owner.clone()).await { warn!("Couldn't notify inexistant peer {old_owner} about loosing name {name}: {e}") } } if let Some(new_owner) = new_owner { - let msg = MessageBuilder::signal(fdo::DBus::PATH, fdo::DBus::INTERFACE, "NameAcquired") + let msg = Message::signal(fdo::DBus::PATH, fdo::DBus::INTERFACE, "NameAcquired") .unwrap() .sender(fdo::BUS_NAME) .unwrap() .destination(new_owner.clone()) .unwrap() .build(&name)?; - if let Err(e) = self - .send_msg_to_unique_name(Arc::new(msg), new_owner.clone()) - .await - { + if let Err(e) = self.send_msg_to_unique_name(msg, new_owner.clone()).await { warn!("Couldn't notify peer {new_owner} about acquiring name {name}: {e}") } } @@ -203,8 +197,8 @@ impl Peers { match msg.message_type() { MessageType::Signal => self.broadcast_msg(msg).await, - _ => match msg.fields()?.get_field(MessageFieldCode::Destination) { - Some(MessageField::Destination(dest)) => { + _ => match msg.header().destination() { + Some(dest) => { if let Err(e) = self.send_msg(msg.clone(), dest.clone()).await { warn!("{}", e); } @@ -239,7 +233,7 @@ impl Peers { Ok(()) } - async fn send_msg(&self, msg: Arc, destination: BusName<'_>) -> Result<()> { + async fn send_msg(&self, msg: Message, destination: BusName<'_>) -> Result<()> { trace!( "Forwarding message: {:?}, destination: {}", msg, @@ -259,7 +253,7 @@ impl Peers { async fn send_msg_to_unique_name( &self, - msg: Arc, + msg: Message, destination: UniqueName<'_>, ) -> Result<()> { let conn = self @@ -269,10 +263,7 @@ impl Peers { .get(destination.as_str()) .map(|peer| peer.conn().clone()); match conn { - Some(mut conn) => conn - .send(msg.clone()) - .await - .context("failed to send message")?, + Some(conn) => conn.send(&msg).await.context("failed to send message")?, None => debug!("no peer for destination `{destination}`"), } let name_registry = self.name_registry().await; @@ -281,7 +272,7 @@ impl Peers { Ok(()) } - async fn broadcast_msg(&self, msg: Arc) { + async fn broadcast_msg(&self, msg: Message) { trace!("Broadcasting message: {:?}", msg); let name_registry = self.name_registry().await; for peer in self.peers.read().await.values() { @@ -292,7 +283,7 @@ impl Peers { if let Err(e) = peer .conn() - .send(msg.clone()) + .send(&msg) .await .context("failed to send message") { @@ -303,7 +294,7 @@ impl Peers { self.broadcast_to_monitors(msg, &name_registry).await; } - async fn broadcast_to_monitors(&self, msg: Arc, name_registry: &NameRegistry) { + async fn broadcast_to_monitors(&self, msg: Message, name_registry: &NameRegistry) { let monitors = self.monitors.read().await; if monitors.is_empty() { return; @@ -324,7 +315,7 @@ impl Peers { if let Err(e) = monitor .conn() - .send(msg.clone()) + .send(&msg) .await .context("failed to send message") { diff --git a/tests/fdo.rs b/tests/fdo.rs index be35b11..534b03b 100644 --- a/tests/fdo.rs +++ b/tests/fdo.rs @@ -101,7 +101,7 @@ async fn name_ownership_changes_client(address: &str, tx: Sender<()>) -> anyhow: "expected new owner to be us" ); ensure!( - changed.header()?.destination()?.is_none(), + changed.message().header().destination().is_none(), "expected no destination for our signal", ); let acquired = name_acquired_stream.next().await.unwrap(); @@ -110,7 +110,8 @@ async fn name_ownership_changes_client(address: &str, tx: Sender<()>) -> anyhow: "expected name acquired signal for our name" ); ensure!( - *acquired.header()?.destination()?.unwrap() == BusName::from(conn.unique_name().unwrap()), + *acquired.message().header().destination().unwrap() + == BusName::from(conn.unique_name().unwrap()), "expected name acquired signal to be unicasted to the acquiring connection", ); @@ -185,7 +186,7 @@ async fn name_ownership_changes_client(address: &str, tx: Sender<()>) -> anyhow: "expected new owner to be our second connection" ); ensure!( - changed.header()?.destination()?.is_none(), + changed.message().header().destination().is_none(), "expected no destination for our signal", ); let lost = name_lost_stream.next().await.unwrap(); @@ -194,7 +195,8 @@ async fn name_ownership_changes_client(address: &str, tx: Sender<()>) -> anyhow: "expected name lost signal for our name" ); ensure!( - *lost.header()?.destination()?.unwrap() == BusName::from(conn.unique_name().unwrap()), + *lost.message().header().destination().unwrap() + == BusName::from(conn.unique_name().unwrap()), "expected name lost signal to be unicasted to the loosing connection", ); let acquired = name_acquired_stream.next().await.unwrap(); @@ -203,7 +205,8 @@ async fn name_ownership_changes_client(address: &str, tx: Sender<()>) -> anyhow: "expected name acquired signal for our name" ); ensure!( - *acquired.header()?.destination()?.unwrap() == BusName::from(conn2.unique_name().unwrap()), + *acquired.message().header().destination().unwrap() + == BusName::from(conn2.unique_name().unwrap()), "expected name acquired signal to be unicasted to the acquiring connection", ); diff --git a/tests/greet.rs b/tests/greet.rs index 51ca8b0..52c4ab1 100644 --- a/tests/greet.rs +++ b/tests/greet.rs @@ -11,8 +11,8 @@ use rand::{ use tokio::{select, sync::mpsc::channel, time::timeout}; use tracing::instrument; use zbus::{ - dbus_interface, dbus_proxy, fdo::{self, DBusProxy}, + interface, proxy, zvariant::ObjectPath, AsyncDrop, AuthMechanism, CacheProperties, Connection, ConnectionBuilder, MatchRule, MessageHeader, MessageStream, SignalContext, @@ -73,7 +73,7 @@ async fn greet_service(socket_addr: &str) -> anyhow::Result { count: u64, } - #[dbus_interface(name = "org.zbus.MyGreeter1")] + #[interface(name = "org.zbus.MyGreeter1")] impl Greeter { async fn say_hello( &mut self, @@ -82,7 +82,7 @@ async fn greet_service(socket_addr: &str) -> anyhow::Result { #[zbus(header)] header: MessageHeader<'_>, ) -> fdo::Result { self.count += 1; - let path = header.path()?.unwrap().clone(); + let path = header.path().unwrap().clone(); Self::greeted(&ctxt, name, self.count, path).await?; Ok(format!( "Hello {}! I have been called {} times.", @@ -90,7 +90,7 @@ async fn greet_service(socket_addr: &str) -> anyhow::Result { )) } - #[dbus_interface(signal)] + #[zbus(signal)] async fn greeted( ctxt: &SignalContext<'_>, name: &str, @@ -110,14 +110,14 @@ async fn greet_service(socket_addr: &str) -> anyhow::Result { #[instrument] async fn greet_client(socket_addr: &str) -> anyhow::Result<()> { - #[dbus_proxy( + #[proxy( interface = "org.zbus.MyGreeter1", default_path = "/org/zbus/MyGreeter" )] trait MyGreeter { fn say_hello(&self, name: &str) -> zbus::Result; - #[dbus_proxy(signal)] + #[zbus(signal)] async fn greeted(name: &str, count: u64, path: ObjectPath<'_>); } diff --git a/tests/monitor.rs b/tests/monitor.rs index 4a38723..45f9ad0 100644 --- a/tests/monitor.rs +++ b/tests/monitor.rs @@ -95,20 +95,21 @@ async fn become_monitor_client(address: &str, tx: Sender<()>) -> anyhow::Result< let mut request_name_serial = None; while num_received < 8 { let msg = msg_stream.try_next().await?.unwrap(); - let member = msg.member(); + let header = msg.header(); + let member = header.member(); match msg.message_type() { MessageType::MethodCall => match member.unwrap().as_str() { "Hello" => { - hello_serial = msg.primary_header().serial_num().cloned(); + hello_serial = Some(msg.primary_header().serial_num()); } "RequestName" => { - request_name_serial = msg.primary_header().serial_num().cloned(); + request_name_serial = Some(msg.primary_header().serial_num()); } method => panic!("unexpected method call: {}", method), }, MessageType::MethodReturn => { - let serial = msg.reply_serial(); + let serial = header.reply_serial(); if serial == hello_serial { hello_serial = None; } else if serial == request_name_serial {