TUI client: WebSocket with HTTP fallback

poll_loop now:
1. Tries WebSocket connection to /v1/ws/<fingerprint>
2. On success: receives messages in real-time (instant push)
3. On disconnect: reconnects after 3 seconds
4. On WS failure: falls back to HTTP polling every 2 seconds

Refactored message processing into shared functions:
- process_incoming() handles raw bytes
- process_wire_message() handles deserialized WireMessage
- Used by both WS and HTTP paths

Both CLI TUI and web client now use WebSocket:
- No more HTTP polling spam in server logs
- Messages arrive instantly on both clients
- HTTP poll kept as fallback for scripts/mules

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-03-27 09:49:46 +04:00
parent c8a95e27e4
commit fe2b7d8e8a
3 changed files with 140 additions and 85 deletions

6
warzone/Cargo.lock generated
View File

@@ -2330,7 +2330,9 @@ checksum = "edc5f74e248dc973e0dbb7b74c7e0d6fcc301c694ff50049504004ef4d0cdcd9"
dependencies = [
"futures-util",
"log",
"native-tls",
"tokio",
"tokio-native-tls",
"tungstenite",
]
@@ -2501,6 +2503,7 @@ dependencies = [
"http",
"httparse",
"log",
"native-tls",
"rand",
"sha1",
"thiserror 1.0.69",
@@ -2654,6 +2657,7 @@ dependencies = [
"chrono",
"clap",
"crossterm",
"futures-util",
"hex",
"libc",
"rand",
@@ -2663,8 +2667,10 @@ dependencies = [
"serde_json",
"sled",
"tokio",
"tokio-tungstenite",
"tracing",
"tracing-subscriber",
"url",
"uuid",
"warzone-protocol",
"x25519-dalek",