P4: messages, topics, pubkey

Backend
- api/messages.rs covers send/pop/reply/status with an externally
  tagged MessageDestination enum that matches the daemon's
  {ip|pk: ...} body shape; pop_message uses an inflated request
  timeout to outlast the long-poll window
- api/topics.rs implements default action, topic CRUD, sources
  whitelist, and forward-socket get/set/remove. POST /topics ships
  the raw base64 string as the body (not JSON); path segments are
  percent-encoded inline (topics contain '/' and '+')
- api/pubkey.rs resolves an overlay IPv6 to a hex public key
- poller spawns a third long-poll loop on /messages?peek=false
  that fans every inbound message into a 200-deep ring buffer and
  emits messages://incoming for the UI

Frontend
- messages store: live inbox via the event, persisted outbox via
  tauri-plugin-store keyed under outbox.json
- ComposeMessage form: ip/pk toggle, optional UTF-8 topic and
  payload that get base64-encoded with a TextEncoder-based helper
- MessageList renders printable payloads decoded; binary payloads
  fall back to a "(N bytes binary)" hint
- Topics view: split layout with whitelist on the left, per-topic
  sources/forward editor on the right; default-action toggle is
  surfaced at the top
This commit is contained in:
syoul
2026-04-25 23:10:21 +02:00
parent 95e7cb4bd3
commit f28d0e1338
17 changed files with 1449 additions and 22 deletions

View File

@@ -1,6 +1,11 @@
use crate::api::admin::NodeInfo;
use crate::api::messages::{
IncomingMessage, MessageDestination, MessageStatus, PushMessageBody, PushMessageReceipt,
};
use crate::api::peers::{AggregatedStats, PeerInfo};
use crate::api::pubkey::PubkeyLookup;
use crate::api::routes::RoutesSnapshot;
use crate::api::topics::DefaultAction;
use crate::api::MyceliumClient;
use crate::error::{AppError, AppResult};
use crate::sidecar::SidecarConfig;
@@ -99,3 +104,146 @@ pub async fn peers_stats(state: State<'_, AppState>) -> AppResult<AggregatedStat
pub async fn routes_snapshot(state: State<'_, AppState>) -> AppResult<RoutesSnapshot> {
require_client(&state)?.routes_snapshot().await
}
// ─── Messages ────────────────────────────────────────────────────────────────
#[tauri::command]
pub async fn send_message(
state: State<'_, AppState>,
destination: MessageDestination,
topic_b64: String,
payload_b64: String,
) -> AppResult<PushMessageReceipt> {
let body = PushMessageBody {
dst: destination,
topic: topic_b64,
payload: payload_b64,
};
require_client(&state)?.send_message(&body).await
}
#[tauri::command]
pub async fn reply_message(
state: State<'_, AppState>,
id: String,
destination: MessageDestination,
topic_b64: String,
payload_b64: String,
) -> AppResult<PushMessageReceipt> {
let body = PushMessageBody {
dst: destination,
topic: topic_b64,
payload: payload_b64,
};
require_client(&state)?.reply_message(&id, &body).await
}
#[tauri::command]
pub async fn message_status(state: State<'_, AppState>, id: String) -> AppResult<MessageStatus> {
require_client(&state)?.message_status(&id).await
}
#[tauri::command]
pub fn inbox_messages(state: State<'_, AppState>) -> Vec<IncomingMessage> {
state.poller.inbox_snapshot()
}
#[tauri::command]
pub fn inbox_clear(state: State<'_, AppState>) {
state.poller.clear_inbox();
}
// ─── Topics ──────────────────────────────────────────────────────────────────
#[tauri::command]
pub async fn topics_default_get(state: State<'_, AppState>) -> AppResult<DefaultAction> {
require_client(&state)?.topics_default_get().await
}
#[tauri::command]
pub async fn topics_default_set(state: State<'_, AppState>, accept: bool) -> AppResult<()> {
require_client(&state)?
.topics_default_set(&DefaultAction { accept })
.await
}
#[tauri::command]
pub async fn topics_list(state: State<'_, AppState>) -> AppResult<Vec<String>> {
require_client(&state)?.topics_list().await
}
#[tauri::command]
pub async fn topic_add(state: State<'_, AppState>, topic_b64: String) -> AppResult<()> {
if topic_b64.trim().is_empty() {
return Err(AppError::BadInput("topic must not be empty".into()));
}
require_client(&state)?.topic_add(topic_b64.trim()).await
}
#[tauri::command]
pub async fn topic_remove(state: State<'_, AppState>, topic_b64: String) -> AppResult<()> {
require_client(&state)?.topic_remove(&topic_b64).await
}
#[tauri::command]
pub async fn topic_sources_list(
state: State<'_, AppState>,
topic_b64: String,
) -> AppResult<Vec<String>> {
require_client(&state)?.topic_sources_list(&topic_b64).await
}
#[tauri::command]
pub async fn topic_source_add(
state: State<'_, AppState>,
topic_b64: String,
subnet: String,
) -> AppResult<()> {
require_client(&state)?
.topic_source_add(&topic_b64, &subnet)
.await
}
#[tauri::command]
pub async fn topic_source_remove(
state: State<'_, AppState>,
topic_b64: String,
subnet: String,
) -> AppResult<()> {
require_client(&state)?
.topic_source_remove(&topic_b64, &subnet)
.await
}
#[tauri::command]
pub async fn topic_forward_get(
state: State<'_, AppState>,
topic_b64: String,
) -> AppResult<Option<String>> {
require_client(&state)?.topic_forward_get(&topic_b64).await
}
#[tauri::command]
pub async fn topic_forward_set(
state: State<'_, AppState>,
topic_b64: String,
socket_path: String,
) -> AppResult<()> {
require_client(&state)?
.topic_forward_set(&topic_b64, &socket_path)
.await
}
#[tauri::command]
pub async fn topic_forward_remove(state: State<'_, AppState>, topic_b64: String) -> AppResult<()> {
require_client(&state)?
.topic_forward_remove(&topic_b64)
.await
}
// ─── Pubkey ──────────────────────────────────────────────────────────────────
#[tauri::command]
pub async fn lookup_pubkey(state: State<'_, AppState>, ip: String) -> AppResult<PubkeyLookup> {
require_client(&state)?.lookup_pubkey(&ip).await
}