diff --git a/Cargo.lock b/Cargo.lock index 197184f..cd56dfb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -552,9 +552,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.59" +version = "1.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7a4d3ec6524d28a329fc53654bbadc9bdd7b0431f5d65f1a56ffb28a1ee5283" +checksum = "e1e928d4b69e3077709075a938a05ffbedfa53a84c8f766efbf8220bb1ff60e1" dependencies = [ "find-msvc-tools", "jobserver", @@ -1028,9 +1028,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.4.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a043dc74da1e37d6afe657061213aa6f425f855399a11d3463c6ecccc4dfda1f" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fiat-crypto" @@ -1679,9 +1679,9 @@ checksum = "e8a5a9a0ff0086c7a148acb942baaabeadf9504d10400b5a05645853729b9cd2" [[package]] name = "indexmap" -version = "2.13.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a8a2b9cb3e0b0c1803dbb0758ffac5de2f425b23c28f518faabd9d805342ff" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown 0.16.1", @@ -1721,7 +1721,7 @@ dependencies = [ ] [[package]] -name = "iota-cli" +name = "iota" version = "0.1.0" dependencies = [ "actix-web", @@ -1738,14 +1738,8 @@ dependencies = [ "hkdf", "hyper", "hyper-util", - "iota-logger", - "iota-state", - "iota-storage", - "iota-terms", - "iota-util", "json", "lazy_static", - "omikron-connector", "once_cell", "open", "pnet", @@ -1773,116 +1767,6 @@ dependencies = [ "zip", ] -[[package]] -name = "iota-core" -version = "0.1.0" -dependencies = [ - "dashmap", - "iota-cli", - "iota-logger", - "iota-state", - "iota-storage", - "iota-terms", - "iota-util", - "json", - "omikron-connector", - "once_cell", - "pnet", - "ratatui", - "reqwest", - "tokio", - "ttp-core", - "ttp-native", - "web-server", - "web-ui", -] - -[[package]] -name = "iota-logger" -version = "0.1.0" -dependencies = [ - "iota-state", - "iota-util", - "ratatui", - "ttp-core", -] - -[[package]] -name = "iota-state" -version = "0.1.0" -dependencies = [ - "dashmap", - "json", - "once_cell", - "sysinfo", - "tokio", - "ttp-core", -] - -[[package]] -name = "iota-storage" -version = "0.1.0" -dependencies = [ - "aes-gcm", - "base64", - "hex", - "hkdf", - "iota-logger", - "iota-state", - "iota-util", - "json", - "once_cell", - "rand 0.8.5", - "rand_core 0.6.4", - "ratatui", - "reqwest", - "rusqlite", - "sha2", - "sysinfo", - "tokio", - "ttp-core", - "ttp-native", - "uuid", - "walkdir", - "x448", - "zip", -] - -[[package]] -name = "iota-terms" -version = "0.1.0" -dependencies = [ - "iota-state", - "iota-util", - "json", - "reqwest", -] - -[[package]] -name = "iota-util" -version = "0.1.0" -dependencies = [ - "aes-gcm", - "base64", - "hex", - "hkdf", - "json", - "once_cell", - "pnet", - "rand_core 0.6.4", - "ratatui", - "reqwest", - "sha2", - "sysinfo", - "tokio", - "ttp-core", - "ttp-native", - "uuid", - "walkdir", - "x448", - "zip", -] - [[package]] name = "ipnet" version = "2.12.0" @@ -2373,27 +2257,6 @@ dependencies = [ "asn1-rs", ] -[[package]] -name = "omikron-connector" -version = "0.1.0" -dependencies = [ - "base64", - "dashmap", - "hex", - "iota-logger", - "iota-state", - "iota-storage", - "iota-util", - "json", - "rand_core 0.6.4", - "sha2", - "tokio", - "ttp-core", - "ttp-native", - "uuid", - "x448", -] - [[package]] name = "once_cell" version = "1.21.4" @@ -3361,9 +3224,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.28" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" [[package]] name = "serde" @@ -3851,9 +3714,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.51.0" +version = "1.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bd1c4c0fc4a7ab90fc15ef6daaa3ec3b893f004f915f2392557ed23237820cd" +checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" dependencies = [ "bytes", "libc", @@ -3868,9 +3731,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.7.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" dependencies = [ "proc-macro2", "quote", @@ -4010,7 +3873,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "ttp-core" version = "0.1.0" -source = "git+https://git.methanium.net/Tensamin/TTP.git#bacbcb0e38791cf1a38cf5851beb20d5645002ba" +source = "git+https://github.com/Tensamin/TTP.git#e246d1af6a42c71514d0ccc06fef94d71e4ad167" dependencies = [ "base64", "byteorder", @@ -4022,7 +3885,7 @@ dependencies = [ [[package]] name = "ttp-native" version = "0.1.0" -source = "git+https://git.methanium.net/Tensamin/TTP.git#bacbcb0e38791cf1a38cf5851beb20d5645002ba" +source = "git+https://github.com/Tensamin/TTP.git#e246d1af6a42c71514d0ccc06fef94d71e4ad167" dependencies = [ "quinn", "rustls", @@ -4341,14 +4204,6 @@ dependencies = [ "semver", ] -[[package]] -name = "web-server" -version = "0.1.0" -dependencies = [ - "ttp-core", - "ttp-native", -] - [[package]] name = "web-sys" version = "0.3.94" @@ -4369,58 +4224,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "web-ui" -version = "0.1.0" -dependencies = [ - "actix-web", - "actix-web-actors", - "aes-gcm", - "async-trait", - "base64", - "chrono", - "crossterm", - "dashmap", - "futures", - "futures-util", - "hex", - "hkdf", - "hyper", - "hyper-util", - "iota-logger", - "iota-state", - "iota-storage", - "iota-util", - "json", - "lazy_static", - "omikron-connector", - "once_cell", - "open", - "pnet", - "rand 0.8.5", - "rand_core 0.6.4", - "ratatui", - "reqwest", - "rusqlite", - "rustls", - "rustls-pemfile", - "serde_json", - "sha2", - "strum 0.27.2", - "strum_macros 0.27.2", - "sysinfo", - "tokio", - "tokio-tungstenite", - "ttp-core", - "ttp-native", - "tungstenite", - "uuid", - "walkdir", - "warp", - "x448", - "zip", -] - [[package]] name = "webpki-root-certs" version = "1.0.6" @@ -4966,9 +4769,9 @@ dependencies = [ [[package]] name = "writeable" -version = "0.6.3" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" [[package]] name = "wtransport" diff --git a/Cargo.toml b/Cargo.toml index 30a7a09..8767b56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,56 @@ -[workspace] -members = ["iota-storage", "iota-terms", "iota-state", "iota-cli", "iota-core", "omikron-connector", "web-server", "web-ui", "iota-logger", "iota-util"] +[package] +name = "iota" +version = "0.1.0" +edition = "2024" + +[dependencies] +ttp-core = { git = "https://github.com/Tensamin/TTP.git", package = "ttp-core" } +ttp-native = { git = "https://github.com/Tensamin/TTP.git", package = "ttp-native" } + +actix-web = { version = "4", features = ["rustls-0_23"] } +actix-web-actors = "4" +aes-gcm = "0.10.3" +base64 = "0.22.1" +crossterm = "*" +futures = "*" +futures-util = "*" +hex = "*" +hkdf = "0.12.4" +hyper-util = { version = "*" } +hyper = { version = "1.8.1", features = [ + "capi", + "client", + "full", + "http1", + "http2", + "nightly", + "server", +] } +json = "*" +once_cell = "1.21.3" +rand = "0.8" +rand_core = { version = "0.6", features = ["getrandom", "std"] } +reqwest = "0.13.2" +rustls = { version = "0.23.37", features = ["aws-lc-rs"] } +sha2 = "0.10.9" +sysinfo = "0.38.3" +tokio = { version = "1.50.0", features = ["full"] } +tokio-tungstenite = { version = "*", features = ["native-tls"] } +tungstenite = "*" +uuid = { version = "*", features = ["v4"] } +walkdir = "2.5.0" +warp = "*" +x448 = { version = "*" } +rustls-pemfile = "2.2.0" +async-trait = "0.1.89" +zip = "6.0.0" +pnet = "0.35.0" +dashmap = "6.1.0" +strum = "0.27.2" +strum_macros = "0.27.2" +ratatui = "0.30.0" +open = "5.3.3" +chrono = "0.4.43" +serde_json = "1.0.149" +rusqlite = "0.39.0" +lazy_static = "1.5.0" diff --git a/decentralized/src/lib.rs b/decentralized/src/lib.rs deleted file mode 100644 index e7896d5..0000000 --- a/decentralized/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod communities; -pub mod local_auth; diff --git a/decentralized/unused-Cargo.toml b/decentralized/unused-Cargo.toml deleted file mode 100644 index 8af10a1..0000000 --- a/decentralized/unused-Cargo.toml +++ /dev/null @@ -1,60 +0,0 @@ -[package] -name = "decentralized" -version = "0.1.0" -edition = "2024" - -[dependencies] -ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } -ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-native" } -iota-logger = { path = "../iota-logger" } -iota-util = { path = "../iota-util" } -iota-storage = { path = "../iota-storage" } -iota-state = { path = "../iota-state" } - -actix-web = { version = "4", features = ["rustls-0_23"] } -actix-web-actors = "4" -aes-gcm = "0.10.3" -async-trait = "0.1.89" -base64 = "0.22.1" -chrono = "0.4.43" -crossterm = "*" -dashmap = "6.1.0" -futures = "*" -futures-util = "*" -hex = "*" -hkdf = "0.12.4" -hyper = { version = "1.8.1", features = [ - "capi", - "client", - "full", - "http1", - "http2", - "nightly", - "server", -] } -hyper-util = { version = "*" } -json = "*" -lazy_static = "1.5.0" -once_cell = "1.21.3" -open = "5.3.3" -pnet = "0.35.0" -rand = "0.8" -rand_core = { version = "0.6", features = ["getrandom", "std"] } -ratatui = "0.30.0" -reqwest = "0.13.2" -rusqlite = "0.39.0" -rustls = { version = "0.23.37", features = ["aws-lc-rs"] } -rustls-pemfile = "2.2.0" -serde_json = "1.0.149" -sha2 = "0.10.9" -strum = "0.27.2" -strum_macros = "0.27.2" -sysinfo = "0.38.3" -tokio = { version = "1.50.0", features = ["full"] } -tokio-tungstenite = { version = "*", features = ["native-tls"] } -tungstenite = "*" -uuid = { version = "*", features = ["v4"] } -walkdir = "2.5.0" -warp = "*" -x448 = { version = "*" } -zip = "6.0.0" diff --git a/dockerfile b/dockerfile index 5f07197..ee00add 100644 --- a/dockerfile +++ b/dockerfile @@ -13,8 +13,8 @@ WORKDIR /app RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* -COPY --from=builder /app/target/release/iota-core . +COPY --from=builder /app/target/release/iota . EXPOSE 1984 -CMD ["./iota-core"] +CMD ["./iota"] \ No newline at end of file diff --git a/iota-cli/Cargo.toml b/iota-cli/Cargo.toml deleted file mode 100644 index 60a0ce1..0000000 --- a/iota-cli/Cargo.toml +++ /dev/null @@ -1,64 +0,0 @@ -[package] -name = "iota-cli" -version = "0.1.0" -edition = "2024" - -[dependencies] -iota-logger = { path = "../iota-logger" } -iota-state = { path = "../iota-state" } -iota-storage = { path = "../iota-storage" } -iota-terms = { path = "../iota-terms" } -iota-util = { path = "../iota-util" } -omikron-connector = { path = "../omikron-connector" } - - -ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } -ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-native" } - -actix-web = { version = "4", features = ["rustls-0_23"] } -actix-web-actors = "4" -aes-gcm = "0.10.3" -async-trait = "0.1.89" -base64 = "0.22.1" -chrono = "0.4.43" -crossterm = "*" -dashmap = "6.1.0" -futures = "*" -futures-util = "*" -hex = "*" -hkdf = "0.12.4" -hyper = { version = "1.8.1", features = [ - "capi", - "client", - "full", - "http1", - "http2", - "nightly", - "server", -] } -hyper-util = { version = "*" } -json = "*" -lazy_static = "1.5.0" -once_cell = "1.21.3" -open = "5.3.3" -pnet = "0.35.0" -rand = "0.8" -rand_core = { version = "0.6", features = ["getrandom", "std"] } -ratatui = "0.30.0" -reqwest = "0.13.2" -rusqlite = "0.39.0" -rustls = { version = "0.23.37", features = ["aws-lc-rs"] } -rustls-pemfile = "2.2.0" -serde_json = "1.0.149" -sha2 = "0.10.9" -strum = "0.27.2" -strum_macros = "0.27.2" -sysinfo = "0.38.3" -tokio = { version = "1.50.0", features = ["full"] } -tokio-tungstenite = { version = "*", features = ["native-tls"] } -tungstenite = "*" -uuid = { version = "*", features = ["v4"] } -walkdir = "2.5.0" -warp = "*" -x448 = { version = "*" } -zip = "6.0.0" diff --git a/iota-cli/src/app_state.rs b/iota-cli/src/app_state.rs deleted file mode 100755 index cfb4b3b..0000000 --- a/iota-cli/src/app_state.rs +++ /dev/null @@ -1 +0,0 @@ -pub use iota_state::*; diff --git a/iota-core/Cargo.toml b/iota-core/Cargo.toml deleted file mode 100644 index acb6c34..0000000 --- a/iota-core/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "iota-core" -version = "0.1.0" -edition = "2024" - -[dependencies] -iota-cli = { path = "../iota-cli" } -iota-logger = { path = "../iota-logger" } -iota-state = { path = "../iota-state" } -iota-storage = { path = "../iota-storage" } -iota-terms = { path = "../iota-terms" } -iota-util = { path = "../iota-util" } -omikron-connector = { path = "../omikron-connector" } -web-server = { path = "../web-server" } -web-ui = { path = "../web-ui" } - -ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } -ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-native" } - -dashmap = "6.1.0" -json = "*" -once_cell = "1.21.3" -pnet = "0.35.0" -ratatui = "0.30.0" -reqwest = "0.13.2" -tokio = { version = "1.50.0", features = ["full"] } diff --git a/iota-logger/Cargo.toml b/iota-logger/Cargo.toml deleted file mode 100644 index aa71144..0000000 --- a/iota-logger/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "iota-logger" -version = "0.1.0" -edition = "2024" - -[dependencies] -ratatui = "0.30.0" -ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } -iota-state = { path = "../iota-state" } -iota-util = { path = "../iota-util" } diff --git a/iota-state/Cargo.toml b/iota-state/Cargo.toml deleted file mode 100644 index ce37258..0000000 --- a/iota-state/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "iota-state" -version = "0.1.0" -edition = "2024" - -[dependencies] -dashmap = "6.1.0" -once_cell = "1.21.3" -tokio = { version = "1.50.0", features = ["full"] } -json = "*" -sysinfo = "0.38.3" -ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } diff --git a/iota-storage/Cargo.toml b/iota-storage/Cargo.toml deleted file mode 100644 index 2baa309..0000000 --- a/iota-storage/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "iota-storage" -version = "0.1.0" -edition = "2024" - -[dependencies] -iota-logger = { path = "../iota-logger" } -iota-state = { path = "../iota-state" } -iota-util = { path = "../iota-util" } - -ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } -ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-native" } - -aes-gcm = "0.10.3" -base64 = "0.22.1" -hex = "*" -hkdf = "0.12.4" -json = "*" -once_cell = "1.21.3" -rand = "0.8" -rand_core = { version = "0.6", features = ["getrandom", "std"] } -ratatui = "0.30.0" -reqwest = "0.13.2" -rusqlite = "0.39.0" -sha2 = "0.10.9" -sysinfo = "0.38.3" -tokio = { version = "1.50.0", features = ["full"] } -uuid = { version = "*", features = ["v4"] } -walkdir = "2.5.0" -x448 = { version = "*" } -zip = "6.0.0" diff --git a/iota-storage/src/lib.rs b/iota-storage/src/lib.rs deleted file mode 100644 index 7f0e8ef..0000000 --- a/iota-storage/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod users; -pub mod util; diff --git a/iota-terms/Cargo.toml b/iota-terms/Cargo.toml deleted file mode 100644 index 607dce1..0000000 --- a/iota-terms/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "iota-terms" -version = "0.1.0" -edition = "2024" - -[dependencies] -iota-state = { path = "../iota-state" } -iota-util = { path = "../iota-util" } - -json = "*" -reqwest = "0.13.2" diff --git a/iota-terms/src/lib.rs b/iota-terms/src/lib.rs deleted file mode 100644 index 4d99cc6..0000000 --- a/iota-terms/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ - - -pub mod terms_getter; - -pub use terms_getter::Type as TermsType; -pub use terms_getter::get_current_docs; -pub use terms_getter::get_link; -pub use terms_getter::get_newest_docs; -pub use terms_getter::get_newest_link; -pub use terms_getter::get_terms; - -pub mod doc; - -pub use doc::Doc; diff --git a/iota-util/Cargo.toml b/iota-util/Cargo.toml deleted file mode 100644 index 9a1d4cb..0000000 --- a/iota-util/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "iota-util" -version = "0.1.0" -edition = "2024" - -[dependencies] - -ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } -ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-native" } - -json = "*" -pnet = "0.35.0" -ratatui = "0.30.0" -reqwest = "0.13.2" -tokio = { version = "1.50.0", features = ["full"] } -sysinfo = "0.38.3" -uuid = { version = "*", features = ["v4"] } -walkdir = "2.5.0" -zip = "6.0.0" -aes-gcm = "0.10.3" -base64 = "0.22.1" -rand_core = { version = "0.6", features = ["getrandom", "std"] } -sha2 = "0.10.9" -x448 = { version = "*" } -hkdf = "0.12.4" -once_cell = "1.21.3" -hex = "*" diff --git a/iota-util/src/lib.rs b/iota-util/src/lib.rs deleted file mode 100644 index d104f80..0000000 --- a/iota-util/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod crypto_helper; -pub mod crypto_util; -pub mod file_util; -pub mod langu; diff --git a/omikron-connector/Cargo.toml b/omikron-connector/Cargo.toml deleted file mode 100644 index 5b29a2f..0000000 --- a/omikron-connector/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "omikron-connector" -version = "0.1.0" -edition = "2024" - -[dependencies] -iota-logger = { path = "../iota-logger" } -iota-state = { path = "../iota-state" } -iota-storage = { path = "../iota-storage" } -iota-util = { path = "../iota-util" } -ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } -ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-native" } - -dashmap = "6.1.0" -json = "*" -tokio = { version = "1.50.0", features = ["full"] } -uuid = { version = "*", features = ["v4"] } -base64 = "0.22.1" -hex = "*" -rand_core = { version = "0.6", features = ["getrandom", "std"] } -sha2 = "0.10.9" -x448 = { version = "*" } diff --git a/omikron-connector/src/user_ops.rs b/omikron-connector/src/user_ops.rs deleted file mode 100644 index 1c34670..0000000 --- a/omikron-connector/src/user_ops.rs +++ /dev/null @@ -1,93 +0,0 @@ -use base64::{Engine as _, engine::general_purpose::STANDARD}; -use hex; -use iota_logger::{PrintType, log, log_cv}; -use iota_state::{RELOAD, SHUTDOWN}; -use iota_storage::users::user_manager::{add_user, save_users}; -use iota_storage::users::user_profile::UserProfile; -use iota_util::crypto_helper::public_key_to_base64; -use iota_util::file_util::save_file; -use rand_core::{OsRng, RngCore}; -use sha2::{Digest, Sha256}; -use std::time::Duration; -use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; -use x448::{PublicKey, Secret}; - -use crate::omikron_connection::OMIKRON_CONNECTION; - -pub async fn create_user(username: &str) -> (Option, Option) { - let register_cv = CommunicationValue::new(CommunicationType::get_register); - - let conn = OMIKRON_CONNECTION.clone(); - - let response_cv = match conn - .await_response(®ister_cv, Some(Duration::from_secs(20))) - .await - { - Ok(cv) => cv, - Err(_) => return (None, None), - }; - log_cv!(PrintType::Omega, response_cv); - - let user_id = match response_cv.get_data(DataTypes::user_id).as_number() { - Some(id) => id, - None => return (None, None), - }; - let mut buf = [0u8; 56]; - let mut rng = OsRng; - rng.fill_bytes(&mut buf); - let private_key = Secret::from_bytes(&buf).unwrap(); - let public_key = PublicKey::from(&private_key); - - let mut hasher = Sha256::new(); - hasher.update(&STANDARD.encode(&private_key.as_bytes()).as_bytes()); - let result = hasher.finalize(); - let private_key_hash = hex::encode(result); - - let mut bytes = [0u8; 192]; - OsRng.fill_bytes(&mut bytes); - let reset_token = STANDARD.encode(&bytes); - - let up = UserProfile::new( - user_id, - username.to_string(), - None, - STANDARD.encode(&public_key.as_bytes()), - private_key_hash, - reset_token.clone(), - ); - - let cv = CommunicationValue::new(CommunicationType::complete_register_user) - .add_data(DataTypes::user_id, DataValue::Number(user_id)) - .add_data(DataTypes::username, DataValue::Str(username.to_string())) - .add_data( - DataTypes::public_key, - DataValue::Str(public_key_to_base64(&public_key)), - ) - .add_data(DataTypes::iota_id, DataValue::Number(user_id)) - .add_data(DataTypes::reset_token, DataValue::Str(reset_token)); - - let response_cv = conn - .await_response(&cv, Some(Duration::from_secs(20))) - .await; - - if let Ok(resp) = response_cv { - log_cv!(PrintType::Omega, resp); - if !resp.is_type(CommunicationType::success) { - return (None, None); - } - } else { - return (None, None); - } - *SHUTDOWN.write().await = true; - *RELOAD.write().await = true; - log!("Created User"); - save_file( - "", - &format!("{}.tu", username), - &format!("{}::{}", user_id, STANDARD.encode(&private_key.as_bytes())), - ); - - add_user(up.clone()); - save_users(); - (Some(up), Some(STANDARD.encode(&private_key.as_bytes()))) -} diff --git a/decentralized/src/local_auth/auth_user.rs b/src/auth/auth_user.rs similarity index 100% rename from decentralized/src/local_auth/auth_user.rs rename to src/auth/auth_user.rs diff --git a/decentralized/src/local_auth/local_auth.rs b/src/auth/local_auth.rs similarity index 91% rename from decentralized/src/local_auth/local_auth.rs rename to src/auth/local_auth.rs index f9c0fd1..112ee2b 100644 --- a/decentralized/src/local_auth/local_auth.rs +++ b/src/auth/local_auth.rs @@ -1,6 +1,6 @@ use json::JsonValue; -use iota_iota_util::file_util::load_file; +use crate::util::file_util::load_file; // NOT USED AT MOMENT pub fn is_private_key_valid(user_id: &i64, key_hash: &str) -> bool { let file_contents = load_file("", "users.json"); diff --git a/decentralized/src/local_auth/mod.rs b/src/auth/mod.rs similarity index 100% rename from decentralized/src/local_auth/mod.rs rename to src/auth/mod.rs diff --git a/decentralized/src/communities/community.rs b/src/communities/community.rs similarity index 100% rename from decentralized/src/communities/community.rs rename to src/communities/community.rs diff --git a/decentralized/src/communities/community_connection.rs b/src/communities/community_connection.rs similarity index 100% rename from decentralized/src/communities/community_connection.rs rename to src/communities/community_connection.rs diff --git a/decentralized/src/communities/community_manager.rs b/src/communities/community_manager.rs similarity index 100% rename from decentralized/src/communities/community_manager.rs rename to src/communities/community_manager.rs diff --git a/decentralized/src/communities/interactables/category.rs b/src/communities/interactables/category.rs similarity index 100% rename from decentralized/src/communities/interactables/category.rs rename to src/communities/interactables/category.rs diff --git a/decentralized/src/communities/interactables/interactable.rs b/src/communities/interactables/interactable.rs similarity index 100% rename from decentralized/src/communities/interactables/interactable.rs rename to src/communities/interactables/interactable.rs diff --git a/decentralized/src/communities/interactables/registry.rs b/src/communities/interactables/registry.rs similarity index 100% rename from decentralized/src/communities/interactables/registry.rs rename to src/communities/interactables/registry.rs diff --git a/decentralized/src/communities/interactables/text_chat.rs b/src/communities/interactables/text_chat.rs similarity index 100% rename from decentralized/src/communities/interactables/text_chat.rs rename to src/communities/interactables/text_chat.rs diff --git a/decentralized/src/communities/interactables/voice_chat.rs b/src/communities/interactables/voice_chat.rs similarity index 100% rename from decentralized/src/communities/interactables/voice_chat.rs rename to src/communities/interactables/voice_chat.rs diff --git a/decentralized/src/communities/mod.rs b/src/communities/mod.rs similarity index 100% rename from decentralized/src/communities/mod.rs rename to src/communities/mod.rs diff --git a/decentralized/src/communities/perms/permission.rs b/src/communities/perms/permission.rs similarity index 100% rename from decentralized/src/communities/perms/permission.rs rename to src/communities/perms/permission.rs diff --git a/iota-state/src/lib.rs b/src/gui/app_state.rs old mode 100644 new mode 100755 similarity index 75% rename from iota-state/src/lib.rs rename to src/gui/app_state.rs index 1e5d1c2..a161226 --- a/iota-state/src/lib.rs +++ b/src/gui/app_state.rs @@ -1,35 +1,7 @@ -use dashmap::DashSet; +use crate::{ACTIVE_TASKS, APP_STATE, SHUTDOWN, gui::elements::log_card::UiLogEntry}; use json::{JsonValue, object}; -use once_cell::sync::Lazy; -use std::collections::VecDeque; -use std::sync::{Arc, LazyLock, Mutex, atomic::AtomicBool}; -use std::thread; -use std::time::Duration; +use std::{collections::VecDeque, thread, time::Duration}; use sysinfo::{RefreshKind, System}; -use tokio::sync::RwLock; - -pub const MAX_POINTS: usize = 1000; -pub const MAX_LOGS: usize = 100; - -pub static UNIQUE: AtomicBool = AtomicBool::new(true); - -#[derive(Clone, Debug)] -pub struct UiLogEntry { - pub timestamp_ms: u128, - pub sender: String, - pub message: String, - pub is_error: bool, -} - -impl UiLogEntry { - pub fn format_timestamp(&self) -> String { - let secs = (self.timestamp_ms / 1000) as i64; - let hours = (secs / 3600) % 24; - let minutes = (secs / 60) % 60; - let seconds = secs % 60; - format!("{:02}:{:02}:{:02}", hours, minutes, seconds) - } -} #[derive(Clone)] pub struct AppState { @@ -41,6 +13,8 @@ pub struct AppState { pub net_down: Vec<(f64, f64)>, pub sys_info: String, } +const MAX_POINTS: usize = 1000; +const MAX_LOGS: usize = 100; impl AppState { pub fn new() -> Self { @@ -100,17 +74,34 @@ impl AppState { self.net_down.remove(0); } } - pub fn to_json(&self) -> JsonValue { - object! { - "cpu" => self.cpu.iter().map(|(_, y)| *y).collect::>(), - "ram" => self.ram.iter().map(|(_, y)| *y).collect::>(), - "ping" => self.ping.iter().map(|(_, y)| *y).collect::>(), - "net_up" => self.net_up.iter().map(|(_, y)| *y).collect::>(), - "net_down" => self.net_down.iter().map(|(_, y)| *y).collect::>(), - } + let json = object! { + "cpu" => self.cpu + .iter() + .map(|(_, y)| *y) + .collect::>(), + "ram" => self.ram + .iter() + .map(|(_, y)| *y) + .collect::>(), + "ping" => self + .ping + .iter() + .map(|(_, y)| *y) + .collect::>(), + "net_up" => self + .net_up + .iter() + .map(|(_, y)| *y) + .collect::>(), + "net_down" => self + .net_down + .iter() + .map(|(_, y)| *y) + .collect::>(), + }; + json } - pub fn with_width(&self, width: u16) -> Self { let mut new = self.clone(); new.cpu = Self::downsample_to_fit_width(&new.cpu, width); @@ -137,9 +128,10 @@ impl AppState { .first() .map(|(x, _)| x - (dx * pad_len as f64)) .unwrap_or(0.0); + let _ = data.first().map(|(_, y)| *y).unwrap_or(0.0); for i in 0..pad_len { - result.push((start_x + i as f64 * dx, -1.0)); + result.push((start_x + i as f64 * dx, -1 as f64)); } result.extend_from_slice(data); @@ -148,13 +140,6 @@ impl AppState { } } -pub static APP_STATE: LazyLock>> = - LazyLock::new(|| Arc::new(Mutex::new(AppState::new()))); - -pub static SHUTDOWN: Lazy> = Lazy::new(|| RwLock::new(false)); -pub static RELOAD: Lazy> = Lazy::new(|| RwLock::new(true)); -pub static ACTIVE_TASKS: Lazy> = Lazy::new(|| DashSet::new()); - pub fn setup() { ACTIVE_TASKS.insert("System info loader".to_string()); tokio::spawn(async move { diff --git a/iota-cli/src/elements/console_card.rs b/src/gui/elements/console_card.rs similarity index 96% rename from iota-cli/src/elements/console_card.rs rename to src/gui/elements/console_card.rs index f7b0c8f..b189bd4 100644 --- a/iota-cli/src/elements/console_card.rs +++ b/src/gui/elements/console_card.rs @@ -1,9 +1,4 @@ use crossterm::event::{KeyCode, KeyEvent}; -use iota_logger::{log, log_command, log_cv}; -use iota_state::{ACTIVE_TASKS, RELOAD, SHUTDOWN}; -use iota_storage::users::{user_manager, user_profile::UserProfile}; -use iota_util::file_util; -use omikron_connector::omikron_connection::OMIKRON_CONNECTION; use ratatui::{ Frame, layout::Rect, @@ -14,6 +9,19 @@ use ratatui::{ use ttp_core::{CommunicationType, CommunicationValue}; use uuid::Uuid; +use crate::{ + ACTIVE_TASKS, RELOAD, SHUTDOWN, + gui::{ + elements::elements::{Element, InteractableElement, JoinableElement}, + interaction_result::InteractionResult, + ui::FPS, + util::borders::draw_block_joins, + }, + log, log_command, log_cv, + omikron::omikron_connection::OMIKRON_CONNECTION, + users::{user_manager, user_profile::UserProfile}, + util::file_util, +}; use std::{ any::Any, sync::{Arc, Mutex}, @@ -21,13 +29,6 @@ use std::{ }; use tokio::time::Instant; -use crate::{ - elements::elements::{Element, InteractableElement, JoinableElement}, - interaction_result::InteractionResult, - ui::FPS, - util::borders::draw_block_joins, -}; - pub struct ConsoleCard { focused: bool, pub title: String, @@ -424,8 +425,7 @@ pub async fn run_command(command: &str) { ping(time).await; } ["user", "add", username] => { - if let (Some(user), Some(_)) = omikron_connector::user_ops::create_user(username).await - { + if let (Some(user), Some(_)) = user_manager::create_user(username).await { log!("Created user {}", user.user_id); } else { log!("Failed to create user"); diff --git a/iota-cli/src/elements/elements.rs b/src/gui/elements/elements.rs similarity index 94% rename from iota-cli/src/elements/elements.rs rename to src/gui/elements/elements.rs index abe9ab9..3429e52 100644 --- a/iota-cli/src/elements/elements.rs +++ b/src/gui/elements/elements.rs @@ -3,7 +3,7 @@ use std::any::Any; use crossterm::event::KeyEvent; use ratatui::{Frame, layout::Rect, widgets::Borders}; -use crate::{interaction_result::InteractionResult, screens::screens::Screen}; +use crate::gui::{interaction_result::InteractionResult, screens::screens::Screen}; #[allow(unused)] pub trait Element: Send + Sync + Any { diff --git a/iota-cli/src/elements/graph_card.rs b/src/gui/elements/graph_card.rs similarity index 95% rename from iota-cli/src/elements/graph_card.rs rename to src/gui/elements/graph_card.rs index c7ec2d6..d95f937 100644 --- a/iota-cli/src/elements/graph_card.rs +++ b/src/gui/elements/graph_card.rs @@ -1,7 +1,6 @@ use std::{any::Any, sync::Arc}; use crossterm::event::KeyEvent; -use iota_state::APP_STATE; use ratatui::{ Frame, layout::Rect, @@ -13,10 +12,13 @@ use ratatui::{ }; use crate::{ - elements::elements::{Element, InteractableElement, JoinableElement}, - interaction_result::InteractionResult, - ui::UI, - util::borders::draw_block_joins, + APP_STATE, + gui::{ + elements::elements::{Element, InteractableElement, JoinableElement}, + interaction_result::InteractionResult, + ui::UI, + util::borders::draw_block_joins, + }, }; pub enum GRAPHS { diff --git a/iota-cli/src/elements/log_card.rs b/src/gui/elements/log_card.rs similarity index 93% rename from iota-cli/src/elements/log_card.rs rename to src/gui/elements/log_card.rs index a0ce8fd..e2d4ba1 100755 --- a/iota-cli/src/elements/log_card.rs +++ b/src/gui/elements/log_card.rs @@ -1,9 +1,9 @@ -use crate::app_state::APP_STATE; -use crate::elements::elements::{Element, InteractableElement, JoinableElement}; -use crate::interaction_result::InteractionResult; -use crate::util::borders::draw_block_joins; +use crate::APP_STATE; +use crate::gui::elements::elements::{Element, InteractableElement, JoinableElement}; +use crate::gui::interaction_result::InteractionResult; +use crate::gui::util::borders::draw_block_joins; +use crate::util::logger::PrintType; use crossterm::event::{KeyCode, KeyEvent}; -use iota_logger::PrintType; use ratatui::{ Frame, layout::Rect, @@ -90,24 +90,7 @@ impl LogCard { fn get_logs(&self) -> Vec { let state = APP_STATE.lock().unwrap(); - state - .get_logs() - .iter() - .map(|e| UiLogEntry { - timestamp_ms: e.timestamp_ms, - sender: match e.sender.as_str() { - "Call" => PrintType::Call, - "Client" => PrintType::Client, - "Iota" => PrintType::Iota, - "Omikron" => PrintType::Omikron, - "Omega" => PrintType::Omega, - "Command" => PrintType::Command, - _ => PrintType::General, - }, - message: e.message.clone(), - is_error: e.is_error, - }) - .collect() + state.get_logs().iter().cloned().collect() } fn find_split_point(s: &str, max_width: usize) -> usize { diff --git a/iota-cli/src/input_handler.rs b/src/gui/input_handler.rs similarity index 96% rename from iota-cli/src/input_handler.rs rename to src/gui/input_handler.rs index 524ce2e..b2557c5 100644 --- a/iota-cli/src/input_handler.rs +++ b/src/gui/input_handler.rs @@ -1,6 +1,6 @@ -use crate::ui::UI; +use crate::gui::ui::{UI, UNIQUE}; +use crate::{RELOAD, SHUTDOWN}; use crossterm::event::{Event, KeyEvent, KeyEventKind, KeyModifiers, poll, read}; -use iota_state::{RELOAD, SHUTDOWN, UNIQUE}; use std::sync::Arc; use std::sync::atomic::Ordering; use std::time::Duration; diff --git a/iota-cli/src/interaction_result.rs b/src/gui/interaction_result.rs similarity index 97% rename from iota-cli/src/interaction_result.rs rename to src/gui/interaction_result.rs index f9ba7e0..462149a 100644 --- a/iota-cli/src/interaction_result.rs +++ b/src/gui/interaction_result.rs @@ -2,7 +2,7 @@ use std::fmt::{Debug, Formatter}; use std::future::Future; use std::pin::Pin; -use crate::screens::screens::Screen; +use crate::gui::screens::screens::Screen; #[allow(unused)] pub enum InteractionResult { diff --git a/iota-cli/src/lib.rs b/src/gui/mod.rs similarity index 89% rename from iota-cli/src/lib.rs rename to src/gui/mod.rs index aaa23ef..b355046 100644 --- a/iota-cli/src/lib.rs +++ b/src/gui/mod.rs @@ -13,8 +13,6 @@ pub mod screens { } pub mod util { pub mod borders; - pub mod buttons; - pub mod terms_focus; } pub mod app_state; pub mod input_handler; diff --git a/iota-cli/src/screens/main_screen.rs b/src/gui/screens/main_screen.rs similarity index 99% rename from iota-cli/src/screens/main_screen.rs rename to src/gui/screens/main_screen.rs index e10947d..85dbbaa 100644 --- a/iota-cli/src/screens/main_screen.rs +++ b/src/gui/screens/main_screen.rs @@ -1,4 +1,4 @@ -use crate::{ +use crate::gui::{ elements::{ console_card::ConsoleCard, elements::{InteractableElement, JoinableElement}, diff --git a/iota-cli/src/screens/md_viewer.rs b/src/gui/screens/md_viewer.rs similarity index 99% rename from iota-cli/src/screens/md_viewer.rs rename to src/gui/screens/md_viewer.rs index 2faa2f1..10eabce 100644 --- a/iota-cli/src/screens/md_viewer.rs +++ b/src/gui/screens/md_viewer.rs @@ -7,7 +7,7 @@ use ratatui::{ }; use std::{any::Any, time::Duration}; -use crate::{interaction_result::InteractionResult, screens::screens::Screen}; +use crate::gui::{interaction_result::InteractionResult, screens::screens::Screen}; pub struct FileViewer { title: String, diff --git a/iota-cli/src/screens/screens.rs b/src/gui/screens/screens.rs similarity index 89% rename from iota-cli/src/screens/screens.rs rename to src/gui/screens/screens.rs index 7606521..9676fbb 100644 --- a/iota-cli/src/screens/screens.rs +++ b/src/gui/screens/screens.rs @@ -3,7 +3,7 @@ use std::any::Any; use crossterm::event::KeyEvent; use ratatui::{Frame, layout::Rect}; -use crate::interaction_result::InteractionResult; +use crate::gui::interaction_result::InteractionResult; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum NavDirection { diff --git a/iota-cli/src/screens/terms_checker.rs b/src/gui/screens/terms_checker.rs similarity index 94% rename from iota-cli/src/screens/terms_checker.rs rename to src/gui/screens/terms_checker.rs index 0d64187..26bb7c6 100644 --- a/iota-cli/src/screens/terms_checker.rs +++ b/src/gui/screens/terms_checker.rs @@ -1,14 +1,17 @@ use crate::{ - interaction_result::InteractionResult, - screens::{md_viewer::FileViewer, screens::Screen}, - ui::UI, - util::{ + gui::{ + interaction_result::InteractionResult, + screens::{md_viewer::FileViewer, screens::Screen}, + ui::UI, + }, + terms::{ buttons::{checkbox, draw_buttons}, - terms_focus::Focus, + consent_state::UserChoice, + focus::Focus, + terms_getter::{Type, get_link, get_terms}, }, }; use crossterm::event::{KeyCode, KeyEvent}; -use iota_terms::{TermsType, get_link, get_terms}; use ratatui::{ Frame, layout::{Alignment, Constraint, Direction, Layout, Rect}, @@ -19,13 +22,6 @@ use ratatui::{ use std::{any::Any, pin::Pin, sync::Arc}; use tokio::sync::oneshot; -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum UserChoice { - Deny, - AcceptEULA, - AcceptAll, -} - pub struct TermsCheckerScreen { ui: Arc, sender: Option>, @@ -280,9 +276,9 @@ impl Screen for TermsCheckerScreen { } KeyCode::Char('o') | KeyCode::Char('O') => { let terms_type = match self.focus { - Focus::Eula => Some(TermsType::EULA), - Focus::Tos => Some(TermsType::TOS), - Focus::Pp => Some(TermsType::PP), + Focus::Eula => Some(Type::EULA), + Focus::Tos => Some(Type::TOS), + Focus::Pp => Some(Type::PP), _ => None, }; if let Some(terms_type) = terms_type { @@ -300,15 +296,15 @@ impl Screen for TermsCheckerScreen { } KeyCode::Char('l') | KeyCode::Char('L') => match self.focus { Focus::Eula => { - let _ = open::that(get_link(TermsType::EULA)); + let _ = open::that(get_link(Type::EULA)); InteractionResult::Handled } Focus::Tos => { - let _ = open::that(get_link(TermsType::TOS)); + let _ = open::that(get_link(Type::TOS)); InteractionResult::Handled } Focus::Pp => { - let _ = open::that(get_link(TermsType::PP)); + let _ = open::that(get_link(Type::PP)); InteractionResult::Handled } _ => InteractionResult::Unhandled, diff --git a/iota-cli/src/screens/terms_updater.rs b/src/gui/screens/terms_updater.rs similarity index 97% rename from iota-cli/src/screens/terms_updater.rs rename to src/gui/screens/terms_updater.rs index ee91cba..35da364 100644 --- a/iota-cli/src/screens/terms_updater.rs +++ b/src/gui/screens/terms_updater.rs @@ -1,15 +1,18 @@ -use crate::screens::terms_checker::UserChoice; use crate::{ - interaction_result::InteractionResult, - screens::{md_viewer::FileViewer, screens::Screen}, - util::{ + gui::{ + interaction_result::InteractionResult, + screens::{md_viewer::FileViewer, screens::Screen}, + }, + terms::{ buttons::{checkbox, draw_buttons}, - terms_focus::Focus, + consent_state::{UpdateDecision, UserChoice}, + doc::Doc, + focus::Focus, + terms_getter::{Type, get_newest_link, get_terms}, }, }; use chrono::{Local, TimeZone, Utc}; use crossterm::event::{KeyCode, KeyEvent}; -use iota_terms::{Doc, TermsType, get_newest_link, get_terms}; use ratatui::{ Frame, layout::{Alignment, Constraint, Direction, Layout, Rect}, @@ -20,13 +23,6 @@ use ratatui::{ use std::any::Any; use tokio::sync::oneshot; -#[derive(Debug, Clone)] -pub enum UpdateDecision { - NoChange, - Future { newest: Doc }, - Forced(Doc), -} - pub struct TermsUpdaterScreen { sender: Option>, @@ -648,9 +644,9 @@ impl Screen for TermsUpdaterScreen { }, KeyCode::Char('o') | KeyCode::Char('O') => { let terms_type = match self.focus { - Focus::Eula => Some(TermsType::EULA), - Focus::Tos => Some(TermsType::TOS), - Focus::Pp => Some(TermsType::PP), + Focus::Eula => Some(Type::EULA), + Focus::Tos => Some(Type::TOS), + Focus::Pp => Some(Type::PP), _ => None, }; @@ -668,15 +664,15 @@ impl Screen for TermsUpdaterScreen { } KeyCode::Char('l') | KeyCode::Char('L') => match self.focus { Focus::Eula => { - let _ = open::that(get_newest_link(TermsType::EULA)); + let _ = open::that(get_newest_link(Type::EULA)); InteractionResult::Handled } Focus::Tos => { - let _ = open::that(get_newest_link(TermsType::TOS)); + let _ = open::that(get_newest_link(Type::TOS)); InteractionResult::Handled } Focus::Pp => { - let _ = open::that(get_newest_link(TermsType::PP)); + let _ = open::that(get_newest_link(Type::PP)); InteractionResult::Handled } _ => InteractionResult::Unhandled, diff --git a/iota-cli/src/tui.rs b/src/gui/tui.rs similarity index 100% rename from iota-cli/src/tui.rs rename to src/gui/tui.rs diff --git a/iota-cli/src/ui.rs b/src/gui/ui.rs similarity index 95% rename from iota-cli/src/ui.rs rename to src/gui/ui.rs index 723babe..5903a4b 100644 --- a/iota-cli/src/ui.rs +++ b/src/gui/ui.rs @@ -1,9 +1,11 @@ use crate::{ - input_handler::setup_input_handler, interaction_result::InteractionResult, - screens::screens::Screen, + ACTIVE_TASKS, SHUTDOWN, + gui::{ + input_handler::setup_input_handler, interaction_result::InteractionResult, + screens::screens::Screen, + }, }; use crossterm::event::KeyEvent; -use iota_state::{ACTIVE_TASKS, SHUTDOWN, UNIQUE}; use once_cell::sync::Lazy; use ratatui::{Terminal, backend::CrosstermBackend, init}; use std::{ @@ -18,6 +20,7 @@ use std::{ use tokio::{sync::RwLock, time::Instant}; /// UI state and rendering +pub static UNIQUE: AtomicBool = AtomicBool::new(true); pub static FPS: Lazy> = Lazy::new(|| RwLock::new((0.0, 0.0))); diff --git a/iota-cli/src/util/borders.rs b/src/gui/util/borders.rs similarity index 100% rename from iota-cli/src/util/borders.rs rename to src/gui/util/borders.rs diff --git a/iota-util/src/langu/language_creator.rs b/src/langu/language_creator.rs similarity index 98% rename from iota-util/src/langu/language_creator.rs rename to src/langu/language_creator.rs index e740e5b..fc6d1c5 100644 --- a/iota-util/src/langu/language_creator.rs +++ b/src/langu/language_creator.rs @@ -1,4 +1,4 @@ -use crate::file_util::save_file; +use crate::util::file_util::save_file; use json::{self, JsonError, JsonValue}; pub fn create_languages() -> Result<(), JsonError> { diff --git a/iota-util/src/langu/language_manager.rs b/src/langu/language_manager.rs similarity index 98% rename from iota-util/src/langu/language_manager.rs rename to src/langu/language_manager.rs index 0dcfa70..c903886 100644 --- a/iota-util/src/langu/language_manager.rs +++ b/src/langu/language_manager.rs @@ -1,4 +1,4 @@ -use crate::file_util::{self}; +use crate::util::file_util::{self}; use json::parse; use once_cell::sync::Lazy; use std::collections::HashMap; diff --git a/iota-util/src/langu/mod.rs b/src/langu/mod.rs similarity index 100% rename from iota-util/src/langu/mod.rs rename to src/langu/mod.rs diff --git a/iota-core/src/main.rs b/src/main.rs similarity index 82% rename from iota-core/src/main.rs rename to src/main.rs index 67f72e2..5df39b6 100644 --- a/iota-core/src/main.rs +++ b/src/main.rs @@ -1,18 +1,39 @@ -mod consent_state; +use dashmap::DashSet; +use once_cell::sync::Lazy; use pnet::datalink::NetworkInterface; +use std::sync::Arc; +use std::sync::LazyLock; +use std::sync::Mutex; +use tokio::sync::RwLock; use tokio::time::{Duration, sleep}; -use iota_state::{ACTIVE_TASKS, APP_STATE, AppState, RELOAD, SHUTDOWN}; +mod auth; +mod gui; +mod langu; +mod omikron; +mod terms; +mod users; +mod util; -use iota_cli::screens::main_screen::MainScreen; -use iota_cli::ui::start_tui; -use iota_logger as logger; -use iota_logger::{log, log_t}; -use iota_storage::users::user_manager; -use iota_storage::util::config_util::CONFIG; -use iota_util::file_util::{download_and_extract_zip, has_dir}; -use iota_util::langu::language_creator; -use omikron_connector as omikron; +use crate::gui::app_state; +use crate::gui::app_state::AppState; +use crate::gui::screens::main_screen::MainScreen; +use crate::gui::ui::start_tui; +use crate::langu::language_creator; +use crate::omikron::omikron_connection::OmikronConnection; +use crate::terms::consent_state; +use crate::users::user_manager; +use crate::util::config_util::CONFIG; +use crate::util::file_util::download_and_extract_zip; +use crate::util::file_util::has_dir; +use crate::util::logger; + +pub static APP_STATE: LazyLock>> = + LazyLock::new(|| Arc::new(Mutex::new(AppState::new()))); + +pub static SHUTDOWN: Lazy> = Lazy::new(|| RwLock::new(false)); +pub static RELOAD: Lazy> = Lazy::new(|| RwLock::new(true)); +pub static ACTIVE_TASKS: Lazy> = Lazy::new(|| DashSet::new()); #[tokio::main(flavor = "multi_thread", worker_threads = 16)] #[allow(unused_must_use, dead_code)] @@ -52,7 +73,7 @@ async fn main() { println!("You can find this at 'agreements'!"); return; } - iota_state::setup(); + app_state::setup(); let main_screen = MainScreen::new(ui.clone()).await; ui.set_screen(Box::new(main_screen)).await; diff --git a/omikron-connector/src/lib.rs b/src/omikron/mod.rs similarity index 74% rename from omikron-connector/src/lib.rs rename to src/omikron/mod.rs index 5d9124d..acb0f59 100644 --- a/omikron-connector/src/lib.rs +++ b/src/omikron/mod.rs @@ -1,3 +1,2 @@ pub mod omikron_connection; pub mod ping_pong_task; -pub mod user_ops; diff --git a/omikron-connector/src/omikron_connection.rs b/src/omikron/omikron_connection.rs similarity index 90% rename from omikron-connector/src/omikron_connection.rs rename to src/omikron/omikron_connection.rs index 4e8af77..240da6f 100755 --- a/omikron-connector/src/omikron_connection.rs +++ b/src/omikron/omikron_connection.rs @@ -1,15 +1,13 @@ +use crate::users::contact::Contact; +use crate::util::chat_files::{MessageState, change_message_state}; +use crate::util::chats_util::{get_user, mod_user}; +use crate::util::communities_util::CommunitiesUtil; +use crate::util::crypto_util::{DataFormat, SecurePayload}; +use crate::util::file_util::{get_children, load_file, save_file}; +use crate::util::{chat_files, chats_util}; +use crate::util::{config_util::CONFIG, crypto_helper}; +use crate::{ACTIVE_TASKS, SHUTDOWN, log, log_cv_in, log_cv_out, log_t}; use dashmap::DashMap; -use iota_logger::{log, log_cv_in, log_cv_out, log_t}; -use iota_state::{ACTIVE_TASKS, SHUTDOWN}; -use iota_storage::users::contact::Contact; -use iota_storage::util::chat_files::{MessageState, change_message_state}; -use iota_storage::util::chats_util::{get_user, mod_user}; -use iota_storage::util::communities_util::CommunitiesUtil; -use iota_storage::util::config_util::CONFIG; -use iota_storage::util::{chat_files, chats_util}; -use iota_util::crypto_helper; -use iota_util::crypto_util::{DataFormat, SecurePayload}; -use iota_util::file_util::{get_children, load_file, save_file}; use json::JsonValue; use std::collections::HashMap; use std::sync::{Arc, LazyLock}; @@ -225,15 +223,15 @@ impl OmikronConnection { *self.sender.write().await = Some(sender_arc.clone()); *self.state.write().await = ConnectionState::Connected { identified: false }; + // Handle registration/identification + self.handle_authentication().await; + // Start read loop let read_self = self.clone(); let read_handle = tokio::spawn(async move { read_self.read_loop(&mut receiver).await; }); - // Handle registration/identification - self.handle_authentication().await; - // Start heartbeat let heartbeat_self = self.clone(); let heartbeat_handle = tokio::spawn(async move { @@ -280,26 +278,26 @@ impl OmikronConnection { let private_key = conf.get_private_key(); drop(conf); - if iota_id == 0 { + if iota_id == 0 || public_key.is_none() || private_key.is_none() { log_t!("iota_register_new"); - let (pub_k, priv_k) = if let (Some(pk), Some(sk)) = (public_key, private_key) { - (pk, sk) - } else { - let key_pair = crypto_helper::generate_keypair(); - let public_key_base64 = crypto_helper::public_key_to_base64(&key_pair.public); - let private_key_base64 = crypto_helper::secret_key_to_base64(&key_pair.secret); + let key_pair = crypto_helper::generate_keypair(); + let public_key_base64 = crypto_helper::public_key_to_base64(&key_pair.public); + let _private_key_base64 = crypto_helper::secret_key_to_base64(&key_pair.secret); - let mut conf_write = CONFIG.write().await; - conf_write.change("public_key", JsonValue::from(public_key_base64.clone())); - conf_write.change("private_key", JsonValue::from(private_key_base64.clone())); - conf_write.update(); - drop(conf_write); - (public_key_base64, private_key_base64) - }; + let mut conf_write = CONFIG.write().await; + // NOTE: + // Intentionally not storing the generated private/public keys directly into the + // config file here to avoid persisting sensitive material in plaintext. If you + // want to persist them, uncomment the two lines below and accept the security + // implications (they will be saved by `conf_write.update()`). + // conf_write.change("public_key", DataValue::Str(public_key_base64.clone())); + // conf_write.change("private_key", DataValue::Str(private_key_base64)); + conf_write.update(); + drop(conf_write); let register_msg = CommunicationValue::new(CommunicationType::register_iota) - .add_data(DataTypes::public_key, DataValue::Str(pub_k)); + .add_data(DataTypes::public_key, DataValue::Str(public_key_base64)); let msg_id = register_msg.get_id(); @@ -311,7 +309,7 @@ impl OmikronConnection { return false; } - let iota_value = cv.get_data(DataTypes::iota_id); + let iota_value = cv.get_data(DataTypes::register_id); let iota_id = iota_value.as_number().unwrap_or(0); if iota_id != 0 { @@ -424,68 +422,6 @@ impl OmikronConnection { return; } - if cv.is_type(CommunicationType::client_connected) { - let user_id = cv.get_data(DataTypes::user_id).as_number().unwrap_or(0) as i64; - let session_id = cv.get_data(DataTypes::session_id).as_number().unwrap_or(0) as i64; - - let mut contacts = chats_util::get_users(user_id); - let mut contacts_array = Vec::new(); - - for (i, contact) in contacts.iter().enumerate() { - let mut contact_container = Vec::new(); - contact_container.push((DataTypes::user_id, DataValue::Number(contact.user_id))); - contact_container.push(( - DataTypes::last_message_at, - DataValue::Number(contact.last_message_at.unwrap_or(0)), - )); - - if let Some(ref name) = contact.user_name { - contact_container.push((DataTypes::username, DataValue::Str(name.clone()))); - } - - let amount = if i < 10 { 20 } else { 1 }; - let messages = chat_files::get_messages(user_id, contact.user_id, 0, amount); - - let mut msg_array = Vec::new(); - for m in messages.members() { - let message_time = m["message_time"].as_i64().unwrap_or(0); - let content = m["content"].as_str().unwrap_or("").to_string(); - let sent_by_self = m["sent_by_self"].as_bool().unwrap_or(false); - let height = m["height"].as_i64().unwrap_or(0); - let message_state = m["message_state"].as_str().unwrap_or("").to_string(); - - let mut msg_container = Vec::new(); - msg_container.push((DataTypes::send_time, DataValue::Number(message_time))); - msg_container.push((DataTypes::content, DataValue::Str(content.clone()))); - msg_container.push((DataTypes::message_state, DataValue::Str(message_state))); - msg_container.push((DataTypes::height, DataValue::Number(height))); - msg_container.push((DataTypes::sent_by_self, DataValue::Bool(sent_by_self))); - msg_array.push(DataValue::Container(msg_container)); - - if msg_array.len() == 1 { - let sender_id = if sent_by_self { - user_id - } else { - contact.user_id - }; - let mut last_msg = Vec::new(); - last_msg.push((DataTypes::content, DataValue::Str(content))); - last_msg.push((DataTypes::sender_id, DataValue::Number(sender_id))); - contact_container - .push((DataTypes::last_message, DataValue::Container(last_msg))); - } - } - contact_container.push((DataTypes::messages, DataValue::Array(msg_array))); - contacts_array.push(DataValue::Container(contact_container)); - } - - let resp = CommunicationValue::new(CommunicationType::client_connected) - .with_id(cv.get_id()) - .add_data(DataTypes::contacts, DataValue::Array(contacts_array)); - self.send_message(&resp).await; - return; - } - if cv.is_type(CommunicationType::identification_response) { if let Some(_accepted) = cv.get_data(DataTypes::accepted).as_bool() { let mut state = self.state.write().await; @@ -641,7 +577,7 @@ impl OmikronConnection { .with_sender(receiver_id as u64) .add_data( DataTypes::chat_partner_id, - DataValue::Number(receiver_id as i64), + DataValue::Number(sender_id as i64), ) .add_data(DataTypes::send_time, DataValue::Number(timestamp_i64)) .add_data( diff --git a/omikron-connector/src/ping_pong_task.rs b/src/omikron/ping_pong_task.rs similarity index 92% rename from omikron-connector/src/ping_pong_task.rs rename to src/omikron/ping_pong_task.rs index 26bec38..f1a891f 100644 --- a/omikron-connector/src/ping_pong_task.rs +++ b/src/omikron/ping_pong_task.rs @@ -1,6 +1,5 @@ -use crate::omikron_connection::OmikronConnection; -use iota_state::APP_STATE; -use iota_logger::log; +use crate::omikron::omikron_connection::OmikronConnection; +use crate::{APP_STATE, log}; use dashmap::DashMap; use std::sync::LazyLock; use std::time::Instant; diff --git a/web-ui/src/api.rs b/src/server/api.rs similarity index 74% rename from web-ui/src/api.rs rename to src/server/api.rs index 26a0544..f9a87a4 100755 --- a/web-ui/src/api.rs +++ b/src/server/api.rs @@ -1,6 +1,6 @@ -use crate::server::is_local_network; +use crate::server::server::is_local_network; +use crate::util::config_util::CONFIG; use actix_web::{HttpRequest, HttpResponse, Responder, web}; -use iota_storage::util::config_util::CONFIG; use serde_json::{Value, json}; use std::net::SocketAddr; use std::sync::Arc; @@ -56,15 +56,15 @@ async fn communities_get(req: HttpRequest, ssl: web::Data) -> impl Respond return forbidden(); } - // let communities = decentralized::communities::community_manager::get_communities().await; + let communities = crate::communities::community_manager::get_communities().await; - let list: Vec = Vec::new(); + let mut list = Vec::new(); - // for c in communities { - // let val = c.frontend().await.to_string(); - // let s_val: Value = serde_json::from_str(&val).unwrap_or(Value::Null); - // list.push(s_val); - // } + for c in communities { + let val = c.frontend().await; + let s_val: Value = serde_json::to_value(val.to_string()).unwrap(); + list.push(s_val); + } HttpResponse::Ok().json(list) } @@ -77,13 +77,12 @@ async fn communities_add( return forbidden(); } - // let name = payload["name"].as_str().unwrap_or("").to_string(); - // let owner = payload["owner"].as_i64().unwrap_or(0); + let name = payload["name"].as_str().unwrap_or("").to_string(); + let owner = payload["owner"].as_i64().unwrap_or(0); - // let community = - // Arc::new(decentralized::communities::community::Community::create(name, owner).await); + let community = Arc::new(crate::communities::community::Community::create(name, owner).await); - // decentralized::communities::community_manager::add_community(community).await; + crate::communities::community_manager::add_community(community).await; success() } @@ -93,13 +92,13 @@ async fn users_get(req: HttpRequest, ssl: web::Data) -> impl Responder { return forbidden(); } - let users = iota_storage::users::user_manager::get_users(); + let users = crate::users::user_manager::get_users(); let list: Vec<_> = users .into_iter() .map(|u| { - let val = u.frontend().to_string(); - serde_json::from_str(&val).unwrap_or(Value::Null) + let val = u.frontend(); + serde_json::to_value(val.to_string()).unwrap() }) .collect(); @@ -117,8 +116,8 @@ async fn users_remove( let uuid = payload.get("uuid").and_then(|v| v.as_i64()).unwrap_or(0); - iota_storage::users::user_manager::remove_user(uuid); - iota_storage::users::user_manager::save_users(); + crate::users::user_manager::remove_user(uuid); + crate::users::user_manager::save_users(); success() } @@ -137,9 +136,9 @@ async fn users_add( _ => return error(), }; - if let (Some(user), Some(_)) = omikron_connector::user_ops::create_user(username).await { - let val = user.frontend().to_string(); - let s_val: Value = serde_json::from_str(&val).unwrap_or(Value::Null); + if let (Some(user), Some(_)) = crate::users::user_manager::create_user(username).await { + let val = user.frontend(); + let s_val: Value = serde_json::to_value(val.to_string()).unwrap(); HttpResponse::Ok().json(s_val) } else { error() @@ -151,7 +150,7 @@ async fn shutdown(req: HttpRequest, ssl: web::Data) -> impl Responder { return forbidden(); } - *iota_state::SHUTDOWN.write().await = true; + *crate::SHUTDOWN.write().await = true; success() } @@ -160,8 +159,8 @@ async fn reload(req: HttpRequest, ssl: web::Data) -> impl Responder { return forbidden(); } - *iota_state::SHUTDOWN.write().await = true; - *iota_state::RELOAD.write().await = true; + *crate::SHUTDOWN.write().await = true; + *crate::RELOAD.write().await = true; success() } diff --git a/web-ui/src/lib.rs b/src/server/mod.rs similarity index 100% rename from web-ui/src/lib.rs rename to src/server/mod.rs diff --git a/web-ui/src/server.rs b/src/server/server.rs similarity index 88% rename from web-ui/src/server.rs rename to src/server/server.rs index 9902fe0..b55a50f 100644 --- a/web-ui/src/server.rs +++ b/src/server/server.rs @@ -1,9 +1,10 @@ -use crate::api::api_config; -use crate::web_path_parser; +use crate::log; +use crate::server::api::api_config; +use crate::server::web_path_parser; +use crate::util::file_util::load_file_buf; +use crate::{ACTIVE_TASKS, SHUTDOWN}; use actix_web::{App, Error, HttpRequest, HttpServer, Responder, dev::ServerHandle, web}; -use iota_logger::log; -use iota_state::{ACTIVE_TASKS, SHUTDOWN}; -use iota_util::file_util::load_file_buf; +use actix_web_actors::ws; use rustls::ServerConfig; use rustls::pki_types::{CertificateDer, PrivateKeyDer}; use std::{ @@ -14,6 +15,13 @@ use std::{ time::Duration, }; +async fn ws_handler(req: HttpRequest, stream: web::Payload) -> Result { + let path = req.path().to_string(); + log!("WS connection from {:?}", req.peer_addr()); + let session = WsSession::new(path); + ws::start(session, &req, stream) +} + use tokio::sync::oneshot; pub async fn start(port: u16) -> bool { @@ -28,6 +36,7 @@ pub async fn start(port: u16) -> bool { App::new() .app_data(web::Data::new(true)) .configure(api_config) + .service(web::resource("/ws/{path:.*}").route(web::get().to(ws_handler))) .default_service(web::to(web_path_parser::handle)) }) .bind(("0.0.0.0", port)) @@ -40,6 +49,7 @@ pub async fn start(port: u16) -> bool { App::new() .app_data(web::Data::new(false)) .configure(api_config) + .service(web::resource("/ws/{path:.*}").route(web::get().to(ws_handler))) .default_service(web::to(web_path_parser::handle)) }) .bind(("0.0.0.0", port)) diff --git a/web-ui/src/web_path_parser.rs b/src/server/web_path_parser.rs similarity index 98% rename from web-ui/src/web_path_parser.rs rename to src/server/web_path_parser.rs index 2eaf3cf..a82c8db 100755 --- a/web-ui/src/web_path_parser.rs +++ b/src/server/web_path_parser.rs @@ -1,7 +1,7 @@ use actix_web::{HttpRequest, HttpResponse}; use std::path::{Path, PathBuf}; -use iota_util::file_util::load_file_vec; +use crate::util::file_util::load_file_vec; fn codec_for_ext(ext: &str) -> &'static str { match ext { diff --git a/iota-cli/src/util/buttons.rs b/src/terms/buttons.rs similarity index 99% rename from iota-cli/src/util/buttons.rs rename to src/terms/buttons.rs index 6c93cce..c545a4c 100644 --- a/iota-cli/src/util/buttons.rs +++ b/src/terms/buttons.rs @@ -5,7 +5,7 @@ use ratatui::{ widgets::{Block, Borders, Paragraph}, }; -use crate::util::terms_focus::Focus; +use crate::terms::focus::Focus; #[allow(mismatched_lifetime_syntaxes)] pub fn checkbox(label: &str, checked: bool, active: bool, allowed: bool) -> Line { diff --git a/iota-core/src/consent_state.rs b/src/terms/consent_state.rs similarity index 97% rename from iota-core/src/consent_state.rs rename to src/terms/consent_state.rs index 723c5a7..1cc6e0a 100644 --- a/iota-core/src/consent_state.rs +++ b/src/terms/consent_state.rs @@ -1,14 +1,19 @@ +use tokio::sync::oneshot; + +use crate::{ + gui::{ + screens::{terms_checker::TermsCheckerScreen, terms_updater::TermsUpdaterScreen}, + ui::UI, + }, + terms::{ + doc::Doc, + terms_getter::{Type, get_current_docs, get_newest_docs}, + }, + util::file_util::{load_file, save_file}, +}; use std::sync::Arc; use std::time::{SystemTime, UNIX_EPOCH}; -use tokio::sync::oneshot; -use iota_cli::ui::UI; -use iota_cli::screens::terms_checker::{TermsCheckerScreen, UserChoice}; -use iota_cli::screens::terms_updater::{TermsUpdaterScreen, UpdateDecision}; -use iota_terms::{Doc, get_current_docs, get_newest_docs, TermsType as Type}; -use iota_util::file_util::{load_file, save_file}; - - pub async fn check(ui: Arc) -> (bool, bool) { let mut state = ConsentState::load_state(); @@ -211,6 +216,19 @@ async fn get_updates() -> Option<( } } +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum UserChoice { + Deny, + AcceptEULA, + AcceptAll, +} + +#[derive(Debug, Clone, PartialEq)] +pub enum UpdateDecision { + NoChange, + Future { newest: Doc }, + Forced(Doc), +} #[derive(Debug, Clone)] pub struct ConsentState { diff --git a/iota-terms/src/doc.rs b/src/terms/doc.rs similarity index 96% rename from iota-terms/src/doc.rs rename to src/terms/doc.rs index 0c2e0d2..2365ba3 100644 --- a/iota-terms/src/doc.rs +++ b/src/terms/doc.rs @@ -1,7 +1,6 @@ use json::{JsonValue, object::Object}; -use crate::terms_getter::Type; -use iota_util::file_util::load_file; +use crate::{terms::terms_getter::Type, util::file_util::load_file}; #[derive(Clone, Debug, PartialEq, Eq)] #[allow(unused)] diff --git a/iota-cli/src/util/terms_focus.rs b/src/terms/focus.rs similarity index 100% rename from iota-cli/src/util/terms_focus.rs rename to src/terms/focus.rs diff --git a/src/terms/mod.rs b/src/terms/mod.rs new file mode 100644 index 0000000..4a11008 --- /dev/null +++ b/src/terms/mod.rs @@ -0,0 +1,5 @@ +pub mod buttons; +pub mod consent_state; +pub mod doc; +pub mod focus; +pub mod terms_getter; diff --git a/iota-terms/src/terms_getter.rs b/src/terms/terms_getter.rs similarity index 98% rename from iota-terms/src/terms_getter.rs rename to src/terms/terms_getter.rs index 65de9b1..a0fa53b 100755 --- a/iota-terms/src/terms_getter.rs +++ b/src/terms/terms_getter.rs @@ -1,6 +1,6 @@ use json::JsonValue::Object; -use crate::doc::Doc; +use crate::terms::doc::Doc; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Type { diff --git a/iota-storage/src/users/contact.rs b/src/users/contact.rs similarity index 100% rename from iota-storage/src/users/contact.rs rename to src/users/contact.rs diff --git a/iota-storage/src/users/mod.rs b/src/users/mod.rs similarity index 100% rename from iota-storage/src/users/mod.rs rename to src/users/mod.rs diff --git a/iota-storage/src/users/user_community_util.rs b/src/users/user_community_util.rs similarity index 98% rename from iota-storage/src/users/user_community_util.rs rename to src/users/user_community_util.rs index 6f01e74..45b036c 100644 --- a/iota-storage/src/users/user_community_util.rs +++ b/src/users/user_community_util.rs @@ -1,4 +1,4 @@ -use iota_util::file_util::save_file; +use crate::util::file_util::save_file; use json::{self, Array, JsonValue}; use std::fs; use std::path::Path; diff --git a/iota-storage/src/users/user_manager.rs b/src/users/user_manager.rs similarity index 53% rename from iota-storage/src/users/user_manager.rs rename to src/users/user_manager.rs index add6ea4..bcb5e26 100644 --- a/iota-storage/src/users/user_manager.rs +++ b/src/users/user_manager.rs @@ -1,9 +1,12 @@ +use crate::omikron::omikron_connection::OMIKRON_CONNECTION; use crate::users::user_profile::UserProfile; +use crate::util::crypto_helper::{self, public_key_to_base64}; +use crate::util::file_util::{load_file, save_file}; +use crate::util::logger::PrintType; +use crate::{RELOAD, SHUTDOWN}; +use crate::{log, log_cv}; use base64::{Engine as _, engine::general_purpose::STANDARD}; use hex::{self}; -use iota_logger::{log, log_cv}; -use iota_util::crypto_helper::{self, public_key_to_base64}; -use iota_util::file_util::{load_file, save_file}; use json::JsonValue; use once_cell::sync::Lazy; use rand::Rng; @@ -45,7 +48,84 @@ pub async fn load_from_tu(username: &str) -> Result<(), ()> { Ok(()) } -pub fn add_user(user: UserProfile) { USERS.lock().unwrap().push(user); } +pub async fn create_user(username: &str) -> (Option, Option) { + let register_cv = CommunicationValue::new(CommunicationType::get_register); + + let conn = OMIKRON_CONNECTION.clone(); + + let response_cv = match conn + .await_response(®ister_cv, Some(Duration::from_secs(20))) + .await + { + Ok(cv) => cv, + Err(_) => return (None, None), + }; + log_cv!(PrintType::Omega, response_cv); + + let user_id = match response_cv.get_data(DataTypes::user_id).as_number() { + Some(id) => id, + None => return (None, None), + }; + let mut buf = [0u8; 56]; + let mut rng = OsRng; + rng.fill_bytes(&mut buf); + let private_key = Secret::from_bytes(&buf).unwrap(); + let public_key = PublicKey::from(&private_key); + + let mut hasher = Sha256::new(); + hasher.update(&STANDARD.encode(&private_key.as_bytes()).as_bytes()); + let result = hasher.finalize(); + let private_key_hash = hex::encode(result); + + let mut bytes = [0u8; 192]; + OsRng.fill(bytes.as_mut()); + let reset_token = STANDARD.encode(&bytes); + + let up = UserProfile::new( + user_id, + username.to_string(), + None, + STANDARD.encode(&public_key.as_bytes()), + private_key_hash, + reset_token.clone(), + ); + + let cv = CommunicationValue::new(CommunicationType::complete_register_user) + .add_data(DataTypes::user_id, DataValue::Number(user_id)) + .add_data(DataTypes::username, DataValue::Str(username.to_string())) + .add_data( + DataTypes::public_key, + DataValue::Str(public_key_to_base64(&public_key)), + ) + .add_data(DataTypes::iota_id, DataValue::Number(user_id)) + .add_data(DataTypes::reset_token, DataValue::Str(reset_token)); + + let response_cv = conn + .await_response(&cv, Some(Duration::from_secs(20))) + .await; + + if let Ok(resp) = response_cv { + log_cv!(PrintType::Omega, resp); + if !resp.is_type(CommunicationType::success) { + return (None, None); + } + } else { + return (None, None); + } + *SHUTDOWN.write().await = true; + *RELOAD.write().await = true; + log!("Created User"); + save_file( + "", + &format!("{}.tu", username), + &format!("{}::{}", user_id, STANDARD.encode(&private_key.as_bytes())), + ); + + USERS.lock().unwrap().push(up.clone()); + save_users(); + (Some(up), Some(STANDARD.encode(&private_key.as_bytes()))) +} + pub fn get_user_by_username(username: &str) -> Option { USERS .lock() diff --git a/iota-storage/src/users/user_profile.rs b/src/users/user_profile.rs similarity index 98% rename from iota-storage/src/users/user_profile.rs rename to src/users/user_profile.rs index ba413ff..5d60277 100644 --- a/iota-storage/src/users/user_profile.rs +++ b/src/users/user_profile.rs @@ -1,6 +1,6 @@ use std::time::{SystemTime, UNIX_EPOCH}; -use iota_util::file_util::{has_file, load_file, used_dir_space}; +use crate::util::file_util::{has_file, load_file, used_dir_space}; use base64::{Engine as _, engine::general_purpose}; use json::{JsonValue, object}; use rand::Rng; diff --git a/iota-storage/src/util/chat_files.rs b/src/util/chat_files.rs similarity index 99% rename from iota-storage/src/util/chat_files.rs rename to src/util/chat_files.rs index 143aa14..e54fe29 100644 --- a/iota-storage/src/util/chat_files.rs +++ b/src/util/chat_files.rs @@ -1,5 +1,5 @@ +use crate::log; use crate::util::db; -use iota_logger::log; use json::{JsonValue, array, object}; use rusqlite::params; use std::io; diff --git a/iota-storage/src/util/chats_util.rs b/src/util/chats_util.rs similarity index 100% rename from iota-storage/src/util/chats_util.rs rename to src/util/chats_util.rs diff --git a/iota-storage/src/util/communities_util.rs b/src/util/communities_util.rs similarity index 100% rename from iota-storage/src/util/communities_util.rs rename to src/util/communities_util.rs diff --git a/iota-storage/src/util/config_util.rs b/src/util/config_util.rs similarity index 65% rename from iota-storage/src/util/config_util.rs rename to src/util/config_util.rs index 6d4082b..6330b59 100644 --- a/iota-storage/src/util/config_util.rs +++ b/src/util/config_util.rs @@ -1,4 +1,4 @@ -use iota_util::file_util::{load_file, save_file}; +use crate::util::file_util::{load_file, save_file}; use json::JsonValue; use once_cell::sync::Lazy; use tokio::sync::RwLock; @@ -19,26 +19,11 @@ impl ConfigUtil { } pub fn clear(&mut self) { self.config = JsonValue::new_object(); - self.unique = false; } pub fn load(&mut self) { let s = load_file("", "config.json"); - if s.is_empty() { - // File might be missing or empty/being written. - // We don't want to wipe the current config if it already has data. - // But if it's the first load, it will stay empty. - return; - } - - match json::parse(&s) { - Ok(parsed) => { - self.config = parsed; - self.unique = false; - } - Err(e) => { - eprintln!("Failed to parse config.json: {}. Content: '{}'", e, s); - // Keep the current config rather than wiping it. - } + if !s.is_empty() { + self.config = json::parse(&s).unwrap_or(JsonValue::new_object()); } } @@ -70,7 +55,6 @@ impl ConfigUtil { pub fn update(&mut self) { if self.unique { save_file("", "config.json", &self.config.to_string()); - self.unique = false; } } } diff --git a/iota-util/src/crypto_helper.rs b/src/util/crypto_helper.rs similarity index 100% rename from iota-util/src/crypto_helper.rs rename to src/util/crypto_helper.rs diff --git a/iota-util/src/crypto_util.rs b/src/util/crypto_util.rs similarity index 100% rename from iota-util/src/crypto_util.rs rename to src/util/crypto_util.rs diff --git a/iota-storage/src/util/db.rs b/src/util/db.rs similarity index 99% rename from iota-storage/src/util/db.rs rename to src/util/db.rs index eb48400..9fb40a0 100644 --- a/iota-storage/src/util/db.rs +++ b/src/util/db.rs @@ -5,7 +5,7 @@ //! reuse. The goal is to centralize the "open and initialize" logic and //! provide small convenience helpers used by other util modules. -use iota_util::file_util::get_directory; +use crate::util::file_util::get_directory; use rusqlite::{Connection, Error as RusqliteError}; use std::path::PathBuf; use std::sync::{Arc, Mutex}; diff --git a/iota-util/src/file_util.rs b/src/util/file_util.rs similarity index 92% rename from iota-util/src/file_util.rs rename to src/util/file_util.rs index b0cd3a3..2d00718 100755 --- a/iota-util/src/file_util.rs +++ b/src/util/file_util.rs @@ -9,6 +9,8 @@ use uuid::Uuid; use walkdir::WalkDir; use zip::ZipArchive; +use crate::log; + #[allow(dead_code)] pub fn delete_directory(path: &str) -> bool { let dir = Path::new(&get_directory()).join(path); @@ -21,7 +23,7 @@ fn delete_dir_recursive(directory: &Path) -> bool { return false; } if let Err(e) = fs::remove_dir_all(directory) { - println!( + log!( "[IMPORTANT] Couldn't delete directory {}: {}", directory.display(), e, @@ -94,10 +96,17 @@ pub fn load_file(path: &str, name: &str) -> String { let file_path = dir.join(name); if !dir.exists() { + if let Err(e) = fs::create_dir_all(&dir) { + log!("[IMPORTANT] Couldn't create directories: {}", e); + return String::new(); + } return String::new(); } if !file_path.exists() { + if let Err(e) = File::create(&file_path) { + log!("[IMPORTANT] Couldn't create file: {}", e); + } return String::new(); } @@ -121,13 +130,13 @@ pub fn save_file(path: &str, name: &str, value: &str) { if !dir.exists() { if let Err(e) = fs::create_dir_all(&dir) { - println!("[IMPORTANT] Couldn't create directories: {}", e); + log!("[IMPORTANT] Couldn't create directories: {}", e); return; } } if let Err(e) = fs::write(&file_path, value) { - println!( + log!( "[IMPORTANT] Couldn't write file {}: {}", file_path.display(), e @@ -222,7 +231,7 @@ pub async fn download_zip(url: &str, zip_path: &Path) -> Result<(), Box true, Err(e) => { - println!("Error during ZIP extraction: {}", e); + log!("Error during ZIP extraction: {}", e); false } }; if let Err(e) = tokio::fs::remove_file(&zip_path).await { - println!("Error cleaning up ZIP file {}: {}", zip_path.display(), e); + log!("Error cleaning up ZIP file {}: {}", zip_path.display(), e); } else if successful { - println!("Downloaded and extracted ZIP file successfully."); + log!("Downloaded and extracted ZIP file successfully."); } } diff --git a/iota-logger/src/lib.rs b/src/util/logger.rs old mode 100644 new mode 100755 similarity index 85% rename from iota-logger/src/lib.rs rename to src/util/logger.rs index 8a4b8b0..a5feb02 --- a/iota-logger/src/lib.rs +++ b/src/util/logger.rs @@ -11,8 +11,11 @@ use std::{ use ratatui::style::Color; use ttp_core::{CommunicationValue, DataTypes, DataValue}; -use iota_state::{APP_STATE, UNIQUE, UiLogEntry}; -use iota_util::langu::language_manager; +use crate::{ + APP_STATE, + gui::{elements::log_card::LogEntry, ui::UNIQUE}, + langu::language_manager, +}; static LOGGER: OnceLock> = OnceLock::new(); @@ -80,6 +83,7 @@ pub fn startup() { }; let timestamp = format_timestamp_inline(msg.timestamp_ms); + let entry = LogEntry::new(msg.kind, resolved_message, msg.is_error); let prefix = if msg.prefix.is_empty() { String::new() @@ -92,20 +96,13 @@ pub fn startup() { "{} {}{}", fixed_box(&msg.timestamp_ms.to_string(), 13), prefix, - resolved_message + entry.message ); let _ = writeln!(file, " {}", timestamp); - let entry = UiLogEntry { - timestamp_ms: msg.timestamp_ms, - sender: format!("{:?}", msg.kind), - message: resolved_message, - is_error: msg.is_error, - }; - let mut state = APP_STATE.lock().unwrap(); - state.push_log(entry); + state.push_log(entry.into()); } }); } @@ -189,8 +186,8 @@ pub fn log_internal(kind: PrintType, prefix: String, is_error: bool, message: St #[macro_export] macro_rules! log_t { ($key:expr) => { - $crate::log_internal_translated( - $crate::PrintType::General, + $crate::util::logger::log_internal_translated( + $crate::util::logger::PrintType::General, "".to_string(), false, $key, @@ -199,8 +196,8 @@ macro_rules! log_t { }; ($key:expr, $($arg:expr),+) => { - $crate::log_internal_translated( - $crate::PrintType::General, + $crate::util::logger::log_internal_translated( + $crate::util::logger::PrintType::General, "".to_string(), false, $key, @@ -212,8 +209,8 @@ macro_rules! log_t { #[macro_export] macro_rules! log_t_err { ($key:expr) => { - $crate::log_internal_translated( - $crate::PrintType::General, + $crate::util::logger::log_internal_translated( + $crate::util::logger::PrintType::General, "".to_string(), true, $key, @@ -222,8 +219,8 @@ macro_rules! log_t_err { }; ($key:expr, $($arg:expr),+) => { - $crate::log_internal_translated( - $crate::PrintType::General, + $crate::util::logger::log_internal_translated( + $crate::util::logger::PrintType::General, "".to_string(), true, $key, @@ -236,8 +233,8 @@ macro_rules! log_t_err { #[macro_export] macro_rules! log_command { ($($arg:tt)*) => { - $crate::log_internal( - $crate::PrintType::Command, + $crate::util::logger::log_internal( + $crate::util::logger::PrintType::Command, "".to_string(), false, format!($($arg)*) @@ -249,8 +246,8 @@ macro_rules! log_command { #[macro_export] macro_rules! log { ($($arg:tt)*) => { - $crate::log_internal( - $crate::PrintType::General, + $crate::util::logger::log_internal( + $crate::util::logger::PrintType::General, "".to_string(), false, format!($($arg)*) @@ -262,8 +259,8 @@ macro_rules! log { #[macro_export] macro_rules! log_in { ($($arg:tt)*) => { - $crate::log_internal( - $crate::PrintType::General, + $crate::util::logger::log_internal( + $crate::util::logger::PrintType::General, ">".to_string(), false, format!($($arg)*) @@ -275,8 +272,8 @@ macro_rules! log_in { #[macro_export] macro_rules! log_out { ($($arg:tt)*) => { - $crate::log_internal( - $crate::PrintType::General, + $crate::util::logger::log_internal( + $crate::util::logger::PrintType::General, "<".to_string(), false, format!($($arg)*) @@ -288,8 +285,8 @@ macro_rules! log_out { #[macro_export] macro_rules! log_err { ($($arg:tt)*) => { - $crate::log_internal( - $crate::PrintType::General, + $crate::util::logger::log_internal( + $crate::util::logger::PrintType::General, ">>".to_string(), true, format!($($arg)*) @@ -407,29 +404,29 @@ fn format_array(arr: Vec) -> String { #[macro_export] macro_rules! log_cv { ($kind:expr, $cv:expr) => { - $crate::log_cv_internal("", &$cv, Some($kind)) + $crate::util::logger::log_cv_internal("", &$cv, Some($kind)) }; ($cv:expr) => { - $crate::log_cv_internal("", &$cv, None) + $crate::util::logger::log_cv_internal("", &$cv, None) }; } #[macro_export] macro_rules! log_cv_in { ($kind:expr, $cv:expr) => { - $crate::log_cv_internal("> ", &$cv, Some($kind)) + $crate::util::logger::log_cv_internal("> ", &$cv, Some($kind)) }; ($cv:expr) => { - $crate::log_cv_internal("> ", &$cv, None) + $crate::util::logger::log_cv_internal("> ", &$cv, None) }; } #[macro_export] macro_rules! log_cv_out { ($kind:expr, $cv:expr) => { - $crate::log_cv_internal("< ", &$cv, Some($kind)) + $crate::util::logger::log_cv_internal("< ", &$cv, Some($kind)) }; ($cv:expr) => { - $crate::log_cv_internal("< ", &$cv, None) + $crate::util::logger::log_cv_internal("< ", &$cv, None) }; } diff --git a/iota-storage/src/util/mod.rs b/src/util/mod.rs similarity index 55% rename from iota-storage/src/util/mod.rs rename to src/util/mod.rs index dff0d65..47901f9 100644 --- a/iota-storage/src/util/mod.rs +++ b/src/util/mod.rs @@ -2,4 +2,8 @@ pub mod chat_files; pub mod chats_util; pub mod communities_util; pub mod config_util; +pub mod crypto_helper; +pub mod crypto_util; pub mod db; +pub mod file_util; +pub mod logger; diff --git a/web-server/Cargo.toml b/web-server/Cargo.toml deleted file mode 100644 index b214806..0000000 --- a/web-server/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ - -[package] -name = "web-server" -version = "0.1.0" -edition = "2024" - -[dependencies] -ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } -ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-native" } diff --git a/web-server/src/lib.rs b/web-server/src/lib.rs deleted file mode 100644 index e69de29..0000000 diff --git a/web-ui/Cargo.toml b/web-ui/Cargo.toml deleted file mode 100644 index 16a8974..0000000 --- a/web-ui/Cargo.toml +++ /dev/null @@ -1,61 +0,0 @@ -[package] -name = "web-ui" -version = "0.1.0" -edition = "2024" - -[dependencies] -omikron-connector = { path = "../omikron-connector" } -iota-storage = { path = "../iota-storage" } -iota-state = { path = "../iota-state" } -iota-util = { path = "../iota-util" } -iota-logger = { path = "../iota-logger" } -ttp-core = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-core" } -ttp-native = { git = "https://git.methanium.net/Tensamin/TTP.git", package = "ttp-native" } - -actix-web = { version = "4", features = ["rustls-0_23"] } -actix-web-actors = "4" -aes-gcm = "0.10.3" -async-trait = "0.1.89" -base64 = "0.22.1" -chrono = "0.4.43" -crossterm = "*" -dashmap = "6.1.0" -futures = "*" -futures-util = "*" -hex = "*" -hkdf = "0.12.4" -hyper = { version = "1.8.1", features = [ - "capi", - "client", - "full", - "http1", - "http2", - "nightly", - "server", -] } -hyper-util = { version = "*" } -json = "*" -lazy_static = "1.5.0" -once_cell = "1.21.3" -open = "5.3.3" -pnet = "0.35.0" -rand = "0.8" -rand_core = { version = "0.6", features = ["getrandom", "std"] } -ratatui = "0.30.0" -reqwest = "0.13.2" -rusqlite = "0.39.0" -rustls = { version = "0.23.37", features = ["aws-lc-rs"] } -rustls-pemfile = "2.2.0" -serde_json = "1.0.149" -sha2 = "0.10.9" -strum = "0.27.2" -strum_macros = "0.27.2" -sysinfo = "0.38.3" -tokio = { version = "1.50.0", features = ["full"] } -tokio-tungstenite = { version = "*", features = ["native-tls"] } -tungstenite = "*" -uuid = { version = "*", features = ["v4"] } -walkdir = "2.5.0" -warp = "*" -x448 = { version = "*" } -zip = "6.0.0" diff --git a/web-ui/src/socket.rs b/web-ui/src/socket.rs deleted file mode 100644 index e69de29..0000000