From 6e3f2b5dbacb4aa258009ac18bdb79b735e7ece1 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 29 Mar 2023 12:26:41 +0200 Subject: [PATCH 01/25] Update `configure_me_codegen` --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- build.rs | 3 ++- src/create_state.rs | 3 --- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index abab881..3bf9442 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -222,9 +222,9 @@ dependencies = [ [[package]] name = "configure_me_codegen" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97f64541226ea2aaaad89ce86ec9453b1e913a54d71eb987ab9d8ed52dacce2f" +checksum = "981fb98983781be95b91dc4ce7c178ae000f91350d783d43d1ce8adc4963c91f" dependencies = [ "cargo_toml", "fmt2io", diff --git a/Cargo.toml b/Cargo.toml index 908f30d..b0095e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ thiserror = "1.0.22" systemd_socket = { version = "0.1.1", default-features = false, features = ["tokio_0_2"] } [build-dependencies] -configure_me_codegen = "0.4.0" +configure_me_codegen = "0.4.3" [package.metadata.deb] assets = [ diff --git a/build.rs b/build.rs index 0219b8f..71cca26 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,4 @@ -fn main() -> Result<(), configure_me_codegen::Error> { +fn main() { configure_me_codegen::build_script_auto() + .unwrap_or_else(|error| error.report_and_exit()) } diff --git a/src/create_state.rs b/src/create_state.rs index fdd7589..809c1e7 100644 --- a/src/create_state.rs +++ b/src/create_state.rs @@ -7,9 +7,6 @@ use slog::Drain; use tokio::sync::RwLock; use systemd_socket::SocketAddr; -#[allow(dead_code)] -#[allow(unused_mut)] -#[allow(unused_variables)] mod config { include!(concat!(env!("OUT_DIR"), "/configure_me_config.rs")); } From 25f20a42fd1cd1cbfabb1794384491102e688f68 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 29 Mar 2023 13:18:04 +0200 Subject: [PATCH 02/25] Updated some dependencies --- Cargo.lock | 139 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 96 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3bf9442..a235f4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,6 +134,12 @@ dependencies = [ "tokio", ] +[[package]] +name = "bumpalo" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad807f2fc2bf185eeb98ff3a901bd46dc5ad58163d0fa4577ba0d25674d71708" + [[package]] name = "byte-tools" version = "0.3.1" @@ -189,14 +195,15 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.9" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68" +checksum = "6127248204b9aba09a362f6c930ef6a78f2c1b2215f8a7b398c06e1083f17af0" dependencies = [ - "libc", + "js-sys", "num-integer", "num-traits", - "time", + "wasm-bindgen", + "winapi 0.3.8", ] [[package]] @@ -608,6 +615,15 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +[[package]] +name = "js-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cedf50c705f7ede60202104d9cb08d02f3156d4a6f4f638ab4fcdfd0e9ecdda" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -626,9 +642,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.79" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "libsystemd" @@ -769,9 +785,9 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.43" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ "autocfg", "num-traits", @@ -779,9 +795,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", ] @@ -798,9 +814,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.4.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" +checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" [[package]] name = "opaque-debug" @@ -876,12 +892,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.1.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" - [[package]] name = "redox_syscall" version = "0.2.5" @@ -898,7 +908,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ "getrandom", - "redox_syscall 0.2.5", + "redox_syscall", ] [[package]] @@ -1014,9 +1024,9 @@ checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06" [[package]] name = "slog-async" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c60813879f820c85dbc4eabf3269befe374591289019775898d56a81a804fbdc" +checksum = "766c59b252e62a34651412870ff55d8c4e6d04df19b43eecb2703e417b097ffe" dependencies = [ "crossbeam-channel", "slog", @@ -1026,9 +1036,9 @@ dependencies = [ [[package]] name = "slog-term" -version = "2.8.0" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95c1e7e5aab61ced6006149ea772770b84a0d16ce0f7885def313e4829946d76" +checksum = "f3668dd2252f4381d64de0c79e6c8dc6bd509d1cab3535b35a3fc9bafd1241d5" dependencies = [ "atty", "chrono", @@ -1068,9 +1078,9 @@ checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" [[package]] name = "syn" -version = "1.0.48" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" +checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702" dependencies = [ "proc-macro2", "quote", @@ -1128,29 +1138,18 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "time" -version = "0.1.42" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" dependencies = [ - "libc", - "redox_syscall 0.1.56", - "winapi 0.3.8", + "once_cell", ] [[package]] name = "tokio" -version = "0.2.22" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" +checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" dependencies = [ "bytes", "fnv", @@ -1172,9 +1171,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" +checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" dependencies = [ "proc-macro2", "quote", @@ -1292,6 +1291,60 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "wasm-bindgen" +version = "0.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "220f01bcb6b306c063e3283f97dd974bcab4e5affed2b654bae1a22d0d99c3aa" +dependencies = [ + "cfg-if 0.1.10", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8894c95e23cc5082786192ebbd2ac0e31e9f77a022132ba03e8b8de32a2323c6" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec031a3190c51dda28c9f3623e2674e58c79f6d88c020c2157417fcf62298a3f" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b7cad0ab0bb5fefbb770279f522dcebb6433585174d93ea648390f61db57401" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9142625bbb0d70710b3f2a6b20924c80fa182b05888b6bd21600ab9075673563" + [[package]] name = "winapi" version = "0.2.8" From 50280a4248376a43c0e6bc015d96adfe2a80e5d9 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 29 Mar 2023 15:02:51 +0200 Subject: [PATCH 03/25] Implement wallet overriding It is sometimes useful to override wallet name. This can improve security and compatibility. This change implements simple wallet override. --- README.md | 7 ++++++- btc_rpc_proxy.toml | 1 + src/proxy.rs | 6 +++++- src/users.rs | 8 ++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c7e5400..9076788 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Finer-grained permission management for bitcoind. ## About -This is a proxy made specifically for `bitcoind` to allow finer-grained control of permissions. It enables you to specify several users and for each user the list of RPC calls they are allowed to make. When run against a prunded node, the proxy will perform on-demand block fetching and verification, enabling features of a non-pruned node while still using a pruned node. +This is a proxy made specifically for `bitcoind` to allow finer-grained control of permissions. It enables you to specify several users and for each user the list of RPC calls they are allowed to make and optionally the name of the wallet they will operate on. When run against a prunded node, the proxy will perform on-demand block fetching and verification, enabling features of a non-pruned node while still using a pruned node. ### Fine-grained permission management @@ -12,6 +12,11 @@ This is useful because `bitcoind` allows every application with password to make There's another interesting advantage: since this is written in Rust, it might serve as a filter for **some** malformed requests which might be exploits. But I don't recommend relying on it! +### Overriding wallet + +For each user you can set a specific wallet name to be used by setting `override_wallet = "wallet_name_here"`. +When this is set the wallet sent in request is ignored and the specified wallet is used instead. Aside from obvious security benefits this can help workaround applications that are incapable of accessing specific wallet (e.g. btc-rpc-explorer at the time of writing). + ### On-demand block fetching By connecting to your pruned Bitcoin node through Bitcoin Proxy, your node will now behave as though it is not pruned. If a user or application requires a block that is not retained by your pruned node, Bitcoin Proxy will dynamically fetch the block over the P2P network, then verify its hash against your node to ensure validity. diff --git a/btc_rpc_proxy.toml b/btc_rpc_proxy.toml index 7705e71..4d6fe94 100644 --- a/btc_rpc_proxy.toml +++ b/btc_rpc_proxy.toml @@ -4,6 +4,7 @@ bind_address = "127.0.0.1" [user.public] password = "public" +# override_wallet = "some_wallet_name_here" allowed_calls = [ "getinfo", "getblock", diff --git a/src/proxy.rs b/src/proxy.rs index 2efaef0..cf24042 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -30,9 +30,13 @@ pub async fn proxy_request( Ok(req) => { let state_local = state.clone(); let name_local = Arc::new(name); + let path = user.override_wallet + .as_ref() + .map(AsRef::as_ref) + .unwrap_or(parts.uri.path()); let response = state .rpc_client - .send(parts.uri.path(), &req, move |_path, req| { + .send(path, &req, move |_path, req| { use futures::TryFutureExt; let name_local_ok = name_local.clone(); let name_local_err = name_local.clone(); diff --git a/src/users.rs b/src/users.rs index 80295c5..faa396c 100644 --- a/src/users.rs +++ b/src/users.rs @@ -30,14 +30,21 @@ pub mod input { pub allowed_calls: HashSet, #[serde(default)] pub fetch_blocks: Option, + #[serde(default)] + pub override_wallet: Option, } impl User { fn map_default(self, default_fetch_blocks: bool) -> super::User { + let wallet = self.override_wallet.map(|mut wallet| { + wallet.insert_str(0, "/wallet/"); + wallet + }); super::User { password: self.password, allowed_calls: self.allowed_calls, fetch_blocks: self.fetch_blocks.unwrap_or(default_fetch_blocks), + override_wallet: wallet, } } } @@ -176,6 +183,7 @@ pub struct User { pub allowed_calls: HashSet, #[serde(default)] pub fetch_blocks: bool, + pub override_wallet: Option, } impl User { pub async fn intercept<'a>( From 245f9dd062445a1ea1d2c440732d35e3373a7d72 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 29 Mar 2023 15:29:27 +0200 Subject: [PATCH 04/25] Fix test --- src/users.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/users.rs b/src/users.rs index faa396c..e16eabe 100644 --- a/src/users.rs +++ b/src/users.rs @@ -324,6 +324,7 @@ mod tests { password: "secret".try_into().expect("failed to create password"), allowed_calls: HashSet::new(), fetch_blocks: input, + override_wallet: None, }); let result = super::input::map_default(users, default); From e94fcc8c3bd214f6aebfddba9fc805cb4b0fa947 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 10 Jul 2024 17:13:07 +0200 Subject: [PATCH 05/25] Remove useless dependencies --- Cargo.lock | 30 +----------------------------- Cargo.toml | 2 -- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0125106..b2548d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,9 +113,7 @@ dependencies = [ "bitcoin", "configure_me", "configure_me_codegen", - "derive_more", - "enum_future", - "futures 0.3.13", + "futures", "hex", "http", "hyper", @@ -275,17 +273,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "derive_more" -version = "0.99.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "digest" version = "0.8.1" @@ -322,15 +309,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -[[package]] -name = "enum_future" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fab1e733e2e6068206c4fc77784f921776ae38e92fe334abb6204f8c249ebf05" -dependencies = [ - "futures 0.1.31", -] - [[package]] name = "error-chain" version = "0.12.4" @@ -380,12 +358,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "futures" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" - [[package]] name = "futures" version = "0.3.13" diff --git a/Cargo.toml b/Cargo.toml index a82161e..b94a50d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,8 +32,6 @@ base32 = "0.4.0" base64 = "0.13.0" bitcoin = { version = "0.26.0", features = ["use-serde"] } configure_me = { version = "0.4.0" } -derive_more = "0.99.11" -enum_future = "0.1" futures = "0.3.12" hex = "0.4.2" http = "0.2.3" From b9911244398216f59c3d828b8e90500b020406ab Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 10 Jul 2024 17:40:41 +0200 Subject: [PATCH 06/25] Update dependencies to match master --- Cargo.lock | 119 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b2548d7..f749ce7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,6 +133,12 @@ dependencies = [ "tokio-compat-02", ] +[[package]] +name = "bumpalo" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad807f2fc2bf185eeb98ff3a901bd46dc5ad58163d0fa4577ba0d25674d71708" + [[package]] name = "byte-tools" version = "0.3.1" @@ -194,14 +200,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "6127248204b9aba09a362f6c930ef6a78f2c1b2215f8a7b398c06e1083f17af0" dependencies = [ - "libc", + "js-sys", "num-integer", "num-traits", - "time", + "wasm-bindgen", "winapi 0.3.9", ] @@ -620,6 +626,15 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +[[package]] +name = "js-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cedf50c705f7ede60202104d9cb08d02f3156d4a6f4f638ab4fcdfd0e9ecdda" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -638,9 +653,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.88" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "libsystemd" @@ -789,9 +804,9 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ "autocfg", "num-traits", @@ -799,9 +814,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", ] @@ -818,9 +833,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.7.2" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" [[package]] name = "opaque-debug" @@ -1064,9 +1079,9 @@ checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06" [[package]] name = "slog-async" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c60813879f820c85dbc4eabf3269befe374591289019775898d56a81a804fbdc" +checksum = "766c59b252e62a34651412870ff55d8c4e6d04df19b43eecb2703e417b097ffe" dependencies = [ "crossbeam-channel", "slog", @@ -1076,9 +1091,9 @@ dependencies = [ [[package]] name = "slog-term" -version = "2.8.0" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95c1e7e5aab61ced6006149ea772770b84a0d16ce0f7885def313e4829946d76" +checksum = "f3668dd2252f4381d64de0c79e6c8dc6bd509d1cab3535b35a3fc9bafd1241d5" dependencies = [ "atty", "chrono", @@ -1124,9 +1139,9 @@ checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" [[package]] name = "syn" -version = "1.0.61" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed22b90a0e734a23a7610f4283ac9e5acfb96cbb30dfefa540d66f866f1c09c5" +checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702" dependencies = [ "proc-macro2", "quote", @@ -1184,23 +1199,13 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" dependencies = [ "once_cell", ] -[[package]] -name = "time" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" -dependencies = [ - "libc", - "winapi 0.3.9", -] - [[package]] name = "tokio" version = "0.2.25" @@ -1383,6 +1388,60 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "wasm-bindgen" +version = "0.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "220f01bcb6b306c063e3283f97dd974bcab4e5affed2b654bae1a22d0d99c3aa" +dependencies = [ + "cfg-if 0.1.10", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8894c95e23cc5082786192ebbd2ac0e31e9f77a022132ba03e8b8de32a2323c6" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec031a3190c51dda28c9f3623e2674e58c79f6d88c020c2157417fcf62298a3f" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b7cad0ab0bb5fefbb770279f522dcebb6433585174d93ea648390f61db57401" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9142625bbb0d70710b3f2a6b20924c80fa182b05888b6bd21600ab9075673563" + [[package]] name = "winapi" version = "0.2.8" From 8f9bcb131dfde17f46a11173a7e9ef77886c9220 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Sat, 13 Jul 2024 14:03:47 +0200 Subject: [PATCH 07/25] Disable HTTP2 HTTP version 2 is not used by the clients so having it enabled just makes attack surface bigger without providing benefits. --- Cargo.lock | 50 -------------------------------------------------- Cargo.toml | 2 +- src/lib.rs | 1 + 3 files changed, 2 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af5698d..a7c4f5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -476,31 +476,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "h2" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d832b01df74254fe364568d6ddc294443f61cbec82816b60904303af87efae78" -dependencies = [ - "bytes 1.0.1", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio 1.2.0", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" - [[package]] name = "hermit-abi" version = "0.1.18" @@ -569,7 +544,6 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", "http", "http-body", "httparse", @@ -583,16 +557,6 @@ dependencies = [ "want", ] -[[package]] -name = "indexmap" -version = "1.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "instant" version = "0.1.9" @@ -1278,20 +1242,6 @@ dependencies = [ "tokio 1.2.0", ] -[[package]] -name = "tokio-util" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebb7cb2f00c5ae8df755b252306272cd1790d39728363936e01827e11f0b017b" -dependencies = [ - "bytes 1.0.1", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.2.6", - "tokio 1.2.0", -] - [[package]] name = "toml" version = "0.5.8" diff --git a/Cargo.toml b/Cargo.toml index f6f6d03..55dce15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ configure_me = { version = "0.4.0" } futures = "0.3.12" hex = "0.4.2" http = "0.2.3" -hyper = { version = "0.14.4", features = ["client", "server", "stream", "http2", "http1", "tcp"] } +hyper = { version = "0.14.4", features = ["client", "server", "stream", "http1", "tcp"] } itertools = "0.10.0" lazy_static = "1.4.0" linear-map = { version = "1.2.0", features = ["serde_impl"] } diff --git a/src/lib.rs b/src/lib.rs index 8b1565f..f26bcbb 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,6 +55,7 @@ pub async fn compat_main( let server = Server::builder(hyper::server::accept::from_stream(TcpListenerCompat( listener, ))) + .http1_only(true) .serve(make_service); Ok(server.await?) From 80717a5826c8911db08c7426107ccbb550fa45ba Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Sat, 13 Jul 2024 15:48:31 +0200 Subject: [PATCH 08/25] Upgrade `systemd_socket` The new `systemd_socket` crate supports `tokio` 1.0 so we can remove the compat dependencies too. --- Cargo.lock | 291 +++++++++++++++-------------------------------------- Cargo.toml | 4 +- src/lib.rs | 28 ++---- 3 files changed, 89 insertions(+), 234 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7c4f5c..eed3296 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,25 +83,13 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "block-buffer" -version = "0.7.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "block-padding", - "byte-tools", - "byteorder", "generic-array", ] -[[package]] -name = "block-padding" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" -dependencies = [ - "byte-tools", -] - [[package]] name = "btc-rpc-proxy" version = "0.3.1" @@ -128,9 +116,7 @@ dependencies = [ "socks", "systemd_socket", "thiserror", - "tokio 0.2.25", - "tokio 1.2.0", - "tokio-compat-02", + "tokio", ] [[package]] @@ -139,24 +125,12 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad807f2fc2bf185eeb98ff3a901bd46dc5ad58163d0fa4577ba0d25674d71708" -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - [[package]] name = "byteorder" version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" -[[package]] -name = "bytes" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - [[package]] name = "bytes" version = "1.0.1" @@ -248,6 +222,15 @@ dependencies = [ "void", ] +[[package]] +name = "cpufeatures" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +dependencies = [ + "libc", +] + [[package]] name = "crossbeam-channel" version = "0.5.0" @@ -270,22 +253,24 @@ dependencies = [ ] [[package]] -name = "crypto-mac" -version = "0.7.0" +name = "crypto-common" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", - "subtle", + "typenum", ] [[package]] name = "digest" -version = "0.8.1" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "generic-array", + "block-buffer", + "crypto-common", + "subtle", ] [[package]] @@ -315,27 +300,12 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -[[package]] -name = "error-chain" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" -dependencies = [ - "version_check", -] - [[package]] name = "event-listener" version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" -[[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" - [[package]] name = "fmt2io" version = "0.1.0" @@ -348,22 +318,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "futures" version = "0.3.13" @@ -449,7 +403,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.6", + "pin-project-lite", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -458,11 +412,12 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.12.4" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", + "version_check", ] [[package]] @@ -493,11 +448,10 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hmac" -version = "0.7.1" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "crypto-mac", "digest", ] @@ -507,7 +461,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" dependencies = [ - "bytes 1.0.1", + "bytes", "fnv", "itoa", ] @@ -518,7 +472,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994" dependencies = [ - "bytes 1.0.1", + "bytes", "http", ] @@ -540,7 +494,7 @@ version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" dependencies = [ - "bytes 1.0.1", + "bytes", "futures-channel", "futures-core", "futures-util", @@ -551,7 +505,7 @@ dependencies = [ "itoa", "pin-project", "socket2", - "tokio 1.2.0", + "tokio", "tower-service", "tracing", "want", @@ -566,15 +520,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - [[package]] name = "itertools" version = "0.10.0" @@ -599,16 +544,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -617,22 +552,25 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.140" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libsystemd" -version = "0.2.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a64961e79726a5b05e0db592097ca895831d755484203578fe75b580847262" +checksum = "8144587c71c16756b1055d3dcb0c75cb605a10ecd6523cc33702d5f90902bf6d" dependencies = [ - "error-chain", "hmac", "libc", + "log", "nix", + "nom", + "once_cell", "serde", "sha2", + "thiserror", "uuid", ] @@ -680,24 +618,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] -name = "mio" -version = "0.6.23" +name = "memoffset" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow 0.2.2", - "net2", - "slab", - "winapi 0.2.8", + "autocfg", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "mio" version = "0.7.9" @@ -706,23 +640,11 @@ checksum = "a5dede4e2065b3842b8b0af444119f3aa331cc7cc2dd20388bfb0f5d5a38823a" dependencies = [ "libc", "log", - "miow 0.3.6", + "miow", "ntapi", "winapi 0.3.9", ] -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - [[package]] name = "miow" version = "0.3.6" @@ -734,27 +656,26 @@ dependencies = [ ] [[package]] -name = "net2" -version = "0.2.37" +name = "nix" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" +checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" dependencies = [ - "cfg-if 0.1.10", + "bitflags", + "cc", + "cfg-if 1.0.0", "libc", - "winapi 0.3.9", + "memoffset", ] [[package]] -name = "nix" -version = "0.17.0" +name = "nom" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ - "bitflags", - "cc", - "cfg-if 0.1.10", - "libc", - "void", + "memchr", + "minimal-lexical", ] [[package]] @@ -797,15 +718,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.5.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" - -[[package]] -name = "opaque-debug" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "parking_lot" @@ -858,12 +773,6 @@ dependencies = [ "syn", ] -[[package]] -name = "pin-project-lite" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" - [[package]] name = "pin-project-lite" version = "0.2.6" @@ -1010,14 +919,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.8.2" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "block-buffer", + "cfg-if 1.0.0", + "cpufeatures", "digest", - "fake-simd", - "opaque-debug", ] [[package]] @@ -1097,9 +1005,9 @@ dependencies = [ [[package]] name = "subtle" -version = "1.0.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -1114,14 +1022,14 @@ dependencies = [ [[package]] name = "systemd_socket" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9142be19400d094bab8a1b93f5059aa2147f7ab5760546ce6632a82b69085a4b" +checksum = "4fc6b7e87092812a4e64d1eaa46b838143df56bef3b713db51136a6f3cc9729b" dependencies = [ "lazy_static", "libsystemd", "thiserror", - "tokio 0.2.25", + "tokio", ] [[package]] @@ -1170,22 +1078,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "tokio" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" -dependencies = [ - "bytes 0.5.6", - "futures-core", - "iovec", - "lazy_static", - "mio 0.6.23", - "num_cpus", - "pin-project-lite 0.1.12", - "slab", -] - [[package]] name = "tokio" version = "1.2.0" @@ -1193,33 +1085,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" dependencies = [ "autocfg", - "bytes 1.0.1", + "bytes", "libc", "memchr", - "mio 0.7.9", + "mio", "num_cpus", "once_cell", "parking_lot", - "pin-project-lite 0.2.6", + "pin-project-lite", "signal-hook-registry", "tokio-macros", "winapi 0.3.9", ] -[[package]] -name = "tokio-compat-02" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7d4237822b7be8fff0a7a27927462fad435dcb6650f95cea9e946bf6bdc7e07" -dependencies = [ - "bytes 0.5.6", - "once_cell", - "pin-project-lite 0.2.6", - "tokio 0.2.25", - "tokio 1.2.0", - "tokio-stream", -] - [[package]] name = "tokio-macros" version = "1.8.2" @@ -1231,17 +1109,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-stream" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1981ad97df782ab506a1f43bf82c967326960d278acf3bf8279809648c3ff3ea" -dependencies = [ - "futures-core", - "pin-project-lite 0.2.6", - "tokio 1.2.0", -] - [[package]] name = "toml" version = "0.5.8" @@ -1264,7 +1131,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ "cfg-if 1.0.0", - "pin-project-lite 0.2.6", + "pin-project-lite", "tracing-core", ] @@ -1285,9 +1152,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "typenum" -version = "1.12.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-segmentation" diff --git a/Cargo.toml b/Cargo.toml index 55dce15..660dcd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,10 +46,8 @@ slog-async = "2.6.0" slog-term = "2.6.0" socks = "0.3.3" tokio = { version = "1.0.2", features = ["full"] } -tokio-compat-02 = "0.2" -tokio_02 = { version = "0.2.22", package = "tokio", features = ["stream"] } thiserror = "1.0.22" -systemd_socket = { version = "0.1.1", default-features = false, features = ["tokio_0_2"] } +systemd_socket = { version = "0.1.2", default-features = false, features = ["tokio"] } [build-dependencies] configure_me_codegen = "0.4.3" diff --git a/src/lib.rs b/src/lib.rs index f26bcbb..e690ee0 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,6 @@ use hyper::{ server::Server, service::{make_service_fn, service_fn}, }; -use tokio_compat_02::FutureExt as _; pub use crate::client::{AuthSource, RpcClient}; pub use crate::fetch_blocks::Peers; @@ -29,13 +28,6 @@ pub use crate::state::{State, TorState}; pub use crate::users::{User, Users}; pub async fn main(state: Arc, bind_addr: systemd_socket::SocketAddr) -> Result<(), Error> { - compat_main(state, bind_addr).compat().await -} - -pub async fn compat_main( - state: Arc, - bind_addr: systemd_socket::SocketAddr, -) -> Result<(), Error> { let state_local = state.clone(); let make_service = make_service_fn(move |_conn| { let state_local_local = state_local.clone(); @@ -46,30 +38,28 @@ pub async fn compat_main( } }); - let listener = bind_addr.bind_tokio_0_2().await.map_err(|error| { + let listener = bind_addr.bind_tokio().await.map_err(|error| { let new_error = anyhow::anyhow!("failed to create the listening socket: {}", error); error!(state.logger, "failed to create the listening socket"; "error" => #error); new_error })?; - let server = Server::builder(hyper::server::accept::from_stream(TcpListenerCompat( - listener, - ))) - .http1_only(true) - .serve(make_service); + let server = Server::builder(hyper::server::accept::from_stream(TcpListener(listener))) + .http1_only(true) + .serve(make_service); Ok(server.await?) } -struct TcpListenerCompat(tokio_02::net::TcpListener); -impl futures::Stream for TcpListenerCompat { - type Item = tokio_02::io::Result>; +struct TcpListener(tokio::net::TcpListener); + +impl futures::Stream for TcpListener { + type Item = std::io::Result; fn poll_next( self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>, ) -> std::task::Poll> { - tokio_02::stream::Stream::poll_next(unsafe { self.map_unchecked_mut(|s| &mut s.0) }, cx) - .map(|a| a.map(|a| a.map(tokio_compat_02::IoCompat::new))) + self.0.poll_accept(cx).map(|result| Some(result.map(|(conn, _addr)| conn))) } } From ca091e1257bbb9f7893463f0d5258f1fbfc50803 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Sat, 13 Jul 2024 15:51:54 +0200 Subject: [PATCH 09/25] Update crossbeam-utils --- Cargo.lock | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eed3296..ae5c9f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -243,13 +243,11 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.3" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" dependencies = [ - "autocfg", "cfg-if 1.0.0", - "lazy_static", ] [[package]] From 3f307094b90b99d5ed46123f8d1dc7029789af16 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Sat, 13 Jul 2024 16:00:37 +0200 Subject: [PATCH 10/25] Update `httparse` --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae5c9f4..f1e09c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -476,9 +476,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.3.5" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "httpdate" From 1c709f546513cec8eb3f251f49d7628a9d426af1 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Sat, 13 Jul 2024 16:09:19 +0200 Subject: [PATCH 11/25] Updated `hyper` and `mio` --- Cargo.lock | 60 +++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1e09c5..f2ff590 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -461,7 +461,7 @@ checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" dependencies = [ "bytes", "fnv", - "itoa", + "itoa 0.4.7", ] [[package]] @@ -482,15 +482,15 @@ checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "httpdate" -version = "0.3.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" +checksum = "05842d0d43232b23ccb7060ecb0f0626922c21f30012e97b767b30afd4a5d4b9" [[package]] name = "hyper" -version = "0.14.4" +version = "0.14.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" +checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" dependencies = [ "bytes", "futures-channel", @@ -500,9 +500,9 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa", - "pin-project", - "socket2", + "itoa 1.0.11", + "pin-project-lite", + "socket2 0.4.10", "tokio", "tower-service", "tracing", @@ -533,6 +533,12 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + [[package]] name = "js-sys" version = "0.3.0" @@ -632,9 +638,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "mio" -version = "0.7.9" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5dede4e2065b3842b8b0af444119f3aa331cc7cc2dd20388bfb0f5d5a38823a" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" dependencies = [ "libc", "log", @@ -649,7 +655,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ - "socket2", + "socket2 0.3.19", "winapi 0.3.9", ] @@ -751,26 +757,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14248cc8eced350e20122a291613de29e4fa129ba2731818c4cdbb44fccd3e55" -[[package]] -name = "pin-project" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "pin-project-lite" version = "0.2.6" @@ -901,7 +887,7 @@ version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ - "itoa", + "itoa 0.4.7", "ryu", "serde", ] @@ -989,6 +975,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "socks" version = "0.3.3" From 03d1c70a0f03d93f7f8dcc4d24fbeffae93eca53 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Sat, 13 Jul 2024 16:48:12 +0200 Subject: [PATCH 12/25] Updated `tokio` and related dependencies --- Cargo.lock | 330 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 262 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2ff590..15e2a83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.38" @@ -32,9 +41,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "base32" @@ -121,9 +130,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "2.6.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad807f2fc2bf185eeb98ff3a901bd46dc5ad58163d0fa4577ba0d25674d71708" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" @@ -160,12 +169,6 @@ version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -174,17 +177,26 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.20" +version = "0.4.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6127248204b9aba09a362f6c930ef6a78f2c1b2215f8a7b398c06e1083f17af0" +checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" dependencies = [ - "js-sys", + "iana-time-zone", "num-integer", "num-traits", - "wasm-bindgen", "winapi 0.3.9", ] +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "concurrent-queue" version = "1.2.2" @@ -222,6 +234,12 @@ dependencies = [ "void", ] +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "cpufeatures" version = "0.2.11" @@ -237,7 +255,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crossbeam-utils", ] @@ -247,7 +265,7 @@ version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -260,6 +278,50 @@ dependencies = [ "typenum", ] +[[package]] +name = "cxx" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e3676b55f0940b8bda1b5572565de145fba36f2d3d52161a0cac0d50ed9682" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0381fd62cd81a77f5b8dba405b4614d6d6f8f4e967bb73864bb5c494d58524f0" +dependencies = [ + "cc", + "codespan-reporting", + "lazy_static", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9298b94e5700ce538cf937e17e60a1d98967fa957f74e9e83ff93f18aece8692" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "797f58b486d6d9579f6ddc2138c6ac0cfcc0be482e93464e1d9a1df5014dd5c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "digest" version = "0.10.7" @@ -277,7 +339,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "dirs-sys-next", ] @@ -424,7 +486,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi", ] @@ -502,20 +564,44 @@ dependencies = [ "httpdate", "itoa 1.0.11", "pin-project-lite", - "socket2 0.4.10", + "socket2", "tokio", "tower-service", "tracing", "want", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "instant" -version = "0.1.9" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -541,9 +627,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.0" +version = "0.3.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cedf50c705f7ede60202104d9cb08d02f3156d4a6f4f638ab4fcdfd0e9ecdda" +checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" dependencies = [ "wasm-bindgen", ] @@ -588,12 +674,22 @@ dependencies = [ "serde_test", ] +[[package]] +name = "link-cplusplus" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d240c6f7e1ba3a28b0249f774e6a9dd0175054b52dfbb61b16eb8505c3785c9" +dependencies = [ + "cc", +] + [[package]] name = "lock_api" -version = "0.4.2" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ + "autocfg", "scopeguard", ] @@ -603,7 +699,7 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -651,11 +747,10 @@ dependencies = [ [[package]] name = "miow" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "socket2 0.3.19", "winapi 0.3.9", ] @@ -667,7 +762,7 @@ checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" dependencies = [ "bitflags", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", "memoffset", ] @@ -684,28 +779,27 @@ dependencies = [ [[package]] name = "ntapi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" dependencies = [ "winapi 0.3.9", ] [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", ] @@ -728,9 +822,9 @@ checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "parking_lot" -version = "0.11.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733" dependencies = [ "instant", "lock_api", @@ -743,7 +837,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "instant", "libc", "redox_syscall", @@ -842,6 +936,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "scratch" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" + [[package]] name = "secp256k1" version = "0.20.1" @@ -907,7 +1007,7 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest", ] @@ -964,17 +1064,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" -[[package]] -name = "socket2" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "winapi 0.3.9", -] - [[package]] name = "socket2" version = "0.4.10" @@ -1043,6 +1132,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.24" @@ -1074,11 +1172,10 @@ dependencies = [ [[package]] name = "tokio" -version = "1.2.0" +version = "1.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" +checksum = "0c27a64b625de6d309e8c57716ba93021dccf1b3b5c97edd6d3dd2d2135afc0a" dependencies = [ - "autocfg", "bytes", "libc", "memchr", @@ -1124,7 +1221,7 @@ version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "pin-project-lite", "tracing-core", ] @@ -1156,6 +1253,12 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + [[package]] name = "unicode-xid" version = "0.2.1" @@ -1201,19 +1304,19 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.49" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "220f01bcb6b306c063e3283f97dd974bcab4e5affed2b654bae1a22d0d99c3aa" +checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.49" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8894c95e23cc5082786192ebbd2ac0e31e9f77a022132ba03e8b8de32a2323c6" +checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" dependencies = [ "bumpalo", "lazy_static", @@ -1226,9 +1329,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.49" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec031a3190c51dda28c9f3623e2674e58c79f6d88c020c2157417fcf62298a3f" +checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1236,9 +1339,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.49" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b7cad0ab0bb5fefbb770279f522dcebb6433585174d93ea648390f61db57401" +checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" dependencies = [ "proc-macro2", "quote", @@ -1249,9 +1352,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.49" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9142625bbb0d70710b3f2a6b20924c80fa182b05888b6bd21600ab9075673563" +checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" [[package]] name = "winapi" @@ -1281,12 +1384,103 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "ws2_32-sys" version = "0.2.1" From 2e52d6a419e1635fc96c3d23026911f879f8b64c Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Sat, 13 Jul 2024 16:52:10 +0200 Subject: [PATCH 13/25] Remove the `old_rust` feature This feature is no longer needed since we're droppin 1.41 support anyway and if it ever needs to be reintroduced using a build script is better. --- Cargo.toml | 1 - src/lib.rs | 2 -- src/rpc_methods.rs | 3 --- src/users.rs | 3 --- src/util.rs | 24 ------------------------ 5 files changed, 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 660dcd6..56cf45e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ spec = "config_spec.toml" [features] default = ["debug_logs", "systemd"] -old_rust = [] debug_logs = ["slog/max_level_debug"] systemd = ["systemd_socket/enable_systemd"] diff --git a/src/lib.rs b/src/lib.rs index e690ee0..5eea47a 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -#![cfg_attr(feature = "old_rust", allow(unstable_name_collisions))] - #[macro_use] extern crate slog; diff --git a/src/rpc_methods.rs b/src/rpc_methods.rs index f430c1b..778b2fc 100644 --- a/src/rpc_methods.rs +++ b/src/rpc_methods.rs @@ -5,9 +5,6 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use crate::client::RpcMethod; use crate::util::{Either, HexBytes}; -#[cfg(feature = "old_rust")] -use crate::util::old_rust::StrCompat; - #[derive(Debug)] pub struct GetBlock; #[derive(Debug, Deserialize, Serialize)] diff --git a/src/users.rs b/src/users.rs index e16eabe..3c7199f 100644 --- a/src/users.rs +++ b/src/users.rs @@ -16,9 +16,6 @@ use crate::rpc_methods::{ }; use crate::state::State; -#[cfg(feature = "old_rust")] -use crate::util::old_rust::StrCompat; - pub use password::Password; pub mod input { diff --git a/src/util.rs b/src/util.rs index b8fe3c6..f7b082d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -58,30 +58,6 @@ pub trait ApplyMut { } impl ApplyMut for T {} -#[cfg(feature = "old_rust")] -pub mod old_rust { - pub trait StrCompat { - fn strip_prefix<'a>(&'a self, prefix: &str) -> Option<&'a str>; - fn strip_suffix<'a>(&'a self, suffix: &str) -> Option<&'a str>; - } - impl StrCompat for str { - fn strip_prefix<'a>(&'a self, prefix: &str) -> Option<&'a str> { - if let Some(s) = self.matches(prefix).next() { - Some(&self[s.len()..]) - } else { - None - } - } - fn strip_suffix<'a>(&'a self, suffix: &str) -> Option<&'a str> { - if let Some(s) = self.rmatches(suffix).next() { - Some(&self[..(self.len() - s.len())]) - } else { - None - } - } - } -} - #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[serde(untagged)] pub enum Either { From 94929fad0a12ca077fbd6a2d08ac8d56c74b0578 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Sat, 13 Jul 2024 20:49:13 +0200 Subject: [PATCH 14/25] Release version 0.4 This release updates dependencies and supports fetching blocks from Onion v3 peers. The MSRV is now increased to 1.48.0 --- .github/workflows/rust.yml | 6 +++--- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 19760d7..0f7d2ba 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,10 +19,10 @@ jobs: - name: Use old rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.41.1 + toolchain: 1.48.0 override: true - name: Build - run: cargo build --features=old_rust --verbose + run: cargo build --verbose - name: Run tests - run: cargo test --features=old_rust --verbose + run: cargo test --verbose diff --git a/Cargo.lock b/Cargo.lock index 15e2a83..23839fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,7 +101,7 @@ dependencies = [ [[package]] name = "btc-rpc-proxy" -version = "0.3.1" +version = "0.4.0" dependencies = [ "anyhow", "async-channel", diff --git a/Cargo.toml b/Cargo.toml index 56cf45e..47110e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ authors = [ description = "Finer-grained permission management for bitcoind." edition = "2018" name = "btc-rpc-proxy" -version = "0.3.1" +version = "0.4.0" [lib] name = "btc_rpc_proxy" From ce38e8950f883683544de0174d21935b0f94b7e7 Mon Sep 17 00:00:00 2001 From: Chris Guida Date: Mon, 28 Mar 2022 12:03:47 -0600 Subject: [PATCH 15/25] add rpc params to debug logs (#11) --- src/proxy.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/proxy.rs b/src/proxy.rs index 2222eec..9f764a7 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -52,9 +52,10 @@ pub async fn proxy_request( debug!( state_local_ok.logger, "processed request"; + "params" => serde_json::to_string(&req.params).unwrap_or_default(), "user" => name_local_ok, "method" => req.method.0.clone(), - "action" => action_description + "action" => action_description, ); res }) @@ -62,6 +63,7 @@ pub async fn proxy_request( warn!( state_local_err.logger, "failed request"; + "params" => serde_json::to_string(&req.params).unwrap_or_default(), "user" => name_local_err, "method" => req.method.0.clone(), "error_code" => error.code, From 75cab4241f3a0e36cf3b6d8b73e63f733836a6ca Mon Sep 17 00:00:00 2001 From: Chris Guida Date: Wed, 8 Jun 2022 16:18:56 -0500 Subject: [PATCH 16/25] remove getblockchaininfo interception, so proxy can no longer masquerade as an archival node (#12) --- src/users.rs | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/users.rs b/src/users.rs index 3c7199f..c221e9f 100644 --- a/src/users.rs +++ b/src/users.rs @@ -47,14 +47,19 @@ pub mod input { } pub fn map_default(users: HashMap, default_fetch_blocks: bool) -> super::Users { - super::Users(users.into_iter().map(|(name, user)| (name, user.map_default(default_fetch_blocks))).collect()) + super::Users( + users + .into_iter() + .map(|(name, user)| (name, user.map_default(default_fetch_blocks))) + .collect(), + ) } } mod password { - use std::fmt; use std::convert::TryFrom; use std::ffi::{OsStr, OsString}; + use std::fmt; #[derive(serde::Deserialize)] #[serde(try_from = "String")] @@ -64,7 +69,10 @@ mod password { fn validate_str(string: &str) -> Result<(), InvalidPasswordError> { for (pos, byte) in string.bytes().enumerate() { if byte <= 0x1F || byte >= 0x7F { - return Err(InvalidPasswordError(InvalidPasswordErrorInner::BadChar { pos, byte, })) + return Err(InvalidPasswordError(InvalidPasswordErrorInner::BadChar { + pos, + byte, + })); } } Ok(()) @@ -99,13 +107,17 @@ mod password { type Error = InvalidPasswordError; fn parse_arg(arg: &OsStr) -> Result { - let string = arg.to_str().ok_or(InvalidPasswordError(InvalidPasswordErrorInner::NonAscii))?; + let string = arg + .to_str() + .ok_or(InvalidPasswordError(InvalidPasswordErrorInner::NonAscii))?; Password::validate_str(string)?; Ok(Password(string.to_owned())) } fn parse_owned_arg(arg: OsString) -> Result { - let string = arg.into_string().map_err(|_| InvalidPasswordError(InvalidPasswordErrorInner::NonAscii))?; + let string = arg + .into_string() + .map_err(|_| InvalidPasswordError(InvalidPasswordErrorInner::NonAscii))?; Password::validate_str(&string)?; Ok(Password(string.to_owned())) } @@ -120,15 +132,14 @@ mod password { // timing safe equality #[inline(never)] fn xor_contents(a: &[u8], b: &[u8]) -> usize { - a - .iter() + a.iter() .enumerate() .map(|(i, byte)| *byte ^ b[i % b.len()]) .fold(a.len() ^ b.len(), |acc, item| acc | usize::from(item)) } if self.0.is_empty() { - return other.is_empty() + return other.is_empty(); } let bits = xor_contents(self.0.as_bytes(), other.as_bytes()); @@ -145,7 +156,7 @@ mod password { #[derive(Debug, thiserror::Error)] enum InvalidPasswordErrorInner { #[error("invalid byte 0x{byte:02X} at position {pos}")] - BadChar { pos: usize, byte: u8, }, + BadChar { pos: usize, byte: u8 }, // non-utf-8 implies non-ascii #[error("not an ascii string")] NonAscii, @@ -289,14 +300,6 @@ impl User { } _ => Ok(None), // TODO } - } else if self.fetch_blocks && &*req.method == GetBlockchainInfo.as_str() { - let mut res = state.rpc_client.call(req).await?; - res.result.as_mut().map(|r| match r { - Value::Object(o) => o.get_mut("pruned").map(|p| *p = Value::Bool(false)), - _ => None, - }); - - Ok(Some(res)) } else { Ok(None) } From 898718b9f84f360b7202d51b8d2d6da50132c7de Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Mon, 19 Sep 2022 12:59:57 -0600 Subject: [PATCH 17/25] add support for object args --- Cargo.toml | 12 ++- src/client.rs | 51 ++++++++++++- src/users.rs | 207 ++++++++++++++++++++++++++------------------------ 3 files changed, 166 insertions(+), 104 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 47110e1..067eb64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,8 +53,16 @@ configure_me_codegen = "0.4.3" [package.metadata.deb] assets = [ - ["target/release/btc_rpc_proxy", "usr/bin/btc_rpc_proxy", "755"], - ["target/man/btc_rpc_proxy.1", "usr/bin/btc_rpc_proxy", "644"], + [ + "target/release/btc_rpc_proxy", + "usr/bin/btc_rpc_proxy", + "755", + ], + [ + "target/man/btc_rpc_proxy.1", + "usr/bin/btc_rpc_proxy", + "644", + ], ] extended-description = """ This is a proxy made specifically for `bitcoind` to allow finer-grained control of permissions. It enables you to specify several users and for each user the list of RPC calls he's allowed to make. diff --git a/src/client.rs b/src/client.rs index 13a07ff..8f39311 100644 --- a/src/client.rs +++ b/src/client.rs @@ -16,7 +16,7 @@ use serde::{ de::{Deserialize, Deserializer}, ser::{Serialize, Serializer}, }; -use serde_json::Value; +use serde_json::{Map, Value}; use tokio::sync::RwLock; pub const MISC_ERROR_CODE: i64 = -1; @@ -104,8 +104,54 @@ pub trait RpcMethod { #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct GenericRpcMethod(pub String); +#[derive(Debug)] +pub enum GenericRpcParams { + Array(Vec), + Object(Map), +} +impl Serialize for GenericRpcParams { + fn serialize(&self, serializer: S) -> Result { + match self { + GenericRpcParams::Array(s) => s.serialize(serializer), + GenericRpcParams::Object(b) => b.serialize(serializer), + } + } +} +impl<'de> Deserialize<'de> for GenericRpcParams { + fn deserialize>(deserializer: D) -> Result { + struct Visitor; + impl<'de> serde::de::Visitor<'de> for Visitor { + type Value = GenericRpcParams; + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(formatter, "an array or object") + } + fn visit_seq>( + self, + mut seq: A, + ) -> Result { + let mut res = Vec::with_capacity(seq.size_hint().unwrap_or(16)); + while let Some(elem) = seq.next_element()? { + res.push(elem); + } + Ok(GenericRpcParams::Array(res)) + } + fn visit_map>( + self, + mut map: A, + ) -> Result { + let mut res = Map::with_capacity(map.size_hint().unwrap_or(16)); + while let Some((k, v)) = map.next_entry()? { + res.insert(k, v); + } + Ok(GenericRpcParams::Object(res)) + } + } + deserializer.deserialize_any(Visitor) + } +} + impl RpcMethod for GenericRpcMethod { - type Params = Vec; + type Params = GenericRpcParams; type Response = Value; fn as_str<'a>(&'a self) -> &'a str { self.0.as_str() @@ -120,7 +166,6 @@ impl std::ops::Deref for GenericRpcMethod { } } - #[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct RpcRequest { #[serde(default)] diff --git a/src/users.rs b/src/users.rs index c221e9f..c5ca918 100644 --- a/src/users.rs +++ b/src/users.rs @@ -7,13 +7,12 @@ use hyper::{header::HeaderValue, StatusCode}; use serde_json::Value; use crate::client::{ - GenericRpcMethod, RpcError, RpcMethod, RpcRequest, RpcResponse, METHOD_NOT_ALLOWED_ERROR_CODE, - METHOD_NOT_ALLOWED_ERROR_MESSAGE, MISC_ERROR_CODE, PRUNE_ERROR_MESSAGE, + GenericRpcMethod, GenericRpcParams, RpcError, RpcMethod, RpcRequest, RpcResponse, + METHOD_NOT_ALLOWED_ERROR_CODE, METHOD_NOT_ALLOWED_ERROR_MESSAGE, MISC_ERROR_CODE, + PRUNE_ERROR_MESSAGE, }; use crate::fetch_blocks::fetch_block; -use crate::rpc_methods::{ - GetBlock, GetBlockHeader, GetBlockHeaderParams, GetBlockResult, GetBlockchainInfo, -}; +use crate::rpc_methods::{GetBlock, GetBlockHeader, GetBlockHeaderParams, GetBlockResult}; use crate::state::State; pub use password::Password; @@ -200,108 +199,118 @@ impl User { req: &'a RpcRequest, ) -> Result>, RpcError> { if self.allowed_calls.contains(&*req.method) { - if self.fetch_blocks && &*req.method == GetBlock.as_str() - // only non-verbose for now - { - match req.params.get(1).unwrap_or(&1_u64.into()) { - Value::Number(ref n) if n.as_u64() == Some(0) => { - match fetch_block( - state.clone(), - state.get_peers().await?, - serde_json::from_value(req.params[0].clone()).map_err(Error::from)?, - ) - .await - { - Ok(Some(block)) => { - let mut block_data = Vec::new(); - block - .consensus_encode(&mut block_data) - .map_err(Error::from)?; - let block_data = hex::encode(&block_data); - Ok(Some(RpcResponse { + match &req.params { + GenericRpcParams::Array(params) + if self.fetch_blocks && &*req.method == GetBlock.as_str() => + // only non-verbose for now + { + match params.get(1).unwrap_or(&1_u64.into()) { + Value::Number(ref n) if n.as_u64() == Some(0) => { + match fetch_block( + state.clone(), + state.get_peers().await?, + serde_json::from_value(params[0].clone()).map_err(Error::from)?, + ) + .await + { + Ok(Some(block)) => { + let mut block_data = Vec::new(); + block + .consensus_encode(&mut block_data) + .map_err(Error::from)?; + let block_data = hex::encode(&block_data); + Ok(Some(RpcResponse { + id: req.id.clone(), + result: Some(Value::String(block_data)), + error: None, + })) + } + Ok(None) => Ok(Some(RpcResponse { id: req.id.clone(), - result: Some(Value::String(block_data)), - error: None, - })) + result: None, + error: Some(RpcError { + code: MISC_ERROR_CODE, + message: PRUNE_ERROR_MESSAGE.to_owned(), + status: None, + }), + })), + Err(e) => Ok(Some(e.into())), } - Ok(None) => Ok(Some(RpcResponse { - id: req.id.clone(), - result: None, - error: Some(RpcError { - code: MISC_ERROR_CODE, - message: PRUNE_ERROR_MESSAGE.to_owned(), - status: None, - }), - })), - Err(e) => Ok(Some(e.into())), } - } - Value::Number(ref n) if n.as_u64() == Some(1) => { - let hash = - serde_json::from_value(req.params[0].clone()).map_err(Error::from)?; - let fetch_header_req = RpcRequest { - id: None, - method: GetBlockHeader, - params: GetBlockHeaderParams(hash, Some(true)), - }; - match futures::try_join!( - async { - state - .rpc_client - .call(&fetch_header_req) - .await? - .into_result() - }, - async { - fetch_block(state.clone(), state.clone().get_peers().await?, hash) + Value::Number(ref n) if n.as_u64() == Some(1) => { + let hash = + serde_json::from_value(params[0].clone()).map_err(Error::from)?; + let fetch_header_req = RpcRequest { + id: None, + method: GetBlockHeader, + params: GetBlockHeaderParams(hash, Some(true)), + }; + match futures::try_join!( + async { + state + .rpc_client + .call(&fetch_header_req) + .await? + .into_result() + }, + async { + fetch_block( + state.clone(), + state.clone().get_peers().await?, + hash, + ) .await + } + ) { + Ok((header, Some(block))) => Ok(Some(RpcResponse { + id: req.id.clone(), + result: { + let size = block.get_size(); + let witness = block + .txdata + .iter() + .flat_map(|tx| tx.input.iter()) + .flat_map(|input| input.witness.iter()) + .map(|witness| witness.len()) + .fold(0, |acc, x| acc + x); + Some(serde_json::to_value(GetBlockResult { + header: header.into_right().ok_or_else(|| { + anyhow::anyhow!( + "unexpected response for getblockheader" + ) + })?, + size, + strippedsize: if witness > 0 { + Some(size - witness) + } else { + None + }, + weight: block.get_weight(), + tx: block + .txdata + .into_iter() + .map(|tx| tx.txid()) + .collect(), + })?) + }, + error: None, + })), + Ok((_, None)) => Ok(Some(RpcResponse { + id: req.id.clone(), + result: None, + error: Some(RpcError { + code: MISC_ERROR_CODE, + message: PRUNE_ERROR_MESSAGE.to_owned(), + status: None, + }), + })), + Err(e) => Ok(Some(e.into())), } - ) { - Ok((header, Some(block))) => Ok(Some(RpcResponse { - id: req.id.clone(), - result: { - let size = block.get_size(); - let witness = block - .txdata - .iter() - .flat_map(|tx| tx.input.iter()) - .flat_map(|input| input.witness.iter()) - .map(|witness| witness.len()) - .fold(0, |acc, x| acc + x); - Some(serde_json::to_value(GetBlockResult { - header: header.into_right().ok_or_else(|| { - anyhow::anyhow!( - "unexpected response for getblockheader" - ) - })?, - size, - strippedsize: if witness > 0 { - Some(size - witness) - } else { - None - }, - weight: block.get_weight(), - tx: block.txdata.into_iter().map(|tx| tx.txid()).collect(), - })?) - }, - error: None, - })), - Ok((_, None)) => Ok(Some(RpcResponse { - id: req.id.clone(), - result: None, - error: Some(RpcError { - code: MISC_ERROR_CODE, - message: PRUNE_ERROR_MESSAGE.to_owned(), - status: None, - }), - })), - Err(e) => Ok(Some(e.into())), } + _ => Ok(None), // TODO } - _ => Ok(None), // TODO } - } else { - Ok(None) + _ => Ok(None), } } else { Err(RpcError { From 2ea7c1e541a400c16399c6fae41e1c294cff4dcf Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Tue, 1 Nov 2022 15:32:07 -0600 Subject: [PATCH 18/25] update dependencies --- Cargo.lock | 29 +++++++++++++++-------------- Cargo.toml | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 23839fb..34c3c0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,15 +59,15 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bech32" -version = "0.7.3" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dabbe35f96fb9507f7330793dc490461b2962659ac5d427181e451a623751d1" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" [[package]] name = "bitcoin" -version = "0.26.0" +version = "0.29.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ec5f88a446d66e7474a3b8fa2e348320b574463fb78d799d90ba68f79f48e0e" +checksum = "0694ea59225b0c5f3cb405ff3f670e4828358ed26aec49dc352f730f0cb1a8a3" dependencies = [ "bech32", "bitcoin_hashes", @@ -77,9 +77,9 @@ dependencies = [ [[package]] name = "bitcoin_hashes" -version = "0.9.4" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aaf87b776808e26ae93289bc7d025092b6d909c193f0cdee0b3a86e7bd3c776" +checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" dependencies = [ "serde", ] @@ -833,9 +833,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.3" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" dependencies = [ "cfg-if", "instant", @@ -895,9 +895,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.5" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] @@ -944,19 +944,20 @@ checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" [[package]] name = "secp256k1" -version = "0.20.1" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "733b114f058f260c0af7591434eef4272ae1a8ec2751766d3cb89c6df8d5e450" +checksum = "ff55dc09d460954e9ef2fa8a7ced735a964be9981fd50e870b2b3b0705e14964" dependencies = [ + "bitcoin_hashes", "secp256k1-sys", "serde", ] [[package]] name = "secp256k1-sys" -version = "0.4.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67e4b6455ee49f5901c8985b88f98fb0a0e1d90a6661f5a03f4888bd987dad29" +checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index 067eb64..f040531 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ anyhow = "1.0.38" async-channel = "1.5.1" base32 = "0.4.0" base64 = "0.13.0" -bitcoin = { version = "0.26.0", features = ["use-serde"] } +bitcoin = { version = "0.29.2", features = ["serde"] } configure_me = { version = "0.4.0" } futures = "0.3.12" hex = "0.4.2" From f5f8cfb9996839ee4e6d7b52a02809bfc2d708d6 Mon Sep 17 00:00:00 2001 From: Shadowy Super Coder Date: Mon, 12 Aug 2024 20:43:43 -0600 Subject: [PATCH 19/25] Add Dockerfile --- Dockerfile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..96c43e5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Builder +FROM rust:latest AS builder + +RUN apt-get update && apt-get install + +WORKDIR /app + +COPY . . + +RUN cargo build --release + +# Final +FROM debian:buster-slim + +WORKDIR /app + +COPY --from=builder /app/target/release/btc_rpc_proxy /app/btc_rpc_proxy + +COPY btc_rpc_proxy.toml /app/btc_rpc_proxy.toml + +RUN chmod 600 /app/btc_rpc_proxy.toml +RUN chmod +x /app/btc_rpc_proxy + +CMD [ "/app/btc_rpc_proxy", "--conf", "btc_rpc_proxy.toml" ] \ No newline at end of file From f60b7f2f88a2a1e76e53fd73a12449464a997f61 Mon Sep 17 00:00:00 2001 From: Shadowy Super Coder Date: Tue, 13 Aug 2024 15:37:07 -0600 Subject: [PATCH 20/25] update final base image to bookworm --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 96c43e5..8318307 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ COPY . . RUN cargo build --release # Final -FROM debian:buster-slim +FROM debian:bookworm-slim WORKDIR /app From fd4315c31389af13348d7c89339ceb1bdac1fade Mon Sep 17 00:00:00 2001 From: Shadowy Super Coder Date: Tue, 13 Aug 2024 19:23:01 -0600 Subject: [PATCH 21/25] fix broken dependencies --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 34c3c0b..ba03fdf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -833,9 +833,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.6" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ "cfg-if", "instant", @@ -895,9 +895,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" dependencies = [ "bitflags", ] @@ -944,9 +944,9 @@ checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" [[package]] name = "secp256k1" -version = "0.24.1" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff55dc09d460954e9ef2fa8a7ced735a964be9981fd50e870b2b3b0705e14964" +checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" dependencies = [ "bitcoin_hashes", "secp256k1-sys", From 0772278816e27c84cf53458a81ee64548a2e3c26 Mon Sep 17 00:00:00 2001 From: Shadowy Super Coder Date: Thu, 15 Aug 2024 14:11:31 -0600 Subject: [PATCH 22/25] accept conf as a runtime mount --- Dockerfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8318307..0ab286f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,9 +16,7 @@ WORKDIR /app COPY --from=builder /app/target/release/btc_rpc_proxy /app/btc_rpc_proxy -COPY btc_rpc_proxy.toml /app/btc_rpc_proxy.toml - -RUN chmod 600 /app/btc_rpc_proxy.toml RUN chmod +x /app/btc_rpc_proxy -CMD [ "/app/btc_rpc_proxy", "--conf", "btc_rpc_proxy.toml" ] \ No newline at end of file +SHELL [ "/bin/bash", "-c" ] +ENTRYPOINT chmod 600 /app/btc_rpc_proxy.toml && exec /app/btc_rpc_proxy --conf /app/btc_rpc_proxy.toml \ No newline at end of file From a498e01a7d6b099e5901a4d453987b8a3e9488a4 Mon Sep 17 00:00:00 2001 From: Shadowy Super Coder Date: Thu, 15 Aug 2024 14:16:19 -0600 Subject: [PATCH 23/25] revert Rust Analyzer changes to match upstream --- Cargo.lock | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff25f11..72f0a94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,15 +59,15 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bech32" -version = "0.9.1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +checksum = "2dabbe35f96fb9507f7330793dc490461b2962659ac5d427181e451a623751d1" [[package]] name = "bitcoin" -version = "0.29.2" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0694ea59225b0c5f3cb405ff3f670e4828358ed26aec49dc352f730f0cb1a8a3" +checksum = "1ec5f88a446d66e7474a3b8fa2e348320b574463fb78d799d90ba68f79f48e0e" dependencies = [ "bech32", "bitcoin_hashes", @@ -77,9 +77,9 @@ dependencies = [ [[package]] name = "bitcoin_hashes" -version = "0.11.0" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" +checksum = "0aaf87b776808e26ae93289bc7d025092b6d909c193f0cdee0b3a86e7bd3c776" dependencies = [ "serde", ] @@ -488,7 +488,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -825,24 +825,24 @@ name = "parking_lot" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733" - dependencies = [ + "instant", "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.9.4" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ "cfg-if", "instant", "libc", "redox_syscall", "smallvec", - "windows-sys", + "winapi 0.3.9", ] [[package]] @@ -895,9 +895,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" dependencies = [ "bitflags", ] @@ -944,20 +944,19 @@ checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" [[package]] name = "secp256k1" -version = "0.24.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" +checksum = "733b114f058f260c0af7591434eef4272ae1a8ec2751766d3cb89c6df8d5e450" dependencies = [ - "bitcoin_hashes", "secp256k1-sys", "serde", ] [[package]] name = "secp256k1-sys" -version = "0.6.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" +checksum = "67e4b6455ee49f5901c8985b88f98fb0a0e1d90a6661f5a03f4888bd987dad29" dependencies = [ "cc", ] @@ -1182,10 +1181,10 @@ dependencies = [ "memchr", "mio", "num_cpus", + "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", "tokio-macros", "winapi 0.3.9", ] @@ -1490,4 +1489,4 @@ checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" dependencies = [ "winapi 0.2.8", "winapi-build", -] +] \ No newline at end of file From 44180f5d34d3955d31d0579529bd0e436e673e8c Mon Sep 17 00:00:00 2001 From: Shadowy Super Coder Date: Thu, 15 Aug 2024 14:38:34 -0600 Subject: [PATCH 24/25] refactor fs --- Dockerfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0ab286f..9579456 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,11 +12,9 @@ RUN cargo build --release # Final FROM debian:bookworm-slim -WORKDIR /app - -COPY --from=builder /app/target/release/btc_rpc_proxy /app/btc_rpc_proxy +COPY --from=builder /app/target/release/btc_rpc_proxy /usr/bin/btc_rpc_proxy -RUN chmod +x /app/btc_rpc_proxy +RUN chmod +x /usr/bin/btc_rpc_proxy SHELL [ "/bin/bash", "-c" ] -ENTRYPOINT chmod 600 /app/btc_rpc_proxy.toml && exec /app/btc_rpc_proxy --conf /app/btc_rpc_proxy.toml \ No newline at end of file +ENTRYPOINT chmod 600 /etc/btc_rpc_proxy.toml && exec /usr/bin/btc_rpc_proxy --conf /etc/btc_rpc_proxy.toml \ No newline at end of file From 25ec884bf7e38e9be428b99ea6a546ba69d19cb9 Mon Sep 17 00:00:00 2001 From: Shadowy Super Coder Date: Thu, 15 Aug 2024 14:44:19 -0600 Subject: [PATCH 25/25] mkdir for btc_rpc_proxy.toml --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9579456..c4d27e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,4 @@ COPY --from=builder /app/target/release/btc_rpc_proxy /usr/bin/btc_rpc_proxy RUN chmod +x /usr/bin/btc_rpc_proxy SHELL [ "/bin/bash", "-c" ] -ENTRYPOINT chmod 600 /etc/btc_rpc_proxy.toml && exec /usr/bin/btc_rpc_proxy --conf /etc/btc_rpc_proxy.toml \ No newline at end of file +ENTRYPOINT chmod 600 /etc/btc_rpc_proxy/btc_rpc_proxy.toml && exec /usr/bin/btc_rpc_proxy --conf /etc/btc_rpc_proxy/btc_rpc_proxy.toml \ No newline at end of file