From 8521fe946dceb3dfb9bfcb9ebb0718774b2d1dab Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sat, 30 Nov 2024 01:37:04 +0800 Subject: [PATCH 1/3] Using proxy version of tentacle --- Cargo.lock | 859 ++++++++++++++++++++++++++++++++++++++++++++- network/Cargo.toml | 6 +- 2 files changed, 846 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81294b3686..2d79bf497f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,6 +27,31 @@ dependencies = [ "generic-array", ] +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "aes-gcm" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", +] + [[package]] name = "ahash" version = "0.3.8" @@ -155,6 +180,12 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" +[[package]] +name = "arrayref" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" + [[package]] name = "arrayvec" version = "0.7.6" @@ -299,6 +330,12 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base64" version = "0.21.7" @@ -402,6 +439,19 @@ dependencies = [ "cty", ] +[[package]] +name = "blake3" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8ee0c1824c4dea5b5f81736aff91bae041d2c07ee1192bec91054e10e3e601e" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if", + "constant_time_eq", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -445,6 +495,12 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "byte_string" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11aade7a05aa8c3a351cedc44c3fc45806430543382fcc4743a9b757a2a0b4ed" + [[package]] name = "byteorder" version = "1.5.0" @@ -651,8 +707,8 @@ dependencies = [ "serde", "serde_json", "tempfile", - "tentacle-multiaddr", - "tentacle-secio", + "tentacle-multiaddr 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tentacle-secio 0.6.4", "toml", "ubyte", "url", @@ -2056,6 +2112,12 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "constant_time_eq" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" + [[package]] name = "convert_case" version = "0.4.0" @@ -2218,6 +2280,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -2239,6 +2313,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + [[package]] name = "ctrlc" version = "3.4.5" @@ -2438,6 +2521,17 @@ dependencies = [ "subtle", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "dlv-list" version = "0.5.2" @@ -2465,6 +2559,27 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d978bd5d343e8ab9b5c0fc8d93ff9c602fdc96616ffff9c05ac7a155419b824" +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "elliptic-curve", + "signature", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature", +] + [[package]] name = "either" version = "1.13.0" @@ -2474,6 +2589,24 @@ dependencies = [ "serde", ] +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest", + "ff", + "generic-array", + "group", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "encode_unicode" version = "0.3.6" @@ -2607,12 +2740,34 @@ dependencies = [ "libc", ] +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "fiat-crypto" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" +[[package]] +name = "filetime" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" +dependencies = [ + "cfg-if", + "libc", + "libredox", + "windows-sys 0.59.0", +] + [[package]] name = "findshlibs" version = "0.10.2" @@ -2692,6 +2847,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + [[package]] name = "futures" version = "0.3.31" @@ -2819,6 +2983,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] @@ -2845,6 +3010,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "ghash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" +dependencies = [ + "opaque-debug", + "polyval", +] + [[package]] name = "gimli" version = "0.31.1" @@ -2941,6 +3116,17 @@ dependencies = [ "smallvec", ] +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "h2" version = "0.4.6" @@ -3075,6 +3261,51 @@ dependencies = [ "arrayvec", ] +[[package]] +name = "hickory-proto" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07698b8420e2f0d6447a436ba999ec85d8fbf2a398bbd737b82cac4a2e96e512" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.4.0", + "ipnet", + "once_cell", + "rand 0.8.5", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28757f23aa75c98f254cf0405e6d8c25b831b32921b050a66692427679b1f243" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot 0.12.3", + "rand 0.8.5", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "hkdf" version = "0.12.4" @@ -3305,6 +3536,124 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "idb" version = "0.6.4" @@ -3345,6 +3694,27 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "igd-next" version = "0.15.1" @@ -3446,6 +3816,26 @@ dependencies = [ "regex", ] +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + [[package]] name = "inout" version = "0.1.3" @@ -3492,12 +3882,21 @@ dependencies = [ ] [[package]] -name = "is-terminal" -version = "0.4.13" +name = "iprange" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +checksum = "37209be0ad225457e63814401415e748e2453a5297f9b637338f5fb8afa4ec00" dependencies = [ - "hermit-abi 0.4.0", + "ipnet", +] + +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi 0.4.0", "libc", "windows-sys 0.52.0", ] @@ -3565,6 +3964,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json5" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" +dependencies = [ + "pest", + "pest_derive", + "serde", +] + [[package]] name = "jsonrpc-core" version = "18.0.0" @@ -3619,6 +4029,26 @@ dependencies = [ "indexmap 1.9.3", ] +[[package]] +name = "kqueue" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -3656,6 +4086,17 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.6.0", + "libc", + "redox_syscall 0.5.7", +] + [[package]] name = "libsqlite3-sys" version = "0.30.1" @@ -3682,6 +4123,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + [[package]] name = "lock_api" version = "0.4.12" @@ -3716,6 +4163,12 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "lru_time_cache" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9106e1d747ffd48e6be5bb2d97fa706ed25b144fbee4d5c02eae110cd8d6badd" + [[package]] name = "match_cfg" version = "0.1.0" @@ -3825,6 +4278,18 @@ dependencies = [ "web-time", ] +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.48.0", +] + [[package]] name = "mio" version = "1.0.2" @@ -3932,6 +4397,25 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44a1290799eababa63ea60af0cbc3f03363e328e58f32fb0294798ed3e85f444" +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.6.0", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio 0.8.11", + "walkdir", + "windows-sys 0.48.0", +] + [[package]] name = "num-bigint" version = "0.4.6" @@ -4159,6 +4643,27 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", +] + +[[package]] +name = "p384" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70786f51bcc69f6a4c0360e063a4cac5419ef7c5cd5b3c99ad70f3be5ba79209" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", +] + [[package]] name = "parking" version = "2.2.1" @@ -4493,6 +4998,18 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "polyval" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" +dependencies = [ + "cfg-if", + "cpufeatures", + "opaque-debug", + "universal-hash", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -4528,6 +5045,15 @@ dependencies = [ "syn 2.0.79", ] +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -4961,6 +5487,25 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "ring-compat" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccce7bae150b815f0811db41b8312fcb74bffa4cab9cee5429ee00f356dd5bd4" +dependencies = [ + "aead", + "digest", + "ecdsa", + "ed25519", + "generic-array", + "p256", + "p384", + "pkcs8", + "rand_core 0.6.4", + "ring", + "signature", +] + [[package]] name = "rsa" version = "0.9.6" @@ -5133,6 +5678,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "subtle", + "zeroize", +] + [[package]] name = "secp256k1" version = "0.30.0" @@ -5188,6 +5746,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" +[[package]] +name = "sendfd" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604b71b8fc267e13bb3023a2c901126c8f349393666a6d98ac1ae5729b701798" +dependencies = [ + "libc", + "tokio", +] + [[package]] name = "sentry" version = "0.34.0" @@ -5425,6 +5993,92 @@ dependencies = [ "digest", ] +[[package]] +name = "shadowsocks" +version = "1.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ecb3780dfbc654de9383758015b9bb95c6e32fecace36ebded09d67e854d130" +dependencies = [ + "arc-swap", + "async-trait", + "base64 0.22.1", + "blake3", + "byte_string", + "bytes", + "cfg-if", + "futures", + "hickory-resolver", + "libc", + "log", + "notify", + "once_cell", + "percent-encoding", + "pin-project", + "sendfd", + "serde", + "serde_json", + "serde_urlencoded", + "shadowsocks-crypto", + "socket2", + "spin", + "thiserror", + "tokio", + "tokio-tfo", + "url", + "windows-sys 0.59.0", +] + +[[package]] +name = "shadowsocks-crypto" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc77ecb3a97509d22751b76665894fcffad2d10df8758f4e3f20c92ccde6bf4f" +dependencies = [ + "aes-gcm", + "cfg-if", + "chacha20poly1305", + "hkdf", + "md-5", + "rand 0.8.5", + "ring-compat", + "sha1", +] + +[[package]] +name = "shadowsocks-service" +version = "1.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79e4f64b489b29e542dea54ea5b4c69e51701e25b222034c257f8b84f74b7e3" +dependencies = [ + "arc-swap", + "async-trait", + "byte_string", + "byteorder", + "bytes", + "cfg-if", + "futures", + "httparse", + "idna 1.0.3", + "ipnet", + "iprange", + "json5", + "libc", + "log", + "lru_time_cache", + "nix", + "once_cell", + "pin-project", + "rand 0.8.5", + "regex", + "serde", + "shadowsocks", + "socket2", + "spin", + "thiserror", + "tokio", + "windows-sys 0.59.0", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -5789,6 +6443,12 @@ dependencies = [ "xxhash-rust", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -5861,6 +6521,17 @@ dependencies = [ "futures-core", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "system-configuration" version = "0.6.1" @@ -5897,15 +6568,13 @@ dependencies = [ [[package]] name = "tentacle" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19a42caa9f5a8bf3f40b75b4e8e4bf1dcacf92998463afce9cfe5e5e4824de9a" +version = "0.6.4" +source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" dependencies = [ "async-trait", "bytes", "futures", "futures-timer", - "httparse", "igd-next", "js-sys", "libc", @@ -5914,9 +6583,11 @@ dependencies = [ "nohash-hasher", "parking_lot 0.12.3", "rand 0.8.5", + "shadowsocks", + "shadowsocks-service", "socket2", - "tentacle-multiaddr", - "tentacle-secio", + "tentacle-multiaddr 0.3.4 (git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy)", + "tentacle-secio 0.6.3", "thiserror", "tokio", "tokio-tungstenite", @@ -5940,6 +6611,44 @@ dependencies = [ "unsigned-varint", ] +[[package]] +name = "tentacle-multiaddr" +version = "0.3.4" +source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" +dependencies = [ + "bs58", + "bytes", + "serde", + "sha2", + "unsigned-varint", +] + +[[package]] +name = "tentacle-secio" +version = "0.6.3" +source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" +dependencies = [ + "bs58", + "bytes", + "chacha20poly1305", + "futures", + "getrandom 0.2.15", + "hmac", + "log", + "molecule", + "openssl", + "openssl-sys", + "rand 0.8.5", + "rand_core 0.6.4", + "ring", + "secp256k1", + "sha2", + "tokio", + "tokio-util", + "unsigned-varint", + "x25519-dalek", +] + [[package]] name = "tentacle-secio" version = "0.6.4" @@ -6125,6 +6834,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinytemplate" version = "1.2.1" @@ -6159,7 +6878,8 @@ dependencies = [ "backtrace", "bytes", "libc", - "mio", + "mio 1.0.2", + "parking_lot 0.12.3", "pin-project-lite", "signal-hook-registry", "socket2", @@ -6211,6 +6931,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-tfo" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb4382c6371e29365853d2b71e915d5398df46312a2158097d8bb3f54d0f1b4" +dependencies = [ + "cfg-if", + "futures", + "libc", + "log", + "once_cell", + "pin-project", + "socket2", + "tokio", + "windows-sys 0.52.0", +] + [[package]] name = "tokio-tungstenite" version = "0.24.0" @@ -6238,9 +6975,8 @@ dependencies = [ [[package]] name = "tokio-yamux" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "966579a01e6900c22634f5915fda56358496e71067f3dd26572f9fbe85f4b62e" +version = "0.3.9" +source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" dependencies = [ "bytes", "futures", @@ -6663,6 +7399,18 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -7150,6 +7898,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "x25519-dalek" version = "2.0.1" @@ -7195,6 +7955,30 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -7216,6 +8000,27 @@ dependencies = [ "syn 2.0.79", ] +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", + "synstructure", +] + [[package]] name = "zeroize" version = "1.8.1" @@ -7235,3 +8040,25 @@ dependencies = [ "quote", "syn 2.0.79", ] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.79", +] diff --git a/network/Cargo.toml b/network/Cargo.toml index 4f7e0bcf25..4ed949321a 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -34,10 +34,10 @@ serde_json = "1.0" bloom-filters = "0.1" ckb-spawn = { path = "../util/spawn", version = "= 0.120.0-pre" } bitflags = "1.0" -p2p = { version = "0.6.2", package = "tentacle", default-features = false } +p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", package = "tentacle", default-features = false } [target.'cfg(not(target_family = "wasm"))'.dependencies] -p2p = { version = "0.6.2", package = "tentacle", default-features = false, features = [ +p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", package = "tentacle", default-features = false, features = [ "upnp", "parking_lot", "openssl-vendored", @@ -48,7 +48,7 @@ p2p = { version = "0.6.2", package = "tentacle", default-features = false, featu socket2 = "0.5" [target.'cfg(target_family = "wasm")'.dependencies] -p2p = { version = "0.6.2", package = "tentacle", default-features = false, features = [ +p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", package = "tentacle", default-features = false, features = [ "wasm-timer", ] } idb = "0.6" From 10b60c5aae2a3bb7d1e6eb961373bf730d79e20f Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 2 Dec 2024 13:14:42 +0800 Subject: [PATCH 2/3] Add proxy support for ckb Signed-off-by: Eval EXEC --- Cargo.lock | 59 ++++---------------------- network/Cargo.toml | 6 +-- network/src/network.rs | 9 ++++ util/app-config/Cargo.toml | 4 +- util/app-config/src/configs/network.rs | 10 +++++ 5 files changed, 32 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d79bf497f..d19039b51a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -707,8 +707,8 @@ dependencies = [ "serde", "serde_json", "tempfile", - "tentacle-multiaddr 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "tentacle-secio 0.6.4", + "tentacle-multiaddr", + "tentacle-secio", "toml", "ubyte", "url", @@ -4077,7 +4077,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -6568,13 +6568,13 @@ dependencies = [ [[package]] name = "tentacle" -version = "0.6.4" -source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" +version = "0.6.5" dependencies = [ "async-trait", "bytes", "futures", "futures-timer", + "httparse", "igd-next", "js-sys", "libc", @@ -6586,8 +6586,8 @@ dependencies = [ "shadowsocks", "shadowsocks-service", "socket2", - "tentacle-multiaddr 0.3.4 (git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy)", - "tentacle-secio 0.6.3", + "tentacle-multiaddr", + "tentacle-secio", "thiserror", "tokio", "tokio-tungstenite", @@ -6601,20 +6601,6 @@ dependencies = [ [[package]] name = "tentacle-multiaddr" version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9e71b28bf0bbf274b92f47cb2c5b42755d84a11e2246cf7bcb7b65c89483b9" -dependencies = [ - "bs58", - "bytes", - "serde", - "sha2", - "unsigned-varint", -] - -[[package]] -name = "tentacle-multiaddr" -version = "0.3.4" -source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" dependencies = [ "bs58", "bytes", @@ -6623,37 +6609,9 @@ dependencies = [ "unsigned-varint", ] -[[package]] -name = "tentacle-secio" -version = "0.6.3" -source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" -dependencies = [ - "bs58", - "bytes", - "chacha20poly1305", - "futures", - "getrandom 0.2.15", - "hmac", - "log", - "molecule", - "openssl", - "openssl-sys", - "rand 0.8.5", - "rand_core 0.6.4", - "ring", - "secp256k1", - "sha2", - "tokio", - "tokio-util", - "unsigned-varint", - "x25519-dalek", -] - [[package]] name = "tentacle-secio" version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d53673d63399e1d557c2e884b045d242811079d3b2f17a569310e5c3f1db33" dependencies = [ "bs58", "bytes", @@ -6975,8 +6933,7 @@ dependencies = [ [[package]] name = "tokio-yamux" -version = "0.3.9" -source = "git+https://github.com/eval-exec/tentacle.git?branch=exec/proxy#5146d4d9ff2dfa629789b3b5155dee7b32ccd9bc" +version = "0.3.10" dependencies = [ "bytes", "futures", diff --git a/network/Cargo.toml b/network/Cargo.toml index 4ed949321a..c653ddf17e 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -34,10 +34,10 @@ serde_json = "1.0" bloom-filters = "0.1" ckb-spawn = { path = "../util/spawn", version = "= 0.120.0-pre" } bitflags = "1.0" -p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", package = "tentacle", default-features = false } +p2p = { path = "/home/exec/Projects/github.com/nervosnetwork/tentacle/tentacle", package = "tentacle", default-features = false } [target.'cfg(not(target_family = "wasm"))'.dependencies] -p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", package = "tentacle", default-features = false, features = [ +p2p = { path = "/home/exec/Projects/github.com/nervosnetwork/tentacle/tentacle", package = "tentacle", default-features = false, features = [ "upnp", "parking_lot", "openssl-vendored", @@ -48,7 +48,7 @@ p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", pa socket2 = "0.5" [target.'cfg(target_family = "wasm")'.dependencies] -p2p = { git="https://github.com/eval-exec/tentacle.git", branch="exec/proxy", package = "tentacle", default-features = false, features = [ +p2p = { path = "/home/exec/Projects/github.com/nervosnetwork/tentacle/tentacle", package = "tentacle", default-features = false, features = [ "wasm-timer", ] } idb = "0.6" diff --git a/network/src/network.rs b/network/src/network.rs index 6134e7cb12..3215965daf 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -28,6 +28,7 @@ use ckb_systemtime::{Duration, Instant}; use ckb_util::{Condvar, Mutex, RwLock}; use futures::{channel::mpsc::Sender, Future}; use ipnetwork::IpNetwork; +use p2p::service::ProxyConfig; use p2p::{ async_trait, builder::ServiceBuilder, @@ -1015,6 +1016,14 @@ impl NetworkService { }; init.transform(TransportType::Tcp); service_builder = service_builder.tcp_config(bind_fn); + + if config.proxy_config.enable { + let proxy_config = Some(ProxyConfig { + proxy_url: config.proxy_config.proxy_url.clone(), + }); + service_builder = + service_builder.tcp_proxy_config(proxy_config); + } } } TransportType::Ws => { diff --git a/util/app-config/Cargo.toml b/util/app-config/Cargo.toml index 5acccab4bd..7f86de1783 100644 --- a/util/app-config/Cargo.toml +++ b/util/app-config/Cargo.toml @@ -22,8 +22,8 @@ ckb-pow = { path = "../../pow", version = "= 0.120.0-pre" } ckb-resource = { path = "../../resource", version = "= 0.120.0-pre" } ckb-build-info = { path = "../build-info", version = "= 0.120.0-pre" } ckb-types = { path = "../types", version = "= 0.120.0-pre" } -secio = { version = "0.6", package = "tentacle-secio" } -multiaddr = { version = "0.3.0", package = "tentacle-multiaddr" } +secio = { path="/home/exec/Projects/github.com/nervosnetwork/tentacle/secio", package = "tentacle-secio" } +multiaddr = { path="/home/exec/Projects/github.com/nervosnetwork/tentacle/multiaddr", package = "tentacle-multiaddr" } rand = "0.8" sentry = { version = "0.34.0", optional = true } ckb-systemtime = { path = "../systemtime", version = "= 0.120.0-pre" } diff --git a/util/app-config/src/configs/network.rs b/util/app-config/src/configs/network.rs index 70d8cb3550..bcfcd7048a 100644 --- a/util/app-config/src/configs/network.rs +++ b/util/app-config/src/configs/network.rs @@ -92,6 +92,16 @@ pub struct Config { #[cfg(target_family = "wasm")] #[serde(skip)] pub secret_key: [u8; 32], + + #[serde(default)] + pub proxy_config: ProxyConfig, +} + +/// Proxy related config options +#[derive(Clone, Debug, Serialize, Deserialize, Default)] +pub struct ProxyConfig { + pub enable: bool, + pub proxy_url: String, } /// Chain synchronization config options. From e55f631cff8ab51ef5f8ebcd73977cdc282ae9c2 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Wed, 4 Dec 2024 11:22:39 +0800 Subject: [PATCH 3/3] wip Signed-off-by: Eval EXEC --- Cargo.lock | 24 ++++++++-------------- network/Cargo.toml | 1 + network/src/errors.rs | 2 ++ network/src/lib.rs | 1 + network/src/network.rs | 14 +++++++++---- network/src/proxy.rs | 28 ++++++++++++++++++++++++++ util/app-config/src/configs/network.rs | 1 + 7 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 network/src/proxy.rs diff --git a/Cargo.lock b/Cargo.lock index d19039b51a..c6f23c7051 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1363,6 +1363,7 @@ dependencies = [ "tokio", "tokio-util", "trust-dns-resolver", + "url", ] [[package]] @@ -3684,16 +3685,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "idna" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "1.0.3" @@ -5392,9 +5383,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "reqwest" -version = "0.12.8" +version = "0.12.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" dependencies = [ "base64 0.22.1", "bytes", @@ -6568,7 +6559,7 @@ dependencies = [ [[package]] name = "tentacle" -version = "0.6.5" +version = "0.6.6" dependencies = [ "async-trait", "bytes", @@ -6593,6 +6584,7 @@ dependencies = [ "tokio-tungstenite", "tokio-util", "tokio-yamux", + "url", "wasm-bindgen", "wasm-bindgen-futures", "winapi", @@ -7340,12 +7332,12 @@ dependencies = [ [[package]] name = "url" -version = "2.5.2" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", - "idna 0.5.0", + "idna 1.0.3", "percent-encoding", "serde", ] diff --git a/network/Cargo.toml b/network/Cargo.toml index c653ddf17e..861865177d 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -35,6 +35,7 @@ bloom-filters = "0.1" ckb-spawn = { path = "../util/spawn", version = "= 0.120.0-pre" } bitflags = "1.0" p2p = { path = "/home/exec/Projects/github.com/nervosnetwork/tentacle/tentacle", package = "tentacle", default-features = false } +url = "2.5.4" [target.'cfg(not(target_family = "wasm"))'.dependencies] p2p = { path = "/home/exec/Projects/github.com/nervosnetwork/tentacle/tentacle", package = "tentacle", default-features = false, features = [ diff --git a/network/src/errors.rs b/network/src/errors.rs index 0e3bb8d496..4814159db0 100644 --- a/network/src/errors.rs +++ b/network/src/errors.rs @@ -27,6 +27,8 @@ pub enum Error { Dial(String), /// Peer store error PeerStore(PeerStoreError), + /// Config error + Config(String), } /// Error from tentacle diff --git a/network/src/lib.rs b/network/src/lib.rs index c672dab65a..57423034a9 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -17,6 +17,7 @@ pub mod peer_registry; pub mod peer_store; mod protocols; mod services; +mod proxy; #[cfg(test)] mod tests; diff --git a/network/src/network.rs b/network/src/network.rs index 3215965daf..be9889a5b9 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -19,7 +19,7 @@ use crate::services::{ dump_peer_store::DumpPeerStoreService, outbound_peer::OutboundPeerService, protocol_type_checker::ProtocolTypeCheckerService, }; -use crate::{Behaviour, CKBProtocol, Peer, PeerIndex, ProtocolId, ServiceControl}; +use crate::{proxy, Behaviour, CKBProtocol, Peer, PeerIndex, ProtocolId, ServiceControl}; use ckb_app_config::{default_support_all_protocols, NetworkConfig, SupportProtocol}; use ckb_logger::{debug, error, info, trace, warn}; use ckb_spawn::Spawn; @@ -122,6 +122,12 @@ impl NetworkState { let peer_store = Mutex::new(PeerStore::load_from_dir_or_default( config.peer_store_path(), )); + info!("Loaded the peer store."); + if config.proxy_config.enable { + proxy::check_proxy_url(&config.proxy_config.proxy_url) + .map_err(|reason| Error::Config(reason))?; + } + let bootnodes = config.bootnodes(); let peer_registry = PeerRegistry::new( @@ -1018,11 +1024,11 @@ impl NetworkService { service_builder = service_builder.tcp_config(bind_fn); if config.proxy_config.enable { - let proxy_config = Some(ProxyConfig { + let proxy_config = ProxyConfig { proxy_url: config.proxy_config.proxy_url.clone(), - }); + }; service_builder = - service_builder.tcp_proxy_config(proxy_config); + service_builder.tcp_proxy_config(Some(proxy_config)); } } } diff --git a/network/src/proxy.rs b/network/src/proxy.rs new file mode 100644 index 0000000000..ca1e4fd014 --- /dev/null +++ b/network/src/proxy.rs @@ -0,0 +1,28 @@ +pub(crate) fn check_proxy_url(proxy_url: &str) -> Result<(), String> { + let parsed_url = url::Url::parse(proxy_url).map_err(|e| e.to_string())?; + if parsed_url.host_str().is_none() { + return Err( format!("missing host in proxy url: {}", proxy_url) ); + } + let scheme = parsed_url.scheme(); + if scheme.ne("socks5") { + return Err(format!("CKB doesn't support proxy scheme: {}", scheme)); + } + Ok(()) +} + +#[test] +fn parse_socks5_url() { + let result = url::Url::parse("socks5://username:password@localhost:1080"); + assert!(result.is_ok()); + let parsed_url = result.unwrap(); + dbg!(&parsed_url); + assert_eq!(parsed_url.scheme(), "socks5"); + // username + assert_eq!(parsed_url.username(), "username"); + // password + assert_eq!(parsed_url.password(), Some("password")); + // host + assert_eq!(parsed_url.host_str(), Some("localhost")); + // port + assert_eq!(parsed_url.port(), Some(1080)); +} diff --git a/util/app-config/src/configs/network.rs b/util/app-config/src/configs/network.rs index bcfcd7048a..060e357309 100644 --- a/util/app-config/src/configs/network.rs +++ b/util/app-config/src/configs/network.rs @@ -101,6 +101,7 @@ pub struct Config { #[derive(Clone, Debug, Serialize, Deserialize, Default)] pub struct ProxyConfig { pub enable: bool, + // like: socks5://username:password@127.0.0.1:1080 pub proxy_url: String, }