mirror of
https://github.com/ratspeak/rsLXMF
synced 2026-11-27 13:52:18 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ac04f0311 | ||
|
|
b790ca91d3 | ||
|
|
511e0a77f1 | ||
|
|
fedba0bdfa | ||
|
|
c0bf58eb52 |
No files matched your search
Generated
+20
-41
@@ -149,21 +149,11 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
||||
|
||||
[[package]]
|
||||
name = "bzip2"
|
||||
version = "0.5.2"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47"
|
||||
checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c"
|
||||
dependencies = [
|
||||
"bzip2-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bzip2-sys"
|
||||
version = "0.1.13+1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
"libbz2-rs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -175,16 +165,6 @@ dependencies = [
|
||||
"cipher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e1e928d4b69e3077709075a938a05ffbedfa53a84c8f766efbf8220bb1ff60e1"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cesu8"
|
||||
version = "1.1.0"
|
||||
@@ -411,12 +391,6 @@ version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
@@ -634,6 +608,12 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
||||
|
||||
[[package]]
|
||||
name = "libbz2-rs-sys"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34b357333733e8260735ba5894eb928c02ecc69c78715f01a8019e7fa7f2db4c"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.183"
|
||||
@@ -716,6 +696,16 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "md-5"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.0"
|
||||
@@ -870,12 +860,6 @@ dependencies = [
|
||||
"spki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
@@ -1161,6 +1145,7 @@ dependencies = [
|
||||
"bytes",
|
||||
"hex",
|
||||
"hmac",
|
||||
"md-5",
|
||||
"nix 0.29.0",
|
||||
"rmp-serde",
|
||||
"rmpv",
|
||||
@@ -1353,12 +1338,6 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.8"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use bytes::Bytes;
|
||||
use clap::Parser;
|
||||
@@ -46,6 +46,7 @@ use rns_identity::identity::Identity;
|
||||
use rns_identity::ratchet::{
|
||||
RatchetRing, ReceivedRatchet, clean_received_ratchets_dir, purge_expired_ratchets_in_memory,
|
||||
};
|
||||
use rns_runtime::lifecycle::ShutdownSignal;
|
||||
use rns_transport::messages::{
|
||||
AnnounceHandlerEvent, TransportMessage, TransportQuery, TransportQueryResponse,
|
||||
};
|
||||
@@ -95,6 +96,13 @@ fn now_f64() -> f64 {
|
||||
.as_secs_f64()
|
||||
}
|
||||
|
||||
async fn sleep_or_shutdown(shutdown: &ShutdownSignal, duration: Duration) -> bool {
|
||||
tokio::select! {
|
||||
_ = shutdown.wait() => true,
|
||||
_ = tokio::time::sleep(duration) => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn mark_delivery_attempt(message: &mut LxMessage) -> u32 {
|
||||
let now = now_f64();
|
||||
message.delivery_attempts += 1;
|
||||
@@ -564,8 +572,7 @@ impl LxmdRunner {
|
||||
delivery_rx,
|
||||
&identity,
|
||||
LXMF_APP_NAME,
|
||||
signing_key
|
||||
.unwrap_or_else(|| panic!("Identity must have signing key for link management")),
|
||||
signing_key,
|
||||
);
|
||||
link_mgr.set_link_packet_channel(link_packet_tx);
|
||||
link_mgr.set_resource_completed_channel(resource_tx);
|
||||
@@ -637,6 +644,8 @@ impl LxmdRunner {
|
||||
}
|
||||
};
|
||||
|
||||
// TODO(hardware-identity): route propagation link signing through the
|
||||
// backend-aware Identity path before supporting hardware-backed lxmd.
|
||||
let prop_signing_key = identity.get_signing_key().unwrap_or_else(|| {
|
||||
panic!("Identity must have signing key for propagation link management")
|
||||
});
|
||||
@@ -645,7 +654,7 @@ impl LxmdRunner {
|
||||
prop_delivery_rx,
|
||||
&identity,
|
||||
"lxmf.propagation",
|
||||
prop_signing_key,
|
||||
Some(prop_signing_key),
|
||||
);
|
||||
prop_link_mgr.set_link_packet_channel(prop_link_packet_tx);
|
||||
prop_link_mgr.set_resource_completed_channel(prop_resource_tx);
|
||||
@@ -722,6 +731,8 @@ impl LxmdRunner {
|
||||
delivery_tx: Some(control_delivery_tx),
|
||||
});
|
||||
|
||||
// TODO(hardware-identity): route control link signing through the
|
||||
// backend-aware Identity path before supporting hardware-backed lxmd.
|
||||
let control_signing_key = identity.get_signing_key().unwrap_or_else(|| {
|
||||
panic!("Identity must have signing key for control link management")
|
||||
});
|
||||
@@ -730,7 +741,7 @@ impl LxmdRunner {
|
||||
control_delivery_rx,
|
||||
&identity,
|
||||
CONTROL_APP_NAME,
|
||||
control_signing_key,
|
||||
Some(control_signing_key),
|
||||
);
|
||||
let control_link_identities = control_link_mgr.link_identities_handle();
|
||||
let stats_path_hash =
|
||||
@@ -2755,16 +2766,29 @@ pub(crate) async fn main() {
|
||||
tracing::info!("Waiting for interfaces to come online before announcing...");
|
||||
let mut announced = false;
|
||||
for _ in 0..30 {
|
||||
if shutdown.is_triggered() {
|
||||
break;
|
||||
}
|
||||
let poll_started = Instant::now();
|
||||
let (otx, orx) = tokio::sync::oneshot::channel();
|
||||
let _ = runner
|
||||
.transport_tx
|
||||
.send(TransportMessage::Rpc {
|
||||
tokio::select! {
|
||||
_ = shutdown.wait() => break,
|
||||
result = runner.transport_tx.send(TransportMessage::Rpc {
|
||||
query: rns_transport::messages::TransportQuery::GetInterfaceStats,
|
||||
response_tx: otx,
|
||||
})
|
||||
.await;
|
||||
if let Ok(rns_transport::messages::TransportQueryResponse::InterfaceStats(stats)) =
|
||||
orx.await
|
||||
}) => {
|
||||
if result.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let stats_result = tokio::select! {
|
||||
_ = shutdown.wait() => break,
|
||||
result = tokio::time::timeout(Duration::from_secs(1), orx) => result,
|
||||
};
|
||||
if let Ok(Ok(rns_transport::messages::TransportQueryResponse::InterfaceStats(stats))) =
|
||||
stats_result
|
||||
{
|
||||
let any_online = stats
|
||||
.iter()
|
||||
@@ -2781,16 +2805,26 @@ pub(crate) async fn main() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
let elapsed = poll_started.elapsed();
|
||||
if elapsed < Duration::from_secs(1)
|
||||
&& sleep_or_shutdown(&shutdown, Duration::from_secs(1) - elapsed).await
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !announced {
|
||||
if shutdown.is_triggered() {
|
||||
tracing::info!("Startup announce cancelled by shutdown");
|
||||
} else if !announced {
|
||||
tracing::warn!("No online interface detected after 30s, announcing anyway");
|
||||
let _ = runner.send_announce().await;
|
||||
runner.last_peer_announce = now_f64();
|
||||
}
|
||||
}
|
||||
|
||||
if daemon_config.node_announce_at_start && daemon_config.propagation_enabled {
|
||||
if !shutdown.is_triggered()
|
||||
&& daemon_config.node_announce_at_start
|
||||
&& daemon_config.propagation_enabled
|
||||
{
|
||||
match runner.send_propagation_announce().await {
|
||||
Ok(()) => {
|
||||
tracing::info!("Startup propagation announce sent");
|
||||
@@ -2810,7 +2844,9 @@ pub(crate) async fn main() {
|
||||
tracing::info!("On-inbound command: {}", cmd);
|
||||
}
|
||||
|
||||
if let Some(ref send_args) = args.send {
|
||||
if !shutdown.is_triggered()
|
||||
&& let Some(ref send_args) = args.send
|
||||
{
|
||||
let dest_hex = normalize_hash_hex(&send_args[0]);
|
||||
let content = match args.send_file.as_ref() {
|
||||
Some(path) => match std::fs::read_to_string(path) {
|
||||
@@ -2857,7 +2893,10 @@ pub(crate) async fn main() {
|
||||
if have_key && saw_dest_announce {
|
||||
break;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
if sleep_or_shutdown(&shutdown, Duration::from_millis(500)).await {
|
||||
tracing::info!("message send interrupted by shutdown");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if !have_key {
|
||||
tracing::warn!(
|
||||
@@ -2912,7 +2951,10 @@ pub(crate) async fn main() {
|
||||
runner.refresh_route_hops_from_transport().await;
|
||||
runner.drain_link_packets();
|
||||
runner.tick();
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
if sleep_or_shutdown(&shutdown, Duration::from_secs(1)).await {
|
||||
tracing::info!("message send interrupted by shutdown");
|
||||
return;
|
||||
}
|
||||
|
||||
let stats = runner.router.stats();
|
||||
if stats.pending_outbound == 0 && stats.pending_deferred_stamps == 0 {
|
||||
@@ -2943,7 +2985,10 @@ pub(crate) async fn main() {
|
||||
runner.refresh_route_hops_from_transport().await;
|
||||
runner.drain_link_packets();
|
||||
runner.tick();
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
if sleep_or_shutdown(&shutdown, Duration::from_secs(1)).await {
|
||||
tracing::info!("message send interrupted by shutdown");
|
||||
return;
|
||||
}
|
||||
|
||||
if runner
|
||||
.link_delivery
|
||||
@@ -2974,7 +3019,9 @@ pub(crate) async fn main() {
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
tracing::info!("LXMF Daemon running. Press Ctrl+C to stop.");
|
||||
if !shutdown.is_triggered() {
|
||||
tracing::info!("LXMF Daemon running. Press Ctrl+C to stop.");
|
||||
}
|
||||
|
||||
// Event-driven for inbound, periodic for outbound and maintenance.
|
||||
let mut tick_timer = tokio::time::interval(Duration::from_secs(4));
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
#[cfg(unix)]
|
||||
use std::process::{Child, Stdio};
|
||||
use std::process::{Command, Output};
|
||||
#[cfg(unix)]
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
struct TestDir {
|
||||
@@ -55,6 +59,20 @@ fn write_rust_identity(path: &Path) {
|
||||
.expect("write Rust identity");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn wait_with_timeout(child: &mut Child, timeout: Duration) -> Option<std::process::ExitStatus> {
|
||||
let deadline = Instant::now() + timeout;
|
||||
loop {
|
||||
if let Some(status) = child.try_wait().expect("poll lxmd-rs child") {
|
||||
return Some(status);
|
||||
}
|
||||
if Instant::now() >= deadline {
|
||||
return None;
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_lists_cli_surface_without_starting_runtime() {
|
||||
let output = lxmd(&["--help"]);
|
||||
@@ -76,6 +94,94 @@ fn help_lists_cli_surface_without_starting_runtime() {
|
||||
assert!(text.contains("[possible values: opportunistic, direct, propagated]"));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn ctrl_c_exits_during_startup_announce_wait() {
|
||||
let lxmf_dir = TestDir::new("lxmf-ctrlc");
|
||||
let rns_dir = TestDir::new("rns-ctrlc");
|
||||
fs::write(
|
||||
lxmf_dir.path().join("config"),
|
||||
"\
|
||||
[lxmf]
|
||||
display_name = Test
|
||||
announce_at_start = yes
|
||||
|
||||
[propagation]
|
||||
enable_node = no
|
||||
",
|
||||
)
|
||||
.expect("write LXMF config");
|
||||
fs::write(
|
||||
rns_dir.path().join("config"),
|
||||
"\
|
||||
[reticulum]
|
||||
share_instance = No
|
||||
enable_transport = No
|
||||
respond_to_probes = No
|
||||
panic_on_interface_error = No
|
||||
discover_interfaces = No
|
||||
|
||||
[interfaces]
|
||||
",
|
||||
)
|
||||
.expect("write no-interface Reticulum config");
|
||||
|
||||
let mut child = Command::new(env!("CARGO_BIN_EXE_lxmd-rs"))
|
||||
.arg("--config")
|
||||
.arg(lxmf_dir.path())
|
||||
.arg("--rnsconfig")
|
||||
.arg(rns_dir.path())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("lxmd-rs subprocess should start");
|
||||
|
||||
let identity_path = lxmf_dir.path().join("identity");
|
||||
let startup_deadline = Instant::now() + Duration::from_secs(5);
|
||||
while !identity_path.exists() {
|
||||
if let Some(status) = child.try_wait().expect("poll lxmd-rs startup") {
|
||||
let output = child.wait_with_output().expect("collect lxmd-rs output");
|
||||
panic!(
|
||||
"lxmd-rs exited before startup announce wait ({status}):\n{}",
|
||||
combined_output(&output)
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
Instant::now() < startup_deadline,
|
||||
"lxmd-rs did not reach startup announce wait"
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
let signal_status = Command::new("kill")
|
||||
.arg("-INT")
|
||||
.arg(child.id().to_string())
|
||||
.status()
|
||||
.expect("send SIGINT to lxmd-rs");
|
||||
assert!(signal_status.success(), "kill -INT should succeed");
|
||||
|
||||
if wait_with_timeout(&mut child, Duration::from_secs(3)).is_none() {
|
||||
let _ = child.kill();
|
||||
let output = child.wait_with_output().expect("collect lxmd-rs output");
|
||||
panic!(
|
||||
"lxmd-rs did not exit after Ctrl+C during startup announce wait:\n{}",
|
||||
combined_output(&output)
|
||||
);
|
||||
}
|
||||
|
||||
let output = child.wait_with_output().expect("collect lxmd-rs output");
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"expected clean shutdown after Ctrl+C, got:\n{}",
|
||||
combined_output(&output)
|
||||
);
|
||||
assert!(
|
||||
combined_output(&output).contains("Startup announce cancelled by shutdown"),
|
||||
"expected startup announce cancellation log, got:\n{}",
|
||||
combined_output(&output)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_reports_binary_name_and_package_version() {
|
||||
let output = lxmd(&["--version"]);
|
||||
|
||||
Reference in new issue
Block a user