Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src-tauri/src/commands/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,24 @@ async fn handle_incoming_message(app: &AppHandle, frame: &[u8]) -> anyhow::Resul
return Ok(());
}

let state = app.state::<AppState>();

// Check for duplicate message to provide idempotency on network redelivery
let mut received_ids = state.received_message_ids.lock().await;
if received_ids.contains(&wire.id) {
// Duplicate message - skip silently
#[cfg(debug_assertions)]
log::debug!("duplicate message ignored: {}", wire.id);
drop(received_ids);
return Ok(());
}
received_ids.insert(wire.id.clone());
drop(received_ids);

let ct = B64
.decode(&wire.ct)
.map_err(|e| anyhow::anyhow!("base64 decode: {}", e))?;

let state = app.state::<AppState>();
let settings = state.settings.lock().await.clone();

let plaintext_buf = {
Expand Down Expand Up @@ -515,6 +528,8 @@ pub async fn close_session(state: State<'_, AppState>) -> Result<(), String> {
let _ = s.stream_writer.shutdown().await;
}
state.messages.lock().await.clear();
// Clear message ID tracking so new session can receive same IDs
state.received_message_ids.lock().await.clear();
Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions src-tauri/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::Serialize;
use std::collections::HashSet;
use tokio::{
io::WriteHalf,
net::TcpStream,
Expand Down Expand Up @@ -81,6 +82,8 @@ pub struct AppState {
pub router_sam_port: Mutex<Option<u16>>,
/// Last known router status — queried by frontend on mount to avoid event race on release.
pub router_status: Mutex<String>,
/// Track message IDs we've already received to provide idempotency on network redelivery.
pub received_message_ids: Mutex<HashSet<String>>,
}

impl Default for AppState {
Expand All @@ -93,6 +96,7 @@ impl Default for AppState {
i2p: Mutex::new(None),
router_sam_port: Mutex::new(None),
router_status: Mutex::new("idle".to_string()),
received_message_ids: Mutex::new(HashSet::new()),
}
}
}