diff --git a/.eslintignore b/.eslintignore index fc0688908..09540b74a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,4 +4,5 @@ out .gitignore migration.stub hydra-python-rpc/ +hydra-native/ src/main/generated/ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 31354bc32..fb87d3b97 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,26 +28,12 @@ jobs: with: node-version: 22.21.0 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Install dependencies run: yarn --frozen-lockfile - - name: Install Python - uses: actions/setup-python@v5 - with: - python-version: 3.9 - - - name: Install dependencies - run: pip install -r requirements.txt - - - name: Build with cx_Freeze - run: python python_rpc/setup.py build - - - name: Copy OpenSSL DLLs - if: matrix.os == 'windows-2022' - run: | - cp hydra-python-rpc/lib/libcrypto-1_1.dll hydra-python-rpc/lib/libcrypto-1_1-x64.dll - cp hydra-python-rpc/lib/libssl-1_1.dll hydra-python-rpc/lib/libssl-1_1-x64.dll - - name: Build Linux if: matrix.os == 'ubuntu-latest' run: | diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 89e8b59f4..a68374d9a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,7 +20,7 @@ jobs: node-version: 22.21.0 - name: Install dependencies - run: yarn --frozen-lockfile + run: yarn --frozen-lockfile --ignore-scripts - name: Validate current commit (last commit) with commitlint run: npx commitlint --last --verbose diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45163c4b0..e8a21db7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,26 +26,12 @@ jobs: with: node-version: 22.21.0 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Install dependencies run: yarn --frozen-lockfile - - name: Install Python - uses: actions/setup-python@v5 - with: - python-version: 3.9 - - - name: Install dependencies - run: pip install -r requirements.txt - - - name: Build with cx_Freeze - run: python python_rpc/setup.py build - - - name: Copy OpenSSL DLLs - if: matrix.os == 'windows-2022' - run: | - cp hydra-python-rpc/lib/libcrypto-1_1.dll hydra-python-rpc/lib/libcrypto-1_1-x64.dll - cp hydra-python-rpc/lib/libssl-1_1.dll hydra-python-rpc/lib/libssl-1_1-x64.dll - - name: Build Linux if: matrix.os == 'ubuntu-latest' run: | diff --git a/.gitignore b/.gitignore index ac8094b0f..3e965214a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ out ludusavi/** !ludusavi/config.yaml hydra-python-rpc/ +/hydra-native/ +native/hydra-native/target/ .python-version # Sentry Config File diff --git a/README.md b/README.md index 79dc4b6e0..3d7a5b036 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@

Hydra Launcher

- Hydra Launcher is an open-source gaming platform created to be the single tool that you need in order to manage your gaming library. Hydra is written in Node.js (Electron, React, Typescript) and Python. + Hydra Launcher is an open-source gaming platform created to be the single tool that you need in order to manage your gaming library. Hydra is written in Node.js (Electron, React, Typescript) and Rust.

[![build](https://img.shields.io/github/actions/workflow/status/hydralauncher/hydra/build.yml)](https://github.com/hydralauncher/hydra/actions) @@ -29,6 +29,13 @@ Please, refer to our Documentation pages: [docs.hydralauncher.gg](https://docs.hydralauncher.gg/getting-started) +### Local development requirements + +- Node.js + Yarn +- Rust toolchain (for `hydra-native`) + +After installing dependencies, `postinstall` now builds the Rust native addon automatically (`hydra-native/hydra-native.node`). + ## Contributors diff --git a/binaries/aria2c b/binaries/aria2c deleted file mode 100755 index 129ccd4b5..000000000 Binary files a/binaries/aria2c and /dev/null differ diff --git a/binaries/aria2c.exe b/binaries/aria2c.exe deleted file mode 100755 index 5004e1034..000000000 Binary files a/binaries/aria2c.exe and /dev/null differ diff --git a/electron-builder.yml b/electron-builder.yml index c7def7c1f..6fa487afa 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -4,7 +4,7 @@ directories: buildResources: build extraResources: - ludusavi - - hydra-python-rpc + - hydra-native - seeds - from: node_modules/create-desktop-shortcuts/src/windows.vbs - from: resources/achievement.wav @@ -22,7 +22,6 @@ asarUnpack: win: executableName: Hydra extraResources: - - from: binaries/aria2c.exe - from: binaries/7z.exe - from: binaries/7z.dll target: @@ -53,7 +52,6 @@ dmg: linux: extraResources: - from: binaries/7zzs - - from: binaries/aria2c - from: binaries/umu/umu-run target: - AppImage diff --git a/native/hydra-native/Cargo.lock b/native/hydra-native/Cargo.lock new file mode 100644 index 000000000..0df7761e6 --- /dev/null +++ b/native/hydra-native/Cargo.lock @@ -0,0 +1,3670 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "arc-swap" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9f3647c145568cec02c42054e07bdf9a5a698e15b466fb2341bfc393cd24aa5" +dependencies = [ + "rustversion", +] + +[[package]] +name = "assert_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e2651f366b7ee3f97729fded1441539b49d5f39eeb05b842689e11e84501b2" +dependencies = [ + "const_panic", +] + +[[package]] +name = "async-compression" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0f9ee0f6e02ffd7ad5816e9464499fba7b3effd01123b515c41d1697c43dad1" +dependencies = [ + "compression-codecs", + "compression-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "async-stream" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "backoff" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1" +dependencies = [ + "getrandom 0.2.17", + "instant", + "rand 0.8.5", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bincode" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740" +dependencies = [ + "bincode_derive", + "serde", + "unty", +] + +[[package]] +name = "bincode_derive" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09" +dependencies = [ + "virtue", +] + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "bstr" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytemuck" +version = "1.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "byteorder-lite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link 0.2.1", +] + +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + +[[package]] +name = "commoncrypto" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007" +dependencies = [ + "commoncrypto-sys", +] + +[[package]] +name = "commoncrypto-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2" +dependencies = [ + "libc", +] + +[[package]] +name = "compression-codecs" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb7b51a7d9c967fc26773061ba86150f19c50c0d65c887cb1fbe295fd16619b7" +dependencies = [ + "compression-core", + "flate2", + "memchr", +] + +[[package]] +name = "compression-core" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75984efb6ed102a0d42db99afb6c1948f0380d1d91808d5529916e6c08b49d8d" + +[[package]] +name = "const_panic" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e262cdaac42494e3ae34c43969f9cdeb7da178bdb4b66fa6a1ea2edb4c8ae652" +dependencies = [ + "typewit", +] + +[[package]] +name = "convert_case" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "affbf0190ed2caf063e3def54ff444b449371d55c58e513a95ab98eca50adb49" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crypto-hash" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a77162240fd97248d19a564a565eb563a3f592b386e4136fb300909e67dddca" +dependencies = [ + "commoncrypto", + "hex 0.3.2", + "openssl", + "winapi", +] + +[[package]] +name = "ctor" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "424e0138278faeb2b401f174ad17e715c829512d74f3d1e81eb43365c2e0590e" +dependencies = [ + "ctor-proc-macro", + "dtor", +] + +[[package]] +name = "ctor-proc-macro" +version = "0.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52560adf09603e58c9a7ee1fe1dcb95a16927b17c127f0ac02d6e768a0e25bc1" + +[[package]] +name = "darling" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0" +dependencies = [ + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "dashmap" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core", + "serde", +] + +[[package]] +name = "data-encoding" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea" + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", + "serde_core", +] + +[[package]] +name = "directories" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.61.2", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dtor" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404d02eeb088a82cfd873006cb713fe411306c7d182c344905e101fb1167d301" +dependencies = [ + "dtor-proc-macro", +] + +[[package]] +name = "dtor-proc-macro" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f678cf4a922c215c63e0de95eb1ff08a958a81d47e485cf9da1e27bf6305cfa5" + +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] +name = "fdeflate" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" +dependencies = [ + "simd-adler32", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-executor" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-timer" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 5.3.0", + "wasip2", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "wasip2", + "wasip3", +] + +[[package]] +name = "gif" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5df2ba84018d80c213569363bdcd0c64e6933c67fe4c1d60ecf822971a3c35e" +dependencies = [ + "color_quant", + "weezl", +] + +[[package]] +name = "governor" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9efcab3c1958580ff1f25a2a41be1668f7603d849bb63af523b208a3cc1223b8" +dependencies = [ + "cfg-if", + "dashmap", + "futures-sink", + "futures-timer", + "futures-util", + "getrandom 0.3.4", + "hashbrown 0.16.1", + "nonzero_ext", + "parking_lot", + "portable-atomic", + "quanta", + "rand 0.9.2", + "smallvec", + "spinning_top", + "web-time", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash 0.1.5", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.2.0", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hydra-native" +version = "0.1.0" +dependencies = [ + "anyhow", + "data-encoding", + "image", + "librqbit", + "mime_guess", + "napi", + "napi-build", + "napi-derive", + "once_cell", + "regex", + "reqwest", + "sysinfo", + "tokio", + "url", + "urlencoding", + "uuid", +] + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "image" +version = "0.25.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104" +dependencies = [ + "bytemuck", + "byteorder-lite", + "color_quant", + "gif", + "image-webp", + "moxcms", + "num-traits", + "png", + "zune-core", + "zune-jpeg", +] + +[[package]] +name = "image-webp" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3" +dependencies = [ + "byteorder-lite", + "quick-error", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", + "serde", + "serde_core", +] + +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "intervaltree" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "270bc34e57047cab801a8c871c124d9dc7132f6473c6401f645524f4e6edd111" +dependencies = [ + "smallvec", +] + +[[package]] +name = "ipnet" +version = "2.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" + +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "leaky-bucket" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a396bb213c2d09ed6c5495fd082c991b6ab39c9daf4fff59e6727f85c73e4c5" +dependencies = [ + "parking_lot", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.183" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" + +[[package]] +name = "libloading" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "754ca22de805bb5744484a5b151a9e1a8e837d5dc232c2d7d8c2e3492edc8b60" +dependencies = [ + "cfg-if", + "windows-link 0.2.1", +] + +[[package]] +name = "libredox" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1744e39d1d6a9948f4f388969627434e31128196de472883b39f148769bfe30a" +dependencies = [ + "libc", +] + +[[package]] +name = "librqbit" +version = "8.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dadca8f521242010a4c846ef5f224c217009c92e272709cdc08ba9cdabe62983" +dependencies = [ + "anyhow", + "arc-swap", + "async-compression", + "async-stream", + "async-trait", + "backoff", + "base64", + "bincode 2.0.1", + "bitvec", + "byteorder", + "bytes", + "dashmap", + "futures", + "governor", + "hex 0.4.3", + "http", + "intervaltree", + "itertools", + "librqbit-bencode", + "librqbit-buffers", + "librqbit-clone-to-owned", + "librqbit-core", + "librqbit-dht", + "librqbit-peer-protocol", + "librqbit-sha1-wrapper", + "librqbit-tracker-comms", + "librqbit-upnp", + "memmap2", + "mime_guess", + "parking_lot", + "rand 0.9.2", + "regex", + "reqwest", + "rlimit", + "serde", + "serde_json", + "serde_urlencoded", + "serde_with", + "size_format", + "tokio", + "tokio-socks", + "tokio-stream", + "tokio-util", + "tracing", + "url", + "urlencoding", + "uuid", + "walkdir", +] + +[[package]] +name = "librqbit-bencode" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "606dff526ba81e3eca33e2bb28b53afa2bc0b2c41d252333fa44e6c11abb37da" +dependencies = [ + "anyhow", + "bytes", + "librqbit-buffers", + "librqbit-clone-to-owned", + "librqbit-sha1-wrapper", + "serde", +] + +[[package]] +name = "librqbit-buffers" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78c78b907d6171a7191c162b2b60db46d254ebde6a95282b77372af556c1463" +dependencies = [ + "bytes", + "librqbit-clone-to-owned", + "serde", +] + +[[package]] +name = "librqbit-clone-to-owned" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbd1e66d773ba9c475ff89286dc1d6f9d167cbb898603797467dd0ea6844c445" +dependencies = [ + "bytes", +] + +[[package]] +name = "librqbit-core" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55a02cc6fce6743ad38661ccd6fafc6cf1ae5e0106a9922836b0524dbe752378" +dependencies = [ + "anyhow", + "assert_cfg", + "bytes", + "data-encoding", + "directories", + "hex 0.4.3", + "itertools", + "librqbit-bencode", + "librqbit-buffers", + "librqbit-clone-to-owned", + "parking_lot", + "rand 0.9.2", + "serde", + "tokio", + "tokio-util", + "tracing", + "url", +] + +[[package]] +name = "librqbit-dht" +version = "5.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7cc129194337771a86b0399956c4d9bf1cd97c5f24d14a50be38e170f76a54b" +dependencies = [ + "anyhow", + "backoff", + "byteorder", + "bytes", + "chrono", + "dashmap", + "futures", + "hex 0.4.3", + "indexmap 2.13.0", + "leaky-bucket", + "librqbit-bencode", + "librqbit-clone-to-owned", + "librqbit-core", + "parking_lot", + "rand 0.9.2", + "serde", + "serde_json", + "tokio", + "tokio-stream", + "tokio-util", + "tracing", +] + +[[package]] +name = "librqbit-peer-protocol" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a73129497b500505f33d1dc0426319b6a6a208f13fdfaae56224ab8c2346a773" +dependencies = [ + "anyhow", + "bincode 1.3.3", + "bitvec", + "byteorder", + "bytes", + "itertools", + "librqbit-bencode", + "librqbit-buffers", + "librqbit-clone-to-owned", + "librqbit-core", + "serde", +] + +[[package]] +name = "librqbit-sha1-wrapper" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79373a02db73159e4de7ca5d27b6eeae2d540df66c6801db2b01c5513d087524" +dependencies = [ + "assert_cfg", + "crypto-hash", +] + +[[package]] +name = "librqbit-tracker-comms" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08204944c5be677a5de8e1230e0249fce5c14abef23048e26452c6fb03f1b260" +dependencies = [ + "anyhow", + "async-stream", + "byteorder", + "futures", + "librqbit-bencode", + "librqbit-buffers", + "librqbit-core", + "parking_lot", + "rand 0.9.2", + "reqwest", + "serde", + "tokio", + "tokio-util", + "tracing", + "url", + "urlencoding", +] + +[[package]] +name = "librqbit-upnp" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "545aad6124c97201055983137e12a19f34acad565120c3cd30596cbd72e8fa86" +dependencies = [ + "anyhow", + "bstr", + "futures", + "httparse", + "network-interface", + "quick-xml", + "reqwest", + "serde", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "memmap2" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "714098028fe011992e1c3962653c96b2d578c4b4bce9036e15ff220319b1e0e3" +dependencies = [ + "libc", +] + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "moxcms" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb85c154ba489f01b25c0d36ae69a87e4a1c73a72631fc6c0eb6dde34a73e44b" +dependencies = [ + "num-traits", + "pxfm", +] + +[[package]] +name = "napi" +version = "3.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6944d0bf100571cd6e1a98a316cdca262deb6fccf8d93f5ae1502ca3fc88bd3" +dependencies = [ + "bitflags", + "ctor", + "futures", + "napi-build", + "napi-sys", + "nohash-hasher", + "rustc-hash", +] + +[[package]] +name = "napi-build" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d376940fd5b723c6893cd1ee3f33abbfd86acb1cd1ec079f3ab04a2a3bc4d3b1" + +[[package]] +name = "napi-derive" +version = "3.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c914b5e420182bfb73504e0607592cdb8e2e21437d450883077669fb72a114d" +dependencies = [ + "convert_case", + "ctor", + "napi-derive-backend", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "napi-derive-backend" +version = "5.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0864cf6a82e2cfb69067374b64c9253d7e910e5b34db833ed7495dda56ccb18" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "semver", + "syn", +] + +[[package]] +name = "napi-sys" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb602b84d7c1edae45e50bbf1374696548f36ae179dfa667f577e384bb90c2b" +dependencies = [ + "libloading", +] + +[[package]] +name = "native-tls" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "network-interface" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ddcb8865ad3d9950f22f42ffa0ef0aecbfbf191867b3122413602b0a360b2a6" +dependencies = [ + "cc", + "libc", + "thiserror 2.0.18", + "winapi", +] + +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + +[[package]] +name = "nonzero_ext" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" + +[[package]] +name = "ntapi" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3b335231dfd352ffb0f8017f3b6027a4917f7df785ea2143d8af2adc66980ae" +dependencies = [ + "winapi", +] + +[[package]] +name = "num" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36" +dependencies = [ + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "objc2-core-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" +dependencies = [ + "bitflags", +] + +[[package]] +name = "objc2-io-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33fafba39597d6dc1fb709123dfa8289d39406734be322956a69f0931c73bb15" +dependencies = [ + "libc", + "objc2-core-foundation", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "openssl" +version = "0.10.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "951c002c75e16ea2c65b8c7e4d3d51d5530d8dfa7d060b4776828c88cfb18ecf" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "openssl-sys" +version = "0.9.112" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d55af3b3e226502be1526dfdba67ab0e9c96fc293004e79576b2b9edb0dbdb" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link 0.2.1", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "png" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60769b8b31b2a9f263dae2776c37b1b28ae246943cf719eb6946a1db05128a61" +dependencies = [ + "bitflags", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide", +] + +[[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pxfm" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a041e753da8b807c9255f28de81879c78c876392ff2469cde94799b2896b9d" + +[[package]] +name = "quanta" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3ab5a9d756f0d97bdc89019bd2e4ea098cf9cde50ee7564dde6b81ccc8f06c7" +dependencies = [ + "crossbeam-utils", + "libc", + "once_cell", + "raw-cpuid", + "wasi", + "web-sys", + "winapi", +] + +[[package]] +name = "quick-error" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" + +[[package]] +name = "quick-xml" +version = "0.37.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "quinn" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 2.0.18", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" +dependencies = [ + "bytes", + "getrandom 0.3.4", + "lru-slab", + "rand 0.9.2", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.18", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.60.2", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "raw-cpuid" +version = "11.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "498cd0dc59d73224351ee52a95fee0f1a617a2eae0e7d9d720cc622c73a54186" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" +dependencies = [ + "getrandom 0.2.17", + "libredox", + "thiserror 2.0.18", +] + +[[package]] +name = "ref-cast" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f354300ae66f76f1c85c5f84693f0ce81d747e2c3f21a45fef496d89c960bf7d" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "js-sys", + "log", + "native-tls", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-native-tls", + "tokio-rustls", + "tokio-util", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rlimit" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7043b63bd0cd1aaa628e476b80e6d4023a3b50eb32789f2728908107bd0c793a" +dependencies = [ + "libc", +] + +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "schemars" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "schemars" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2b42f36aa1cd011945615b92222f6bf73c599a102a300334cd7f8dbeec726cc" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "3.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd5414fad8e6907dbdd5bc441a50ae8d6e26151a03b1de04d89a5576de61d01f" +dependencies = [ + "base64", + "chrono", + "hex 0.4.3", + "indexmap 1.9.3", + "indexmap 2.13.0", + "schemars 0.9.0", + "schemars 1.2.1", + "serde_core", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3db8978e608f1fe7357e211969fd9abdcae80bac1ba7a3369bb7eb6b404eb65" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "simd-adler32" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" + +[[package]] +name = "size_format" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed5f6ab2122c6dec69dca18c72fa4590a27e581ad20d44960fe74c032a0b23b" +dependencies = [ + "generic-array", + "num", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "spinning_top" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96d2d1d716fb500937168cc09353ffdc7a012be8475ac7308e1bdf0e3923300" +dependencies = [ + "lock_api", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sysinfo" +version = "0.37.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16607d5caffd1c07ce073528f9ed972d88db15dd44023fa57142963be3feb11f" +dependencies = [ + "libc", + "memchr", + "ntapi", + "objc2-core-foundation", + "objc2-io-kit", + "windows", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.2", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" + +[[package]] +name = "time-macros" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-socks" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4770b8024672c1101b3f6733eab95b18007dbe0847a8afe341fcf79e06043f" +dependencies = [ + "either", + "futures-util", + "thiserror 1.0.69", + "tokio", +] + +[[package]] +name = "tokio-stream" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", + "tokio-util", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "typewit" +version = "1.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8c1ae7cc0fdb8b842d65d127cb981574b0d2b249b74d1c7a2986863dc134f71" + +[[package]] +name = "unicase" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "unty" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", + "serde_derive", +] + +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "1.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a68d3c8f01c0cfa54a75291d83601161799e4a89a39e0929f4b0354d88757a37" +dependencies = [ + "getrandom 0.4.2", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "virtue" +version = "0.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9c5522b3a28661442748e09d40924dfb9ca614b21c00d3fd135720e48b67db8" +dependencies = [ + "cfg-if", + "futures-util", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap 2.13.0", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasm-streams" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap 2.13.0", + "semver", +] + +[[package]] +name = "web-sys" +version = "0.3.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854ba17bb104abfb26ba36da9729addc7ce7f06f5c0f90f3c391f8461cca21f9" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "weezl" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.61.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-link 0.1.3", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" +dependencies = [ + "windows-core", +] + +[[package]] +name = "windows-core" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link 0.1.3", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" +dependencies = [ + "windows-core", + "windows-link 0.1.3", + "windows-threading", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-numerics" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" +dependencies = [ + "windows-core", + "windows-link 0.1.3", +] + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link 0.1.3", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" +dependencies = [ + "windows-link 0.1.3", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link 0.2.1", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link 0.2.1", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows-threading" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" +dependencies = [ + "windows-link 0.1.3", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap 2.13.0", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap 2.13.0", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap 2.13.0", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbb2a062be311f2ba113ce66f697a4dc589f85e78a4aea276200804cea0ed87" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" + +[[package]] +name = "zune-core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb8a0807f7c01457d0379ba880ba6322660448ddebc890ce29bb64da71fb40f9" + +[[package]] +name = "zune-jpeg" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec5f41c76397b7da451efd19915684f727d7e1d516384ca6bd0ec43ec94de23c" +dependencies = [ + "zune-core", +] diff --git a/native/hydra-native/Cargo.toml b/native/hydra-native/Cargo.toml new file mode 100644 index 000000000..ca8455ee6 --- /dev/null +++ b/native/hydra-native/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "hydra-native" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +anyhow = "1.0.100" +image = { version = "0.25.8", default-features = false, features = ["gif", "jpeg", "png", "webp"] } +librqbit = "8.1.1" +mime_guess = "2.0.5" +napi = { version = "3.5.2", default-features = false, features = ["napi8"] } +napi-derive = "3.3.2" +once_cell = "1.21.3" +data-encoding = "2.9.0" +regex = "1.12.2" +reqwest = { version = "0.12.24", default-features = false, features = ["rustls-tls"] } +sysinfo = "0.37.2" +tokio = { version = "1.48.0", features = ["rt-multi-thread", "time"] } +url = "2.5.7" +urlencoding = "2.1.3" +uuid = { version = "1.11.0", features = ["v4"] } + +[build-dependencies] +napi-build = "2.3.1" diff --git a/native/hydra-native/build.rs b/native/hydra-native/build.rs new file mode 100644 index 000000000..0f1b01002 --- /dev/null +++ b/native/hydra-native/build.rs @@ -0,0 +1,3 @@ +fn main() { + napi_build::setup(); +} diff --git a/native/hydra-native/src/lib.rs b/native/hydra-native/src/lib.rs new file mode 100644 index 000000000..43fb44536 --- /dev/null +++ b/native/hydra-native/src/lib.rs @@ -0,0 +1,226 @@ +use std::fs::File; +use std::io::BufReader; +use std::path::{Path, PathBuf}; +use std::{cmp::Ordering, collections::HashMap}; + +mod torrent; + +use image::codecs::gif::GifDecoder; +use image::codecs::png::PngDecoder; +use image::codecs::webp::WebPDecoder; +use image::{AnimationDecoder, ImageFormat, ImageReader}; +use napi::bindgen_prelude::Error; +use napi_derive::napi; +use sysinfo::{ProcessesToUpdate, System}; +use uuid::Uuid; + +#[napi(object)] +pub struct ProcessedImageData { + pub image_path: String, + pub mime_type: String, +} + +#[napi(object)] +pub struct NativeProcessPayload { + pub exe: Option, + pub pid: u32, + pub name: String, + pub environ: Option>, + pub cwd: Option, +} + +#[napi] +pub fn process_profile_image( + image_path: String, + target_extension: Option, +) -> napi::Result { + let input_path = PathBuf::from(image_path); + + if !input_path.exists() { + return Err(Error::from_reason("Image file not found")); + } + + let format = detect_image_format(&input_path)?; + let animated = is_animated_image(&input_path, format)?; + + if !animated { + return Ok(ProcessedImageData { + image_path: input_path.to_string_lossy().to_string(), + mime_type: mime_type_from_format_or_path(format, &input_path), + }); + } + + let extension = target_extension + .map(|value| value.to_ascii_lowercase()) + .unwrap_or_else(|| "webp".to_string()); + + let output_format = output_format_from_extension(&extension)?; + let output_path = build_temp_output_path(&extension); + + let image = ImageReader::open(&input_path) + .map_err(|err| Error::from_reason(err.to_string()))? + .with_guessed_format() + .map_err(|err| Error::from_reason(err.to_string()))? + .decode() + .map_err(|err| Error::from_reason(err.to_string()))?; + + image + .save_with_format(&output_path, output_format) + .map_err(|err| Error::from_reason(err.to_string()))?; + + Ok(ProcessedImageData { + image_path: output_path.to_string_lossy().to_string(), + mime_type: mime_type_from_format_or_path(Some(output_format), &output_path), + }) +} + +#[napi] +pub fn list_processes() -> Vec { + let mut system = System::new_all(); + system.refresh_processes(ProcessesToUpdate::All, true); + + let mut processes: Vec = system + .processes() + .values() + .map(|process| { + let include_linux_extras = !cfg!(target_os = "windows"); + + NativeProcessPayload { + exe: process + .exe() + .map(|value| value.to_string_lossy().to_string()), + pid: process.pid().as_u32(), + name: process.name().to_string_lossy().to_string(), + cwd: if include_linux_extras { + process + .cwd() + .map(|value| value.to_string_lossy().to_string()) + } else { + None + }, + environ: if include_linux_extras { + let env_map: HashMap = process + .environ() + .iter() + .filter_map(|entry| { + let entry_value = entry.to_string_lossy(); + entry_value.split_once('=').and_then(|(key, value)| { + if key.is_empty() { + None + } else { + Some((key.to_string(), value.to_string())) + } + }) + }) + .collect(); + + if env_map.is_empty() { + None + } else { + Some(env_map) + } + } else { + None + }, + } + }) + .collect(); + + processes.sort_by(|left, right| { + let by_pid = left.pid.cmp(&right.pid); + if by_pid == Ordering::Equal { + left.name.cmp(&right.name) + } else { + by_pid + } + }); + + processes +} + +fn detect_image_format(path: &Path) -> napi::Result> { + let reader = ImageReader::open(path).map_err(|err| Error::from_reason(err.to_string()))?; + + let guessed = reader + .with_guessed_format() + .map_err(|err| Error::from_reason(err.to_string()))?; + + Ok(guessed.format()) +} + +fn is_animated_image(path: &Path, format: Option) -> napi::Result { + match format { + Some(ImageFormat::Gif) => is_gif_animated(path), + Some(ImageFormat::WebP) => is_webp_animated(path), + Some(ImageFormat::Png) => is_apng(path), + _ => Ok(false), + } +} + +fn is_gif_animated(path: &Path) -> napi::Result { + let file = File::open(path).map_err(|err| Error::from_reason(err.to_string()))?; + let decoder = + GifDecoder::new(BufReader::new(file)).map_err(|err| Error::from_reason(err.to_string()))?; + + let mut frames = decoder.into_frames(); + let _ = frames.next().transpose(); + Ok(matches!(frames.next().transpose(), Ok(Some(_)))) +} + +fn is_webp_animated(path: &Path) -> napi::Result { + let file = File::open(path).map_err(|err| Error::from_reason(err.to_string()))?; + let decoder = WebPDecoder::new(BufReader::new(file)) + .map_err(|err| Error::from_reason(err.to_string()))?; + + Ok(decoder.has_animation()) +} + +fn is_apng(path: &Path) -> napi::Result { + let file = File::open(path).map_err(|err| Error::from_reason(err.to_string()))?; + let decoder = + PngDecoder::new(BufReader::new(file)).map_err(|err| Error::from_reason(err.to_string()))?; + + decoder + .is_apng() + .map_err(|err| Error::from_reason(err.to_string())) +} + +fn output_format_from_extension(extension: &str) -> napi::Result { + match extension { + "png" => Ok(ImageFormat::Png), + "jpg" | "jpeg" => Ok(ImageFormat::Jpeg), + "webp" => Ok(ImageFormat::WebP), + _ => Err(Error::from_reason("Unsupported target extension")), + } +} + +fn build_temp_output_path(extension: &str) -> PathBuf { + let mut output_path = std::env::temp_dir(); + output_path.push(format!("{}.{}", Uuid::new_v4(), extension)); + output_path +} + +fn mime_type_from_format_or_path(format: Option, path: &Path) -> String { + if let Some(value) = mime_type_from_image_format(format) { + return value.to_string(); + } + + mime_guess::from_path(path) + .first_or_octet_stream() + .essence_str() + .to_string() +} + +fn mime_type_from_image_format(format: Option) -> Option<&'static str> { + match format { + Some(ImageFormat::Png) => Some("image/png"), + Some(ImageFormat::Jpeg) => Some("image/jpeg"), + Some(ImageFormat::Gif) => Some("image/gif"), + Some(ImageFormat::WebP) => Some("image/webp"), + Some(ImageFormat::Bmp) => Some("image/bmp"), + Some(ImageFormat::Ico) => Some("image/x-icon"), + Some(ImageFormat::Tiff) => Some("image/tiff"), + Some(ImageFormat::Avif) => Some("image/avif"), + _ => None, + } +} diff --git a/native/hydra-native/src/torrent.rs b/native/hydra-native/src/torrent.rs new file mode 100644 index 000000000..586454c57 --- /dev/null +++ b/native/hydra-native/src/torrent.rs @@ -0,0 +1,1258 @@ +use std::collections::{HashMap, HashSet}; +use std::num::NonZeroU32; +use std::path::PathBuf; +use std::sync::Arc; +use std::time::SystemTime; +use std::time::{Duration, Instant}; + +use data_encoding::BASE32; +use librqbit::{ + AddTorrent, AddTorrentOptions, AddTorrentResponse, Api, Session, SessionOptions, TorrentStats, + TorrentStatsState, +}; +use napi::bindgen_prelude::Error; +use napi_derive::napi; +use once_cell::sync::Lazy; +use regex::Regex; +use tokio::runtime::Runtime; +use tokio::sync::Mutex; +use tokio::task::JoinHandle; +use tokio::time::timeout; +use url::Url; + +const TORRENT_FILES_CACHE_TTL_SECONDS: u64 = 300; +const TORRENT_FILES_CACHE_MAX_ITEMS: usize = 128; +const TORRENT_MAX_FILES: usize = 100_000; +const SEED_ESTIMATE_TTL_SECONDS: u64 = 600; +const SEED_POLL_INTERVAL_SECONDS: u64 = 90; +const ENABLE_TRACKER_SEED_ESTIMATOR: bool = false; + +static MAGNET_HASH_HEX_RE: Lazy = + Lazy::new(|| Regex::new(r"^[a-fA-F0-9]{40}$").expect("valid regex")); +static MAGNET_HASH_BASE32_RE: Lazy = + Lazy::new(|| Regex::new(r"^[a-zA-Z2-7]{32}$").expect("valid regex")); + +static TOKIO_RT: Lazy = Lazy::new(|| { + Runtime::new().unwrap_or_else(|err| panic!("failed to initialize tokio runtime: {err}")) +}); + +static TORRENT_MANAGER: Lazy> = Lazy::new(|| Mutex::new(TorrentManager::new())); +static TRACKER_HTTP_CLIENT: Lazy = Lazy::new(|| { + reqwest::Client::builder() + .timeout(Duration::from_secs(7)) + .build() + .unwrap_or_else(|err| panic!("failed to initialize tracker http client: {err}")) +}); + +const TRACKER_PEER_ID: &[u8; 20] = b"-HY0001-012345678901"; + +const DEFAULT_TRACKERS: &[&str] = &[ + "udp://tracker.opentrackr.org:1337/announce", + "http://tracker.opentrackr.org:1337/announce", + "udp://open.tracker.cl:1337/announce", + "udp://open.demonii.com:1337/announce", + "udp://open.stealth.si:80/announce", + "udp://tracker.torrent.eu.org:451/announce", + "udp://exodus.desync.com:6969/announce", + "udp://tracker.theoks.net:6969/announce", + "udp://tracker-udp.gbitt.info:80/announce", + "udp://explodie.org:6969/announce", + "https://tracker.tamersunion.org:443/announce", + "udp://tracker2.dler.org:80/announce", + "udp://tracker1.myporn.club:9337/announce", + "udp://tracker.tiny-vps.com:6969/announce", + "udp://tracker.dler.org:6969/announce", + "udp://tracker.bittor.pw:1337/announce", + "udp://tracker.0x7c0.com:6969/announce", + "udp://retracker01-msk-virt.corbina.net:80/announce", + "udp://opentracker.io:6969/announce", + "udp://open.free-tracker.ga:6969/announce", + "udp://new-line.net:6969/announce", + "udp://moonburrow.club:6969/announce", + "udp://leet-tracker.moe:1337/announce", + "udp://bt2.archive.org:6969/announce", + "udp://bt1.archive.org:6969/announce", + "http://tracker2.dler.org:80/announce", + "http://tracker1.bt.moack.co.kr:80/announce", + "http://tracker.dler.org:6969/announce", + "http://tr.kxmp.cf:80/announce", + "udp://u.peer-exchange.download:6969/announce", + "udp://ttk2.nbaonlineservice.com:6969/announce", + "udp://tracker.tryhackx.org:6969/announce", + "udp://tracker.srv00.com:6969/announce", + "udp://tracker.skynetcloud.site:6969/announce", + "udp://tracker.jamesthebard.net:6969/announce", + "udp://tracker.fnix.net:6969/announce", + "udp://tracker.filemail.com:6969/announce", + "udp://tracker.farted.net:6969/announce", + "udp://tracker.edkj.club:6969/announce", + "udp://tracker.dump.cl:6969/announce", + "udp://tracker.deadorbit.nl:6969/announce", + "udp://tracker.darkness.services:6969/announce", + "udp://tracker.ccp.ovh:6969/announce", + "udp://tamas3.ynh.fr:6969/announce", + "udp://ryjer.com:6969/announce", + "udp://run.publictracker.xyz:6969/announce", + "udp://public.tracker.vraphim.com:6969/announce", + "udp://p4p.arenabg.com:1337/announce", + "udp://p2p.publictracker.xyz:6969/announce", + "udp://open.u-p.pw:6969/announce", + "udp://open.publictracker.xyz:6969/announce", + "udp://open.dstud.io:6969/announce", + "udp://open.demonoid.ch:6969/announce", + "udp://odd-hd.fr:6969/announce", + "udp://martin-gebhardt.eu:25/announce", + "udp://jutone.com:6969/announce", + "udp://isk.richardsw.club:6969/announce", + "udp://evan.im:6969/announce", + "udp://epider.me:6969/announce", + "udp://d40969.acod.regrucolo.ru:6969/announce", + "udp://bt.rer.lol:6969/announce", + "udp://amigacity.xyz:6969/announce", + "udp://1c.premierzal.ru:6969/announce", + "https://trackers.run:443/announce", + "https://tracker.yemekyedim.com:443/announce", + "https://tracker.renfei.net:443/announce", + "https://tracker.pmman.tech:443/announce", + "https://tracker.lilithraws.org:443/announce", + "https://tracker.imgoingto.icu:443/announce", + "https://tracker.cloudit.top:443/announce", + "https://tracker-zhuqiy.dgj055.icu:443/announce", + "http://tracker.renfei.net:8080/announce", + "http://tracker.mywaifu.best:6969/announce", + "http://tracker.ipv6tracker.org:80/announce", + "http://tracker.files.fm:6969/announce", + "http://tracker.edkj.club:6969/announce", + "http://tracker.bt4g.com:2095/announce", + "http://tracker-zhuqiy.dgj055.icu:80/announce", + "http://t1.aag.moe:17715/announce", + "http://t.overflow.biz:6969/announce", + "http://bittorrent-tracker.e-n-c-r-y-p-t.net:1337/announce", + "udp://torrents.artixlinux.org:6969/announce", + "udp://mail.artixlinux.org:6969/announce", + "udp://ipv4.rer.lol:2710/announce", + "udp://concen.org:6969/announce", + "udp://bt.rer.lol:2710/announce", + "udp://aegir.sexy:6969/announce", + "https://www.peckservers.com:9443/announce", + "https://tracker.ipfsscan.io:443/announce", + "https://tracker.gcrenwp.top:443/announce", + "http://www.peckservers.com:9000/announce", + "http://tracker1.itzmx.com:8080/announce", + "http://ch3oh.ru:6969/announce", + "http://bvarf.tracker.sh:2086/announce", +]; + +#[napi(object)] +#[derive(Clone)] +pub struct TorrentFileEntry { + pub index: u32, + pub path: String, + pub length: i64, +} + +#[napi(object)] +#[derive(Clone)] +pub struct TorrentFilesPayload { + pub info_hash: String, + pub name: String, + pub total_size: i64, + pub files: Vec, +} + +#[napi(object)] +#[derive(Clone)] +pub struct TorrentStatusPayload { + pub progress: f64, + pub num_peers: u32, + pub num_seeds: u32, + pub download_speed: i64, + pub upload_speed: i64, + pub bytes_downloaded: i64, + pub file_size: i64, + pub folder_name: String, + pub status: u32, +} + +#[napi(object)] +#[derive(Clone)] +pub struct TorrentSeedStatusPayload { + pub game_id: String, + pub progress: f64, + pub num_peers: u32, + pub num_seeds: u32, + pub download_speed: i64, + pub upload_speed: i64, + pub bytes_downloaded: i64, + pub file_size: i64, + pub folder_name: String, + pub status: u32, +} + +#[napi(object)] +pub struct StartTorrentPayload { + pub game_id: String, + pub url: String, + pub save_path: String, + pub file_indices: Option>, + pub timeout_ms: Option, +} + +#[napi(object)] +pub struct ResumeSeedingPayload { + pub game_id: String, + pub url: String, + pub save_path: String, +} + +struct CachedTorrentFiles { + cached_at: Instant, + payload: TorrentFilesPayload, +} + +struct PendingStart { + save_path: String, +} + +#[derive(Clone)] +struct TorrentMeta { + info_hash: String, + trackers: Vec, +} + +struct SeedEstimate { + value: u32, + updated_at: Instant, +} + +struct TorrentManager { + session: Option>, + downloads: HashMap>, + torrent_meta: HashMap, + seed_estimates: HashMap, + pending_starts: HashMap, + pending_tasks: HashMap>, + seed_poll_tasks: HashMap>, + downloading_game_id: Option, + seeding_game_ids: HashSet, + current_download_limit: Option, + torrent_files_cache: HashMap, +} + +impl TorrentManager { + fn new() -> Self { + Self { + session: None, + downloads: HashMap::new(), + torrent_meta: HashMap::new(), + seed_estimates: HashMap::new(), + pending_starts: HashMap::new(), + pending_tasks: HashMap::new(), + seed_poll_tasks: HashMap::new(), + downloading_game_id: None, + seeding_game_ids: HashSet::new(), + current_download_limit: None, + torrent_files_cache: HashMap::new(), + } + } + + fn normalize_timeout_ms(timeout_ms: Option, default_ms: u32) -> u32 { + let value = timeout_ms.unwrap_or(default_ms); + value.clamp(5_000, 120_000) + } + + fn cache_get(&mut self, info_hash: &str) -> Option { + self.prune_expired_cache(); + self.torrent_files_cache + .get(info_hash) + .map(|item| item.payload.clone()) + } + + fn cache_set(&mut self, info_hash: String, payload: TorrentFilesPayload) { + self.prune_expired_cache(); + + if self.torrent_files_cache.len() >= TORRENT_FILES_CACHE_MAX_ITEMS { + let oldest_key = self + .torrent_files_cache + .iter() + .min_by_key(|(_, value)| value.cached_at) + .map(|(key, _)| key.clone()); + + if let Some(key) = oldest_key { + self.torrent_files_cache.remove(&key); + } + } + + self.torrent_files_cache.insert( + info_hash, + CachedTorrentFiles { + cached_at: Instant::now(), + payload, + }, + ); + } + + fn prune_expired_cache(&mut self) { + let ttl = Duration::from_secs(TORRENT_FILES_CACHE_TTL_SECONDS); + self.torrent_files_cache + .retain(|_, value| value.cached_at.elapsed() <= ttl); + } + + fn abort_pending_start(&mut self, game_id: &str) { + if let Some(task) = self.pending_tasks.remove(game_id) { + task.abort(); + } + self.pending_starts.remove(game_id); + } + + fn stop_seed_polling(&mut self, game_id: &str) { + if let Some(task) = self.seed_poll_tasks.remove(game_id) { + task.abort(); + } + self.seed_estimates.remove(game_id); + } +} + +fn map_anyhow_error(error: anyhow::Error) -> Error { + let message = error.to_string().to_lowercase(); + + if message.contains("magnet") || message.contains("btih") || message.contains("scheme") { + return Error::from_reason("invalid_magnet"); + } + + if message.contains("only_files contains invalid value") { + return Error::from_reason("invalid_file_indices"); + } + + Error::from_reason(error.to_string()) +} + +fn validate_magnet_uri(raw_magnet: &str) -> napi::Result<(String, String)> { + let magnet = raw_magnet.trim(); + + if !magnet.starts_with("magnet:") || magnet.len() > 8192 { + return Err(Error::from_reason("invalid_magnet")); + } + + let parsed = Url::parse(magnet).map_err(|_| Error::from_reason("invalid_magnet"))?; + if parsed.scheme() != "magnet" { + return Err(Error::from_reason("invalid_magnet")); + } + + for (key, value) in parsed.query_pairs() { + if key != "xt" { + continue; + } + + if !value.starts_with("urn:btih:") { + continue; + } + + let hash = value[9..].trim().to_lowercase(); + if MAGNET_HASH_HEX_RE.is_match(&hash) || MAGNET_HASH_BASE32_RE.is_match(&hash) { + return Ok((magnet.to_string(), hash)); + } + } + + Err(Error::from_reason("invalid_magnet")) +} + +fn parse_magnet_trackers(magnet: &str) -> Vec { + let mut trackers = DEFAULT_TRACKERS + .iter() + .map(|value| value.to_string()) + .collect::>(); + + if let Ok(parsed) = Url::parse(magnet) { + for (key, value) in parsed.query_pairs() { + if key == "tr" { + let tracker = value.to_string(); + if !trackers.contains(&tracker) { + trackers.push(tracker); + } + } + } + } + + trackers +} + +fn decode_info_hash_bytes(hash: &str) -> Option<[u8; 20]> { + if hash.len() == 40 { + let mut output = [0u8; 20]; + for (index, chunk) in hash.as_bytes().chunks(2).enumerate() { + let piece = std::str::from_utf8(chunk).ok()?; + output[index] = u8::from_str_radix(piece, 16).ok()?; + } + return Some(output); + } + + if hash.len() == 32 { + let decoded = BASE32.decode(hash.to_uppercase().as_bytes()).ok()?; + if decoded.len() == 20 { + let mut output = [0u8; 20]; + output.copy_from_slice(&decoded); + return Some(output); + } + } + + None +} + +fn parse_complete_from_bencode(bytes: &[u8]) -> Option { + let marker = b"8:completei"; + let pos = bytes.windows(marker.len()).position(|window| window == marker)?; + let mut cursor = pos + marker.len(); + let mut value = 0u32; + let mut parsed_digit = false; + + while let Some(byte) = bytes.get(cursor).copied() { + if byte == b'e' { + return if parsed_digit { Some(value) } else { None }; + } + + if !byte.is_ascii_digit() { + return None; + } + + parsed_digit = true; + value = value.saturating_mul(10).saturating_add((byte - b'0') as u32); + cursor += 1; + } + + None +} + +async fn fetch_tracker_seeders_http(tracker: &str, info_hash: &[u8; 20]) -> Option { + let mut url = Url::parse(tracker).ok()?; + if !matches!(url.scheme(), "http" | "https") { + return None; + } + + { + let mut query = url.query_pairs_mut(); + query.append_pair("info_hash", &urlencoding::encode_binary(info_hash)); + query.append_pair("peer_id", &urlencoding::encode_binary(TRACKER_PEER_ID)); + query.append_pair("port", "0"); + query.append_pair("uploaded", "0"); + query.append_pair("downloaded", "0"); + query.append_pair("left", "0"); + query.append_pair("compact", "1"); + query.append_pair("event", "started"); + } + + let response = TRACKER_HTTP_CLIENT.get(url).send().await.ok()?; + let bytes = response.bytes().await.ok()?; + parse_complete_from_bencode(&bytes) +} + +fn next_tracker_transaction_id() -> u32 { + let nanos = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .map(|duration| duration.subsec_nanos()) + .unwrap_or(0); + nanos ^ 0x5A17_4E3D +} + +async fn fetch_tracker_seeders_udp(tracker: &str, info_hash: &[u8; 20]) -> Option { + let parsed = Url::parse(tracker).ok()?; + if parsed.scheme() != "udp" { + return None; + } + + let host = parsed.host_str()?; + let port = parsed.port().unwrap_or(80); + let target = format!("{host}:{port}"); + + let socket = tokio::net::UdpSocket::bind("0.0.0.0:0").await.ok()?; + + let connect_tid = next_tracker_transaction_id(); + let mut connect_request = [0u8; 16]; + connect_request[0..8].copy_from_slice(&0x41727101980u64.to_be_bytes()); + connect_request[8..12].copy_from_slice(&0u32.to_be_bytes()); + connect_request[12..16].copy_from_slice(&connect_tid.to_be_bytes()); + + socket.send_to(&connect_request, &target).await.ok()?; + + let mut response = [0u8; 2048]; + let (connect_len, _) = timeout(Duration::from_secs(4), socket.recv_from(&mut response)) + .await + .ok()? + .ok()?; + + if connect_len < 16 { + return None; + } + + let action = u32::from_be_bytes(response[0..4].try_into().ok()?); + let response_tid = u32::from_be_bytes(response[4..8].try_into().ok()?); + + if action != 0 || response_tid != connect_tid { + return None; + } + + let connection_id = u64::from_be_bytes(response[8..16].try_into().ok()?); + + let announce_tid = next_tracker_transaction_id(); + let mut announce_request = vec![0u8; 98]; + announce_request[0..8].copy_from_slice(&connection_id.to_be_bytes()); + announce_request[8..12].copy_from_slice(&1u32.to_be_bytes()); + announce_request[12..16].copy_from_slice(&announce_tid.to_be_bytes()); + announce_request[16..36].copy_from_slice(info_hash); + announce_request[36..56].copy_from_slice(TRACKER_PEER_ID); + announce_request[56..64].copy_from_slice(&0u64.to_be_bytes()); + announce_request[64..72].copy_from_slice(&0u64.to_be_bytes()); + announce_request[72..80].copy_from_slice(&0u64.to_be_bytes()); + announce_request[80..84].copy_from_slice(&2u32.to_be_bytes()); + announce_request[84..88].copy_from_slice(&0u32.to_be_bytes()); + announce_request[88..92].copy_from_slice(&0u32.to_be_bytes()); + announce_request[92..96].copy_from_slice(&(-1i32).to_be_bytes()); + announce_request[96..98].copy_from_slice(&0u16.to_be_bytes()); + + socket.send_to(&announce_request, &target).await.ok()?; + + let (announce_len, _) = timeout(Duration::from_secs(5), socket.recv_from(&mut response)) + .await + .ok()? + .ok()?; + + if announce_len < 20 { + return None; + } + + let action = u32::from_be_bytes(response[0..4].try_into().ok()?); + let response_tid = u32::from_be_bytes(response[4..8].try_into().ok()?); + + if action != 1 || response_tid != announce_tid { + return None; + } + + let seeders = u32::from_be_bytes(response[16..20].try_into().ok()?); + Some(seeders) +} + +async fn update_seed_estimate(game_id: &str, meta: &TorrentMeta) { + let Some(info_hash) = decode_info_hash_bytes(&meta.info_hash) else { + return; + }; + + let mut best = None; + for tracker in &meta.trackers { + let estimate = if tracker.starts_with("udp://") { + fetch_tracker_seeders_udp(tracker, &info_hash).await + } else { + fetch_tracker_seeders_http(tracker, &info_hash).await + }; + + if let Some(value) = estimate { + best = Some(best.map_or(value, |current: u32| current.max(value))); + } + } + + if let Some(value) = best { + let mut manager = TORRENT_MANAGER.lock().await; + manager.seed_estimates.insert( + game_id.to_string(), + SeedEstimate { + value, + updated_at: Instant::now(), + }, + ); + } +} + +async fn ensure_seed_polling(game_id: String) { + if !ENABLE_TRACKER_SEED_ESTIMATOR { + return; + } + + let meta = { + let mut manager = TORRENT_MANAGER.lock().await; + + if manager.seed_poll_tasks.contains_key(&game_id) { + return; + } + + let Some(meta) = manager.torrent_meta.get(&game_id).cloned() else { + return; + }; + + let game_id_for_task = game_id.clone(); + let meta_for_task = meta.clone(); + + let task = TOKIO_RT.spawn(async move { + loop { + update_seed_estimate(&game_id_for_task, &meta_for_task).await; + tokio::time::sleep(Duration::from_secs(SEED_POLL_INTERVAL_SECONDS)).await; + } + }); + + manager.seed_poll_tasks.insert(game_id.clone(), task); + meta + }; + + update_seed_estimate(&game_id, &meta).await; +} + +fn current_seed_estimate(manager: &TorrentManager, game_id: &str) -> Option { + if !ENABLE_TRACKER_SEED_ESTIMATOR { + return None; + } + + let estimate = manager.seed_estimates.get(game_id)?; + if estimate.updated_at.elapsed() > Duration::from_secs(SEED_ESTIMATE_TTL_SECONDS) { + return None; + } + Some(estimate.value) +} + +fn build_tracker_set() -> HashSet { + DEFAULT_TRACKERS + .iter() + .filter_map(|value| Url::parse(value).ok()) + .collect() +} + +async fn get_or_create_session() -> napi::Result> { + let (existing, limit) = { + let manager = TORRENT_MANAGER.lock().await; + (manager.session.clone(), manager.current_download_limit) + }; + + if let Some(session) = existing { + return Ok(session); + } + + let mut opts = SessionOptions::default(); + opts.listen_port_range = Some(5881..5892); + opts.trackers = build_tracker_set(); + opts.enable_upnp_port_forwarding = true; + + let session = Session::new_with_opts(std::env::temp_dir(), opts) + .await + .map_err(map_anyhow_error)?; + + if let Some(value) = limit { + session.ratelimits.set_download_bps(NonZeroU32::new(value)); + } + + let mut manager = TORRENT_MANAGER.lock().await; + if manager.session.is_none() { + manager.session = Some(session.clone()); + } + + Ok(manager.session.as_ref().expect("session exists").clone()) +} + +fn compute_status( + stats: &TorrentStats, + metadata_available: bool, + seeding_hint: bool, +) -> (u32, u32, u32, i64, i64, u32) { + match stats.state { + TorrentStatsState::Initializing => { + let state = if metadata_available { 1 } else { 2 }; + (state, 0, 0, 0, 0, 0) + } + TorrentStatsState::Live => { + let status = if stats.finished { + if seeding_hint { + 5 + } else { + 4 + } + } else { + 3 + }; + + let (num_peers, download_speed, upload_speed, connected_seeders) = + if let Some(live) = &stats.live { + ( + (live.snapshot.peer_stats.live + live.snapshot.peer_stats.connecting) as u32, + (live.download_speed.mbps * 1024.0 * 1024.0).max(0.0) as i64, + (live.upload_speed.mbps * 1024.0 * 1024.0).max(0.0) as i64, + live.snapshot.peer_stats.not_needed as u32, + ) + } else { + (0, 0, 0, 0) + }; + + ( + status, + num_peers, + 0, + download_speed, + upload_speed, + connected_seeders, + ) + } + TorrentStatsState::Paused => { + let status = if stats.finished { + if seeding_hint { + 5 + } else { + 4 + } + } else { + 3 + }; + (status, 0, 0, 0, 0, 0) + } + TorrentStatsState::Error => (3, 0, 0, 0, 0, 0), + } +} + +fn build_status_payload( + handle: &Arc, + seeding_hint: bool, + tracker_seed_estimate: Option, +) -> TorrentStatusPayload { + let stats = handle.stats(); + let metadata_available = handle.with_metadata(|_| ()).is_ok(); + let (status, num_peers, _num_seeds, download_speed, upload_speed, connected_seeders) = + compute_status(&stats, metadata_available, seeding_hint); + + let num_seeds = tracker_seed_estimate + .unwrap_or(0) + .max(connected_seeders); + + let file_size = stats.total_bytes; + let bytes_downloaded = stats.progress_bytes; + let progress = if file_size > 0 { + (bytes_downloaded as f64 / file_size as f64).clamp(0.0, 1.0) + } else if stats.finished { + 1.0 + } else { + 0.0 + }; + + TorrentStatusPayload { + progress, + num_peers, + num_seeds, + download_speed, + upload_speed, + bytes_downloaded: bytes_downloaded as i64, + file_size: file_size as i64, + folder_name: handle.name().unwrap_or_default(), + status, + } +} + +async fn fetch_torrent_files_internal( + magnet: String, + info_hash: String, + timeout_ms: u32, +) -> napi::Result { + { + let mut manager = TORRENT_MANAGER.lock().await; + if let Some(cached) = manager.cache_get(&info_hash) { + return Ok(cached); + } + } + + let session = get_or_create_session().await?; + let api = Api::new(session, None); + let mut opts = AddTorrentOptions::default(); + opts.list_only = true; + + let add_future = api.api_add_torrent(AddTorrent::from_url(magnet), Some(opts)); + let response = timeout(Duration::from_millis(timeout_ms as u64), add_future) + .await + .map_err(|_| Error::from_reason("metadata_timeout"))? + .map_err(|error| { + let message = error.to_string(); + if message.to_lowercase().contains("timeout") { + Error::from_reason("metadata_timeout") + } else { + Error::from_reason("metadata_incomplete") + } + })?; + + let files = response + .details + .files + .ok_or_else(|| Error::from_reason("metadata_incomplete"))?; + + if files.len() > TORRENT_MAX_FILES { + return Err(Error::from_reason("too_many_files")); + } + + let mut mapped_files = Vec::with_capacity(files.len()); + let mut total_size = 0u64; + + for (index, file) in files.into_iter().enumerate() { + let path = if file.components.is_empty() { + file.name + } else { + let mut components = file.components; + components.push(file.name); + PathBuf::from_iter(components) + .to_string_lossy() + .to_string() + }; + + total_size = total_size.saturating_add(file.length); + + mapped_files.push(TorrentFileEntry { + index: index as u32, + path, + length: file.length as i64, + }); + } + + let payload = TorrentFilesPayload { + info_hash: info_hash.clone(), + name: response.details.name.unwrap_or_default(), + total_size: total_size as i64, + files: mapped_files, + }; + + let mut manager = TORRENT_MANAGER.lock().await; + manager.cache_set(info_hash, payload.clone()); + + Ok(payload) +} + +async fn complete_pending_start( + game_id: String, + info_hash: String, + magnet: String, + save_path: String, +) -> napi::Result<()> { + let trackers = parse_magnet_trackers(&magnet); + let session = get_or_create_session().await?; + + let mut opts = AddTorrentOptions::default(); + opts.output_folder = Some(save_path); + opts.overwrite = true; + + let response = session + .add_torrent(AddTorrent::from_url(magnet), Some(opts)) + .await + .map_err(map_anyhow_error)?; + + let handle = match response { + AddTorrentResponse::Added(_, handle) | AddTorrentResponse::AlreadyManaged(_, handle) => { + handle + } + AddTorrentResponse::ListOnly(_) => { + return Err(Error::from_reason("metadata_incomplete")); + } + }; + + let mut manager = TORRENT_MANAGER.lock().await; + manager.pending_starts.remove(&game_id); + manager.pending_tasks.remove(&game_id); + manager.downloads.insert(game_id.clone(), handle); + manager.torrent_meta.insert( + game_id.clone(), + TorrentMeta { + info_hash, + trackers, + }, + ); + manager.downloading_game_id = Some(game_id.clone()); + manager.seeding_game_ids.remove(&game_id); + drop(manager); + + ensure_seed_polling(game_id).await; + Ok(()) +} + +#[napi] +pub fn torrent_get_status() -> napi::Result> { + TOKIO_RT.block_on(async { + let manager = TORRENT_MANAGER.lock().await; + + let Some(game_id) = &manager.downloading_game_id else { + return Ok(None); + }; + + if let Some(handle) = manager.downloads.get(game_id) { + let tracker_seed_estimate = current_seed_estimate(&manager, game_id); + return Ok(Some(build_status_payload( + handle, + manager.seeding_game_ids.contains(game_id), + tracker_seed_estimate, + ))); + } + + if let Some(pending) = manager.pending_starts.get(game_id) { + return Ok(Some(TorrentStatusPayload { + progress: 0.0, + num_peers: 0, + num_seeds: 0, + download_speed: 0, + upload_speed: 0, + bytes_downloaded: 0, + file_size: 0, + folder_name: PathBuf::from(&pending.save_path) + .file_name() + .map(|value| value.to_string_lossy().to_string()) + .unwrap_or_default(), + status: 2, + })); + } + + Ok(None) + }) +} + +#[napi] +pub fn torrent_get_seed_status() -> napi::Result> { + TOKIO_RT.block_on(async { + let manager = TORRENT_MANAGER.lock().await; + let mut payload = Vec::new(); + + for game_id in &manager.seeding_game_ids { + let Some(handle) = manager.downloads.get(game_id) else { + continue; + }; + + let status = build_status_payload(handle, true, current_seed_estimate(&manager, game_id)); + if status.status != 5 { + continue; + } + + payload.push(TorrentSeedStatusPayload { + game_id: game_id.clone(), + progress: status.progress, + num_peers: status.num_peers, + num_seeds: status.num_seeds, + download_speed: status.download_speed, + upload_speed: status.upload_speed, + bytes_downloaded: status.bytes_downloaded, + file_size: status.file_size, + folder_name: status.folder_name, + status: status.status, + }); + } + + Ok(payload) + }) +} + +#[napi] +pub fn torrent_get_files( + magnet: String, + timeout_ms: Option, +) -> napi::Result { + TOKIO_RT.block_on(async { + let (magnet, info_hash) = validate_magnet_uri(&magnet)?; + let timeout_ms = TorrentManager::normalize_timeout_ms(timeout_ms, 30_000); + fetch_torrent_files_internal(magnet, info_hash, timeout_ms).await + }) +} + +#[napi] +pub fn torrent_start(payload: StartTorrentPayload) -> napi::Result<()> { + TOKIO_RT.block_on(async { + if payload.save_path.trim().is_empty() { + return Err(Error::from_reason("invalid_save_path")); + } + + let (magnet, info_hash) = validate_magnet_uri(&payload.url)?; + let is_selective = payload.file_indices.is_some(); + + let existing_handle = { + let manager = TORRENT_MANAGER.lock().await; + manager.downloads.get(&payload.game_id).cloned() + }; + + if !is_selective { + if let Some(handle) = existing_handle { + let session = get_or_create_session().await?; + let _ = session.unpause(&handle).await; + + let mut manager = TORRENT_MANAGER.lock().await; + manager.downloading_game_id = Some(payload.game_id.clone()); + manager.seeding_game_ids.remove(&payload.game_id); + manager.pending_starts.remove(&payload.game_id); + drop(manager); + ensure_seed_polling(payload.game_id).await; + return Ok(()); + } + + { + let mut manager = TORRENT_MANAGER.lock().await; + manager.abort_pending_start(&payload.game_id); + manager.pending_starts.insert( + payload.game_id.clone(), + PendingStart { + save_path: payload.save_path.clone(), + }, + ); + manager.downloading_game_id = Some(payload.game_id.clone()); + manager.seeding_game_ids.remove(&payload.game_id); + } + + { + let mut manager = TORRENT_MANAGER.lock().await; + manager.torrent_meta.insert( + payload.game_id.clone(), + TorrentMeta { + info_hash: info_hash.clone(), + trackers: parse_magnet_trackers(&magnet), + }, + ); + } + + if let Err(error) = complete_pending_start( + payload.game_id.clone(), + info_hash, + magnet, + payload.save_path, + ) + .await + { + eprintln!( + "[hydra-native] pending torrent start failed for {}: {}", + payload.game_id, error + ); + + let mut manager = TORRENT_MANAGER.lock().await; + manager.pending_starts.remove(&payload.game_id); + manager.pending_tasks.remove(&payload.game_id); + + if manager.downloading_game_id.as_deref() == Some(payload.game_id.as_str()) { + manager.downloading_game_id = None; + } + + return Err(error); + } + return Ok(()); + } + + if let Some(handle) = existing_handle { + let session = get_or_create_session().await?; + let _ = session.delete(handle.id().into(), false).await; + } + + { + let mut manager = TORRENT_MANAGER.lock().await; + manager.abort_pending_start(&payload.game_id); + } + + let timeout_ms = + TorrentManager::normalize_timeout_ms(payload.timeout_ms, 60_000); + + let trackers = parse_magnet_trackers(&magnet); + + let files_payload = + fetch_torrent_files_internal(magnet.clone(), info_hash.clone(), timeout_ms).await?; + + let raw_indices = payload + .file_indices + .ok_or_else(|| Error::from_reason("invalid_file_indices"))?; + + if raw_indices.is_empty() { + return Err(Error::from_reason("empty_selection")); + } + + let max_index = files_payload.files.len().saturating_sub(1) as u32; + let mut sanitized = HashSet::new(); + + for index in raw_indices { + if index > max_index { + return Err(Error::from_reason("invalid_file_indices")); + } + sanitized.insert(index as usize); + } + + if sanitized.is_empty() { + return Err(Error::from_reason("empty_selection")); + } + + let mut only_files: Vec = sanitized.into_iter().collect(); + only_files.sort_unstable(); + + let session = get_or_create_session().await?; + let mut opts = AddTorrentOptions::default(); + opts.output_folder = Some(payload.save_path); + opts.overwrite = true; + opts.only_files = Some(only_files); + + let add_future = session.add_torrent(AddTorrent::from_url(magnet), Some(opts)); + let response = timeout(Duration::from_millis(timeout_ms as u64), add_future) + .await + .map_err(|_| Error::from_reason("metadata_timeout"))? + .map_err(map_anyhow_error)?; + + let handle = match response { + AddTorrentResponse::Added(_, handle) | AddTorrentResponse::AlreadyManaged(_, handle) => { + handle + } + AddTorrentResponse::ListOnly(_) => { + return Err(Error::from_reason("metadata_incomplete")); + } + }; + + let mut manager = TORRENT_MANAGER.lock().await; + manager.downloads.insert(payload.game_id.clone(), handle); + manager.torrent_meta.insert( + payload.game_id.clone(), + TorrentMeta { + info_hash, + trackers, + }, + ); + manager.downloading_game_id = Some(payload.game_id.clone()); + manager.seeding_game_ids.remove(&payload.game_id); + drop(manager); + + ensure_seed_polling(payload.game_id).await; + + Ok(()) + }) +} + +#[napi] +pub fn torrent_pause(game_id: String) -> napi::Result<()> { + TOKIO_RT.block_on(async { + let handle = { + let mut manager = TORRENT_MANAGER.lock().await; + manager.abort_pending_start(&game_id); + manager.stop_seed_polling(&game_id); + + if manager.downloading_game_id.as_deref() == Some(game_id.as_str()) { + manager.downloading_game_id = None; + } + + manager.downloads.get(&game_id).cloned() + }; + + if let Some(handle) = handle { + let session = get_or_create_session().await?; + let _ = session.pause(&handle).await; + } + + Ok(()) + }) +} + +#[napi] +pub fn torrent_cancel(game_id: String) -> napi::Result<()> { + TOKIO_RT.block_on(async { + let handle = { + let mut manager = TORRENT_MANAGER.lock().await; + manager.abort_pending_start(&game_id); + manager.stop_seed_polling(&game_id); + manager.seeding_game_ids.remove(&game_id); + manager.torrent_meta.remove(&game_id); + + if manager.downloading_game_id.as_deref() == Some(game_id.as_str()) { + manager.downloading_game_id = None; + } + + manager.downloads.remove(&game_id) + }; + + if let Some(handle) = handle { + let session = get_or_create_session().await?; + let _ = session.delete(handle.id().into(), false).await; + } + + Ok(()) + }) +} + +#[napi] +pub fn torrent_resume_seeding(payload: ResumeSeedingPayload) -> napi::Result<()> { + TOKIO_RT.block_on(async { + if payload.save_path.trim().is_empty() { + return Err(Error::from_reason("invalid_save_path")); + } + + let (magnet, info_hash) = validate_magnet_uri(&payload.url)?; + + let handle = { + let mut manager = TORRENT_MANAGER.lock().await; + manager.abort_pending_start(&payload.game_id); + manager.downloads.get(&payload.game_id).cloned() + }; + + let session = get_or_create_session().await?; + + if let Some(handle) = handle { + let _ = session.unpause(&handle).await; + + let mut manager = TORRENT_MANAGER.lock().await; + manager.seeding_game_ids.insert(payload.game_id.clone()); + if !manager.torrent_meta.contains_key(&payload.game_id) { + manager.torrent_meta.insert( + payload.game_id.clone(), + TorrentMeta { + info_hash, + trackers: parse_magnet_trackers(&payload.url), + }, + ); + } + drop(manager); + + ensure_seed_polling(payload.game_id).await; + return Ok(()); + } + + let mut opts = AddTorrentOptions::default(); + opts.output_folder = Some(payload.save_path); + opts.overwrite = true; + + let add_future = session.add_torrent(AddTorrent::from_url(magnet), Some(opts)); + let response = timeout(Duration::from_secs(30), add_future) + .await + .map_err(|_| Error::from_reason("metadata_timeout"))? + .map_err(map_anyhow_error)?; + + let handle = match response { + AddTorrentResponse::Added(_, handle) | AddTorrentResponse::AlreadyManaged(_, handle) => { + handle + } + AddTorrentResponse::ListOnly(_) => { + return Err(Error::from_reason("metadata_incomplete")); + } + }; + + let mut manager = TORRENT_MANAGER.lock().await; + manager.downloads.insert(payload.game_id.clone(), handle); + manager.seeding_game_ids.insert(payload.game_id.clone()); + manager.torrent_meta.insert( + payload.game_id.clone(), + TorrentMeta { + info_hash, + trackers: parse_magnet_trackers(&payload.url), + }, + ); + drop(manager); + ensure_seed_polling(payload.game_id).await; + Ok(()) + }) +} + +#[napi] +pub fn torrent_pause_seeding(game_id: String) -> napi::Result<()> { + torrent_cancel(game_id) +} + +#[napi] +pub fn torrent_set_download_limit( + max_download_speed_bytes_per_second: Option, +) -> napi::Result<()> { + TOKIO_RT.block_on(async { + let limit = max_download_speed_bytes_per_second.filter(|value| *value > 0); + + let session = { + let mut manager = TORRENT_MANAGER.lock().await; + manager.current_download_limit = limit; + manager.session.clone() + }; + + if let Some(session) = session { + session + .ratelimits + .set_download_bps(limit.and_then(NonZeroU32::new)); + } + + Ok(()) + }) +} diff --git a/package.json b/package.json index 91e4e619c..4719ca35c 100644 --- a/package.json +++ b/package.json @@ -20,14 +20,15 @@ "typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false", "typecheck:web": "tsc --noEmit -p tsconfig.web.json --composite false", "typecheck": "npm run typecheck:node && npm run typecheck:web", + "build:native": "node ./scripts/build-native-addon.cjs", "start": "electron-vite preview", "dev": "electron-vite dev", "build": "npm run typecheck && electron-vite build", - "postinstall": "electron-builder install-app-deps && node ./scripts/postinstall.cjs", + "postinstall": "npm run build:native && electron-builder install-app-deps && node ./scripts/postinstall.cjs", "build:unpack": "npm run build && electron-builder --dir", - "build:win": "electron-vite build && electron-builder --win", - "build:mac": "electron-vite build && electron-builder --mac", - "build:linux": "electron-vite build && electron-builder --linux", + "build:win": "npm run build:native && electron-vite build && electron-builder --win", + "build:mac": "npm run build:native && electron-vite build && electron-builder --mac", + "build:linux": "npm run build:native && electron-vite build && electron-builder --linux", "prepare": "husky", "protoc": "npx protoc --ts_out src/main/generated --proto_path proto proto/*.proto" }, diff --git a/python_rpc/http_downloader.py b/python_rpc/http_downloader.py deleted file mode 100644 index cbbad9ff3..000000000 --- a/python_rpc/http_downloader.py +++ /dev/null @@ -1,68 +0,0 @@ -import aria2p -from aria2p.client import ClientException as DownloadNotFound - -class HttpDownloader: - def __init__(self): - self.download = None - self.max_download_speed = None - self.aria2 = aria2p.API( - aria2p.Client( - host="http://localhost", - port=6800, - secret="" - ) - ) - - def set_download_limit(self, max_download_speed: int = None): - self.max_download_speed = max_download_speed if max_download_speed and max_download_speed > 0 else None - speed_limit = str(self.max_download_speed) if self.max_download_speed else "0" - try: - self.aria2.set_global_options({"max-overall-download-limit": speed_limit}) - except Exception: - pass - - def start_download(self, url: str, save_path: str, header, out: str = None): - if self.download: - self.aria2.resume([self.download]) - else: - options = {"dir": save_path} - if self.max_download_speed: - options["max-download-limit"] = str(self.max_download_speed) - if header: - options["header"] = header - if out: - options["out"] = out - downloads = self.aria2.add(url, options=options) - self.download = downloads[0] - - def pause_download(self): - if self.download: - self.aria2.pause([self.download]) - - def cancel_download(self): - if self.download: - self.aria2.remove([self.download]) - self.download = None - - def get_download_status(self): - if self.download == None: - return None - - try: - download = self.aria2.get_download(self.download.gid) - except DownloadNotFound: - self.download = None - return None - - response = { - 'folderName': download.name, - 'fileSize': download.total_length, - 'progress': download.completed_length / download.total_length if download.total_length else 0, - 'downloadSpeed': download.download_speed, - 'numPeers': 0, - 'numSeeds': 0, - 'status': download.status, - 'bytesDownloaded': download.completed_length, - } - - return response diff --git a/python_rpc/main.py b/python_rpc/main.py deleted file mode 100644 index a0372547a..000000000 --- a/python_rpc/main.py +++ /dev/null @@ -1,541 +0,0 @@ -import hmac -import json -import logging -import re -import sys -import tempfile -import threading -import time -import urllib.parse - -import libtorrent as lt -import psutil -from flask import Flask, jsonify, request - -from http_downloader import HttpDownloader -from profile_image_processor import ProfileImageProcessor -from torrent_downloader import TorrentDownloader - -app = Flask(__name__) - -logging.basicConfig( - level=logging.INFO, - format="[%(asctime)s] %(levelname)s %(name)s: %(message)s", -) -logger = logging.getLogger("hydra.rpc") - - -# Retrieve command line arguments -torrent_port = sys.argv[1] -http_port = sys.argv[2] -rpc_password = sys.argv[3] -start_download_payload = sys.argv[4] -start_seeding_payload = sys.argv[5] - - -downloads = {} -downloads_lock = threading.RLock() -metadata_semaphore = threading.BoundedSemaphore(value=2) - -# This can be streamed down from Node -downloading_game_id = -1 -current_download_limit = None - -torrent_session = lt.session( - {"listen_interfaces": "0.0.0.0:{port}".format(port=torrent_port)} -) - -MAGNET_HASH_HEX_RE = re.compile(r"^[a-fA-F0-9]{40}$") -MAGNET_HASH_BASE32_RE = re.compile(r"^[a-zA-Z2-7]{32}$") - -TORRENT_FILES_CACHE_TTL_SECONDS = 300 -TORRENT_FILES_CACHE_MAX_ITEMS = 128 -torrent_files_cache = {} -torrent_files_cache_lock = threading.RLock() - - -def load_json_payload(raw_payload: str): - if not raw_payload: - return None - - return json.loads(urllib.parse.unquote(raw_payload)) - - -def parse_file_indices(file_indices): - if file_indices is None: - return None - - if not isinstance(file_indices, list): - raise ValueError("invalid_file_indices") - - parsed = [] - for index in file_indices: - if isinstance(index, bool) or not isinstance(index, int): - raise ValueError("invalid_file_indices") - parsed.append(index) - - return parsed - - -def validate_magnet_uri(magnet: str): - if not isinstance(magnet, str): - raise ValueError("invalid_magnet") - - magnet = magnet.strip() - if not magnet.startswith("magnet:"): - raise ValueError("invalid_magnet") - - if len(magnet) > 8192: - raise ValueError("invalid_magnet") - - parsed = urllib.parse.urlparse(magnet) - if parsed.scheme != "magnet": - raise ValueError("invalid_magnet") - - query = urllib.parse.parse_qs(parsed.query) - xt_values = query.get("xt") or [] - - info_hash = None - for xt in xt_values: - if not xt.startswith("urn:btih:"): - continue - - hash_candidate = xt[len("urn:btih:") :].strip() - - if MAGNET_HASH_HEX_RE.match(hash_candidate) or MAGNET_HASH_BASE32_RE.match( - hash_candidate - ): - info_hash = hash_candidate.lower() - break - - if info_hash is None: - raise ValueError("invalid_magnet") - - return magnet, info_hash - - -def get_cached_torrent_files(info_hash: str): - with torrent_files_cache_lock: - item = torrent_files_cache.get(info_hash) - if not item: - return None - - if time.time() - item["timestamp"] > TORRENT_FILES_CACHE_TTL_SECONDS: - torrent_files_cache.pop(info_hash, None) - return None - - return item["value"] - - -def set_cached_torrent_files(info_hash: str, value): - with torrent_files_cache_lock: - if len(torrent_files_cache) >= TORRENT_FILES_CACHE_MAX_ITEMS: - oldest_key = min( - torrent_files_cache, - key=lambda cache_key: torrent_files_cache[cache_key]["timestamp"], - ) - torrent_files_cache.pop(oldest_key, None) - - torrent_files_cache[info_hash] = { - "timestamp": time.time(), - "value": value, - } - - -def map_downloader_error(error: Exception): - code = str(error) - - if isinstance(error, TimeoutError) or code == "metadata_timeout": - return jsonify({"error": "metadata_timeout"}), 408 - - if code in { - "invalid_magnet", - "invalid_file_indices", - "empty_selection", - "invalid_url", - "invalid_save_path", - }: - return jsonify({"error": code}), 400 - - if code == "metadata_incomplete": - return jsonify({"error": "metadata_incomplete"}), 422 - - if code == "too_many_files": - return jsonify({"error": "too_many_files"}), 413 - - logger.error("Unhandled RPC error: %s", error, exc_info=True) - return jsonify({"error": "internal_error"}), 500 - - -def normalize_download_limit(value): - try: - parsed = int(value) - except (TypeError, ValueError): - return None - - return parsed if parsed > 0 else None - - -def apply_download_limit(downloader): - if not downloader: - return - - set_download_limit = getattr(downloader, "set_download_limit", None) - if callable(set_download_limit): - set_download_limit(current_download_limit) - -def validate_rpc_password(): - """Middleware to validate RPC password.""" - header_password = request.headers.get("x-hydra-rpc-password") - if not isinstance(header_password, str) or not hmac.compare_digest( - header_password, rpc_password - ): - return jsonify({"error": "Unauthorized"}), 401 - - -def start_torrent_download(game_id, url, save_path, file_indices=None, flags=None): - with downloads_lock: - existing_downloader = downloads.get(game_id) - - if existing_downloader and isinstance(existing_downloader, TorrentDownloader): - apply_download_limit(existing_downloader) - existing_downloader.start_download(url, save_path, file_indices=file_indices) - return - - torrent_downloader = TorrentDownloader( - torrent_session, - flags or lt.torrent_flags.auto_managed, - session_lock=downloads_lock, - ) - apply_download_limit(torrent_downloader) - - with downloads_lock: - downloads[game_id] = torrent_downloader - - try: - torrent_downloader.start_download(url, save_path, file_indices=file_indices) - except Exception: - with downloads_lock: - downloads.pop(game_id, None) - raise - - -def start_http_download(game_id, url, save_path, header=None, out=None): - with downloads_lock: - existing_downloader = downloads.get(game_id) - - if existing_downloader and isinstance(existing_downloader, HttpDownloader): - apply_download_limit(existing_downloader) - existing_downloader.start_download(url, save_path, header, out) - return - - http_downloader = HttpDownloader() - apply_download_limit(http_downloader) - - with downloads_lock: - downloads[game_id] = http_downloader - - try: - http_downloader.start_download(url, save_path, header, out) - except Exception: - with downloads_lock: - downloads.pop(game_id, None) - raise - - -def bootstrap_downloads(): - global downloading_game_id - - initial_download = load_json_payload(start_download_payload) - if initial_download: - downloading_game_id = initial_download["game_id"] - - try: - if initial_download["url"].startswith("magnet"): - file_indices = parse_file_indices(initial_download.get("file_indices")) - start_torrent_download( - initial_download["game_id"], - initial_download["url"], - initial_download["save_path"], - file_indices=file_indices, - ) - else: - start_http_download( - initial_download["game_id"], - initial_download["url"], - initial_download["save_path"], - initial_download.get("header"), - initial_download.get("out"), - ) - except Exception as error: - logger.error("Error starting initial download: %s", error, exc_info=True) - - initial_seeding = load_json_payload(start_seeding_payload) - if initial_seeding: - for seed in initial_seeding: - try: - start_torrent_download( - seed["game_id"], - seed["url"], - seed["save_path"], - flags=lt.torrent_flags.upload_mode, - ) - except Exception as error: - logger.error("Error starting initial seeding: %s", error, exc_info=True) - - -@app.route("/status", methods=["GET"]) -def status(): - auth_error = validate_rpc_password() - if auth_error: - return auth_error - - with downloads_lock: - downloader = downloads.get(downloading_game_id) - - if not downloader: - return jsonify(None) - - status_payload = downloader.get_download_status() - if not status_payload: - return jsonify(None) - - return jsonify(status_payload), 200 - - -@app.route("/seed-status", methods=["GET"]) -def seed_status(): - auth_error = validate_rpc_password() - if auth_error: - return auth_error - - with downloads_lock: - download_items = list(downloads.items()) - - seed_payload = [] - for game_id, downloader in download_items: - if not downloader: - continue - - response = downloader.get_download_status() - if not response: - continue - - if response.get("status") == 5: # Torrent seeding check - seed_payload.append( - { - "gameId": game_id, - **response, - } - ) - - return jsonify(seed_payload), 200 - - -@app.route("/healthcheck", methods=["GET"]) -def healthcheck(): - return "ok", 200 - - -@app.route("/torrent-files", methods=["POST"]) -def torrent_files(): - auth_error = validate_rpc_password() - if auth_error: - return auth_error - - data = request.get_json(silent=True) or {} - - try: - magnet, info_hash = validate_magnet_uri(data.get("magnet")) - except Exception as error: - return map_downloader_error(error) - - cached_payload = get_cached_torrent_files(info_hash) - if cached_payload is not None: - return jsonify(cached_payload), 200 - - timeout_ms = data.get("timeout_ms", 30000) - try: - timeout_ms = int(timeout_ms) - except (TypeError, ValueError): - timeout_ms = 30000 - - timeout_ms = max(5000, min(timeout_ms, 120000)) - timeout_seconds = timeout_ms / 1000 - - if not metadata_semaphore.acquire(timeout=5): - return jsonify({"error": "metadata_busy"}), 429 - - temp_downloader = TorrentDownloader( - torrent_session, - lt.torrent_flags.upload_mode, - session_lock=downloads_lock, - ) - - started_at = time.time() - - try: - temp_downloader.start_download(magnet, tempfile.gettempdir()) - files_payload = temp_downloader.get_torrent_files(timeout_seconds=timeout_seconds) - response = { - "infoHash": info_hash, - **files_payload, - } - - set_cached_torrent_files(info_hash, response) - - elapsed_ms = int((time.time() - started_at) * 1000) - logger.info("Resolved torrent metadata hash=%s in %sms", info_hash, elapsed_ms) - - return jsonify(response), 200 - except Exception as error: - return map_downloader_error(error) - finally: - temp_downloader.cancel_download() - metadata_semaphore.release() - - -@app.route("/process-list", methods=["GET"]) -def process_list(): - auth_error = validate_rpc_password() - if auth_error: - return auth_error - - iter_list = ["exe", "pid", "name"] - if sys.platform != "win32": - iter_list.append("cwd") - iter_list.append("environ") - - process_list_payload = [proc.info for proc in psutil.process_iter(iter_list)] - return jsonify(process_list_payload), 200 - - -@app.route("/profile-image", methods=["POST"]) -def profile_image(): - auth_error = validate_rpc_password() - if auth_error: - return auth_error - - data = request.get_json() - image_path = data.get("image_path") - - # use webp as default value for target_extension - target_extension = data.get("target_extension") or "webp" - - try: - processed_image_path, mime_type = ProfileImageProcessor.process_image( - image_path, target_extension - ) - return jsonify({"imagePath": processed_image_path, "mimeType": mime_type}), 200 - except Exception as error: - return jsonify({"error": str(error)}), 400 - - -@app.route("/action", methods=["POST"]) -def action(): - global downloading_game_id - global current_download_limit - - auth_error = validate_rpc_password() - if auth_error: - return auth_error - - data = request.get_json(silent=True) or {} - action_name = data.get("action") - game_id = data.get("game_id") - - if not action_name: - return jsonify({"error": "invalid_action"}), 400 - - requires_game_id = {"start", "pause", "cancel", "resume_seeding", "pause_seeding"} - if action_name in requires_game_id and not game_id: - return jsonify({"error": "invalid_game_id"}), 400 - - try: - if action_name == "start": - url = data.get("url") - if not isinstance(url, str): - raise ValueError("invalid_url") - - save_path = data.get("save_path") - if not isinstance(save_path, str): - raise ValueError("invalid_save_path") - - if url.startswith("magnet"): - file_indices = parse_file_indices(data.get("file_indices")) - start_torrent_download( - game_id, - url, - save_path, - file_indices=file_indices, - ) - else: - start_http_download( - game_id, - url, - save_path, - data.get("header"), - data.get("out"), - ) - - downloading_game_id = game_id - elif action_name == "pause": - with downloads_lock: - downloader = downloads.get(game_id) - - if downloader: - downloader.pause_download() - - if downloading_game_id == game_id: - downloading_game_id = -1 - elif action_name == "cancel": - with downloads_lock: - downloader = downloads.get(game_id) - - if downloader: - downloader.cancel_download() - - with downloads_lock: - downloads.pop(game_id, None) - - if downloading_game_id == game_id: - downloading_game_id = -1 - elif action_name == "resume_seeding": - start_torrent_download( - game_id, - data["url"], - data["save_path"], - flags=lt.torrent_flags.upload_mode, - ) - elif action_name == "pause_seeding": - with downloads_lock: - downloader = downloads.get(game_id) - - if downloader: - downloader.cancel_download() - - with downloads_lock: - downloads.pop(game_id, None) - elif action_name == "set_download_limit": - current_download_limit = normalize_download_limit( - data.get("max_download_speed_bytes_per_second") - ) - - with downloads_lock: - active_downloaders = list(downloads.values()) - - for downloader in active_downloaders: - apply_download_limit(downloader) - else: - return jsonify({"error": "invalid_action"}), 400 - except Exception as error: - return map_downloader_error(error) - - return "", 200 - - -bootstrap_downloads() - - -if __name__ == "__main__": - app.run(host="127.0.0.1", port=int(http_port), threaded=True) diff --git a/python_rpc/profile_image_processor.py b/python_rpc/profile_image_processor.py deleted file mode 100644 index eac8c32a6..000000000 --- a/python_rpc/profile_image_processor.py +++ /dev/null @@ -1,30 +0,0 @@ -from PIL import Image -import os, uuid, tempfile - -class ProfileImageProcessor: - - @staticmethod - def get_parsed_image_data(image_path, target_extension): - Image.MAX_IMAGE_PIXELS = 933120000 - - image = Image.open(image_path) - - try: - image.seek(1) - except EOFError: - mime_type = image.get_format_mimetype() - return image_path, mime_type - else: - new_uuid = str(uuid.uuid4()) - new_image_path = os.path.join(tempfile.gettempdir(), new_uuid) + "." + target_extension - image.save(new_image_path) - - new_image = Image.open(new_image_path) - mime_type = new_image.get_format_mimetype() - - return new_image_path, mime_type - - - @staticmethod - def process_image(image_path, target_extension): - return ProfileImageProcessor.get_parsed_image_data(image_path, target_extension) diff --git a/python_rpc/setup.py b/python_rpc/setup.py deleted file mode 100644 index 1dc5a06e3..000000000 --- a/python_rpc/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -from cx_Freeze import setup, Executable - -# Dependencies are automatically detected, but it might need fine tuning. -build_exe_options = { - "packages": ["libtorrent"], - "build_exe": "hydra-python-rpc", - "include_msvcr": True -} - -setup( - name="hydra-python-rpc", - version="0.1", - description="Hydra", - options={"build_exe": build_exe_options}, - executables=[Executable( - "python_rpc/main.py", - target_name="hydra-python-rpc", - icon="build/icon.ico" - )] -) diff --git a/python_rpc/torrent_downloader.py b/python_rpc/torrent_downloader.py deleted file mode 100644 index df801e78a..000000000 --- a/python_rpc/torrent_downloader.py +++ /dev/null @@ -1,391 +0,0 @@ -import logging -import threading -import time -from typing import List, Optional, Set - -import libtorrent as lt - - -class TorrentDownloader: - def __init__( - self, - torrent_session, - flags=lt.torrent_flags.auto_managed, - session_lock: Optional[threading.RLock] = None, - ): - self.torrent_handle = None - self.session = torrent_session - self.flags = flags - self.session_lock = session_lock or threading.RLock() - self.selected_file_indices = None - self.selected_size_bytes = None - self.logger = logging.getLogger("hydra.torrent") - self.trackers = [ - "udp://tracker.opentrackr.org:1337/announce", - "http://tracker.opentrackr.org:1337/announce", - "udp://open.tracker.cl:1337/announce", - "udp://open.demonii.com:1337/announce", - "udp://open.stealth.si:80/announce", - "udp://tracker.torrent.eu.org:451/announce", - "udp://exodus.desync.com:6969/announce", - "udp://tracker.theoks.net:6969/announce", - "udp://tracker-udp.gbitt.info:80/announce", - "udp://explodie.org:6969/announce", - "https://tracker.tamersunion.org:443/announce", - "udp://tracker2.dler.org:80/announce", - "udp://tracker1.myporn.club:9337/announce", - "udp://tracker.tiny-vps.com:6969/announce", - "udp://tracker.dler.org:6969/announce", - "udp://tracker.bittor.pw:1337/announce", - "udp://tracker.0x7c0.com:6969/announce", - "udp://retracker01-msk-virt.corbina.net:80/announce", - "udp://opentracker.io:6969/announce", - "udp://open.free-tracker.ga:6969/announce", - "udp://new-line.net:6969/announce", - "udp://moonburrow.club:6969/announce", - "udp://leet-tracker.moe:1337/announce", - "udp://bt2.archive.org:6969/announce", - "udp://bt1.archive.org:6969/announce", - "http://tracker2.dler.org:80/announce", - "http://tracker1.bt.moack.co.kr:80/announce", - "http://tracker.dler.org:6969/announce", - "http://tr.kxmp.cf:80/announce", - "udp://u.peer-exchange.download:6969/announce", - "udp://ttk2.nbaonlineservice.com:6969/announce", - "udp://tracker.tryhackx.org:6969/announce", - "udp://tracker.srv00.com:6969/announce", - "udp://tracker.skynetcloud.site:6969/announce", - "udp://tracker.jamesthebard.net:6969/announce", - "udp://tracker.fnix.net:6969/announce", - "udp://tracker.filemail.com:6969/announce", - "udp://tracker.farted.net:6969/announce", - "udp://tracker.edkj.club:6969/announce", - "udp://tracker.dump.cl:6969/announce", - "udp://tracker.deadorbit.nl:6969/announce", - "udp://tracker.darkness.services:6969/announce", - "udp://tracker.ccp.ovh:6969/announce", - "udp://tamas3.ynh.fr:6969/announce", - "udp://ryjer.com:6969/announce", - "udp://run.publictracker.xyz:6969/announce", - "udp://public.tracker.vraphim.com:6969/announce", - "udp://p4p.arenabg.com:1337/announce", - "udp://p2p.publictracker.xyz:6969/announce", - "udp://open.u-p.pw:6969/announce", - "udp://open.publictracker.xyz:6969/announce", - "udp://open.dstud.io:6969/announce", - "udp://open.demonoid.ch:6969/announce", - "udp://odd-hd.fr:6969/announce", - "udp://martin-gebhardt.eu:25/announce", - "udp://jutone.com:6969/announce", - "udp://isk.richardsw.club:6969/announce", - "udp://evan.im:6969/announce", - "udp://epider.me:6969/announce", - "udp://d40969.acod.regrucolo.ru:6969/announce", - "udp://bt.rer.lol:6969/announce", - "udp://amigacity.xyz:6969/announce", - "udp://1c.premierzal.ru:6969/announce", - "https://trackers.run:443/announce", - "https://tracker.yemekyedim.com:443/announce", - "https://tracker.renfei.net:443/announce", - "https://tracker.pmman.tech:443/announce", - "https://tracker.lilithraws.org:443/announce", - "https://tracker.imgoingto.icu:443/announce", - "https://tracker.cloudit.top:443/announce", - "https://tracker-zhuqiy.dgj055.icu:443/announce", - "http://tracker.renfei.net:8080/announce", - "http://tracker.mywaifu.best:6969/announce", - "http://tracker.ipv6tracker.org:80/announce", - "http://tracker.files.fm:6969/announce", - "http://tracker.edkj.club:6969/announce", - "http://tracker.bt4g.com:2095/announce", - "http://tracker-zhuqiy.dgj055.icu:80/announce", - "http://t1.aag.moe:17715/announce", - "http://t.overflow.biz:6969/announce", - "http://bittorrent-tracker.e-n-c-r-y-p-t.net:1337/announce", - "udp://torrents.artixlinux.org:6969/announce", - "udp://mail.artixlinux.org:6969/announce", - "udp://ipv4.rer.lol:2710/announce", - "udp://concen.org:6969/announce", - "udp://bt.rer.lol:2710/announce", - "udp://aegir.sexy:6969/announce", - "https://www.peckservers.com:9443/announce", - "https://tracker.ipfsscan.io:443/announce", - "https://tracker.gcrenwp.top:443/announce", - "http://www.peckservers.com:9000/announce", - "http://tracker1.itzmx.com:8080/announce", - "http://ch3oh.ru:6969/announce", - "http://bvarf.tracker.sh:2086/announce", - ] - - def set_download_limit(self, max_download_speed: int = None): - download_limit = ( - max_download_speed if max_download_speed and max_download_speed > 0 else 0 - ) - try: - self.session.set_download_rate_limit(download_limit) - except Exception: - pass - - def _wait_for_metadata(self, timeout_seconds: float = 30.0, poll_interval: float = 0.25): - if not self.torrent_handle or not self.torrent_handle.is_valid(): - return False - - deadline = time.monotonic() + max(timeout_seconds, 1.0) - - while time.monotonic() < deadline: - try: - status = self.torrent_handle.status() - except RuntimeError: - return False - - if status.has_metadata: - return True - - time.sleep(max(poll_interval, 0.05)) - - return False - - def wait_for_metadata(self, timeout_seconds: float = 30.0): - return self._wait_for_metadata(timeout_seconds=timeout_seconds) - - def _sanitize_file_indices(self, file_indices: List[int], files_storage): - if file_indices is None: - return None - - if not isinstance(file_indices, list): - raise ValueError("invalid_file_indices") - - max_index = files_storage.num_files() - 1 - sanitized: Set[int] = set() - - for index in file_indices: - if isinstance(index, bool) or not isinstance(index, int): - raise ValueError("invalid_file_indices") - - if index < 0 or index > max_index: - raise ValueError("invalid_file_indices") - - sanitized.add(index) - - if not sanitized: - raise ValueError("empty_selection") - - return sorted(sanitized) - - def _set_selected_file_priorities(self, selected_indices: List[int], files_storage): - priorities = [0] * files_storage.num_files() - for index in selected_indices: - priorities[index] = 1 - - self.torrent_handle.prioritize_files(priorities) - - deadline = time.monotonic() + 3.0 - while time.monotonic() < deadline: - try: - current_priorities = [int(priority) for priority in self.torrent_handle.get_file_priorities()] - except RuntimeError: - break - - if current_priorities == priorities: - return - - time.sleep(0.1) - - self.logger.warning("File priority synchronization timeout") - - def start_download( - self, - magnet: str, - save_path: str, - file_indices: Optional[List[int]] = None, - wait_timeout_seconds: float = 30.0, - ): - selective_download = file_indices is not None - - with self.session_lock: - if self.torrent_handle and self.torrent_handle.is_valid(): - if not selective_download: - self.torrent_handle.set_flags(lt.torrent_flags.auto_managed) - self.torrent_handle.resume() - return - - self.torrent_handle.pause() - self.session.remove_torrent(self.torrent_handle) - self.torrent_handle = None - - initial_flags = self.flags | lt.torrent_flags.paused - - if selective_download: - initial_flags |= lt.torrent_flags.default_dont_download - initial_flags |= lt.torrent_flags.auto_managed - else: - initial_flags |= lt.torrent_flags.auto_managed - - params = { - "url": magnet, - "save_path": save_path, - "trackers": self.trackers, - "flags": initial_flags, - } - - if self.torrent_handle is None or not self.torrent_handle.is_valid(): - self.torrent_handle = self.session.add_torrent(params) - - self.selected_file_indices = None - self.selected_size_bytes = None - - if selective_download: - try: - self.torrent_handle.set_flags(lt.torrent_flags.auto_managed) - self.torrent_handle.resume() - - if not self._wait_for_metadata(timeout_seconds=wait_timeout_seconds): - raise TimeoutError("metadata_timeout") - - try: - info = self.torrent_handle.get_torrent_info() - files_storage = info.files() - except RuntimeError as error: - raise RuntimeError("metadata_incomplete") from error - - self.torrent_handle.pause() - self.torrent_handle.unset_flags(lt.torrent_flags.auto_managed) - - sanitized_indices = self._sanitize_file_indices(file_indices, files_storage) - self._set_selected_file_priorities(sanitized_indices, files_storage) - - self.selected_file_indices = sanitized_indices - self.selected_size_bytes = sum(files_storage.file_size(index) for index in sanitized_indices) - except Exception: - self.cancel_download() - raise - - self.torrent_handle.set_flags(lt.torrent_flags.auto_managed) - self.torrent_handle.resume() - - def get_torrent_files(self, timeout_seconds: float = 30.0, max_files: int = 100000): - if not self._wait_for_metadata(timeout_seconds=timeout_seconds): - raise TimeoutError("metadata_timeout") - - try: - info = self.torrent_handle.get_torrent_info() - except RuntimeError as error: - raise RuntimeError("metadata_incomplete") from error - - files_storage = info.files() - file_count = files_storage.num_files() - - if file_count > max_files: - raise OverflowError("too_many_files") - - files = [] - for index in range(file_count): - files.append( - { - "index": index, - "path": files_storage.file_path(index), - "length": files_storage.file_size(index), - } - ) - - return { - "name": info.name(), - "totalSize": info.total_size(), - "files": files, - } - - def pause_download(self): - if self.torrent_handle: - self.torrent_handle.pause() - self.torrent_handle.unset_flags(lt.torrent_flags.auto_managed) - - def cancel_download(self): - with self.session_lock: - if self.torrent_handle: - if self.torrent_handle.is_valid(): - self.torrent_handle.pause() - self.session.remove_torrent(self.torrent_handle, lt.session.delete_partfile) - self.torrent_handle = None - self.selected_file_indices = None - self.selected_size_bytes = None - - def abort_session(self): - self.cancel_download() - self.session.abort() - self.torrent_handle = None - self.selected_file_indices = None - self.selected_size_bytes = None - - def _get_handle_status(self): - if self.torrent_handle is None: - return None - - if not self.torrent_handle.is_valid(): - return None - - try: - return self.torrent_handle.status() - except RuntimeError: - return None - - def _get_torrent_info_if_available(self, status): - if not status.has_metadata: - return None - - try: - return self.torrent_handle.get_torrent_info() - except RuntimeError: - return None - - def _get_file_size(self, status, info): - total_wanted = getattr(status, "total_wanted", 0) - if total_wanted > 0: - return total_wanted - - if self.selected_size_bytes is not None: - return self.selected_size_bytes - - if info: - return info.total_size() - - return 0 - - def _get_bytes_downloaded(self, status, file_size): - total_wanted_done = getattr(status, "total_wanted_done", -1) - if total_wanted_done >= 0: - return total_wanted_done - - if file_size > 0: - return int(status.progress * file_size) - - return status.all_time_download - - def _get_progress(self, status, file_size, bytes_downloaded): - if file_size <= 0: - return status.progress - - return min(max(bytes_downloaded / file_size, 0), 1) - - def get_download_status(self): - status = self._get_handle_status() - if status is None: - return None - - info = self._get_torrent_info_if_available(status) - file_size = self._get_file_size(status, info) - bytes_downloaded = self._get_bytes_downloaded(status, file_size) - progress = self._get_progress(status, file_size, bytes_downloaded) - - response = { - 'folderName': info.name() if info else "", - 'fileSize': file_size, - 'progress': progress, - 'downloadSpeed': status.download_rate, - 'uploadSpeed': status.upload_rate, - 'numPeers': status.num_peers, - 'numSeeds': status.num_seeds, - 'status': status.state, - 'bytesDownloaded': bytes_downloaded, - } - - return response diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index ffdfb59b6..000000000 --- a/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -libtorrent -cx_Freeze == 7.2.3 -cx_Logging; sys_platform == 'win32' -pywin32; sys_platform == 'win32' -psutil -Pillow -flask -aria2p diff --git a/scripts/build-native-addon.cjs b/scripts/build-native-addon.cjs new file mode 100644 index 000000000..6ef537dd4 --- /dev/null +++ b/scripts/build-native-addon.cjs @@ -0,0 +1,117 @@ +const fs = require("node:fs"); +const path = require("node:path"); +const util = require("node:util"); +const childProcess = require("node:child_process"); + +const execFile = util.promisify(childProcess.execFile); + +const projectRoot = process.cwd(); +const manifestPath = path.join( + projectRoot, + "native", + "hydra-native", + "Cargo.toml" +); +const cargoTargetDir = path.join( + projectRoot, + "native", + "hydra-native", + "target" +); +const outputDir = path.join(projectRoot, "hydra-native"); +const outputNodePath = path.join(outputDir, "hydra-native.node"); + +const sourceLibraryNameByPlatform = { + linux: "libhydra_native.so", + darwin: "libhydra_native.dylib", + win32: "hydra_native.dll", +}; + +const run = async (command, args, options = {}) => { + await execFile(command, args, { + cwd: projectRoot, + maxBuffer: 1024 * 1024 * 10, + ...options, + }); +}; + +const ensureDepsResolvableOnLinux = async () => { + if (process.platform !== "linux") return; + + const { stdout } = await execFile("ldd", [outputNodePath], { + cwd: projectRoot, + maxBuffer: 1024 * 1024 * 10, + }); + + if (stdout.includes("not found")) { + throw new Error( + `Unresolved dynamic dependencies found for ${outputNodePath}\n${stdout}` + ); + } +}; + +const copySidecarLibrariesOnWindows = async (sourceDirectory) => { + if (process.platform !== "win32") return; + + const candidateDlls = [ + "libgcc_s_seh-1.dll", + "libstdc++-6.dll", + "libwinpthread-1.dll", + "vcruntime140.dll", + "vcruntime140_1.dll", + "msvcp140.dll", + ]; + + for (const dll of candidateDlls) { + const sourcePath = path.join(sourceDirectory, dll); + if (!fs.existsSync(sourcePath)) continue; + const targetPath = path.join(outputDir, dll); + if (!fs.existsSync(targetPath)) { + fs.copyFileSync(sourcePath, targetPath); + } + } +}; + +const build = async () => { + const sourceLibraryName = sourceLibraryNameByPlatform[process.platform]; + + if (!sourceLibraryName) { + throw new Error( + `Unsupported platform for native build: ${process.platform}` + ); + } + + console.log("Building hydra-native Rust addon..."); + + await run("cargo", [ + "build", + "--release", + "--manifest-path", + manifestPath, + "--target-dir", + cargoTargetDir, + ]); + + const sourceLibraryPath = path.join( + cargoTargetDir, + "release", + sourceLibraryName + ); + + if (!fs.existsSync(sourceLibraryPath)) { + throw new Error(`Native build output not found at ${sourceLibraryPath}`); + } + + fs.mkdirSync(outputDir, { recursive: true }); + fs.copyFileSync(sourceLibraryPath, outputNodePath); + + await copySidecarLibrariesOnWindows(path.dirname(sourceLibraryPath)); + await ensureDepsResolvableOnLinux(); + + console.log(`Hydra native addon ready at ${outputNodePath}`); +}; + +build().catch((error) => { + console.error(error); + process.exit(1); +}); diff --git a/src/main/events/library/close-game.ts b/src/main/events/library/close-game.ts index a59229eea..d03e23d0b 100644 --- a/src/main/events/library/close-game.ts +++ b/src/main/events/library/close-game.ts @@ -2,11 +2,10 @@ import { registerEvent } from "../register-event"; import { logger, Wine } from "@main/services"; import sudo from "sudo-prompt"; import { app } from "electron"; -import { PythonRPC } from "@main/services/python-rpc"; -import { ProcessPayload } from "@main/services/download/types"; import { gamesSublevel, levelKeys } from "@main/level"; import { GameShop } from "@types"; import path from "node:path"; +import { NativeAddon } from "@main/services/native-addon"; const getKillCommand = (pid: number) => { if (process.platform == "win32") { @@ -21,9 +20,7 @@ const closeGame = async ( shop: GameShop, objectId: string ) => { - const processes = - (await PythonRPC.rpc.get("/process-list")).data || - []; + const processes = NativeAddon.listProcesses(); const game = await gamesSublevel.get(levelKeys.game(shop, objectId)); diff --git a/src/main/events/profile/process-profile-image.ts b/src/main/events/profile/process-profile-image.ts index bec17cb68..5c0a843a2 100644 --- a/src/main/events/profile/process-profile-image.ts +++ b/src/main/events/profile/process-profile-image.ts @@ -1,5 +1,5 @@ import { registerEvent } from "../register-event"; -import { PythonRPC } from "@main/services/python-rpc"; +import { NativeAddon } from "@main/services/native-addon"; const processProfileImageEvent = async ( _event: Electron.IpcMainInvokeEvent, @@ -9,12 +9,7 @@ const processProfileImageEvent = async ( }; export const processProfileImage = async (path: string, extension?: string) => { - return PythonRPC.rpc - .post<{ - imagePath: string; - mimeType: string; - }>("/profile-image", { image_path: path, target_extension: extension }) - .then((response) => response.data); + return NativeAddon.processProfileImage(path, extension); }; registerEvent("processProfileImage", processProfileImageEvent); diff --git a/src/main/events/torrenting/get-torrent-files.ts b/src/main/events/torrenting/get-torrent-files.ts index 1185a6417..1f63a102f 100644 --- a/src/main/events/torrenting/get-torrent-files.ts +++ b/src/main/events/torrenting/get-torrent-files.ts @@ -1,15 +1,11 @@ import { registerEvent } from "../register-event"; -import { PythonRPC } from "@main/services/python-rpc"; +import { NativeAddon } from "@main/services/native-addon"; import type { TorrentFilesResponse } from "@types"; -import { AxiosError } from "axios"; import { DownloadError } from "@shared"; const mapTorrentFilesError = (error: unknown) => { - if (error instanceof AxiosError) { - const rpcError = (error.response?.data as { error?: string } | undefined) - ?.error; - - switch (rpcError) { + if (error instanceof Error) { + switch (error.message) { case "invalid_magnet": return DownloadError.InvalidMagnet; case "metadata_timeout": @@ -18,17 +14,11 @@ const mapTorrentFilesError = (error: unknown) => { return DownloadError.TorrentMetadataIncomplete; case "too_many_files": return DownloadError.TorrentTooManyFiles; - case "metadata_busy": - return DownloadError.TorrentMetadataTimeout; default: return DownloadError.TorrentFilesUnavailable; } } - if (error instanceof Error) { - return error.message; - } - return DownloadError.TorrentFilesUnavailable; }; @@ -41,21 +31,11 @@ const getTorrentFiles = async ( } try { - await PythonRPC.ensureReady(); - - const response = await PythonRPC.rpc.post( - "/torrent-files", - { - magnet, - }, - { - timeout: 45000, - } - ); + const response = NativeAddon.getTorrentFiles(magnet, 45_000); return { ok: true, - data: response.data, + data: response as TorrentFilesResponse, }; } catch (error) { return { diff --git a/src/main/helpers/download-error-handler.ts b/src/main/helpers/download-error-handler.ts index 9c4c627fb..b0ee1d2f3 100644 --- a/src/main/helpers/download-error-handler.ts +++ b/src/main/helpers/download-error-handler.ts @@ -114,6 +114,34 @@ const handleHostSpecificError = ( return null; }; +const mapTorrentErrorCode = (code: string): DownloadErrorResult | null => { + if (code === "invalid_magnet") { + return { ok: false, error: DownloadError.InvalidMagnet }; + } + + if (code === "metadata_timeout") { + return { ok: false, error: DownloadError.TorrentMetadataTimeout }; + } + + if (code === "metadata_incomplete") { + return { ok: false, error: DownloadError.TorrentMetadataIncomplete }; + } + + if (code === "empty_selection") { + return { ok: false, error: DownloadError.TorrentNoFilesSelected }; + } + + if (code === "invalid_file_indices") { + return { ok: false, error: DownloadError.TorrentInvalidFileSelection }; + } + + if (code === "too_many_files") { + return { ok: false, error: DownloadError.TorrentTooManyFiles }; + } + + return null; +}; + export const handleDownloadError = ( err: unknown, downloader: Downloader @@ -124,6 +152,11 @@ export const handleDownloadError = ( } if (err instanceof Error) { + if (downloader === Downloader.Torrent) { + const mapped = mapTorrentErrorCode(err.message); + if (mapped) return mapped; + } + const hostResult = handleHostSpecificError(err.message, downloader); if (hostResult) return hostResult; diff --git a/src/main/helpers/launch-game.ts b/src/main/helpers/launch-game.ts index b45d97ed2..9563c3d12 100644 --- a/src/main/helpers/launch-game.ts +++ b/src/main/helpers/launch-game.ts @@ -9,10 +9,9 @@ import { Umu, PowerSaveBlockerManager, Wine, + NativeAddon, } from "@main/services"; import { CommonRedistManager } from "@main/services/common-redist-manager"; -import { ProcessPayload } from "@main/services/download/types"; -import { PythonRPC } from "@main/services/python-rpc"; import { parseExecutablePath } from "../events/helpers/parse-executable-path"; import { isGamemodeAvailable } from "./is-gamemode-available"; import { isMangohudAvailable } from "./is-mangohud-available"; @@ -147,9 +146,7 @@ const cleanupStaleCompatibilityProcesses = async ( const defaultPrefixPath = Wine.getDefaultPrefixPathForGame(objectId); if (defaultPrefixPath !== winePrefixPath) return; - const processes = - (await PythonRPC.rpc.get("/process-list")).data || - []; + const processes = NativeAddon.listProcesses(); const stalePids = processes .filter((runningProcess) => { diff --git a/src/main/index.ts b/src/main/index.ts index e1430226f..5b3535eb5 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -9,11 +9,9 @@ import { clearGamesPlaytime, WindowManager, Lock, - Aria2, PowerSaveBlockerManager, } from "@main/services"; import resources from "@locales"; -import { PythonRPC } from "./services/python-rpc"; import { db, gamesSublevel, levelKeys } from "./level"; import { GameShop, UserPreferences } from "@types"; import { launchGame } from "./helpers"; @@ -281,9 +279,6 @@ app.on("before-quit", async (e) => { if (!canAppBeClosed) { e.preventDefault(); PowerSaveBlockerManager.reset(); - /* Disconnects libtorrent */ - PythonRPC.kill(); - Aria2.kill(); await clearGamesPlaytime(); canAppBeClosed = true; app.quit(); diff --git a/src/main/main.ts b/src/main/main.ts index 6ddc0cf52..b5de0e305 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -10,7 +10,6 @@ import { RealDebridClient, PremiumizeClient, AllDebridClient, - Aria2, DownloadManager, HydraApi, uploadGamesBatch, @@ -36,8 +35,6 @@ export const loadState = async () => { await import("./events"); - Aria2.spawn(); - if (userPreferences?.realDebridApiToken) { RealDebridClient.authorize(userPreferences.realDebridApiToken); } diff --git a/src/main/services/aria2.ts b/src/main/services/aria2.ts deleted file mode 100644 index f3f490184..000000000 --- a/src/main/services/aria2.ts +++ /dev/null @@ -1,35 +0,0 @@ -import path from "node:path"; -import cp from "node:child_process"; -import { app } from "electron"; -import { logger } from "./logger"; - -export class Aria2 { - private static process: cp.ChildProcess | null = null; - - public static spawn() { - const binaryPath = - process.platform === "darwin" - ? "aria2c" - : app.isPackaged - ? path.join(process.resourcesPath, "aria2c") - : path.join(__dirname, "..", "..", "binaries", "aria2c"); - - this.process = cp.spawn( - binaryPath, - [ - "--enable-rpc", - "--rpc-listen-all", - "--file-allocation=none", - "--allow-overwrite=true", - ], - { stdio: "inherit", windowsHide: true } - ); - } - - public static kill() { - if (this.process) { - logger.log("Killing aria2 process"); - this.process.kill(); - } - } -} diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index 483371715..9b2de741a 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -10,12 +10,8 @@ import { VikingFileApi, RootzApi, } from "../hosters"; -import { PythonRPC } from "../python-rpc"; -import { - LibtorrentPayload, - LibtorrentStatus, - PauseDownloadPayload, -} from "./types"; +import { NativeAddon } from "../native-addon"; +import { LibtorrentStatus } from "./types"; import { calculateETA, getDirSize } from "./helpers"; import { RealDebridClient } from "./real-debrid"; import path from "node:path"; @@ -167,7 +163,7 @@ export class DownloadManager { logger.log(`[DownloadManager] Using filename: ${sanitizedFilename}`); } else { logger.log( - `[DownloadManager] No filename extracted, aria2 will use default` + `[DownloadManager] No filename extracted, downloader will use default` ); } @@ -182,12 +178,7 @@ export class DownloadManager { } private static async shouldUseJsDownloader(): Promise { - const userPreferences = await db.get( - levelKeys.userPreferences, - { valueEncoding: "json" } - ); - // Default to true - native HTTP downloader is enabled by default (opt-out) - return userPreferences?.useNativeHttpDownloader ?? true; + return true; } private static isHttpDownloader(downloader: Downloader): boolean { @@ -226,40 +217,32 @@ export class DownloadManager { this.maxDownloadSpeedBytesPerSecond = normalizedLimit; this.jsDownloader?.setMaxDownloadSpeedBytesPerSecond(normalizedLimit); - await PythonRPC.rpc - .post("/action", { - action: "set_download_limit", - max_download_speed_bytes_per_second: normalizedLimit, - }) - .catch((error) => { - logger.error( - "[DownloadManager] Failed to update RPC download speed limit:", - error - ); - }); + try { + NativeAddon.setTorrentDownloadLimit(normalizedLimit); + } catch (error) { + logger.error( + "[DownloadManager] Failed to update torrent speed limit:", + error + ); + } } public static async startRPC( download?: Download, downloadsToSeed?: Download[] ) { - await PythonRPC.spawn( - download?.status === "active" - ? await this.getDownloadPayload(download).catch((err) => { - logger.error("Error getting download payload", err); - return undefined; - }) - : undefined, - downloadsToSeed?.map((download) => ({ - action: "seed", - game_id: levelKeys.game(download.shop, download.objectId), - url: download.uri, - save_path: download.downloadPath, - })) - ); + if (downloadsToSeed?.length) { + for (const seedDownload of downloadsToSeed) { + await this.resumeSeeding(seedDownload).catch((error) => { + logger.error("[DownloadManager] Failed to resume seeding", error); + }); + } + } - if (download) { - this.downloadingGameId = levelKeys.game(download.shop, download.objectId); + if (download?.status === "active") { + await this.startDownload(download).catch((error) => { + logger.error("[DownloadManager] Failed to resume download", error); + }); } await this.applyDownloadSpeedLimit(); @@ -398,10 +381,8 @@ export class DownloadManager { } private static async getDownloadStatusFromRpc(): Promise { - const response = await PythonRPC.rpc.get( - "/status" - ); - if (response.data === null || !this.downloadingGameId) return null; + const response = NativeAddon.getTorrentStatus(); + if (response === null || !this.downloadingGameId) return null; const downloadId = this.downloadingGameId; try { @@ -414,7 +395,7 @@ export class DownloadManager { fileSize, folderName, status, - } = response.data; + } = response; const isDownloadingMetadata = status === LibtorrentStatus.DownloadingMetadata; @@ -685,9 +666,7 @@ export class DownloadManager { } public static async getSeedStatus() { - const seedStatus = await PythonRPC.rpc - .get("/seed-status") - .then((res) => res.data); + const seedStatus = NativeAddon.getTorrentSeedStatus(); if (!seedStatus.length) return; @@ -723,13 +702,12 @@ export class DownloadManager { if (this.usingJsDownloader && this.jsDownloader) { logger.log("[DownloadManager] Pausing JS download"); this.jsDownloader.pauseDownload(); - } else { - await PythonRPC.rpc - .post("/action", { - action: "pause", - game_id: downloadKey, - } as PauseDownloadPayload) - .catch(() => {}); + } else if (downloadKey) { + try { + NativeAddon.pauseTorrentDownload(downloadKey); + } catch { + // ignore pause failures + } } if (downloadKey === this.downloadingGameId) { @@ -753,9 +731,11 @@ export class DownloadManager { this.usingJsDownloader = false; this.allDebridBatch = null; } else if (!this.isPreparingDownload) { - await PythonRPC.rpc - .post("/action", { action: "cancel", game_id: downloadKey }) - .catch((err) => logger.error("Failed to cancel game download", err)); + try { + NativeAddon.cancelTorrentDownload(downloadKey!); + } catch (err) { + logger.error("Failed to cancel game download", err); + } } WindowManager.mainWindow?.setProgressBar(-1); @@ -768,19 +748,15 @@ export class DownloadManager { } static async resumeSeeding(download: Download) { - await PythonRPC.rpc.post("/action", { - action: "resume_seeding", - game_id: levelKeys.game(download.shop, download.objectId), + NativeAddon.resumeTorrentSeeding({ + gameId: levelKeys.game(download.shop, download.objectId), url: download.uri, - save_path: download.downloadPath, + savePath: download.downloadPath, }); } static async pauseSeeding(downloadKey: string) { - await PythonRPC.rpc.post("/action", { - action: "pause_seeding", - game_id: downloadKey, - }); + NativeAddon.pauseTorrentSeeding(downloadKey); } private static async getJsDownloadOptions(download: Download): Promise<{ @@ -1442,18 +1418,18 @@ export class DownloadManager { throw err; } } else { - logger.log("[DownloadManager] Using Python RPC downloader"); - const payload = await this.getDownloadPayload(download); + logger.log("[DownloadManager] Using native torrent downloader"); const isSelectiveTorrentStart = download.downloader === Downloader.Torrent && Array.isArray(download.fileIndices) && download.fileIndices.length > 0; - if (payload?.url) { - this.logResolvedUrl(payload.url); - } - await PythonRPC.rpc.post("/action", payload, { - timeout: isSelectiveTorrentStart ? 60_000 : 10_000, + NativeAddon.startTorrentDownload({ + gameId: downloadId, + url: download.uri, + savePath: download.downloadPath, + fileIndices: download.fileIndices, + timeoutMs: isSelectiveTorrentStart ? 60_000 : 10_000, }); this.downloadingGameId = downloadId; this.usingJsDownloader = false; diff --git a/src/main/services/index.ts b/src/main/services/index.ts index 1b88692d4..f0368292c 100644 --- a/src/main/services/index.ts +++ b/src/main/services/index.ts @@ -12,7 +12,6 @@ export * from "./7zip"; export * from "./game-files-manager"; export * from "./game-executables"; export * from "./common-redist-manager"; -export * from "./aria2"; export * from "./ws"; export * from "./system-path"; export * from "./library-sync"; @@ -24,3 +23,4 @@ export * from "./user"; export * from "./download-sources-checker"; export * from "./notifications/local-notifications"; export * from "./power-save-blocker"; +export * from "./native-addon"; diff --git a/src/main/services/native-addon.ts b/src/main/services/native-addon.ts new file mode 100644 index 000000000..79fe69e28 --- /dev/null +++ b/src/main/services/native-addon.ts @@ -0,0 +1,178 @@ +import fs from "node:fs"; +import path from "node:path"; +import { createRequire } from "node:module"; + +import { app } from "electron"; +import type { ProcessPayload, LibtorrentPayload } from "./download/types"; +import type { TorrentFilesResponse } from "@types"; + +import { logger } from "./logger"; + +type NativeProcessProfileImageResponse = { + imagePath?: string; + image_path?: string; + mimeType?: string; + mime_type?: string; +}; + +type HydraNativeModule = { + processProfileImage: ( + imagePath: string, + targetExtension?: string + ) => NativeProcessProfileImageResponse; + listProcesses: () => ProcessPayload[]; + torrentGetStatus: () => LibtorrentPayload | null; + torrentGetSeedStatus: () => Array; + torrentGetFiles: (magnet: string, timeoutMs?: number) => TorrentFilesResponse; + torrentStart: (payload: { + gameId: string; + url: string; + savePath: string; + fileIndices?: number[]; + timeoutMs?: number; + }) => void; + torrentPause: (gameId: string) => void; + torrentCancel: (gameId: string) => void; + torrentResumeSeeding: (payload: { + gameId: string; + url: string; + savePath: string; + }) => void; + torrentPauseSeeding: (gameId: string) => void; + torrentSetDownloadLimit: ( + maxDownloadSpeedBytesPerSecond?: number | null + ) => void; +}; + +export class NativeAddon { + private static nativeModule: HydraNativeModule | null = null; + + private static resolveAddonPath() { + if (app.isPackaged) { + return path.join( + process.resourcesPath, + "hydra-native", + "hydra-native.node" + ); + } + + return path.join(app.getAppPath(), "hydra-native", "hydra-native.node"); + } + + private static load() { + if (this.nativeModule) return this.nativeModule; + + const addonPath = this.resolveAddonPath(); + + if (!fs.existsSync(addonPath)) { + throw new Error(`Hydra native addon not found at ${addonPath}`); + } + + const require = createRequire(import.meta.url); + const nativeModule = require(addonPath) as HydraNativeModule; + this.nativeModule = nativeModule; + + return nativeModule; + } + + public static processProfileImage( + imagePath: string, + targetExtension = "webp" + ) { + try { + const response = this.load().processProfileImage( + imagePath, + targetExtension + ); + + const normalizedImagePath = response.imagePath ?? response.image_path; + const normalizedMimeType = response.mimeType ?? response.mime_type; + + if (!normalizedImagePath || !normalizedMimeType) { + throw new Error("Hydra native addon returned an invalid payload"); + } + + return { + imagePath: normalizedImagePath, + mimeType: normalizedMimeType, + }; + } catch (error) { + logger.error("Failed to process profile image via native addon", error); + throw error; + } + } + + public static listProcesses(): ProcessPayload[] { + try { + const response = this.load().listProcesses(); + + if (!Array.isArray(response)) { + throw new Error("Hydra native addon returned an invalid process list"); + } + + return response.filter((process): process is ProcessPayload => { + return ( + typeof process?.pid === "number" && + typeof process?.name === "string" && + process.name.length > 0 + ); + }); + } catch (error) { + logger.error("Failed to list processes via native addon", error); + return []; + } + } + + public static getTorrentStatus(): LibtorrentPayload | null { + return this.load().torrentGetStatus(); + } + + public static getTorrentSeedStatus(): Array< + LibtorrentPayload & { gameId: string } + > { + return this.load().torrentGetSeedStatus(); + } + + public static getTorrentFiles( + magnet: string, + timeoutMs?: number + ): TorrentFilesResponse { + return this.load().torrentGetFiles(magnet, timeoutMs); + } + + public static startTorrentDownload(payload: { + gameId: string; + url: string; + savePath: string; + fileIndices?: number[]; + timeoutMs?: number; + }) { + this.load().torrentStart(payload); + } + + public static pauseTorrentDownload(gameId: string) { + this.load().torrentPause(gameId); + } + + public static cancelTorrentDownload(gameId: string) { + this.load().torrentCancel(gameId); + } + + public static resumeTorrentSeeding(payload: { + gameId: string; + url: string; + savePath: string; + }) { + this.load().torrentResumeSeeding(payload); + } + + public static pauseTorrentSeeding(gameId: string) { + this.load().torrentPauseSeeding(gameId); + } + + public static setTorrentDownloadLimit( + maxDownloadSpeedBytesPerSecond?: number | null + ) { + this.load().torrentSetDownloadLimit(maxDownloadSpeedBytesPerSecond); + } +} diff --git a/src/main/services/process-watcher.ts b/src/main/services/process-watcher.ts index 9ef28e652..e7bff1e52 100644 --- a/src/main/services/process-watcher.ts +++ b/src/main/services/process-watcher.ts @@ -1,17 +1,16 @@ import { WindowManager } from "./window-manager"; import { createGame, trackGamePlaytime } from "./library-sync"; import type { Game, GameRunning, UserPreferences } from "@types"; -import { PythonRPC } from "./python-rpc"; import axios from "axios"; -import { ProcessPayload } from "./download/types"; import { db, gamesSublevel, levelKeys } from "@main/level"; import { CloudSync } from "./cloud-sync"; import { logger } from "./logger"; import { PowerSaveBlockerManager } from "./power-save-blocker"; -import path from "path"; +import path from "node:path"; import { AchievementWatcherManager } from "./achievements/achievement-watcher-manager"; import { MAIN_LOOP_INTERVAL } from "@main/constants"; import { Wine } from "./wine"; +import { NativeAddon } from "./native-addon"; export const gamesPlaytime = new Map< string, @@ -123,9 +122,7 @@ const findGamePathByProcess = async ( }; const getSystemProcessMap = async () => { - const processes = - (await PythonRPC.rpc.get("/process-list")).data || - []; + const processes = NativeAddon.listProcesses(); const processMap = new Map>(); const winePrefixMap = new Map(); diff --git a/src/main/services/python-rpc.ts b/src/main/services/python-rpc.ts deleted file mode 100644 index 3fd407adc..000000000 --- a/src/main/services/python-rpc.ts +++ /dev/null @@ -1,223 +0,0 @@ -import axios from "axios"; -import http from "node:http"; - -import cp from "node:child_process"; -import crypto from "node:crypto"; -import fs from "node:fs"; -import net from "node:net"; -import path from "node:path"; - -import { pythonRpcLogger } from "./logger"; -import { Readable } from "node:stream"; -import { app, dialog } from "electron"; -import { db, levelKeys } from "@main/level"; - -interface GamePayload { - action: string; - game_id: string; - url: string | string[]; - save_path: string; - header?: string; - out?: string; - total_size?: number; - file_indices?: number[]; -} - -const binaryNameByPlatform: Partial> = { - darwin: "hydra-python-rpc", - linux: "hydra-python-rpc", - win32: "hydra-python-rpc.exe", -}; - -const RPC_PORT_RANGE_START = 8080; -const RPC_PORT_RANGE_END = 9000; -const DEFAULT_RPC_PORT = 8087; - -export class PythonRPC { - public static readonly BITTORRENT_PORT = "5881"; - public static readonly rpc = axios.create({ - baseURL: `http://localhost:${DEFAULT_RPC_PORT}`, - timeout: 10000, - httpAgent: new http.Agent({ - family: 4, // Force IPv4 - }), - }); - - private static pythonProcess: cp.ChildProcess | null = null; - - private static logStderr(readable: Readable | null) { - if (!readable) return; - - readable.setEncoding("utf-8"); - readable.on("data", pythonRpcLogger.log); - } - - private static async getRPCPassword() { - const existingPassword = await db.get(levelKeys.rpcPassword, { - valueEncoding: "utf8", - }); - - if (existingPassword) return existingPassword; - - const newPassword = crypto.randomBytes(32).toString("hex"); - - await db.put(levelKeys.rpcPassword, newPassword, { - valueEncoding: "utf8", - }); - - return newPassword; - } - - private static async isPortAvailable(port: number) { - return new Promise((resolve) => { - const server = net.createServer(); - server.unref(); - - server.on("error", () => { - server.close(() => resolve(false)); - }); - - server.listen(port, "127.0.0.1", () => { - server.close(() => resolve(true)); - }); - }); - } - - private static async findAvailablePort() { - const scannedPorts = new Set(); - const enqueuePort = (port: number) => { - if (port < RPC_PORT_RANGE_START || port > RPC_PORT_RANGE_END) return; - if (!scannedPorts.has(port)) scannedPorts.add(port); - }; - - enqueuePort(DEFAULT_RPC_PORT); - for (let port = RPC_PORT_RANGE_START; port <= RPC_PORT_RANGE_END; port++) { - enqueuePort(port); - } - - for (const port of scannedPorts) { - if (await this.isPortAvailable(port)) { - return port; - } - } - - throw new Error("No available RPC port found"); - } - - private static updateRpcPort(port: number) { - this.rpc.defaults.baseURL = `http://localhost:${port}`; - } - - public static async ensureReady( - retries = 20, - delayMs = 250, - timeoutMs = 2000 - ): Promise { - let lastError: unknown = null; - - for (let attempt = 0; attempt < retries; attempt++) { - try { - await this.rpc.get("/healthcheck", { timeout: timeoutMs }); - return; - } catch (error) { - lastError = error; - if (attempt < retries - 1) { - await new Promise((resolve) => setTimeout(resolve, delayMs)); - } - } - } - - throw lastError instanceof Error - ? lastError - : new Error("Python RPC healthcheck failed"); - } - - public static async spawn( - initialDownload?: GamePayload, - initialSeeding?: GamePayload[] - ) { - const rpcPassword = await this.getRPCPassword(); - - let port: number; - try { - port = await this.findAvailablePort(); - } catch (err) { - const message = - err instanceof Error && err.message - ? err.message - : "Unknown error while selecting RPC port"; - dialog.showErrorBox( - "RPC Error", - `Failed to select an available port for the download service.\n\n${message}` - ); - throw err; - } - - this.updateRpcPort(port); - pythonRpcLogger.log(`Using RPC port: ${port}`); - - const commonArgs = [ - this.BITTORRENT_PORT, - String(port), - rpcPassword, - initialDownload ? JSON.stringify(initialDownload) : "", - initialSeeding ? JSON.stringify(initialSeeding) : "", - ]; - - if (app.isPackaged) { - const binaryName = binaryNameByPlatform[process.platform]!; - const binaryPath = path.join( - process.resourcesPath, - "hydra-python-rpc", - binaryName - ); - - if (!fs.existsSync(binaryPath)) { - dialog.showErrorBox( - "Fatal", - "Hydra Python Instance binary not found. Please check if it has been removed by Windows Defender." - ); - - app.quit(); - return; - } - - const childProcess = cp.spawn(binaryPath, commonArgs, { - windowsHide: true, - stdio: ["inherit", "inherit"], - }); - - this.logStderr(childProcess.stderr); - - this.pythonProcess = childProcess; - } else { - const scriptPath = path.join( - __dirname, - "..", - "..", - "python_rpc", - "main.py" - ); - - const childProcess = cp.spawn("python", [scriptPath, ...commonArgs], { - stdio: ["inherit", "inherit"], - }); - - this.logStderr(childProcess.stderr); - - this.pythonProcess = childProcess; - } - - this.rpc.defaults.headers.common["x-hydra-rpc-password"] = rpcPassword; - - await this.ensureReady(); - } - - public static kill() { - if (this.pythonProcess) { - pythonRpcLogger.log("Killing python process"); - this.pythonProcess.kill(); - this.pythonProcess = null; - } - } -} diff --git a/src/renderer/src/components/header/header.tsx b/src/renderer/src/components/header/header.tsx index e50562704..013290681 100644 --- a/src/renderer/src/components/header/header.tsx +++ b/src/renderer/src/components/header/header.tsx @@ -1,5 +1,12 @@ import { useTranslation } from "react-i18next"; -import { useEffect, useId, useMemo, useRef, useState } from "react"; +import { + useDeferredValue, + useEffect, + useId, + useMemo, + useRef, + useState, +} from "react"; import { useLocation, useNavigate, useSearchParams } from "react-router-dom"; import { ArrowLeftIcon, @@ -24,6 +31,7 @@ import cn from "classnames"; import { SearchDropdown } from "@renderer/components"; import { buildGameDetailsPath } from "@renderer/helpers"; import type { GameShop } from "@types"; +import { debounce } from "lodash-es"; const pathTitle: Record = { "/": "home", @@ -61,8 +69,27 @@ export function Header() { ? librarySearchValue : catalogueSearchValue; + const [localSearchValue, setLocalSearchValue] = useState(searchValue); + const deferredSearchValue = useDeferredValue(localSearchValue); + const dispatch = useAppDispatch(); + const debouncedLibrarySearch = useMemo( + () => + debounce((value: string) => { + dispatch(setLibrarySearchQuery(value)); + }, 180), + [dispatch] + ); + + const debouncedCatalogueSearch = useMemo( + () => + debounce((value: string) => { + dispatch(setFilters({ title: value })); + }, 250), + [dispatch] + ); + const [isFocused, setIsFocused] = useState(false); const [isDropdownVisible, setIsDropdownVisible] = useState(false); const [activeIndex, setActiveIndex] = useState(-1); @@ -83,7 +110,7 @@ export function Header() { useSearchHistory(); const { suggestions, isLoading: isLoadingSuggestions } = useSearchSuggestions( - searchValue, + deferredSearchValue, isOnLibraryPage, isDropdownVisible && isFocused && !isOnCataloguePage ); @@ -107,6 +134,17 @@ export function Header() { const totalItems = historyItems.length + suggestions.length; + useEffect(() => { + setLocalSearchValue(searchValue); + }, [searchValue, isOnLibraryPage, isOnCataloguePage]); + + useEffect(() => { + return () => { + debouncedLibrarySearch.cancel(); + debouncedCatalogueSearch.cancel(); + }; + }, [debouncedCatalogueSearch, debouncedLibrarySearch]); + const updateDropdownPosition = () => { if (searchContainerRef.current) { const rect = searchContainerRef.current.getBoundingClientRect(); @@ -149,6 +187,9 @@ export function Header() { }; const handleSearch = (value: string) => { + debouncedLibrarySearch.cancel(); + debouncedCatalogueSearch.cancel(); + if (isOnLibraryPage) { dispatch(setLibrarySearchQuery(value.slice(0, 255))); } else { @@ -157,7 +198,23 @@ export function Header() { setActiveIndex(-1); }; + const handleInputChange = (value: string) => { + const normalizedValue = value.slice(0, 255); + + setLocalSearchValue(normalizedValue); + setActiveIndex(-1); + + if (isOnLibraryPage) { + debouncedCatalogueSearch.cancel(); + debouncedLibrarySearch(normalizedValue); + } else { + debouncedLibrarySearch.cancel(); + debouncedCatalogueSearch(normalizedValue); + } + }; + const executeSearch = (query: string) => { + setLocalSearchValue(query.slice(0, 255)); const context = isOnLibraryPage ? "library" : "catalogue"; if (query.trim()) { addToHistory(query, context); @@ -187,6 +244,11 @@ export function Header() { }; const handleClearSearch = () => { + debouncedLibrarySearch.cancel(); + debouncedCatalogueSearch.cancel(); + + setLocalSearchValue(""); + if (isOnLibraryPage) { dispatch(setLibrarySearchQuery("")); } else { @@ -219,8 +281,8 @@ export function Header() { const suggestionIndex = activeIndex - historyItems.length; handleSelectSuggestion(suggestions[suggestionIndex]); } - } else if (searchValue.trim()) { - executeSearch(searchValue); + } else if (localSearchValue.trim()) { + executeSearch(localSearchValue); } } else if (event.key === "ArrowDown") { event.preventDefault(); @@ -347,15 +409,15 @@ export function Header() { type="text" name="search" placeholder={isOnLibraryPage ? t("search_library") : t("search")} - value={searchValue} + value={localSearchValue} className="header__search-input" - onChange={(event) => handleSearch(event.target.value)} + onChange={(event) => handleInputChange(event.target.value)} onFocus={handleFocus} onBlur={handleBlur} onKeyDown={handleKeyDown} /> - {searchValue && ( + {localSearchValue && (