https works
This commit is contained in:
parent
8e9a9ed86f
commit
940e7984e3
8 changed files with 57 additions and 296 deletions
200
Cargo.lock
generated
200
Cargo.lock
generated
|
@ -47,56 +47,6 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
|
||||
dependencies = [
|
||||
"windows-sys 0.60.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys 0.60.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arc-swap"
|
||||
version = "1.7.1"
|
||||
|
@ -166,7 +116,7 @@ checksum = "021e862c184ae977658b36c4500f7feac3221ca5da43e3f25bd04ab6c79a29b5"
|
|||
dependencies = [
|
||||
"axum-core",
|
||||
"axum-macros",
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
"futures-util",
|
||||
"http",
|
||||
|
@ -199,7 +149,7 @@ version = "0.5.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68464cd0412f486726fb3373129ef5d2993f90c34bc2bc1c1e9943b2f4fc7ca6"
|
||||
dependencies = [
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"http",
|
||||
"http-body",
|
||||
|
@ -231,7 +181,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "495c05f60d6df0093e8fb6e74aa5846a0ad06abaf96d76166283720bf740f8ab"
|
||||
dependencies = [
|
||||
"arc-swap",
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"fs-err",
|
||||
"http",
|
||||
"http-body",
|
||||
|
@ -323,16 +273,6 @@ version = "1.5.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"iovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.10.1"
|
||||
|
@ -414,12 +354,6 @@ dependencies = [
|
|||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
||||
|
||||
[[package]]
|
||||
name = "compact_str"
|
||||
version = "0.8.1"
|
||||
|
@ -644,19 +578,6 @@ dependencies = [
|
|||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.11.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"env_filter",
|
||||
"jiff",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
|
@ -747,12 +668,6 @@ version = "1.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.1.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678"
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.3.31"
|
||||
|
@ -903,7 +818,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386"
|
||||
dependencies = [
|
||||
"atomic-waker",
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"fnv",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
|
@ -953,7 +868,7 @@ version = "1.3.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565"
|
||||
dependencies = [
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"fnv",
|
||||
"itoa",
|
||||
]
|
||||
|
@ -964,7 +879,7 @@ version = "1.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184"
|
||||
dependencies = [
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"http",
|
||||
]
|
||||
|
||||
|
@ -974,7 +889,7 @@ version = "0.1.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a"
|
||||
dependencies = [
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"http",
|
||||
"http-body",
|
||||
|
@ -999,7 +914,7 @@ version = "1.6.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80"
|
||||
dependencies = [
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"h2",
|
||||
|
@ -1036,7 +951,7 @@ version = "0.6.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
|
||||
dependencies = [
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
|
@ -1053,7 +968,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "8d9b05277c7e8da2c93a568989bb6207bef0112e8d17df7a6eda4a3cf143bc5e"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
|
@ -1255,15 +1170,6 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iovec"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.11.0"
|
||||
|
@ -1280,12 +1186,6 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.12.1"
|
||||
|
@ -1310,30 +1210,6 @@ version = "1.0.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "jiff"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49"
|
||||
dependencies = [
|
||||
"jiff-static",
|
||||
"log",
|
||||
"portable-atomic",
|
||||
"portable-atomic-util",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jiff-static"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.104",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.33"
|
||||
|
@ -1353,11 +1229,8 @@ dependencies = [
|
|||
"chrono",
|
||||
"crossterm",
|
||||
"directories",
|
||||
"env_logger",
|
||||
"figment",
|
||||
"futures 0.3.31",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"futures",
|
||||
"julid-rs",
|
||||
"local-ip-address",
|
||||
"log",
|
||||
|
@ -1374,12 +1247,9 @@ dependencies = [
|
|||
"sha256",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-io",
|
||||
"tokio-rustls",
|
||||
"toml 0.9.5",
|
||||
"tower",
|
||||
"tower-http",
|
||||
"tower-service",
|
||||
"tui-input",
|
||||
"tui-logger",
|
||||
"unicode-segmentation",
|
||||
|
@ -1648,12 +1518,6 @@ version = "1.21.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.73"
|
||||
|
@ -1790,21 +1654,6 @@ version = "0.3.32"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic-util"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
|
||||
dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "potential_utf"
|
||||
version = "0.1.2"
|
||||
|
@ -2006,7 +1855,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"encoding_rs",
|
||||
"futures-core",
|
||||
"h2",
|
||||
|
@ -2276,7 +2125,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "f880fc8562bdeb709793f00eb42a2ad0e672c4f883bbe59122b926eca935c8f6"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"hex",
|
||||
"sha2",
|
||||
"tokio",
|
||||
|
@ -2518,7 +2367,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"io-uring",
|
||||
"libc",
|
||||
"mio",
|
||||
|
@ -2529,17 +2378,6 @@ dependencies = [
|
|||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-io"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674"
|
||||
dependencies = [
|
||||
"bytes 0.4.12",
|
||||
"futures 0.1.31",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "2.5.0"
|
||||
|
@ -2577,7 +2415,7 @@ version = "0.7.16"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14307c986784f72ef81c89db7d9e28d6ac26d16213b109ea501696195e6e3ce5"
|
||||
dependencies = [
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"pin-project-lite",
|
||||
|
@ -2687,7 +2525,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bytes 1.10.1",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
|
@ -2842,12 +2680,6 @@ version = "1.0.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
|
|
16
Cargo.toml
16
Cargo.toml
|
@ -5,15 +5,12 @@ edition = "2024"
|
|||
|
||||
[dependencies]
|
||||
axum = { version = "0.8", features = ["macros"] }
|
||||
axum-server = { version = "0.7.2", features = ["tls-rustls", "tokio-rustls"] }
|
||||
axum-server = { version = "0.7", features = ["tls-rustls", "tokio-rustls"] }
|
||||
chrono = "0.4"
|
||||
crossterm = { version = "0.28", features = ["event-stream"] }
|
||||
directories = "6"
|
||||
env_logger = "0.11"
|
||||
figment = { version = "0.10", features = ["toml", "test", "env"] }
|
||||
futures = "0.3"
|
||||
hyper = { version = "1.6.0", features = ["http1"] }
|
||||
hyper-util = { version = "0.1.16", features = ["http1", "tokio", "service", "server"] }
|
||||
julid-rs = { version = "1", default-features = false, features = ["serde"] }
|
||||
local-ip-address = "0.6"
|
||||
log = "0.4"
|
||||
|
@ -22,20 +19,17 @@ mime_guess = "2"
|
|||
network-interface = { version = "2", features = ["serde"] }
|
||||
ratatui = "0.29"
|
||||
ratatui-explorer = "0.2"
|
||||
rcgen = "0.14.3"
|
||||
rcgen = "0.14"
|
||||
reqwest = { version = "0.12", features = ["json"] }
|
||||
rustix = { version = "1.0.8", default-features = false, features = ["system"] }
|
||||
rustix = { version = "1", default-features = false, features = ["system"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
sha256 = "1.6"
|
||||
thiserror = "2"
|
||||
tokio = { version = "1", default-features = false, features = ["time", "macros", "rt-multi-thread"] }
|
||||
tokio-io = "0.1.13"
|
||||
tokio-rustls = { version = "0.26.2", default-features = false, features = ["tls12", "logging"] }
|
||||
toml = "0.9.5"
|
||||
tower = { version = "0.5.2", features = ["make"] }
|
||||
tokio-rustls = { version = "0.26", default-features = false, features = ["tls12", "logging"] }
|
||||
toml = "0.9"
|
||||
tower-http = { version = "0.6", features = ["limit"] }
|
||||
tower-service = "0.3.3"
|
||||
tui-input = "0.14"
|
||||
tui-logger = { version = "0.17", features = ["crossterm"] }
|
||||
unicode-segmentation = "1"
|
||||
|
|
|
@ -65,7 +65,7 @@ impl Config {
|
|||
gen_ssl(&key, &cert)?
|
||||
};
|
||||
|
||||
let mut config = Self {
|
||||
let config = Self {
|
||||
multicast_addr: SocketAddrV4::new(MULTICAST_IP, DEFAULT_PORT),
|
||||
download_dir,
|
||||
local_ip_addr: Some(local_ip_addr),
|
||||
|
|
|
@ -16,9 +16,9 @@ use crate::{Config, JocalService, RunningState, models::Device};
|
|||
impl JocalService {
|
||||
pub async fn announce(&self, socket: Option<SocketAddr>) -> crate::error::Result<()> {
|
||||
trace!("announcing");
|
||||
announce_http(&self.device, socket, self.client.clone()).await?;
|
||||
announce_http(&self.config.device, socket, self.client.clone()).await?;
|
||||
announce_multicast(
|
||||
&self.device,
|
||||
&self.config.device,
|
||||
self.config.multicast_addr,
|
||||
self.socket.clone(),
|
||||
)
|
||||
|
@ -63,7 +63,7 @@ impl JocalService {
|
|||
|
||||
async fn process_device(&self, message: &str, src: SocketAddr, config: &Config) {
|
||||
if let Ok(device) = serde_json::from_str::<Device>(message) {
|
||||
if device.fingerprint == self.device.fingerprint {
|
||||
if device.fingerprint == self.config.device.fingerprint {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ pub async fn register_device(
|
|||
Json(device): Json<Device>,
|
||||
) -> Json<Device> {
|
||||
let mut addr = addr;
|
||||
addr.set_port(service.device.port);
|
||||
addr.set_port(service.config.device.port);
|
||||
service
|
||||
.peers
|
||||
.lock()
|
||||
|
@ -120,7 +120,7 @@ async fn announce_http(
|
|||
client: reqwest::Client,
|
||||
) -> crate::error::Result<()> {
|
||||
if let Some(ip) = ip {
|
||||
let url = format!("http://{ip}/api/localsend/v2/register");
|
||||
let url = format!("https://{ip}/api/localsend/v2/register");
|
||||
client.post(&url).json(device).send().await?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -1,27 +1,17 @@
|
|||
use std::{net::SocketAddr, path::Path, sync::Arc};
|
||||
use std::{net::SocketAddr, path::Path, time::Duration};
|
||||
|
||||
use axum::{
|
||||
Json, Router,
|
||||
extract::{ConnectInfo, DefaultBodyLimit, Request},
|
||||
extract::DefaultBodyLimit,
|
||||
routing::{get, post},
|
||||
};
|
||||
use axum_server::tls_rustls::RustlsConfig;
|
||||
use hyper::body::Incoming;
|
||||
use hyper_util::rt::{TokioExecutor, TokioIo};
|
||||
use tokio::{
|
||||
net::TcpListener,
|
||||
sync::{Mutex, mpsc},
|
||||
use axum_server::{Handle, tls_rustls::RustlsConfig};
|
||||
use tokio::sync::mpsc;
|
||||
use tokio_rustls::rustls::{
|
||||
ServerConfig,
|
||||
pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject},
|
||||
};
|
||||
use tokio_rustls::{
|
||||
TlsAcceptor,
|
||||
rustls::{
|
||||
ServerConfig,
|
||||
pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject},
|
||||
},
|
||||
};
|
||||
use tower::MakeService;
|
||||
use tower_http::limit::RequestBodyLimitLayer;
|
||||
use tower_service::Service;
|
||||
|
||||
use crate::{
|
||||
JocalService,
|
||||
|
@ -38,80 +28,32 @@ impl JocalService {
|
|||
|
||||
let ssl_config = rustls_server_config(key, cert);
|
||||
|
||||
// let stop = Arc::new(Mutex::new(stop_rx));
|
||||
let handle = Handle::new();
|
||||
|
||||
/*
|
||||
loop {
|
||||
let tower_service = app.clone();
|
||||
let tls_acceptor = acceptor.clone();
|
||||
let stop = stop.clone();
|
||||
let mut stop = stop.lock().await;
|
||||
|
||||
tokio::select! {
|
||||
// Wait for new tcp connection
|
||||
Ok((cnx, addr)) = listener.accept() => {
|
||||
tokio::spawn(async move {
|
||||
// Wait for tls handshake to happen
|
||||
let Ok(stream) = tls_acceptor.accept(cnx).await else {
|
||||
log::error!("error during tls handshake connection from {}", addr);
|
||||
return;
|
||||
};
|
||||
|
||||
// Hyper has its own `AsyncRead` and `AsyncWrite` traits and doesn't use tokio.
|
||||
// `TokioIo` converts between them.
|
||||
let stream = TokioIo::new(stream);
|
||||
|
||||
// Hyper also has its own `Service` trait and doesn't use tower. We can use
|
||||
// `hyper::service::service_fn` to create a hyper `Service` that calls our app
|
||||
// through `tower::Service::call`.
|
||||
let hyper_service =
|
||||
hyper::service::service_fn(move |request: Request<Incoming>| {
|
||||
// We have to clone `tower_service` because hyper's `Service` uses `&self`
|
||||
// whereas tower's `Service` requires `&mut self`.
|
||||
//
|
||||
// We don't need to call `poll_ready` since `Router` is always ready.
|
||||
tower_service.clone().call(request)
|
||||
});
|
||||
|
||||
let ret = hyper_util::server::conn::auto::Builder::new(TokioExecutor::new())
|
||||
.serve_connection_with_upgrades(stream, hyper_service)
|
||||
.await;
|
||||
|
||||
if let Err(err) = ret {
|
||||
log::error!("error serving connection from {}: {}", addr, err);
|
||||
}
|
||||
});
|
||||
}
|
||||
_ = stop.recv() => {
|
||||
log::info!("stopping http server");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
tokio::spawn(shutdown(handle.clone(), stop_rx));
|
||||
|
||||
axum_server::bind_rustls(addr, ssl_config)
|
||||
.handle(handle)
|
||||
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
|
||||
.await?;
|
||||
|
||||
// axum::serve(
|
||||
// listener,
|
||||
// app.into_make_service_with_connect_info::<SocketAddr>(),
|
||||
// )
|
||||
// .with_graceful_shutdown(shutdown(stop_rx))
|
||||
// .await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_router(&self) -> Router {
|
||||
let device = self.device.clone();
|
||||
let device = self.config.device.clone();
|
||||
let d2 = device.clone();
|
||||
Router::new()
|
||||
.route("/api/localsend/v2/register", post(register_device))
|
||||
.route(
|
||||
"/api/localsend/v2/info",
|
||||
get(move || async move { Json(device) }),
|
||||
)
|
||||
.route(
|
||||
// the mobile client is trying to hit this one
|
||||
"/api/localsend/v1/info",
|
||||
get(move || async move { Json(d2) }),
|
||||
)
|
||||
.route("/api/localsend/v2/prepare-upload", post(prepare_upload))
|
||||
.route("/api/localsend/v2/upload", post(receive_upload))
|
||||
.layer(DefaultBodyLimit::disable())
|
||||
|
@ -120,10 +62,6 @@ impl JocalService {
|
|||
}
|
||||
}
|
||||
|
||||
async fn shutdown(mut rx: mpsc::Receiver<()>) {
|
||||
rx.recv().await.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn rustls_server_config(key: impl AsRef<Path>, cert: impl AsRef<Path>) -> RustlsConfig {
|
||||
let key = match PrivateKeyDer::from_pem_file(&key) {
|
||||
Ok(k) => k,
|
||||
|
@ -148,3 +86,9 @@ fn rustls_server_config(key: impl AsRef<Path>, cert: impl AsRef<Path>) -> Rustls
|
|||
|
||||
RustlsConfig::from_config(config.into())
|
||||
}
|
||||
|
||||
async fn shutdown(handle: Handle, mut rx: mpsc::Receiver<()>) {
|
||||
let _ = rx.recv().await;
|
||||
log::info!("shutting down http server");
|
||||
handle.graceful_shutdown(Some(Duration::from_secs(5)));
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@ impl Debug for ReceiveRequest {
|
|||
/// Contains the main network and backend state for an application session.
|
||||
#[derive(Clone)]
|
||||
pub struct JocalService {
|
||||
pub device: Device,
|
||||
pub peers: Arc<Mutex<BTreeMap<String, (SocketAddr, Device)>>>,
|
||||
pub sessions: Arc<Mutex<BTreeMap<String, Session>>>, // Session ID to Session
|
||||
pub running_state: Arc<Mutex<RunningState>>,
|
||||
|
@ -87,7 +86,6 @@ pub struct JocalService {
|
|||
|
||||
impl JocalService {
|
||||
pub async fn new(
|
||||
device: Device,
|
||||
config: Config,
|
||||
transfer_event_tx: UnboundedSender<TransferEvent>,
|
||||
) -> crate::error::Result<Self> {
|
||||
|
@ -102,7 +100,6 @@ impl JocalService {
|
|||
.build()?;
|
||||
|
||||
Ok(Self {
|
||||
device,
|
||||
config,
|
||||
client,
|
||||
socket: socket.into(),
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,4 +1,4 @@
|
|||
use jocalsend::{Config, JocalService, Listeners, error::Result, models::Device};
|
||||
use jocalsend::{Config, JocalService, Listeners, error::Result};
|
||||
use log::{error, info};
|
||||
use ratatui::DefaultTerminal;
|
||||
use tokio::{sync::mpsc::unbounded_channel, task::JoinSet};
|
||||
|
@ -8,8 +8,6 @@ mod app;
|
|||
use app::{App, CurrentScreen, Peer};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let device = Device::default();
|
||||
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
unsafe {
|
||||
std::env::set_var("RUST_LOG", "jocalsend");
|
||||
|
@ -21,21 +19,17 @@ fn main() -> Result<()> {
|
|||
let config = Config::new()?;
|
||||
|
||||
let mut terminal = ratatui::init();
|
||||
let result = start_and_run(&mut terminal, config, device);
|
||||
let result = start_and_run(&mut terminal, config);
|
||||
ratatui::restore();
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn start_and_run(
|
||||
terminal: &mut DefaultTerminal,
|
||||
config: Config,
|
||||
device: Device,
|
||||
) -> Result<()> {
|
||||
async fn start_and_run(terminal: &mut DefaultTerminal, config: Config) -> Result<()> {
|
||||
let (event_tx, event_listener) = unbounded_channel();
|
||||
|
||||
let service = JocalService::new(device, config.clone(), event_tx)
|
||||
let service = JocalService::new(config.clone(), event_tx)
|
||||
.await
|
||||
.expect("Could not create JocalService");
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ impl JocalService {
|
|||
device.protocol, addr
|
||||
))
|
||||
.json(&PrepareUploadRequest {
|
||||
info: self.device.clone(),
|
||||
info: self.config.device.clone(),
|
||||
files: files.clone(),
|
||||
});
|
||||
|
||||
|
@ -95,7 +95,7 @@ impl JocalService {
|
|||
files,
|
||||
file_tokens: response.files.clone(),
|
||||
receiver: device,
|
||||
sender: self.device.clone(),
|
||||
sender: self.config.device.clone(),
|
||||
status: SessionStatus::Active,
|
||||
addr,
|
||||
};
|
||||
|
@ -278,7 +278,7 @@ pub async fn prepare_upload(
|
|||
session_id: session_id.clone(),
|
||||
files: req.files.clone(),
|
||||
file_tokens: file_tokens.clone(),
|
||||
receiver: service.device.clone(),
|
||||
receiver: service.config.device.clone(),
|
||||
sender: req.info.clone(),
|
||||
status: SessionStatus::Active,
|
||||
addr,
|
||||
|
|
Loading…
Reference in a new issue