diff --git a/Cargo.lock b/Cargo.lock index abab881..0125106 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,22 +1,18 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "anyhow" -version = "1.0.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf8dcb5b4bbaa28653b647d8c77bd4ed40183b48882e130c1f1ffb73de069fd7" +version = 3 [[package]] -name = "arc-swap" -version = "0.4.8" +name = "anyhow" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dabe5a181f83789739c194cbe5a897dde195078fac08568d09221fd6137a7ba8" +checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" [[package]] name = "async-channel" -version = "1.5.1" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59740d83946db6a5af71ae25ddf9562c2b176b2ca42cf99a455f09f4a220d6b9" +checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" dependencies = [ "concurrent-queue", "event-listener", @@ -25,12 +21,13 @@ dependencies = [ [[package]] name = "atty" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ + "hermit-abi", "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -53,15 +50,15 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bech32" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdcf67bb7ba7797a081cd19009948ab533af7c355d5caf1d08c777582d351e9c" +checksum = "2dabbe35f96fb9507f7330793dc490461b2962659ac5d427181e451a623751d1" [[package]] name = "bitcoin" -version = "0.25.2" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aefc9be9f17185f4ebccae6575d342063f775924d57df0000edb1880c0fb7095" +checksum = "1ec5f88a446d66e7474a3b8fa2e348320b574463fb78d799d90ba68f79f48e0e" dependencies = [ "bech32", "bitcoin_hashes", @@ -71,9 +68,9 @@ dependencies = [ [[package]] name = "bitcoin_hashes" -version = "0.9.0" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed2ce8078898876263683749be6f50af005cc77f93be1422f1c56fecf0b34d7" +checksum = "0aaf87b776808e26ae93289bc7d025092b6d909c193f0cdee0b3a86e7bd3c776" dependencies = [ "serde", ] @@ -107,7 +104,7 @@ dependencies = [ [[package]] name = "btc-rpc-proxy" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "async-channel", @@ -116,7 +113,9 @@ dependencies = [ "bitcoin", "configure_me", "configure_me_codegen", - "futures", + "derive_more", + "enum_future", + "futures 0.3.13", "hex", "http", "hyper", @@ -131,7 +130,9 @@ dependencies = [ "socks", "systemd_socket", "thiserror", - "tokio", + "tokio 0.2.25", + "tokio 1.2.0", + "tokio-compat-02", ] [[package]] @@ -142,9 +143,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "byteorder" -version = "1.3.2" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" [[package]] name = "bytes" @@ -152,6 +153,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +[[package]] +name = "bytes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" + [[package]] name = "cache-padded" version = "1.1.1" @@ -171,9 +178,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.46" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0213d356d3c4ea2c18c40b037c3be23cd639825c18f25ee670ac7813beeef99c" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" [[package]] name = "cfg-if" @@ -189,14 +196,15 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.9" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" dependencies = [ "libc", "num-integer", "num-traits", "time", + "winapi 0.3.9", ] [[package]] @@ -267,6 +275,17 @@ 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" @@ -294,7 +313,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", "redox_users", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -303,6 +322,15 @@ 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" @@ -332,9 +360,9 @@ checksum = "c9db8691f0820ad11ce6eb94057d0dd9c456500da04da0c12a85c90d6f979cc9" [[package]] name = "fnv" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fuchsia-zircon" @@ -354,9 +382,15 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "futures" -version = "0.3.8" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b3b0c040a1fe6529d30b3c5944b280c7f0dcb2930d2c3062bca967b602583d0" +checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" + +[[package]] +name = "futures" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1" dependencies = [ "futures-channel", "futures-core", @@ -369,9 +403,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7109687aa4e177ef6fe84553af6280ef2778bdb7783ba44c9dc3399110fe64" +checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" dependencies = [ "futures-core", "futures-sink", @@ -379,15 +413,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "847ce131b72ffb13b6109a221da9ad97a64cbe48feb1028356b836b47b8f1748" +checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" [[package]] name = "futures-executor" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4caa2b2b68b880003057c1dd49f1ed937e38f22fcf6c212188a121f08cf40a65" +checksum = "891a4b7b96d84d5940084b2a37632dd65deeae662c114ceaa2c879629c9c0ad1" dependencies = [ "futures-core", "futures-task", @@ -396,15 +430,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" +checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" [[package]] name = "futures-macro" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556" +checksum = "ea405816a5139fb39af82c2beb921d52143f556038378d6db21183a5c37fbfb7" dependencies = [ "proc-macro-hack", "proc-macro2", @@ -414,24 +448,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f878195a49cee50e006b02b93cf7e0a95a38ac7b776b4c4d9cc1207cd20fcb3d" +checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3" [[package]] name = "futures-task" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c554eb5bf48b2426c4771ab68c6b14468b6e76cc90996f528c3338d761a4d0d" -dependencies = [ - "once_cell", -] +checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" [[package]] name = "futures-util" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2" +checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" dependencies = [ "futures-channel", "futures-core", @@ -440,7 +471,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project", + "pin-project-lite 0.2.6", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -449,9 +480,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" dependencies = [ "typenum", ] @@ -469,11 +500,11 @@ dependencies = [ [[package]] name = "h2" -version = "0.2.6" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "993f9e0baeed60001cf565546b0d3dbe6a6ad23f2bd31644a133c641eccf6d53" +checksum = "d832b01df74254fe364568d6ddc294443f61cbec82816b60904303af87efae78" dependencies = [ - "bytes", + "bytes 1.0.1", "fnv", "futures-core", "futures-sink", @@ -481,7 +512,7 @@ dependencies = [ "http", "indexmap", "slab", - "tokio", + "tokio 1.2.0", "tokio-util", "tracing", ] @@ -494,18 +525,18 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" [[package]] name = "hermit-abi" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] [[package]] name = "hex" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hmac" @@ -519,30 +550,30 @@ dependencies = [ [[package]] name = "http" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" +checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" dependencies = [ - "bytes", + "bytes 1.0.1", "fnv", "itoa", ] [[package]] name = "http-body" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994" dependencies = [ - "bytes", + "bytes 1.0.1", "http", ] [[package]] name = "httparse" -version = "1.3.4" +version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" [[package]] name = "httpdate" @@ -552,11 +583,11 @@ checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" [[package]] name = "hyper" -version = "0.13.10" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a6f157065790a3ed2f88679250419b5cdd96e714a0d65f7797fd337186e96bb" +checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" dependencies = [ - "bytes", + "bytes 1.0.1", "futures-channel", "futures-core", "futures-util", @@ -568,7 +599,7 @@ dependencies = [ "itoa", "pin-project", "socket2", - "tokio", + "tokio 1.2.0", "tower-service", "tracing", "want", @@ -576,14 +607,23 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.0" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "iovec" version = "0.1.4" @@ -595,18 +635,18 @@ dependencies = [ [[package]] name = "itertools" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319" dependencies = [ "either", ] [[package]] name = "itoa" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "kernel32-sys" @@ -626,9 +666,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.79" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" [[package]] name = "libsystemd" @@ -655,13 +695,22 @@ dependencies = [ "serde_test", ] +[[package]] +name = "lock_api" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" -version = "0.4.8" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", ] [[package]] @@ -675,9 +724,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.3.3" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "mio" @@ -699,26 +748,16 @@ dependencies = [ ] [[package]] -name = "mio-named-pipes" -version = "0.1.7" +name = "mio" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" +checksum = "a5dede4e2065b3842b8b0af444119f3aa331cc7cc2dd20388bfb0f5d5a38823a" dependencies = [ + "libc", "log", - "mio", "miow 0.3.6", - "winapi 0.3.8", -] - -[[package]] -name = "mio-uds" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" -dependencies = [ - "iovec", - "libc", - "mio", + "ntapi", + "winapi 0.3.9", ] [[package]] @@ -740,7 +779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ "socket2", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -751,7 +790,7 @@ checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" dependencies = [ "cfg-if 0.1.10", "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -767,11 +806,20 @@ dependencies = [ "void", ] +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "num-integer" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ "autocfg", "num-traits", @@ -779,9 +827,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ "autocfg", ] @@ -798,9 +846,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.4.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] name = "opaque-debug" @@ -808,6 +856,31 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +[[package]] +name = "parking_lot" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi 0.3.9", +] + [[package]] name = "parse_arg" version = "0.1.4" @@ -816,18 +889,18 @@ checksum = "14248cc8eced350e20122a291613de29e4fa129ba2731818c4cdbb44fccd3e55" [[package]] name = "pin-project" -version = "1.0.1" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee41d838744f60d959d7074e3afb6b35c7456d0f61cad38a24e35e6553f73841" +checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.1" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81a4ffa594b66bff340084d4081df649a7dc049ac8d7fc458d8e628bfbbb2f86" +checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" dependencies = [ "proc-macro2", "quote", @@ -836,9 +909,15 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.1.10" +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" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e555d9e657502182ac97b539fb3dae8b79cda19e3e4f8ffb5e8de4f18df93c95" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -854,9 +933,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro-nested" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" @@ -876,12 +955,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 +971,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ "getrandom", - "redox_syscall 0.2.5", + "redox_syscall", ] [[package]] @@ -915,15 +988,21 @@ checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" [[package]] name = "ryu" -version = "1.0.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "secp256k1" -version = "0.19.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6179428c22c73ac0fbb7b5579a56353ce78ba29759b3b8575183336ea74cdfb" +checksum = "733b114f058f260c0af7591434eef4272ae1a8ec2751766d3cb89c6df8d5e450" dependencies = [ "secp256k1-sys", "serde", @@ -931,27 +1010,27 @@ dependencies = [ [[package]] name = "secp256k1-sys" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11553d210db090930f4432bea123b31f70bbf693ace14504ea2a35e796c28dd2" +checksum = "67e4b6455ee49f5901c8985b88f98fb0a0e1d90a6661f5a03f4888bd987dad29" dependencies = [ "cc", ] [[package]] name = "serde" -version = "1.0.117" +version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a" +checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.117" +version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e" +checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" dependencies = [ "proc-macro2", "quote", @@ -960,9 +1039,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.59" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "itoa", "ryu", @@ -971,9 +1050,9 @@ dependencies = [ [[package]] name = "serde_test" -version = "1.0.117" +version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9a49e2f787c0fddfd5e758cbbd3cbf81c3a8d12ef091283c52d9e9b4d417d3c" +checksum = "38145a8510bdf71d9a8cceeb57664049538446e77f24648328bdbcf22dc7e169" dependencies = [ "serde", ] @@ -992,11 +1071,10 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e12110bc539e657a646068aaf5eb5b63af9d0c1f7b29c97113fad80e15f035" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" dependencies = [ - "arc-swap", "libc", ] @@ -1037,6 +1115,12 @@ dependencies = [ "thread_local", ] +[[package]] +name = "smallvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" + [[package]] name = "socket2" version = "0.3.19" @@ -1045,7 +1129,7 @@ checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ "cfg-if 1.0.0", "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -1068,9 +1152,9 @@ checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" [[package]] name = "syn" -version = "1.0.48" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" +checksum = "ed22b90a0e734a23a7610f4283ac9e5acfb96cbb30dfefa540d66f866f1c09c5" dependencies = [ "proc-macro2", "quote", @@ -1086,7 +1170,7 @@ dependencies = [ "lazy_static", "libsystemd", "thiserror", - "tokio", + "tokio 0.2.25", ] [[package]] @@ -1103,23 +1187,23 @@ checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" dependencies = [ "dirs-next", "rustversion", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "thiserror" -version = "1.0.22" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e" +checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.22" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56" +checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" dependencies = [ "proc-macro2", "quote", @@ -1128,97 +1212,132 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.0.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" dependencies = [ - "lazy_static", + "once_cell", ] [[package]] name = "time" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "redox_syscall 0.1.56", - "winapi 0.3.8", + "winapi 0.3.9", ] [[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", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" +dependencies = [ + "autocfg", + "bytes 1.0.1", "libc", "memchr", - "mio", - "mio-named-pipes", - "mio-uds", + "mio 0.7.9", "num_cpus", - "pin-project-lite", + "once_cell", + "parking_lot", + "pin-project-lite 0.2.6", "signal-hook-registry", - "slab", "tokio-macros", - "winapi 0.3.8", + "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 = "0.2.5" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" dependencies = [ "proc-macro2", "quote", "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 = "tokio-util" -version = "0.3.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +checksum = "ebb7cb2f00c5ae8df755b252306272cd1790d39728363936e01827e11f0b017b" dependencies = [ - "bytes", + "bytes 1.0.1", "futures-core", "futures-sink", "log", - "pin-project-lite", - "tokio", + "pin-project-lite 0.2.6", + "tokio 1.2.0", ] [[package]] name = "toml" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75cf45bb0bef80604d001caaec0d09da99611b3c0fd39d3080468875cdb65645" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ "serde", ] [[package]] name = "tower-service" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.21" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27" +checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ - "cfg-if 0.1.10", - "log", - "pin-project-lite", + "cfg-if 1.0.0", + "pin-project-lite 0.2.6", "tracing-core", ] @@ -1245,21 +1364,21 @@ checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" [[package]] name = "unicode-segmentation" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-xid" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "uuid" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ "serde", ] @@ -1300,9 +1419,9 @@ checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", diff --git a/Cargo.toml b/Cargo.toml index 908f30d..a82161e 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.0" +version = "0.3.1" [lib] name = "btc_rpc_proxy" @@ -26,26 +26,30 @@ debug_logs = ["slog/max_level_debug"] systemd = ["systemd_socket/enable_systemd"] [dependencies] -anyhow = "1.0.34" +anyhow = "1.0.38" async-channel = "1.5.1" base32 = "0.4.0" base64 = "0.13.0" -bitcoin = { version = "0.25.2", features = ["use-serde"] } +bitcoin = { version = "0.26.0", features = ["use-serde"] } configure_me = { version = "0.4.0" } -futures = "0.3.8" +derive_more = "0.99.11" +enum_future = "0.1" +futures = "0.3.12" hex = "0.4.2" -http = "0.2.1" -hyper = "0.13.9" -itertools = "0.9.0" +http = "0.2.3" +hyper = { version = "0.14.4", features = ["client", "server", "stream", "http2", "http1", "tcp"] } +itertools = "0.10.0" lazy_static = "1.4.0" linear-map = { version = "1.2.0", features = ["serde_impl"] } serde = { version = "1.0.117", features = ["derive"] } serde_json = "1.0.59" slog = "2.7.0" -slog-async = "2.5.0" +slog-async = "2.6.0" slog-term = "2.6.0" socks = "0.3.3" -tokio = { version = "0.2.22", features = ["full"] } +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"] } diff --git a/src/client.rs b/src/client.rs index de70d8c..13a07ff 100644 --- a/src/client.rs +++ b/src/client.rs @@ -6,7 +6,7 @@ use std::time::SystemTime; use anyhow::{anyhow, Error}; use futures::{channel::mpsc, StreamExt, TryStreamExt}; use hyper::{ - body::Bytes, + body::to_bytes, client::{Client, HttpConnector}, header::{HeaderValue, AUTHORIZATION, CONTENT_LENGTH}, Body, Method, Request, Response, StatusCode, Uri, @@ -284,7 +284,7 @@ impl RpcClient { message: "internal server error".to_owned(), status: Some(StatusCode::INTERNAL_SERVER_ERROR), }); - }, + } }; let response = client @@ -299,10 +299,7 @@ impl RpcClient { ) .await .map_err(Error::from)?; - let body: Bytes = - tokio::stream::StreamExt::collect::>(response.into_body()) - .await - .map_err(Error::from)?; + let body = to_bytes(response.into_body()).await.map_err(Error::from)?; let forwarded_res: Vec> = serde_json::from_slice(body.as_ref())?; Ok(idxs.into_iter().zip(forwarded_res).collect()) @@ -341,13 +338,21 @@ impl RpcClient { ) .await?; let status = response.status(); - let body: Bytes = - tokio::stream::StreamExt::collect::>(response.into_body()).await?; - let mut rpc_response: RpcResponse = serde_json::from_slice(&body) - .map_err(|serde_error| { + let body = to_bytes(response.into_body()).await?; + let mut rpc_response: RpcResponse = + serde_json::from_slice(&body).map_err(|serde_error| { match std::str::from_utf8(&body) { - Ok(body) => ClientError::ParseResponseUtf8 { method: req.method.as_str().to_owned(), status: status, body: body.to_owned(), serde_error }, - Err(error) => ClientError::ResponseNotUtf8 { method: req.method.as_str().to_owned(), status: status, utf8_error: error, }, + Ok(body) => ClientError::ParseResponseUtf8 { + method: req.method.as_str().to_owned(), + status, + body: body.to_owned(), + serde_error, + }, + Err(error) => ClientError::ResponseNotUtf8 { + method: req.method.as_str().to_owned(), + status, + utf8_error: error, + }, } })?; if let Some(ref mut error) = rpc_response.error { @@ -364,13 +369,25 @@ pub enum ClientError { #[error("failed to load authentication data")] LoadAuth(#[from] AuthLoadError), #[error("hyper failed to process HTTP request")] - Hyper(#[from] hyper::error::Error), + Hyper(#[from] hyper::Error), #[error("invalid HTTP request")] Http(#[from] http::Error), - #[error("HTTP response (status: {status}) to method {method} can't be parsed as json, body: {body}")] - ParseResponseUtf8 { method: String, status: http::status::StatusCode, body: String, #[source] serde_error: serde_json::Error }, + #[error( + "HTTP response (status: {status}) to method {method} can't be parsed as json, body: {body}" + )] + ParseResponseUtf8 { + method: String, + status: http::status::StatusCode, + body: String, + #[source] + serde_error: serde_json::Error, + }, #[error("HTTP response (status: {status}) to method {method} is not UTF-8")] - ResponseNotUtf8 { method: String, status: http::status::StatusCode, utf8_error: std::str::Utf8Error, }, + ResponseNotUtf8 { + method: String, + status: http::status::StatusCode, + utf8_error: std::str::Utf8Error, + }, } impl From for RpcError { @@ -426,13 +443,18 @@ impl AuthSource { } async fn load_from_file(path: &PathBuf) -> Result { - tokio::fs::read_to_string(path).await.map(|mut cookie| { - if cookie.ends_with('\n') { - cookie.pop(); - } - base64::encode(cookie) - }) - .map_err(|error| AuthLoadError::Read { path: path.to_owned(), error, }) + tokio::fs::read_to_string(path) + .await + .map(|mut cookie| { + if cookie.ends_with('\n') { + cookie.pop(); + } + base64::encode(cookie) + }) + .map_err(|error| AuthLoadError::Read { + path: path.to_owned(), + error, + }) } pub async fn try_load(&self) -> Result { @@ -445,9 +467,15 @@ impl AuthSource { let cache = cached.read().await.clone(); let modified = tokio::fs::metadata(&path) .await - .map_err(|error| AuthLoadError::Metadata { path: path.to_owned(), error, })? + .map_err(|error| AuthLoadError::Metadata { + path: path.to_owned(), + error, + })? .modified() - .map_err(|error| AuthLoadError::Modified { path: path.to_owned(), error, })?; + .map_err(|error| AuthLoadError::Modified { + path: path.to_owned(), + error, + })?; match cache { Some(cache) if modified == cache.0 => Ok(cache.1.clone()), _ => { @@ -466,11 +494,23 @@ impl AuthSource { #[derive(Debug, thiserror::Error)] pub enum AuthLoadError { #[error("failed to get metadata of file {path}")] - Metadata { path: PathBuf, #[source] error: std::io::Error, }, + Metadata { + path: PathBuf, + #[source] + error: std::io::Error, + }, #[error("failed to get modification time of file {path}")] - Modified { path: PathBuf, #[source] error: std::io::Error, }, + Modified { + path: PathBuf, + #[source] + error: std::io::Error, + }, #[error("failed to read file {path}")] - Read { path: PathBuf, #[source] error: std::io::Error, }, + Read { + path: PathBuf, + #[source] + error: std::io::Error, + }, #[error("invalid header value")] HeaderValue(#[from] http::header::InvalidHeaderValue), } diff --git a/src/fetch_blocks.rs b/src/fetch_blocks.rs index 0212389..999be34 100644 --- a/src/fetch_blocks.rs +++ b/src/fetch_blocks.rs @@ -10,7 +10,6 @@ use bitcoin::{ consensus::{Decodable, Encodable}, hash_types::BlockHash, network::{ - address::Address, constants::{Network::Bitcoin, ServiceFlags}, message::{NetworkMessage, RawNetworkMessage}, message_blockdata::Inventory, @@ -21,18 +20,20 @@ use bitcoin::{ use futures::FutureExt; use socks::Socks5Stream; -use crate::client::{RpcClient, RpcError, ClientError, RpcRequest, MISC_ERROR_CODE, PRUNE_ERROR_MESSAGE}; +use crate::client::{ + ClientError, RpcClient, RpcError, RpcRequest, MISC_ERROR_CODE, PRUNE_ERROR_MESSAGE, +}; use crate::rpc_methods::{GetBlock, GetBlockParams, GetPeerInfo, PeerAddressError}; use crate::state::{State, TorState}; -type VersionMessageProducer = Box RawNetworkMessage + Send + Sync>; +type VersionMessageProducer = Box RawNetworkMessage + Send + Sync>; lazy_static::lazy_static! { static ref VER_ACK: RawNetworkMessage = RawNetworkMessage { magic: Bitcoin.magic(), payload: NetworkMessage::Verack, }; - static ref VERSION_MESSAGE: VersionMessageProducer = Box::new(|addr| { + static ref VERSION_MESSAGE: VersionMessageProducer = Box::new(|| { use std::time::SystemTime; RawNetworkMessage { magic: Bitcoin.magic(), @@ -42,9 +43,8 @@ lazy_static::lazy_static! { .duration_since(SystemTime::UNIX_EPOCH) .unwrap() .as_secs() as i64, - addr, - Address::new(&([127, 0, 0, 1], 8332).into(), ServiceFlags::NONE), - // This is OK because RPC proxy doesn't listen on P2P + bitcoin::network::Address::new(&([127, 0, 0, 1], 8332).into(), ServiceFlags::NONE), + bitcoin::network::Address::new(&([127, 0, 0, 1], 8332).into(), ServiceFlags::NONE), 0, format!("BTC RPC Proxy v{}", env!("CARGO_PKG_VERSION")), 0, @@ -70,6 +70,9 @@ impl Peers { .map(|f| f.elapsed() > max_peer_age) .unwrap_or(true) } + pub fn is_empty(&self) -> bool { + self.peers.is_empty() + } pub async fn updated(client: &RpcClient) -> Result { Ok(Self { peers: client @@ -83,8 +86,8 @@ impl Peers { .into_iter() .filter(|p| !p.inbound) .filter(|p| p.servicesnames.contains("NETWORK")) - .map(|p| p.into_address().map(Peer::new)) - .collect::>()?, + .map(|p| Peer::new(Arc::new(p.addr))) + .collect(), fetched: Some(Instant::now()), }) } @@ -148,40 +151,22 @@ impl Write for BitcoinPeerConnection { } } impl BitcoinPeerConnection { - pub async fn connect(state: Arc, addr: Address) -> Result { + pub async fn connect(state: Arc, mut addr: Arc) -> Result { + if !addr.contains(":") { + addr = Arc::new(format!("{}:8333", &*addr)); + } tokio::time::timeout( state.peer_timeout, tokio::task::spawn_blocking(move || { - let mut stream = match (addr.socket_addr(), &state.tor) { - (Ok(addr), Some(TorState { only: false, .. })) | (Ok(addr), None) => { - BitcoinPeerConnection::ClearNet(TcpStream::connect(addr)?) + let mut stream = match &state.tor { + Some(TorState { only, proxy }) + if *only || addr.split(":").next().unwrap().ends_with(".onion") => + { + BitcoinPeerConnection::Tor(Socks5Stream::connect(proxy, &**addr)?) } - (Ok(addr), Some(tor)) => { - BitcoinPeerConnection::Tor(Socks5Stream::connect(tor.proxy, addr)?) - } - (Err(_), Some(tor)) => BitcoinPeerConnection::Tor(Socks5Stream::connect( - tor.proxy, - ( - format!( - "{}.onion", - base32::encode( - base32::Alphabet::RFC4648 { padding: false }, - &addr - .address - .iter() - .map(|n| *n) - .flat_map(|n| u16::to_be_bytes(n).to_vec()) - .collect::>() - ) - .to_lowercase() - ) - .as_str(), - addr.port, - ), - )?), - (Err(e), None) => return Err(e.into()), + _ => BitcoinPeerConnection::ClearNet(TcpStream::connect(&*addr)?), }; - VERSION_MESSAGE(addr).consensus_encode(&mut stream)?; + VERSION_MESSAGE().consensus_encode(&mut stream)?; stream.flush()?; let _ = bitcoin::network::message::RawNetworkMessage::consensus_decode(&mut stream)?; // version @@ -198,12 +183,12 @@ impl BitcoinPeerConnection { } pub struct Peer { - addr: Address, + addr: Arc, send: mpmc::Sender, recv: mpmc::Receiver, } impl Peer { - pub fn new(addr: Address) -> Self { + pub fn new(addr: Arc) -> Self { let (send, recv) = mpmc::bounded(1); Peer { addr, send, recv } } @@ -222,7 +207,7 @@ impl std::fmt::Debug for Peer { } pub struct PeerHandle { - addr: Address, + addr: Arc, conn: Option, send: mpmc::Sender, } @@ -384,10 +369,17 @@ async fn fetch_block_from_peers( } futures::future::ready(()) }); - let b = futures::select! { - b = recv.next().fuse() => b, - _ = runner.boxed().fuse() => None, + let mut blk_future = recv.next().fuse(); + let mut b = futures::select! { + b = &mut blk_future => b, + _ = runner.boxed().fuse() => None }; + if b.is_none() { + b = match futures::poll!(blk_future) { + std::task::Poll::Ready(Some(b)) => Some(b), + _ => None, + }; + } b } diff --git a/src/lib.rs b/src/lib.rs index 2173048..8b1565f 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,9 +17,10 @@ use std::sync::Arc; use anyhow::Error; use futures::FutureExt; use hyper::{ + server::Server, service::{make_service_fn, service_fn}, - Server, }; +use tokio_compat_02::FutureExt as _; pub use crate::client::{AuthSource, RpcClient}; pub use crate::fetch_blocks::Peers; @@ -28,6 +29,13 @@ 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(); @@ -38,16 +46,29 @@ pub async fn main(state: Arc, bind_addr: systemd_socket::SocketAddr) -> R } }); - let listener = bind_addr - .bind_tokio_0_2() - .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 listener = bind_addr.bind_tokio_0_2().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(listener)).serve(make_service); + let server = Server::builder(hyper::server::accept::from_stream(TcpListenerCompat( + listener, + ))) + .serve(make_service); Ok(server.await?) } + +struct TcpListenerCompat(tokio_02::net::TcpListener); +impl futures::Stream for TcpListenerCompat { + type Item = tokio_02::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))) + } +} diff --git a/src/proxy.rs b/src/proxy.rs index 2efaef0..ee99b37 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -2,11 +2,10 @@ use std::sync::Arc; use anyhow::Error; use hyper::{ - body::Bytes, + body::to_bytes, header::{AUTHORIZATION, WWW_AUTHENTICATE}, Body, Method, Request, Response, StatusCode, }; -use tokio::stream::StreamExt; use crate::client::{RpcError, RpcResponse}; use crate::state::State; @@ -25,7 +24,7 @@ pub async fn proxy_request( .get(AUTHORIZATION) .and_then(|auth| state_local.users.get(auth)) { - let body_data = body.collect::>().await?; + let body_data = to_bytes(body).await?; match serde_json::from_slice(body_data.as_ref()) { Ok(req) => { let state_local = state.clone(); diff --git a/src/rpc_methods.rs b/src/rpc_methods.rs index b1c230b..f430c1b 100644 --- a/src/rpc_methods.rs +++ b/src/rpc_methods.rs @@ -1,9 +1,4 @@ -use bitcoin::{ - consensus::Decodable, - hash_types::BlockHash, - network::{constants::ServiceFlags, Address}, - util::amount::Amount, -}; +use bitcoin::hash_types::BlockHash; use linear_map::{set::LinearSet, LinearMap}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -133,113 +128,44 @@ pub struct PeerInfo { pub services: String, /// The services offered pub servicesnames: LinearSet, - /// Whether peer has asked us to relay transactions to it - pub relaytxes: bool, - /// The time in seconds since epoch (Jan 1 1970 GMT) of the last send - pub lastsend: u64, - /// The time in seconds since epoch (Jan 1 1970 GMT) of the last receive - pub lastrecv: u64, - /// The total bytes sent - pub bytessent: u64, - /// The total bytes received - pub bytesrecv: u64, - /// The connection time in seconds since epoch (Jan 1 1970 GMT) - pub conntime: u64, - /// The time offset in seconds - pub timeoffset: i64, - /// ping time (if available) - pub pingtime: Option, - /// minimum observed ping time (if any at all) - pub minping: Option, - /// ping wait (if non-zero) - pub pingwait: Option, /// The peer version, such as 70001 pub version: u64, /// The string version pub subver: String, /// Inbound (true) or Outbound (false) pub inbound: bool, - /// Whether connection was due to `addnode`/`-connect` or if it was an - /// automatic/inbound connection - pub addnode: bool, /// The starting height (block) of the peer pub startingheight: i64, - /// The ban score - pub banscore: i64, /// The last header we have in common with this peer pub synced_headers: i64, /// The last block we have in common with this peer pub synced_blocks: i64, /// The heights of blocks we're currently asking from this peer pub inflight: Vec, - /// Whether the peer is whitelisted - pub whitelisted: bool, - #[serde( - rename = "minfeefilter", - default, - with = "bitcoin::util::amount::serde::as_btc::opt" - )] - pub min_fee_filter: Option, - /// The total bytes sent aggregated by message type - pub bytessent_per_msg: LinearMap, - /// The total bytes received aggregated by message type - pub bytesrecv_per_msg: LinearMap, -} - -impl PeerInfo { - pub fn into_address(self) -> Result { - let decoded_services = hex::decode(&self.services) - .map_err(|error| PeerAddressError::InvalidHex { string: self.services.clone(), error, })?; - let services = ServiceFlags::consensus_decode(&mut std::io::Cursor::new(decoded_services)) - .map_err(|error| PeerAddressError::ConsensusDecode { string: self.services.clone(), error, })?; - if let Ok(sock_addr) = self.addr.parse() { - Ok(Address::new(&sock_addr, services)) - } else { - let mut addr_split = self.addr.split(":"); - let host = addr_split - .next() - .expect("error: entered unreachable code: std::str::split() is an empty iterator which should never happen"); - let port = addr_split - .next() - .ok_or_else(|| PeerAddressError::MissingPort(self.addr.clone()))? - .parse() - .map_err(|error| PeerAddressError::InvalidPort { address: self.addr.clone(), error, })?; - let onion_key = host.strip_suffix(".onion") - .ok_or_else(|| PeerAddressError::Unknown(self.addr.clone()))?; - let onion = base32::decode(base32::Alphabet::RFC4648 { padding: false }, onion_key) - .ok_or_else(|| PeerAddressError::InvalidOnionEncoding(self.addr.clone()))?; - if onion.len() < 10 { - return Err(PeerAddressError::InvalidOnionLength(self.addr.clone())); - } - let address: [u16; 8] = [ - 0xFD87, - 0xD87E, - 0xEB43, - ((onion[0] as u16) << 8) + (onion[1] as u16), - ((onion[2] as u16) << 8) + (onion[3] as u16), - ((onion[4] as u16) << 8) + (onion[5] as u16), - ((onion[6] as u16) << 8) + (onion[7] as u16), - ((onion[8] as u16) << 8) + (onion[9] as u16), - ]; - Ok(Address { - services, - address, - port, - }) - } - } } #[derive(Debug, thiserror::Error)] pub enum PeerAddressError { #[error("invalid hexadecimal encoding of {string}")] - InvalidHex { string: String, #[source] error: hex::FromHexError, }, + InvalidHex { + string: String, + #[source] + error: hex::FromHexError, + }, #[error("can't consensus-decode {string}")] - ConsensusDecode { string: String, #[source] error: bitcoin::consensus::encode::Error, }, + ConsensusDecode { + string: String, + #[source] + error: bitcoin::consensus::encode::Error, + }, #[error("missing port in peer address {0}")] MissingPort(String), #[error("invalid port in address {address}")] - InvalidPort { address: String, #[source] error: std::num::ParseIntError, }, + InvalidPort { + address: String, + #[source] + error: std::num::ParseIntError, + }, #[error("the peer address {0} is neither clearnet address nor onion address")] Unknown(String), #[error("base32 encoding of onion address {0} is invalid")] diff --git a/src/state.rs b/src/state.rs index 9a53c3c..61c511f 100644 --- a/src/state.rs +++ b/src/state.rs @@ -35,14 +35,24 @@ impl State { Arc::new(self) } pub async fn get_peers(self: Arc) -> Result, Error> { - let peers = self.peers.read().await.clone(); + let mut peers = self.peers.read().await.clone(); if peers.stale(self.max_peer_age) { - tokio::task::spawn(async move { + let handle = tokio::task::spawn(async move { match Peers::updated(&self.rpc_client).await { - Ok(peers) => *self.peers.write().await = Arc::new(peers), - Err(error) => error!(self.logger, "failed to update peers"; "error" => #error), + Ok(peers) => { + let res = Arc::new(peers); + *self.peers.write().await = res.clone(); + Ok(res) + } + Err(error) => { + error!(self.logger, "failed to update peers"; "error" => #%error); + Err(error) + } } }); + if peers.is_empty() { + peers = handle.await??; + } } Ok(peers.handles()) }