Fix all compiler warnings across server and client
- Remove unused ServerConfig struct (config via CLI args) - Remove unused otpks field from Database (not yet needed) - Wire AppError into message routes with proper error propagation - Remove unused imports in send.rs (Seed, MessageContent, etc.) - Suppress dead_code on BundleResponse.fingerprint (needed by serde) Zero warnings, 17/17 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use warzone_protocol::identity::Seed;
|
|
||||||
use warzone_protocol::message::{MessageContent, MessageType, WarzoneMessage};
|
|
||||||
use warzone_protocol::ratchet::{RatchetMessage, RatchetState};
|
use warzone_protocol::ratchet::{RatchetMessage, RatchetState};
|
||||||
use warzone_protocol::types::{Fingerprint, MessageId, SessionId};
|
use warzone_protocol::types::Fingerprint;
|
||||||
use warzone_protocol::x3dh;
|
use warzone_protocol::x3dh;
|
||||||
use x25519_dalek::PublicKey;
|
use x25519_dalek::PublicKey;
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ struct SendRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct BundleResponse {
|
struct BundleResponse {
|
||||||
fingerprint: String,
|
fingerprint: String,
|
||||||
bundle: String, // base64
|
bundle: String, // base64
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
pub struct ServerConfig {
|
// Server configuration — currently handled via CLI args in main.rs.
|
||||||
pub bind_addr: String,
|
// This module will be used when file-based configuration is added.
|
||||||
pub data_dir: String,
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use anyhow::Result;
|
|||||||
pub struct Database {
|
pub struct Database {
|
||||||
pub keys: sled::Tree,
|
pub keys: sled::Tree,
|
||||||
pub messages: sled::Tree,
|
pub messages: sled::Tree,
|
||||||
pub otpks: sled::Tree,
|
|
||||||
_db: sled::Db,
|
_db: sled::Db,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12,11 +11,9 @@ impl Database {
|
|||||||
let db = sled::open(data_dir)?;
|
let db = sled::open(data_dir)?;
|
||||||
let keys = db.open_tree("keys")?;
|
let keys = db.open_tree("keys")?;
|
||||||
let messages = db.open_tree("messages")?;
|
let messages = db.open_tree("messages")?;
|
||||||
let otpks = db.open_tree("otpks")?;
|
|
||||||
Ok(Database {
|
Ok(Database {
|
||||||
keys,
|
keys,
|
||||||
messages,
|
messages,
|
||||||
otpks,
|
|
||||||
_db: db,
|
_db: db,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
|
|
||||||
|
/// Wraps anyhow::Error into an axum-compatible error response.
|
||||||
pub struct AppError(pub anyhow::Error);
|
pub struct AppError(pub anyhow::Error);
|
||||||
|
|
||||||
impl IntoResponse for AppError {
|
impl IntoResponse for AppError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
|
tracing::error!("{:#}", self.0);
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, self.0.to_string()).into_response()
|
(StatusCode::INTERNAL_SERVER_ERROR, self.0.to_string()).into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,3 +16,6 @@ impl<E: Into<anyhow::Error>> From<E> for AppError {
|
|||||||
AppError(err.into())
|
AppError(err.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convenience type for route handlers.
|
||||||
|
pub type AppResult<T> = Result<T, AppError>;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use axum::{
|
|||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
use crate::errors::AppResult;
|
||||||
use crate::state::AppState;
|
use crate::state::AppState;
|
||||||
|
|
||||||
pub fn routes() -> Router<AppState> {
|
pub fn routes() -> Router<AppState> {
|
||||||
@@ -17,45 +18,41 @@ pub fn routes() -> Router<AppState> {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct SendRequest {
|
struct SendRequest {
|
||||||
to: String,
|
to: String,
|
||||||
message: Vec<u8>, // bincode-serialized WarzoneMessage
|
message: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_message(
|
async fn send_message(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Json(req): Json<SendRequest>,
|
Json(req): Json<SendRequest>,
|
||||||
) -> Json<serde_json::Value> {
|
) -> AppResult<Json<serde_json::Value>> {
|
||||||
// Append to recipient's queue
|
|
||||||
let key = format!("queue:{}", req.to);
|
let key = format!("queue:{}", req.to);
|
||||||
let _ = state.db.messages.insert(
|
state.db.messages.insert(
|
||||||
format!("{}:{}", key, uuid::Uuid::new_v4()).as_bytes(),
|
format!("{}:{}", key, uuid::Uuid::new_v4()).as_bytes(),
|
||||||
req.message,
|
req.message,
|
||||||
);
|
)?;
|
||||||
Json(serde_json::json!({ "ok": true }))
|
Ok(Json(serde_json::json!({ "ok": true })))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn poll_messages(
|
async fn poll_messages(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path(fingerprint): Path<String>,
|
Path(fingerprint): Path<String>,
|
||||||
) -> Json<Vec<String>> {
|
) -> AppResult<Json<Vec<String>>> {
|
||||||
let prefix = format!("queue:{}", fingerprint);
|
let prefix = format!("queue:{}", fingerprint);
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
for item in state.db.messages.scan_prefix(prefix.as_bytes()) {
|
for item in state.db.messages.scan_prefix(prefix.as_bytes()) {
|
||||||
if let Ok((_, value)) = item {
|
let (_, value) = item?;
|
||||||
messages.push(base64::Engine::encode(
|
messages.push(base64::Engine::encode(
|
||||||
&base64::engine::general_purpose::STANDARD,
|
&base64::engine::general_purpose::STANDARD,
|
||||||
&value,
|
&value,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
Ok(Json(messages))
|
||||||
Json(messages)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ack_message(
|
async fn ack_message(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
) -> Json<serde_json::Value> {
|
) -> AppResult<Json<serde_json::Value>> {
|
||||||
// Scan for and remove the message with this ID
|
state.db.messages.remove(id.as_bytes())?;
|
||||||
// In a real implementation, we'd have a proper index
|
Ok(Json(serde_json::json!({ "ok": true })))
|
||||||
let _ = state.db.messages.remove(id.as_bytes());
|
|
||||||
Json(serde_json::json!({ "ok": true }))
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user