You've already forked OpenIntegrations
mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2026-06-12 00:34:16 +02:00
Разделение ws и http серверов
This commit is contained in:
Generated
+2
-221
@@ -46,7 +46,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8"
|
||||
dependencies = [
|
||||
"axum-core",
|
||||
"base64",
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
"futures-util",
|
||||
@@ -65,10 +64,8 @@ dependencies = [
|
||||
"serde_json",
|
||||
"serde_path_to_error",
|
||||
"serde_urlencoded",
|
||||
"sha1",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tokio-tungstenite",
|
||||
"tower",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
@@ -106,15 +103,6 @@ version = "2.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.2"
|
||||
@@ -208,41 +196,6 @@ version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "data-encoding"
|
||||
version = "2.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea"
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
@@ -306,12 +259,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.32"
|
||||
@@ -326,34 +273,11 @@ checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-macro",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi 5.3.0",
|
||||
"wasip2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.4.2"
|
||||
@@ -362,7 +286,7 @@ checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi 6.0.0",
|
||||
"r-efi",
|
||||
"wasip2",
|
||||
"wasip3",
|
||||
]
|
||||
@@ -608,7 +532,6 @@ dependencies = [
|
||||
"common-logs",
|
||||
"common-server",
|
||||
"common-utils",
|
||||
"futures-util",
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -659,15 +582,6 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||
dependencies = [
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.37"
|
||||
@@ -696,47 +610,12 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "5.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||
dependencies = [
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
|
||||
dependencies = [
|
||||
"getrandom 0.3.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.5.18"
|
||||
@@ -836,17 +715,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha1"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
@@ -902,26 +770,6 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.50.0"
|
||||
@@ -950,18 +798,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-tungstenite"
|
||||
version = "0.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d25a406cddcc431a75d3d9afc6a7c0f7428d4891dd973e4d54c56b46127bf857"
|
||||
dependencies = [
|
||||
"futures-util",
|
||||
"log",
|
||||
"tokio",
|
||||
"tungstenite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.5.3"
|
||||
@@ -1026,29 +862,6 @@ dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tungstenite"
|
||||
version = "0.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8628dcc84e5a09eb3d8423d6cb682965dea9133204e8fb3efee74c2a0c259442"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"data-encoding",
|
||||
"http",
|
||||
"httparse",
|
||||
"log",
|
||||
"rand",
|
||||
"sha1",
|
||||
"thiserror",
|
||||
"utf-8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
@@ -1061,12 +874,6 @@ version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
|
||||
[[package]]
|
||||
name = "utf-8"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||
|
||||
[[package]]
|
||||
name = "utf16_lit"
|
||||
version = "2.0.2"
|
||||
@@ -1079,17 +886,11 @@ version = "1.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ac8b6f42ead25368cf5b098aeb3dc8a1a2c05a3eee8a9a1a68c640edbfc79d9"
|
||||
dependencies = [
|
||||
"getrandom 0.4.2",
|
||||
"getrandom",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.1+wasi-snapshot-preview1"
|
||||
@@ -1349,26 +1150,6 @@ dependencies = [
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "efbb2a062be311f2ba113ce66f697a4dc589f85e78a4aea276200804cea0ed87"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.21"
|
||||
|
||||
@@ -24,9 +24,8 @@ common-server = { path = "../commons/common-server" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
axum = { version = "0.8.8", features = ["ws"] }
|
||||
axum = "0.8.8"
|
||||
tower = "0.5"
|
||||
tower-http = { version = "0.6", features = ["cors", "trace"] }
|
||||
uuid = { version = "1.17.0", features = ["v4"] }
|
||||
indexmap = "2.7.0"
|
||||
futures-util = "0.3"
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
"MAIN ---"
|
||||
linux-vdso.so.1 (0x00007ffe67db7000)
|
||||
libm.so.6 => /lib64/libm.so.6 (0x0000778121000000)
|
||||
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000778120c00000)
|
||||
libc.so.6 => /lib64/libc.so.6 (0x0000778120800000)
|
||||
libdl.so.2 => /lib64/libdl.so.2 (0x0000778120400000)
|
||||
/lib64/ld-linux-x86-64.so.2 (0x0000778121400000)
|
||||
GLIBC_2.2.5
|
||||
GLIBC_2.12
|
||||
GLIBC_2.3
|
||||
GLIBC_2.3.2
|
||||
GLIBC_2.3.4
|
||||
GLIBC_2.7
|
||||
GLIBC_2.9
|
||||
GLIBC_2.10
|
||||
GLIBC_2.14
|
||||
GLIBC_2.17
|
||||
@@ -0,0 +1,9 @@
|
||||
@echo off
|
||||
|
||||
:: Установить переменную
|
||||
set CARGO_NAME=opi_httpserver
|
||||
set LIB_NAME=OPI_HTTPServer
|
||||
set ADDIN_DIR=%~dp0
|
||||
set FOLV=true
|
||||
|
||||
call ../build.bat
|
||||
@@ -4,7 +4,7 @@ use common_utils::utils::{json_error, json_success};
|
||||
use common_binary::vault::BinaryVault;
|
||||
use common_logs::Logger;
|
||||
use common_server::{Backend, send_command, handle_async_command, handle_sync_command};
|
||||
use super::HttpServerState;
|
||||
use crate::server::HttpServerState;
|
||||
|
||||
pub struct HttpServerBackend {
|
||||
backend: Backend<HttpCommand>,
|
||||
@@ -1,7 +0,0 @@
|
||||
mod backend;
|
||||
mod server;
|
||||
mod wrapper;
|
||||
|
||||
pub use backend::HttpServerBackend;
|
||||
pub use server::HttpServerState;
|
||||
pub use wrapper::HttpServer;
|
||||
@@ -1,54 +1,38 @@
|
||||
mod http;
|
||||
mod websocket;
|
||||
mod backend;
|
||||
mod server;
|
||||
mod wrapper;
|
||||
|
||||
use std::sync::Arc;
|
||||
use common_core::*;
|
||||
use common_utils::utils::json_error;
|
||||
use common_binary::vault::BinaryVault;
|
||||
use common_logs::Logger;
|
||||
use crate::http::HttpServer;
|
||||
use crate::websocket::WebSocketServer;
|
||||
use wrapper::HttpServer;
|
||||
|
||||
impl_addin_exports!(AddIn);
|
||||
impl_raw_addin!(AddIn, METHODS, PROPS, get_params_amount, cal_func);
|
||||
|
||||
pub const METHODS: &[&[u16]] = &[
|
||||
name!("StartHTTP"), // 0
|
||||
name!("StopHTTP"), // 1
|
||||
name!("GetNextMessageHTTP"), // 2
|
||||
name!("GetMessageHTTP"), // 3
|
||||
name!("SendMessageHTTP"), // 4
|
||||
name!("ListConnectionsHTTP"), // 5
|
||||
|
||||
name!("StartWS"), // 6
|
||||
name!("StopWS"), // 7
|
||||
name!("GetNextMessageWS"), // 8
|
||||
name!("GetMessageWS"), // 9
|
||||
name!("SendMessageWS"), // 10
|
||||
name!("CloseConnectionWS"), // 11
|
||||
name!("ListConnectionsWS"), // 12
|
||||
|
||||
name!("RetrieveBinaryFromVault"), // 13
|
||||
name!("GetLogs"), // 14
|
||||
name!("Start"), // 0
|
||||
name!("Stop"), // 1
|
||||
name!("GetNextMessage"), // 2
|
||||
name!("GetMessage"), // 3
|
||||
name!("SendMessage"), // 4
|
||||
name!("ListConnections"), // 5
|
||||
name!("RetrieveBinaryFromVault"), // 6
|
||||
name!("GetLogs"), // 7
|
||||
];
|
||||
|
||||
pub fn get_params_amount(num: usize) -> usize {
|
||||
match num {
|
||||
0 => 3, // StartHTTP(port, config_json, logger_config_json)
|
||||
1 => 0, // StopHTTP()
|
||||
2 => 1, // GetNextMessageHTTP(timeout_ms)
|
||||
3 => 1, // GetMessageHTTP(request_id)
|
||||
4 => 3, // SendMessageHTTP(request_id, status_code, body)
|
||||
5 => 0, // ListConnectionsHTTP()
|
||||
6 => 3, // StartWS(port, config_json, logger_config_json)
|
||||
7 => 0, // StopWS()
|
||||
8 => 1, // GetNextMessageWS(timeout_ms)
|
||||
9 => 2, // GetMessageWS(connection_id, timeout_ms)
|
||||
10 => 2, // SendMessageWS(connection_id, message)
|
||||
11 => 1, // CloseConnectionWS(connection_id)
|
||||
12 => 0, // ListConnectionsWS()
|
||||
13 => 1, // RetrieveBinaryFromVault(vault_key)
|
||||
14 => 1, // GetLogs(count)
|
||||
0 => 3, // Start(port, config_json, logger_config_json)
|
||||
1 => 0, // Stop()
|
||||
2 => 1, // GetNextMessage(timeout_ms)
|
||||
3 => 1, // GetMessage(request_id)
|
||||
4 => 3, // SendMessage(request_id, status_code, body)
|
||||
5 => 0, // ListConnections()
|
||||
6 => 1, // RetrieveBinaryFromVault(vault_key)
|
||||
7 => 1, // GetLogs(count)
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
@@ -58,6 +42,7 @@ pub fn cal_func(obj: &mut AddIn, num: usize, params: &mut [Variant]) -> Box<dyn
|
||||
|
||||
match num {
|
||||
0 => {
|
||||
// Start(port, config_json, logger_config_json)
|
||||
let port = params[0].get_i32().unwrap_or(8080) as u16;
|
||||
let config = params[1].get_string().unwrap_or_default();
|
||||
let logger_config = params[2].get_string().unwrap_or_default();
|
||||
@@ -65,67 +50,40 @@ pub fn cal_func(obj: &mut AddIn, num: usize, params: &mut [Variant]) -> Box<dyn
|
||||
if let Err(e) = obj.init_logger_if_needed(&logger_config) {
|
||||
return Box::new(json_error(&e));
|
||||
};
|
||||
Box::new(obj.http_server.start(port, &config))
|
||||
Box::new(obj.server.start(port, &config))
|
||||
},
|
||||
1 => {
|
||||
Box::new(obj.http_server.stop())
|
||||
// Stop()
|
||||
Box::new(obj.server.stop())
|
||||
},
|
||||
2 => {
|
||||
// GetNextMessage(timeout_ms)
|
||||
let timeout_ms = params[0].get_i32().unwrap_or(1000) as u64;
|
||||
Box::new(obj.http_server.handle_request(timeout_ms))
|
||||
Box::new(obj.server.handle_request(timeout_ms))
|
||||
},
|
||||
3 => {
|
||||
// GetMessage(request_id)
|
||||
let request_id = params[0].get_string().unwrap_or_default();
|
||||
Box::new(obj.http_server.handle_request_by_id(&request_id))
|
||||
Box::new(obj.server.handle_request_by_id(&request_id))
|
||||
},
|
||||
4 => {
|
||||
// SendMessage(request_id, status_code, body)
|
||||
let request_id = params[0].get_string().unwrap_or_default();
|
||||
let status_code = params[1].get_i32().unwrap_or(200) as u16;
|
||||
let body = params[2].get_blob().unwrap_or(&empty_array);
|
||||
Box::new(obj.http_server.send_response(&request_id, status_code, body.to_vec()))
|
||||
Box::new(obj.server.send_response(&request_id, status_code, body.to_vec()))
|
||||
},
|
||||
5 => {
|
||||
Box::new(obj.http_server.get_pending_requests())
|
||||
// ListConnections()
|
||||
Box::new(obj.server.get_pending_requests())
|
||||
},
|
||||
6 => {
|
||||
let port = params[0].get_i32().unwrap_or(8080) as u16;
|
||||
let config = params[1].get_string().unwrap_or_default();
|
||||
let logger_config = params[2].get_string().unwrap_or_default();
|
||||
|
||||
if let Err(e) = obj.init_logger_if_needed(&logger_config) {
|
||||
return Box::new(json_error(&e));
|
||||
};
|
||||
Box::new(obj.ws_server.start(port, &config))
|
||||
},
|
||||
7 => {
|
||||
Box::new(obj.ws_server.stop())
|
||||
},
|
||||
8 => {
|
||||
let timeout_ms = params[0].get_i32().unwrap_or(1000) as u64;
|
||||
Box::new(obj.ws_server.get_next_message(timeout_ms))
|
||||
},
|
||||
9 => {
|
||||
let connection_id = params[0].get_string().unwrap_or_default();
|
||||
let timeout_ms = params[1].get_i32().unwrap_or(1000) as u64;
|
||||
Box::new(obj.ws_server.get_message(&connection_id, timeout_ms))
|
||||
},
|
||||
10 => {
|
||||
let connection_id = params[0].get_string().unwrap_or_default();
|
||||
let message = params[1].get_blob().unwrap_or(&empty_array);
|
||||
Box::new(obj.ws_server.send_message(&connection_id, message.to_vec()))
|
||||
},
|
||||
11 => {
|
||||
let connection_id = params[0].get_string().unwrap_or_default();
|
||||
Box::new(obj.ws_server.close_connection(&connection_id))
|
||||
},
|
||||
12 => {
|
||||
Box::new(obj.ws_server.get_connections_list())
|
||||
},
|
||||
13 => {
|
||||
// RetrieveBinaryFromVault(vault_key)
|
||||
let vault_key = params[0].get_string().unwrap_or_default();
|
||||
Box::new(obj.retrieve_binary_from_vault(&vault_key))
|
||||
},
|
||||
14 => {
|
||||
7 => {
|
||||
// GetLogs(count)
|
||||
let count = params[0].get_i32().unwrap_or(0) as usize;
|
||||
Box::new(obj.get_logs(count))
|
||||
},
|
||||
@@ -136,8 +94,7 @@ pub fn cal_func(obj: &mut AddIn, num: usize, params: &mut [Variant]) -> Box<dyn
|
||||
pub const PROPS: &[&[u16]] = &[];
|
||||
|
||||
pub struct AddIn {
|
||||
http_server: HttpServer,
|
||||
ws_server: WebSocketServer,
|
||||
server: HttpServer,
|
||||
vault: BinaryVault,
|
||||
logger: Option<Arc<Logger>>,
|
||||
}
|
||||
@@ -146,8 +103,7 @@ impl AddIn {
|
||||
pub fn new() -> Self {
|
||||
let vault = BinaryVault::new();
|
||||
AddIn {
|
||||
http_server: HttpServer::new(vault.clone()),
|
||||
ws_server: WebSocketServer::new(vault.clone()),
|
||||
server: HttpServer::new(vault.clone()),
|
||||
vault,
|
||||
logger: None,
|
||||
}
|
||||
@@ -163,9 +119,7 @@ impl AddIn {
|
||||
|
||||
let logger_arc = Arc::new(logger);
|
||||
self.logger = Some(logger_arc.clone());
|
||||
|
||||
self.http_server.set_logger(logger_arc.clone());
|
||||
self.ws_server.set_logger(logger_arc);
|
||||
self.server.set_logger(logger_arc);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -201,11 +155,8 @@ impl AddIn {
|
||||
|
||||
impl Drop for AddIn {
|
||||
fn drop(&mut self) {
|
||||
if self.http_server.is_started() {
|
||||
let _ = self.http_server.stop();
|
||||
}
|
||||
if self.ws_server.is_started() {
|
||||
let _ = self.ws_server.stop();
|
||||
if self.server.is_started() {
|
||||
let _ = self.server.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
mod backend;
|
||||
mod server;
|
||||
mod wrapper;
|
||||
|
||||
pub use backend::WebSocketServerBackend;
|
||||
pub use server::WebSocketServerState;
|
||||
pub use wrapper::WebSocketServer;
|
||||
@@ -2,7 +2,7 @@ use std::sync::{Arc, Mutex};
|
||||
use common_utils::utils::{json_error, json_success};
|
||||
use common_binary::vault::BinaryVault;
|
||||
use common_logs::Logger;
|
||||
use super::HttpServerBackend;
|
||||
use crate::backend::HttpServerBackend;
|
||||
|
||||
pub struct HttpServer {
|
||||
backend: Arc<Mutex<HttpServerBackend>>,
|
||||
Generated
+1356
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
[package]
|
||||
name = "opi_wsserver"
|
||||
version = "0.1.0"
|
||||
license = "MIT"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[profile.release]
|
||||
lto = "fat"
|
||||
codegen-units = 1
|
||||
panic = "unwind"
|
||||
strip = true
|
||||
opt-level = "z"
|
||||
|
||||
[dependencies]
|
||||
common-core = { path = "../commons/common-core" }
|
||||
common-utils = { path = "../commons/common-utils" }
|
||||
common-binary = { path = "../commons/common-binary" }
|
||||
common-logs = { path = "../commons/common-logs" }
|
||||
common-server = { path = "../commons/common-server" }
|
||||
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
axum = { version = "0.8.8", features = ["ws"] }
|
||||
futures-util = "0.3"
|
||||
@@ -0,0 +1,2 @@
|
||||
[advisories]
|
||||
version = 2
|
||||
@@ -0,0 +1,17 @@
|
||||
"MAIN ---"
|
||||
linux-vdso.so.1 (0x00007ffdd3db9000)
|
||||
libm.so.6 => /lib64/libm.so.6 (0x000072fded200000)
|
||||
libpthread.so.0 => /lib64/libpthread.so.0 (0x000072fdece00000)
|
||||
libc.so.6 => /lib64/libc.so.6 (0x000072fdeca00000)
|
||||
libdl.so.2 => /lib64/libdl.so.2 (0x000072fdec600000)
|
||||
/lib64/ld-linux-x86-64.so.2 (0x000072fded600000)
|
||||
GLIBC_2.2.5
|
||||
GLIBC_2.12
|
||||
GLIBC_2.3
|
||||
GLIBC_2.3.2
|
||||
GLIBC_2.3.4
|
||||
GLIBC_2.7
|
||||
GLIBC_2.9
|
||||
GLIBC_2.10
|
||||
GLIBC_2.14
|
||||
GLIBC_2.17
|
||||
@@ -0,0 +1,9 @@
|
||||
@echo off
|
||||
|
||||
:: Установить переменную
|
||||
set CARGO_NAME=opi_wsserver
|
||||
set LIB_NAME=OPI_WSServer
|
||||
set ADDIN_DIR=%~dp0
|
||||
set FOLV=true
|
||||
|
||||
call ../build.bat
|
||||
+1
-1
@@ -4,7 +4,7 @@ use common_utils::utils::{json_error, json_success};
|
||||
use common_binary::vault::BinaryVault;
|
||||
use common_logs::Logger;
|
||||
use common_server::{Backend, send_command, handle_async_command, handle_sync_command};
|
||||
use super::WebSocketServerState;
|
||||
use crate::server::WebSocketServerState;
|
||||
|
||||
pub struct WebSocketServerBackend {
|
||||
backend: Backend<WebSocketCommand>,
|
||||
@@ -0,0 +1,160 @@
|
||||
mod backend;
|
||||
mod server;
|
||||
mod wrapper;
|
||||
|
||||
use std::sync::Arc;
|
||||
use common_core::*;
|
||||
use common_utils::utils::json_error;
|
||||
use common_binary::vault::BinaryVault;
|
||||
use common_logs::Logger;
|
||||
use wrapper::WebSocketServer;
|
||||
|
||||
impl_addin_exports!(AddIn);
|
||||
impl_raw_addin!(AddIn, METHODS, PROPS, get_params_amount, cal_func);
|
||||
|
||||
pub const METHODS: &[&[u16]] = &[
|
||||
name!("Start"), // 0
|
||||
name!("Stop"), // 1
|
||||
name!("GetNextMessage"), // 2
|
||||
name!("GetMessage"), // 3
|
||||
name!("SendMessage"), // 4
|
||||
name!("CloseConnection"), // 5
|
||||
name!("ListConnections"), // 6
|
||||
name!("RetrieveBinaryFromVault"), // 7
|
||||
name!("GetLogs"), // 8
|
||||
];
|
||||
|
||||
pub fn get_params_amount(num: usize) -> usize {
|
||||
match num {
|
||||
0 => 3, // Start(port, config_json, logger_config_json)
|
||||
1 => 0, // Stop()
|
||||
2 => 1, // GetNextMessage(timeout_ms)
|
||||
3 => 2, // GetMessage(connection_id, timeout_ms)
|
||||
4 => 2, // SendMessage(connection_id, message)
|
||||
5 => 1, // CloseConnection(connection_id)
|
||||
6 => 0, // ListConnections()
|
||||
7 => 1, // RetrieveBinaryFromVault(vault_key)
|
||||
8 => 1, // GetLogs(count)
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cal_func(obj: &mut AddIn, num: usize, params: &mut [Variant]) -> Box<dyn getset::ValueType> {
|
||||
let empty_array: [u8; 0] = [];
|
||||
|
||||
match num {
|
||||
0 => {
|
||||
let port = params[0].get_i32().unwrap_or(8080) as u16;
|
||||
let config = params[1].get_string().unwrap_or_default();
|
||||
let logger_config = params[2].get_string().unwrap_or_default();
|
||||
|
||||
if let Err(e) = obj.init_logger_if_needed(&logger_config) {
|
||||
return Box::new(json_error(&e));
|
||||
};
|
||||
Box::new(obj.server.start(port, &config))
|
||||
},
|
||||
1 => {
|
||||
Box::new(obj.server.stop())
|
||||
},
|
||||
2 => {
|
||||
let timeout_ms = params[0].get_i32().unwrap_or(1000) as u64;
|
||||
Box::new(obj.server.get_next_message(timeout_ms))
|
||||
},
|
||||
3 => {
|
||||
let connection_id = params[0].get_string().unwrap_or_default();
|
||||
let timeout_ms = params[1].get_i32().unwrap_or(1000) as u64;
|
||||
Box::new(obj.server.get_message(&connection_id, timeout_ms))
|
||||
},
|
||||
4 => {
|
||||
let connection_id = params[0].get_string().unwrap_or_default();
|
||||
let message = params[1].get_blob().unwrap_or(&empty_array);
|
||||
Box::new(obj.server.send_message(&connection_id, message.to_vec()))
|
||||
},
|
||||
5 => {
|
||||
let connection_id = params[0].get_string().unwrap_or_default();
|
||||
Box::new(obj.server.close_connection(&connection_id))
|
||||
},
|
||||
6 => {
|
||||
Box::new(obj.server.get_connections_list())
|
||||
},
|
||||
7 => {
|
||||
let vault_key = params[0].get_string().unwrap_or_default();
|
||||
Box::new(obj.retrieve_binary_from_vault(&vault_key))
|
||||
},
|
||||
8 => {
|
||||
let count = params[0].get_i32().unwrap_or(0) as usize;
|
||||
Box::new(obj.get_logs(count))
|
||||
},
|
||||
_ => Box::new(false),
|
||||
}
|
||||
}
|
||||
|
||||
pub const PROPS: &[&[u16]] = &[];
|
||||
|
||||
pub struct AddIn {
|
||||
server: WebSocketServer,
|
||||
vault: BinaryVault,
|
||||
logger: Option<Arc<Logger>>,
|
||||
}
|
||||
|
||||
impl AddIn {
|
||||
pub fn new() -> Self {
|
||||
let vault = BinaryVault::new();
|
||||
AddIn {
|
||||
server: WebSocketServer::new(vault.clone()),
|
||||
vault,
|
||||
logger: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn init_logger_if_needed(&mut self, logger_config: &str) -> Result<(), String> {
|
||||
if logger_config.is_empty() || self.logger.is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let logger = Logger::from_json(logger_config)
|
||||
.map_err(|e| format!("Failed to initialize logger: {}", e))?;
|
||||
|
||||
let logger_arc = Arc::new(logger);
|
||||
self.logger = Some(logger_arc.clone());
|
||||
self.server.set_logger(logger_arc);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_logs(&self, count: usize) -> String {
|
||||
if let Some(ref logger) = self.logger {
|
||||
let logs = logger.get_last_logs(count);
|
||||
let total = logger.len();
|
||||
|
||||
serde_json::json!({
|
||||
"result": true,
|
||||
"logs": logs,
|
||||
"total": total,
|
||||
"returned": logs.len()
|
||||
}).to_string()
|
||||
} else {
|
||||
json_error("Logger not initialized")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn retrieve_binary_from_vault(&self, vault_key: &str) -> Vec<u8> {
|
||||
self.vault.retrieve(&vault_key.to_string()).unwrap_or_else(|_| Vec::new())
|
||||
}
|
||||
|
||||
pub fn get_field_ptr(&self, _index: usize) -> *const dyn getset::ValueType {
|
||||
panic!("Index out of bounds")
|
||||
}
|
||||
|
||||
pub fn get_field_ptr_mut(&mut self, index: usize) -> *mut dyn getset::ValueType {
|
||||
self.get_field_ptr(index) as *mut _
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for AddIn {
|
||||
fn drop(&mut self) {
|
||||
if self.server.is_started() {
|
||||
let _ = self.server.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-10
@@ -138,17 +138,14 @@ impl WebSocketServerState {
|
||||
let message_handler = MessageHandler::new(self.vault.clone());
|
||||
|
||||
let result = waiter.wait_for(|| {
|
||||
// First check for new connections
|
||||
if let Some(ref mut conn_rx) = self.connection_rx {
|
||||
if let Ok(connection_id) = conn_rx.try_recv() {
|
||||
return Some((connection_id, None)); // New connection, no message yet
|
||||
return Some((connection_id, None));
|
||||
}
|
||||
}
|
||||
|
||||
// Then check for messages from existing connections
|
||||
|
||||
if let Some(ref mut msg_rx) = self.message_rx {
|
||||
if let Ok((conn_id, msg)) = msg_rx.try_recv() {
|
||||
// Check if connection still exists by trying to get it
|
||||
let exists = self.manager.get_mut(&conn_id, |_| {}).is_some();
|
||||
if exists {
|
||||
return Some((conn_id, Some(msg)));
|
||||
@@ -278,16 +275,13 @@ async fn handle_websocket(socket: WebSocket, state: Arc<tokio::sync::Mutex<WebSo
|
||||
(locked_state.message_tx.clone(), locked_state.connection_tx.clone())
|
||||
};
|
||||
|
||||
// Notify about new connection
|
||||
let _ = connection_tx.send(connection_id.clone());
|
||||
|
||||
let connection_id_clone = connection_id.clone();
|
||||
let state_clone = state.clone();
|
||||
|
||||
// Split socket into sender and receiver
|
||||
let (mut ws_sender, mut ws_receiver) = socket.split();
|
||||
|
||||
// Task for sending messages to client
|
||||
let send_task = tokio::spawn(async move {
|
||||
while let Some(msg) = rx.recv().await {
|
||||
if ws_sender.send(Message::Binary(msg.into())).await.is_err() {
|
||||
@@ -296,7 +290,6 @@ async fn handle_websocket(socket: WebSocket, state: Arc<tokio::sync::Mutex<WebSo
|
||||
}
|
||||
});
|
||||
|
||||
// Task for receiving messages from client
|
||||
let recv_task = tokio::spawn(async move {
|
||||
while let Some(Ok(msg)) = ws_receiver.next().await {
|
||||
if let Message::Binary(data) = msg {
|
||||
@@ -307,7 +300,6 @@ async fn handle_websocket(socket: WebSocket, state: Arc<tokio::sync::Mutex<WebSo
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for either task to complete
|
||||
tokio::select! {
|
||||
_ = send_task => {},
|
||||
_ = recv_task => {},
|
||||
+1
-1
@@ -2,7 +2,7 @@ use std::sync::{Arc, Mutex};
|
||||
use common_utils::utils::{json_error, json_success};
|
||||
use common_binary::vault::BinaryVault;
|
||||
use common_logs::Logger;
|
||||
use super::WebSocketServerBackend;
|
||||
use crate::backend::WebSocketServerBackend;
|
||||
|
||||
pub struct WebSocketServer {
|
||||
backend: Arc<Mutex<WebSocketServerBackend>>,
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonTemplate xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="171887ca-f296-4a6e-befd-789bb45c3157">
|
||||
<name>OPI_HTTPServer</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Компонента HTTP-сервера (ОПИ)</value>
|
||||
</synonym>
|
||||
<templateType>AddIn</templateType>
|
||||
</mdclass:CommonTemplate>
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:474175e80ac4c75ac6730fe4fd1583c922a22ffd7a39c255b43cc83b3f32e90d
|
||||
size 1966227
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonTemplate xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="d8348139-074a-4a51-82fb-5e34cbd2845c">
|
||||
<name>OPI_WSServer</name>
|
||||
<synonym>
|
||||
<key>ru</key>
|
||||
<value>Компонента Websocket-сервера (ОПИ)</value>
|
||||
</synonym>
|
||||
<templateType>AddIn</templateType>
|
||||
</mdclass:CommonTemplate>
|
||||
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:d90e5e9f3eeec8226255880f549e4d51762a2282e63d1c55d4fbbaca73008ddb
|
||||
size 2124255
|
||||
@@ -47,6 +47,7 @@
|
||||
<commonTemplates>CommonTemplate.OPI_Cryptography</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_FTP</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_GRPC</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_HTTPServer</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_MongoDB</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_MSSQL</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_MySQL</commonTemplates>
|
||||
@@ -56,6 +57,7 @@
|
||||
<commonTemplates>CommonTemplate.OPI_SSH</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_TCPClient</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_TCPServer</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_WSServer</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_Text_ClickHouseProto</commonTemplates>
|
||||
<commonTemplates>CommonTemplate.OPI_Text_MethodSettings</commonTemplates>
|
||||
<commonModules>CommonModule.OPI_Airtable</commonModules>
|
||||
|
||||
Reference in New Issue
Block a user