diff --git a/Cargo.lock b/Cargo.lock index 7a047f7..16b5c20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,6 +83,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + [[package]] name = "atomic_refcell" version = "0.1.8" @@ -115,6 +121,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + [[package]] name = "bit_field" version = "0.10.1" @@ -672,6 +684,15 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if", +] + [[package]] name = "env_logger" version = "0.9.1" @@ -735,6 +756,15 @@ dependencies = [ "threadpool", ] +[[package]] +name = "fastrand" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] + [[package]] name = "fixed-hash" version = "0.7.0" @@ -849,18 +879,54 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "futures-channel" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +dependencies = [ + "futures-core", +] + [[package]] name = "futures-core" version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" +[[package]] +name = "futures-io" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" + [[package]] name = "futures-sink" version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" +[[package]] +name = "futures-task" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" + +[[package]] +name = "futures-util" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +dependencies = [ + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "generic-array" version = "0.14.6" @@ -1017,14 +1083,35 @@ dependencies = [ "image", "log", "monero", + "num-format", "num_cpus", "regex", + "reqwest", "serde", "serde_derive", "sha2", "toml", ] +[[package]] +name = "h2" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "half" version = "2.1.0" @@ -1034,6 +1121,12 @@ dependencies = [ "crunchy", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "heck" version = "0.3.3" @@ -1064,12 +1157,83 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +[[package]] +name = "http" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + [[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "hyper" +version = "0.14.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "iana-time-zone" version = "0.1.50" @@ -1118,6 +1282,16 @@ dependencies = [ "tiff", ] +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "instant" version = "0.1.12" @@ -1130,6 +1304,18 @@ dependencies = [ "web-sys", ] +[[package]] +name = "ipnet" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + [[package]] name = "jni" version = "0.19.0" @@ -1254,6 +1440,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1315,6 +1507,24 @@ dependencies = [ "getrandom 0.2.7", ] +[[package]] +name = "native-tls" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "ndk" version = "0.6.0" @@ -1451,6 +1661,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "num-format" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54b862ff8df690cf089058c98b183676a7ed0f974cc08b426800093227cbff3b" +dependencies = [ + "arrayvec 0.7.2", + "itoa", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -1547,6 +1767,51 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +[[package]] +name = "openssl" +version = "0.10.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types 0.3.2", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5230151e44c0f05157effb743e8d517472843121cf9243e8b81393edb5acd9ce" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "osmesa-sys" version = "0.1.2" @@ -1620,6 +1885,12 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +[[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.25" @@ -1791,12 +2062,64 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "reqwest" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "rustc-hex" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + [[package]] name = "safe_arch" version = "0.5.2" @@ -1815,6 +2138,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +dependencies = [ + "lazy_static", + "windows-sys", +] + [[package]] name = "scoped-tls" version = "1.0.0" @@ -1857,6 +2190,29 @@ dependencies = [ "syn", ] +[[package]] +name = "security-framework" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.145" @@ -1874,6 +2230,29 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[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 = "servo-fontconfig" version = "0.5.1" @@ -1916,6 +2295,15 @@ dependencies = [ "libc", ] +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + [[package]] name = "slotmap" version = "1.0.6" @@ -1960,6 +2348,16 @@ dependencies = [ "wayland-client", ] +[[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "spin" version = "0.9.4" @@ -2004,6 +2402,20 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + [[package]] name = "termcolor" version = "1.1.3" @@ -2080,7 +2492,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "642680569bb895b16e4b9d181c60be1ed136fa0c9c7f11d004daf053ba89bf82" dependencies = [ "arrayref", - "arrayvec", + "arrayvec 0.5.2", "bytemuck", "cfg-if", "png", @@ -2113,6 +2525,47 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +[[package]] +name = "tokio" +version = "1.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "pin-project-lite", + "socket2", + "winapi", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + [[package]] name = "toml" version = "0.5.9" @@ -2122,6 +2575,12 @@ dependencies = [ "serde", ] +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" version = "0.1.36" @@ -2142,6 +2601,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + [[package]] name = "ttf-parser" version = "0.15.2" @@ -2192,6 +2657,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "vec_map" version = "0.8.2" @@ -2215,6 +2686,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -2534,6 +3015,15 @@ dependencies = [ "x11-dl", ] +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + [[package]] name = "wio" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 996ed95..1123ea1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,9 @@ image = { version = "0.24.4", features = ["png"] } log = "0.4.17" monero = "0.18.0" num_cpus = "1.13.1" +num-format = "0.4.0" regex = "1.6.0" +reqwest = { version = "0.11.12", features = ["blocking", "json"] } serde = "1.0.145" serde_derive = "1.0.145" sha2 = "0.10.6" diff --git a/src/README.md b/src/README.md index c082873..77d8607 100644 --- a/src/README.md +++ b/src/README.md @@ -1,7 +1,7 @@ # Gupax source files -* [State](#State) * [Structure](#Structure) * [Bootstrap](#Bootstrap) +* [State](#State) ## Structure | File/Folder | Purpose | @@ -10,6 +10,7 @@ | `constants.rs` | General constants needed in Gupax | `gupax.rs` | Struct/impl for `Gupax` tab | `main.rs` | Struct/enum/impl for `App/Tab/State`, init functions, main function +| `node.rs` | Struct/impl for Community Nodes | `p2pool.rs` | Struct/impl for `P2Pool` tab | `status.rs` | Struct/impl for `Status` tab | `toml.rs` | Struct/impl for `gupax.toml`, the disk state @@ -25,12 +26,13 @@ This is how Gupax works internally when starting up, divided into 3 sections. - Attempt to read `gupax.toml` || *warn!*, *initialize config with default options* - If errors were found, pop-up window -2. **AUTO-UPDATE** +2. **AUTO** - If `auto_update` == `true`, pop-up auto-updating window || *info!*, *skip auto-update* - Multi-threaded GitHub API check on Gupax -> P2Pool -> XMRig || *warn!*, *skip auto-update* - Multi-threaded download if current version != new version || *warn!*, *skip auto-update* - After download, atomically replace current binaries with new || *warn!*, *skip auto-update* - Update version metadata || *warn!*, *skip auto-update* + - If `auto_select` == `true`, ping community nodes and select fastest one || *warn!* 3. **MAIN** - All data must be initialized at this point, either via `gupax.toml` or default options || *panic!* @@ -40,7 +42,7 @@ This is how Gupax works internally when starting up, divided into 3 sections. - Kill processes, kill connections, exit ## State -Internal state is saved in the "OS data folder" as `gupax.toml`, using the [TOML](https://github.com/toml-lang/toml) format. If the version can't be parsed (not in the `vX.X.X` or `vX.X` format), the auto-updater will be skipped. [If not found, a default `gupax.toml` file will be created with `Toml::default`.](https://github.com/hinto-janaiyo/gupax/blob/main/src/toml.rs) +Internal state is saved in the "OS data folder" as `gupax.toml`, using the [TOML](https://github.com/toml-lang/toml) format. If the version can't be parsed (not in the `vX.X.X` or `vX.X` format), the auto-updater will be skipped. [If not found, a default `gupax.toml` file will be created with `Toml::default`.](https://github.com/hinto-janaiyo/gupax/blob/main/src/toml.rs) Gupax will `panic!` if `gupax.toml` has IO or parsing issues. | OS | Data Folder | Example | |----------|----------------------------------------- |-----------------------------------------------------------| diff --git a/src/constants.rs b/src/constants.rs index 77395cd..977adb5 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -15,11 +15,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use std::net::{Ipv4Addr,SocketAddrV4}; -use sha2::{Sha256,Digest}; -use hex_literal::hex; -use std::{io, fs}; - // These are the versions bundled with Gupax. pub const P2POOL_VERSION: &'static str = "v2.4"; pub const XMRIG_VERSION: &'static str = "v6.18.0"; @@ -45,19 +40,6 @@ pub const OS: &'static str = "🐧 Linux"; #[cfg(target_os = "linux")] pub const HUGEPAGES_1GB: bool = true; -// Community Monerod nodes -pub const IP_RINO: &'static str = "node.community.rino.io"; -pub const RPC_RINO: u16 = 18081; -pub const ZMQ_RINO: u16 = 18083; - -pub const IP_SETH: &'static str = "node.sethforprivacy.com"; -pub const RPC_SETH: u16 = 18089; -pub const ZMQ_SETH: u16 = 18083; - -pub const IP_SELSTA: &'static str = "selsta1.featherwallet.net"; -pub const RPC_SELSTA: u16 = 18081; -pub const ZMQ_SELSTA: u16 = 18083; - // Tooltips // Gupax pub const GUPAX_CHECK_FOR_UPDATES: &'static str = "Check for Gupax, P2Pool, and XMRig updates via GitHub's API"; diff --git a/src/main.rs b/src/main.rs index d5824e0..6e516c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,15 +34,17 @@ use env_logger::Builder; use env_logger::WriteStyle; use std::io::Write; use std::time::Instant; +use std::sync::{Arc,Mutex}; mod constants; +mod node; mod toml; mod about; mod status; mod gupax; mod p2pool; mod xmrig; -use {constants::*,crate::toml::*,about::*,status::*,gupax::*,p2pool::*,xmrig::*}; +use {constants::*,node::*,crate::toml::*,about::*,status::*,gupax::*,p2pool::*,xmrig::*}; // The state of the outer [App]. // See the [State] struct for the @@ -63,6 +65,10 @@ pub struct App { og: State, allowed_to_close: bool, show_confirmation_dialog: bool, + now: Instant, + ping: bool, + ping_prog: Arc>, + node: Arc>, } impl App { @@ -104,6 +110,10 @@ impl App { og, allowed_to_close: false, show_confirmation_dialog: false, + now: Instant::now(), + node: Arc::new(Mutex::new(NodeStruct::default())), + ping: false, + ping_prog: Arc::new(Mutex::new(false)), } } } @@ -222,26 +232,71 @@ fn init_options() -> NativeOptions { fn main() { init_logger(); + let toml = match Toml::get() { + Ok(toml) => toml, + Err(err) => { + error!("{}", err); + let error_msg = err.to_string(); + let options = Panic::options(); + eframe::run_native("Gupax", options, Box::new(|cc| Box::new(Panic::new(cc, error_msg))),); + exit(1); + }, + }; let options = init_options(); - let toml = Toml::get(); - info!("Printing gupax.toml..."); - eprintln!("{:#?}", toml); - let now = Instant::now(); - eframe::run_native( - "Gupax", - options, - Box::new(|cc| Box::new(App::new(cc))), - ); + eframe::run_native("Gupax", options, Box::new(|cc| Box::new(App::new(cc))),); +} + +// [App] frame for Panic situations. +struct Panic { error_msg: String, } +impl Panic { + fn options() -> NativeOptions { + let mut options = eframe::NativeOptions::default(); + let frame = Option::from(Vec2::new(1280.0, 720.0)); + options.min_window_size = frame; + options.max_window_size = frame; + options.initial_window_size = frame; + options.follow_system_theme = false; + options.default_theme = eframe::Theme::Dark; + let icon = image::load_from_memory(BYTES_ICON).expect("Failed to read icon bytes").to_rgba8(); + let (icon_width, icon_height) = icon.dimensions(); + options.icon_data = Some(eframe::IconData { + rgba: icon.into_raw(), + width: icon_width, + height: icon_height, + }); + info!("Panic::options() ... OK"); + options + } + fn new(cc: &eframe::CreationContext<'_>, error_msg: String) -> Self { + let resolution = cc.integration_info.window_info.size; + init_text_styles(&cc.egui_ctx, resolution[0] as f32); + Self { error_msg } + } +} + +impl eframe::App for Panic { + fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + egui::CentralPanel::default().show(ctx, |ui| { + let width = ui.available_width(); + let height = ui.available_height(); + init_text_styles(ctx, width); + ui.add_sized([width, height/8.0], Label::new("Gupax has encountered a fatal error:")); + ui.add_sized([width, height/8.0], Label::new(&self.error_msg)); + ui.add_sized([width, height/3.0], Label::new("Please report to: https://github.com/hinto-janaiyo/gupax/issues")); + ui.add_sized([width, height/3.0], egui::Button::new("Quit")).clicked() && exit(1) + }); + } } impl eframe::App for App { fn on_close_event(&mut self) -> bool { - self.show_confirmation_dialog = true; +// self.show_confirmation_dialog = true; + self.ping = true; self.allowed_to_close } fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { + // Close confirmation. if self.show_confirmation_dialog { - // Show confirmation dialog: egui::CentralPanel::default().show(ctx, |ui| { let width = ui.available_width(); let width = width - 10.0; @@ -250,14 +305,50 @@ impl eframe::App for App { ui.add_sized([width, height/2.0], Label::new("Are you sure you want to quit?")); ui.group(|ui| { if ui.add_sized([width, height/10.0], egui::Button::new("Yes")).clicked() { + info!("Quit confirmation = yes ... goodbye!"); exit(0); } else if ui.add_sized([width, height/10.0], egui::Button::new("No")).clicked() { + info!("Quit confirmation = no ... returning!"); self.show_confirmation_dialog = false; } }); }); return } + + // + if self.ping { + self.ping = false; + self.ping_prog = Arc::new(Mutex::new(true)); + let node_clone = Arc::clone(&self.node); + let prog_clone = Arc::clone(&self.ping_prog); + thread::spawn(move|| { + let result = NodeStruct::ping(); + *node_clone.lock().unwrap() = result.node; + *prog_clone.lock().unwrap() = false; + }); + } + + if *self.ping_prog.lock().unwrap() { + egui::CentralPanel::default().show(ctx, |ui| { + let width = ui.available_width(); + let width = width - 10.0; + let height = ui.available_height(); + init_text_styles(ctx, width); + ui.add_sized([width, height/2.0], Label::new(format!("In progress: {}", *self.ping_prog.lock().unwrap()))); + ui.group(|ui| { + if ui.add_sized([width, height/10.0], egui::Button::new("Yes")).clicked() { + info!("Quit confirmation = yes ... goodbye!"); + exit(0); + } else if ui.add_sized([width, height/10.0], egui::Button::new("No")).clicked() { + info!("Quit confirmation = no ... returning!"); + self.show_confirmation_dialog = false; + } + }); + }); + return + } + // Top: Tabs egui::CentralPanel::default().show(ctx, |ui| { init_text_styles(ctx, ui.available_width()); diff --git a/src/node.rs b/src/node.rs new file mode 100644 index 0000000..a15d95e --- /dev/null +++ b/src/node.rs @@ -0,0 +1,219 @@ +// Gupax - GUI Uniting P2Pool And XMRig +// +// Copyright (c) 2022 hinto-janaiyo +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use serde_derive::{Serialize,Deserialize}; +use std::time::{Instant,Duration}; +use std::collections::HashMap; +use std::error::Error; +use std::thread; +use egui::Color32; +use log::*; + +// Community Monerod nodes. All of these have ZMQ on 18083. +// Adding/removing nodes will need changes to pretty +// much all the code in this file, and the code that +// handles the actual Enum selector in the P2Pool tab. +pub const C3POOL: &'static str = "node.c3pool.com:18081"; +pub const CAKE: &'static str = "xmr-node.cakewallet.com:18081"; +pub const CAKE_EU: &'static str = "xmr-node-eu.cakewallet.com:18081"; +pub const CAKE_UK: &'static str = "xmr-node-uk.cakewallet.com:18081"; +pub const CAKE_US: &'static str = "xmr-node-usa-east.cakewallet.com:18081"; +pub const MONERUJO: &'static str = "nodex.monerujo.io:18081"; +pub const RINO: &'static str = "node.community.rino.io:18081"; +pub const SELSTA: &'static str = "selsta1.featherwallet.net:18081"; +pub const SETH: &'static str = "node.sethforprivacy.com:18089"; +pub const SUPPORTXMR: &'static str = "node.supportxmr.com:18081"; +pub const SUPPORTXMR_IR: &'static str = "node.supportxmr.ir:18081"; +pub const XMRVSBEAST: &'static str = "p2pmd.xmrvsbeast.com:18081"; + +#[derive(Debug)] +pub struct NodeStruct { + c3pool: Data, cake: Data, cake_eu: Data, cake_uk: Data, cake_us: Data, monerujo: Data, + rino: Data, selsta: Data, seth: Data, supportxmr: Data, supportxmr_ir: Data, xmrvsbeast: Data, +} + +#[derive(Debug)] +pub struct Data { + pub ms: u128, + pub color: Color32, + pub id: NodeEnum, + pub ip: String, +} + +#[derive(Copy,Clone,Debug,Deserialize,Serialize)] +pub enum NodeEnum { + C3pool, Cake, CakeEu, CakeUk, CakeUs, Monerujo, Rino, + Selsta, Seth, SupportXmr, SupportXmrIr, XmrVsBeast, +} + +#[derive(Debug)] +pub struct PingResult { + pub node: NodeStruct, + pub fastest: NodeEnum, +} + +impl NodeStruct { + pub fn default() -> Self { + use crate::NodeEnum::*; + Self { + c3pool: Data { ms: 0, color: Color32::GRAY, id: C3pool, ip: C3POOL.to_string(), }, + cake: Data { ms: 0, color: Color32::GRAY, id: Cake, ip: CAKE.to_string(), }, + cake_eu: Data { ms: 0, color: Color32::GRAY, id: CakeEu, ip: CAKE_EU.to_string(), }, + cake_uk: Data { ms: 0, color: Color32::GRAY, id: CakeUk, ip: CAKE_UK.to_string(), }, + cake_us: Data { ms: 0, color: Color32::GRAY, id: CakeUs, ip: CAKE_US.to_string(), }, + monerujo: Data { ms: 0, color: Color32::GRAY, id: Monerujo, ip: MONERUJO.to_string(), }, + rino: Data { ms: 0, color: Color32::GRAY, id: Rino, ip: RINO.to_string(), }, + selsta: Data { ms: 0, color: Color32::GRAY, id: Selsta, ip: SELSTA.to_string(), }, + seth: Data { ms: 0, color: Color32::GRAY, id: Seth, ip: SETH.to_string(), }, + supportxmr: Data { ms: 0, color: Color32::GRAY, id: SupportXmr, ip: SUPPORTXMR.to_string(), }, + supportxmr_ir: Data { ms: 0, color: Color32::GRAY, id: SupportXmrIr, ip: SUPPORTXMR_IR.to_string(), }, + xmrvsbeast: Data { ms: 0, color: Color32::GRAY, id: XmrVsBeast, ip: XMRVSBEAST.to_string(), }, + } + } + + // Return array of all IPs + fn array() -> [&'static str; 12] { + [ + C3POOL,CAKE,CAKE_EU,CAKE_UK,CAKE_US,MONERUJO,RINO, + SELSTA,SETH,SUPPORTXMR,SUPPORTXMR_IR,XMRVSBEAST, + ] + } + + // This is for pinging the community nodes to + // find the fastest/slowest one for the user. + // The process: + // - Send 3x [get_info] JSON-RPC requests over HTTP + // - Measure each request in milliseconds as [u128] + // - Timeout on requests over 5 seconds + // - Calculate average time + // - Add data to appropriate struct + // - Sort fastest to lowest + // - Return [PingResult(NodeStruct, NodeEnum)] (data and fastest node) + // + // This is done linearly since per IP since + // multi-threading might affect performance. + // + // <300ms = GREEN + // <1000ms = YELLOW + // >1000ms = RED + // timeout = BLACK + // default = GRAY + pub fn ping() -> PingResult { + use crate::NodeEnum::*; + info!("Starting community node pings..."); + let mut node = NodeStruct::default(); + let mut get_info = HashMap::new(); + get_info.insert("jsonrpc", "2.0"); + get_info.insert("id", "0"); + get_info.insert("method", "get_info"); + let mut vec: Vec<(u128, NodeEnum)> = Vec::new(); + let fastest = false; + let timeout_sec = Duration::from_millis(5000); + + for ip in Self::array().iter() { + let id = match *ip { + C3POOL => C3pool, + CAKE => Cake, + CAKE_EU => CakeEu, + CAKE_UK => CakeUk, + CAKE_US => CakeUs, + MONERUJO => Monerujo, + RINO => Rino, + SELSTA => Selsta, + SETH => Seth, + SUPPORTXMR => SupportXmr, + SUPPORTXMR_IR => SupportXmrIr, +// XMRVSBEAST => XmrVsBeast, + _ => XmrVsBeast, + }; + let mut timeout = false; + let mut mid = Duration::new(0, 0); + let max = 3; + for i in 1..=max { + let client = reqwest::blocking::ClientBuilder::new(); + let client = reqwest::blocking::ClientBuilder::timeout(client, timeout_sec); + let client = reqwest::blocking::ClientBuilder::build(client).unwrap(); + let http = "http://".to_owned() + &**ip + "/json_rpc"; + let now = Instant::now(); + match client.post(http).json(&get_info).send() { + Ok(r) => mid += now.elapsed(), + Err(err) => { + error!("Timeout on [{}] (over 3 seconds)", ip); + mid += timeout_sec; + timeout = true; + }, + }; + } + let ms = mid.as_millis() / 3; + vec.push((ms, id)); + info!("{}ms ... {}", ms, ip); + let color: Color32; + if timeout == true { + color = Color32::BLACK + } else if ms >= 1000 { + color = Color32::LIGHT_RED + } else if ms >= 300 { + color = Color32::LIGHT_YELLOW + } else { + color = Color32::LIGHT_GREEN + } + match id { + C3pool => { node.c3pool.ms = ms; node.c3pool.color = color; }, + Cake => { node.cake.ms = ms; node.cake.color = color; }, + CakeEu => { node.cake_eu.ms = ms; node.cake_eu.color = color; }, + CakeUk => { node.cake_uk.ms = ms; node.cake_uk.color = color; }, + CakeUs => { node.cake_us.ms = ms; node.cake_us.color = color; }, + Monerujo => { node.monerujo.ms = ms; node.monerujo.color = color; }, + Rino => { node.rino.ms = ms; node.rino.color = color; }, + Selsta => { node.selsta.ms = ms; node.selsta.color = color; }, + Seth => { node.seth.ms = ms; node.seth.color = color; }, + SupportXmr => { node.supportxmr.ms = ms; node.supportxmr.color = color; }, + SupportXmrIr => { node.supportxmr_ir.ms = ms; node.supportxmr_ir.color = color; }, + XmrVsBeast => { node.xmrvsbeast.ms = ms; node.xmrvsbeast.color = color; }, + } + } + let mut best_ms: u128 = vec[0].0; + let mut fastest: NodeEnum = vec[0].1; + for (ms, id) in vec.iter() { + if ms < &best_ms { + fastest = *id; + best_ms = *ms; + } + } + // These values have weird behavior. + // The values don't update if not printed beforehand, + // so the match below on [fastest] gets funky. + info!("Fastest node ... {:#?} @ {:#?}ms", fastest, best_ms); + let ip = match fastest { + C3pool => C3POOL, + Cake => CAKE, + CakeEu => CAKE_EU, + CakeUk => CAKE_UK, + CakeUs => CAKE_US, + Monerujo => MONERUJO, + Rino => RINO, + Selsta => SELSTA, + Seth => SETH, + SupportXmr => SUPPORTXMR, + SupportXmrIr => SUPPORTXMR_IR, + XmrVsBeast => XMRVSBEAST, + }; + info!("Using IP ... {}", ip); + info!("Community node ping ... OK"); + PingResult { node, fastest, } + } +} diff --git a/src/toml.rs b/src/toml.rs index b2bd9a1..ff19174 100644 --- a/src/toml.rs +++ b/src/toml.rs @@ -36,7 +36,7 @@ use log::*; //---------------------------------------------------------------------------------------------------- Impl // Since [State] is already used in [main.rs] to represent -// working state, [Toml] is used to disk state. +// working state, [Toml] is used to represent disk state. impl Toml { pub fn default() -> Self { use crate::constants::{P2POOL_VERSION,XMRIG_VERSION}; @@ -53,6 +53,7 @@ impl Toml { out_peers: 10, in_peers: 10, log_level: 3, + node: crate::NodeEnum::C3pool, monerod: "localhost".to_string(), rpc: 18081, zmq: 18083, @@ -83,7 +84,7 @@ impl Toml { let mut path = match dirs::data_dir() { Some(mut path) => { path.push(DIRECTORY); - info!("{}, OS data path ... OK", path.display()); + info!("OS data path ... OK"); path }, None => { error!("Couldn't get OS PATH for data"); return Err(TomlError::Path(PATH_ERROR.to_string())) }, @@ -107,11 +108,16 @@ impl Toml { fs::read_to_string(&path)? }, }; + info!("TOML path ... {}", path.display()); info!("TOML read ... OK"); // Attempt to parse, return Result match toml::from_str(&file) { - Ok(file) => { info!("TOML parse ... OK"); Ok(file) }, + Ok(toml) => { + info!("TOML parse ... OK"); + eprint!("{}", file); + Ok(toml) + }, Err(err) => { error!("Couldn't parse TOML file"); Err(TomlError::Parse(err)) }, } } @@ -198,6 +204,7 @@ struct P2pool { out_peers: u8, in_peers: u8, log_level: u8, + node: crate::node::NodeEnum, monerod: String, rpc: u16, zmq: u16,