protobuf migration: replace JSON with prost-generated wire format
- Expanded protocol/lnex.proto with full message set for all packet types - Added prost + prost-build to gateway build pipeline - Refactored all handlers and framing to use prost encode/decode - Removed serde payload structs (now generated from .proto) - Server starts and admin endpoint responds
This commit is contained in:
parent
5534cd01f7
commit
9821814240
31 changed files with 719 additions and 661 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use chacha20poly1305::{
|
||||
ChaCha20Poly1305, Key, KeyInit, Nonce,
|
||||
aead::{Aead, Payload},
|
||||
ChaCha20Poly1305, Key, KeyInit, Nonce,
|
||||
};
|
||||
|
||||
pub(super) fn make_nonce(cid: &[u8; 8], seq: u64) -> [u8; 12] {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use super::packet::{PacketHeader, PacketId};
|
||||
use serde::Serialize;
|
||||
use prost::Message;
|
||||
|
||||
/// Encode a packet: header + JSON payload bytes.
|
||||
/// Encode a packet: header + protobuf payload bytes.
|
||||
pub fn encode_packet(id: PacketId, seq: u32, payload: &[u8]) -> Vec<u8> {
|
||||
let header = PacketHeader::new(id, seq, payload.len() as u32);
|
||||
let mut out = Vec::with_capacity(PacketHeader::SIZE + payload.len());
|
||||
|
|
@ -10,7 +10,7 @@ pub fn encode_packet(id: PacketId, seq: u32, payload: &[u8]) -> Vec<u8> {
|
|||
out
|
||||
}
|
||||
|
||||
/// Serialize a payload struct to JSON bytes.
|
||||
pub fn to_payload<T: Serialize>(v: &T) -> Vec<u8> {
|
||||
serde_json::to_vec(v).expect("payload serialization is infallible")
|
||||
/// Encode a protobuf payload struct to bytes.
|
||||
pub fn to_payload(msg: &impl Message) -> Vec<u8> {
|
||||
msg.encode_to_vec()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,104 @@
|
|||
mod crypto;
|
||||
mod framing;
|
||||
mod packet;
|
||||
mod payloads;
|
||||
|
||||
pub mod lnex {
|
||||
include!(concat!(env!("OUT_DIR"), "/lnex.rs"));
|
||||
}
|
||||
|
||||
pub use lnex::*;
|
||||
|
||||
pub use crypto::SessionCrypto;
|
||||
|
||||
// Re-export everything so `crate::proto::X` works as before
|
||||
pub use framing::{encode_packet, to_payload};
|
||||
pub use packet::{ErrorCode, PacketHeader, PacketId, flags};
|
||||
pub use payloads::*;
|
||||
pub use packet::{flags, ErrorCode, PacketHeader, PacketId};
|
||||
|
||||
// ─── Backward-compat type aliases ────────────────────────────────
|
||||
// Handshake
|
||||
pub type HelloPayload = Hello;
|
||||
pub type AuthPayload = Auth;
|
||||
pub type SessionPayload = Session;
|
||||
|
||||
// Keepalive
|
||||
pub type PingPayload = Ping;
|
||||
pub type PongPayload = Pong;
|
||||
|
||||
// Error / Disconnect
|
||||
pub type ErrorPayload = Error;
|
||||
pub type DisconnectPayload = Disconnect;
|
||||
|
||||
// Channels
|
||||
pub type JoinChannelPayload = JoinChannel;
|
||||
pub type LeaveChannelPayload = LeaveChannel;
|
||||
pub type ChannelStatePayload = ChannelState;
|
||||
pub type ChannelCreatePayload = ChannelCreate;
|
||||
pub type ChannelDeletePayload = ChannelDelete;
|
||||
pub type ChannelListPayload = ChannelList;
|
||||
pub type UserJoinPayload = UserJoin;
|
||||
pub type UserLeavePayload = UserLeave;
|
||||
|
||||
// Chat
|
||||
pub type ChatMessagePayload = ChatMessage;
|
||||
pub type ChatHistoryPayload = ChatHistory;
|
||||
pub type MessageEditPayload = MessageEdit;
|
||||
pub type MessageDeletePayload = MessageDelete;
|
||||
|
||||
// Voice
|
||||
pub type VoiceStatePayload = VoiceState;
|
||||
|
||||
// Guilds
|
||||
pub type GuildCreatePayload = GuildCreate;
|
||||
pub type GuildDeletePayload = GuildDelete;
|
||||
pub type GuildListPayload = GuildList;
|
||||
pub type GuildMemberJoinPayload = GuildMemberJoin;
|
||||
pub type GuildMemberLeavePayload = GuildMemberLeave;
|
||||
pub type GuildMemberKickPayload = GuildMemberKick;
|
||||
pub type RoleCreatePayload = RoleCreate;
|
||||
pub type RoleDeletePayload = RoleDelete;
|
||||
pub type InviteCreatePayload = InviteCreate;
|
||||
pub type InviteAcceptPayload = InviteAccept;
|
||||
pub type InviteDeletePayload = InviteDelete;
|
||||
pub type GuildAuditLogFetchPayload = GuildAuditLogFetch;
|
||||
pub type AuditLogEntryPayload = AuditLogEntry;
|
||||
pub type GuildAuditLogPayload = GuildAuditLog;
|
||||
pub type GuildMemberListFetchPayload = GuildMemberListFetch;
|
||||
pub type GuildMemberInfoPayload = GuildMemberInfo;
|
||||
pub type GuildMemberListPayload = GuildMemberList;
|
||||
pub type RoleAssignPayload = RoleAssign;
|
||||
pub type GuildRoleListFetchPayload = GuildRoleListFetch;
|
||||
pub type GuildRoleInfoPayload = GuildRoleInfo;
|
||||
pub type GuildRoleListPayload = GuildRoleList;
|
||||
|
||||
// DMs
|
||||
pub type DmStartPayload = DmStart;
|
||||
pub type DmStartResponsePayload = DmStartResponse;
|
||||
pub type DmMessagePayload = DmMessage;
|
||||
pub type DmHistoryPayload = DmHistory;
|
||||
pub type DmReadAckPayload = DmReadAck;
|
||||
|
||||
// Friends
|
||||
pub type FriendRequestPayload = FriendRequest;
|
||||
pub type FriendAcceptPayload = FriendAccept;
|
||||
pub type FriendDeclinePayload = FriendDecline;
|
||||
pub type FriendRemovePayload = FriendRemove;
|
||||
pub type FriendListPayload = FriendList;
|
||||
pub type BlockUserPayload = BlockUser;
|
||||
pub type UnblockUserPayload = UnblockUser;
|
||||
pub type BlockListPayload = BlockList;
|
||||
pub type FriendEventPayload = FriendEvent;
|
||||
|
||||
// Presence
|
||||
pub type PresenceUpdatePayload = PresenceUpdate;
|
||||
pub type PresenceSyncPayload = PresenceSync;
|
||||
pub type PresenceEventPayload = PresenceEvent;
|
||||
|
||||
// Read/typing
|
||||
pub type ReadReceiptPayload = ReadReceipt;
|
||||
pub type TypingStartPayload = TypingStart;
|
||||
|
||||
// Response types
|
||||
pub type ReadReceiptBroadcastPayload = ReadReceiptBroadcast;
|
||||
pub type UserRoleUpdatePayload = UserRoleUpdate;
|
||||
pub type TypingBroadcastPayload = TypingBroadcast;
|
||||
pub type SimpleResponsePayload = SimpleResponse;
|
||||
|
|
|
|||
|
|
@ -1,157 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct HelloPayload {
|
||||
pub lnex_version: String,
|
||||
pub server_pubkey: String,
|
||||
pub challenge_nonce: String,
|
||||
pub node_name: String,
|
||||
pub server_eph_pubkey: String,
|
||||
pub private_mode: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct AuthPayload {
|
||||
pub client_pubkey: String,
|
||||
pub nickname: String,
|
||||
pub lnex_version: String,
|
||||
pub signature: String,
|
||||
pub client_eph_pubkey: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct SessionPayload {
|
||||
pub session_id: String,
|
||||
pub token: String,
|
||||
pub expires_at: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PingPayload {
|
||||
pub timestamp: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PongPayload {
|
||||
pub timestamp: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct JoinChannelPayload {
|
||||
pub channel_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct LeaveChannelPayload {
|
||||
pub channel_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ChannelStatePayload {
|
||||
pub channel_id: String,
|
||||
pub channel_name: String,
|
||||
pub kind: String,
|
||||
pub members: Vec<MemberInfo>,
|
||||
pub voice_endpoint: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ChannelCreatePayload {
|
||||
pub channel_id: String,
|
||||
pub channel_name: String,
|
||||
/// "text" or "voice".
|
||||
pub kind: String,
|
||||
/// Optional guild_id this channel belongs to (Phase 1.x — unused, future).
|
||||
#[serde(default)]
|
||||
pub guild_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ChannelDeletePayload {
|
||||
pub channel_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ChannelListPayload {
|
||||
pub channels: Vec<ChannelListItem>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ChannelListItem {
|
||||
pub channel_id: String,
|
||||
pub channel_name: String,
|
||||
pub kind: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct MemberInfo {
|
||||
pub user_id: String,
|
||||
pub nickname: String,
|
||||
pub in_voice: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct UserJoinPayload {
|
||||
pub channel_id: String,
|
||||
pub user_id: String,
|
||||
pub nickname: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct UserLeavePayload {
|
||||
pub channel_id: String,
|
||||
pub user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ChatMessagePayload {
|
||||
pub message_id: String,
|
||||
pub channel_id: String,
|
||||
pub sender_id: String,
|
||||
pub content: String,
|
||||
pub timestamp: i64,
|
||||
#[serde(default)]
|
||||
pub edited: bool,
|
||||
/// Optional message_id this message is replying to.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub reply_to: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ReactionPayload {
|
||||
pub message_id: String,
|
||||
pub channel_id: String,
|
||||
pub emoji: String,
|
||||
#[serde(default)]
|
||||
pub user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct MessageEditPayload {
|
||||
pub message_id: String,
|
||||
pub channel_id: String,
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct MessageDeletePayload {
|
||||
pub message_id: String,
|
||||
pub channel_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ChatHistoryPayload {
|
||||
pub channel_id: String,
|
||||
pub messages: Vec<ChatMessagePayload>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ErrorPayload {
|
||||
pub code: u32,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct DisconnectPayload {
|
||||
pub reason: String,
|
||||
}
|
||||
|
|
@ -1,161 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildCreatePayload {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct GuildInfo {
|
||||
pub id: String,
|
||||
pub owner_id: String,
|
||||
pub name: String,
|
||||
pub member_count: i64,
|
||||
pub created_at: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildListPayload {
|
||||
pub guilds: Vec<GuildInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildMemberJoinPayload {
|
||||
pub guild_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildMemberLeavePayload {
|
||||
pub guild_id: String,
|
||||
pub user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildMemberKickPayload {
|
||||
pub guild_id: String,
|
||||
pub user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct RoleCreatePayload {
|
||||
pub guild_id: String,
|
||||
pub name: String,
|
||||
pub color: Option<String>,
|
||||
pub permissions: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct RoleDeletePayload {
|
||||
pub guild_id: String,
|
||||
pub role_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct InviteCreatePayload {
|
||||
pub guild_id: String,
|
||||
pub max_uses: Option<i64>,
|
||||
pub expires_in_seconds: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct InviteInfo {
|
||||
pub id: String,
|
||||
pub guild_id: String,
|
||||
pub guild_name: String,
|
||||
pub code: String,
|
||||
pub creator_id: String,
|
||||
pub max_uses: Option<i64>,
|
||||
pub uses: i64,
|
||||
pub expires_at: Option<i64>,
|
||||
pub created_at: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct InviteAcceptPayload {
|
||||
pub code: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct InviteDeletePayload {
|
||||
pub guild_id: String,
|
||||
pub invite_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildAuditLogFetchPayload {
|
||||
pub guild_id: String,
|
||||
#[serde(default = "default_audit_limit")]
|
||||
pub limit: i64,
|
||||
}
|
||||
|
||||
fn default_audit_limit() -> i64 {
|
||||
50
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AuditLogEntryPayload {
|
||||
pub id: String,
|
||||
pub guild_id: String,
|
||||
pub actor_id: String,
|
||||
pub action: String,
|
||||
pub target_id: Option<String>,
|
||||
pub target_type: Option<String>,
|
||||
pub reason: Option<String>,
|
||||
pub created_at: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildAuditLogPayload {
|
||||
pub guild_id: String,
|
||||
pub entries: Vec<AuditLogEntryPayload>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildMemberListFetchPayload {
|
||||
pub guild_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct GuildMemberInfoPayload {
|
||||
pub user_id: String,
|
||||
pub nickname: String,
|
||||
pub joined_at: i64,
|
||||
pub role_color: String,
|
||||
pub role_name: String,
|
||||
/// True if this user is the guild owner.
|
||||
pub is_owner: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildMemberListPayload {
|
||||
pub guild_id: String,
|
||||
pub members: Vec<GuildMemberInfoPayload>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct RoleAssignPayload {
|
||||
pub guild_id: String,
|
||||
pub user_id: String,
|
||||
pub role_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildRoleListFetchPayload {
|
||||
pub guild_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct GuildRoleInfoPayload {
|
||||
pub id: String,
|
||||
pub guild_id: String,
|
||||
pub name: String,
|
||||
pub color: String,
|
||||
pub permissions: u64,
|
||||
pub position: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct GuildRoleListPayload {
|
||||
pub guild_id: String,
|
||||
pub roles: Vec<GuildRoleInfoPayload>,
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
mod channel;
|
||||
mod guild;
|
||||
mod social;
|
||||
|
||||
pub use channel::*;
|
||||
pub use guild::*;
|
||||
pub use social::*;
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct DmStartPayload {
|
||||
pub target_user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct DmStartResponsePayload {
|
||||
pub dm_id: String,
|
||||
pub other_user_id: String,
|
||||
pub other_nickname: String,
|
||||
pub messages: Vec<DmMessagePayload>,
|
||||
#[serde(default)]
|
||||
pub unread_count: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct DmMessagePayload {
|
||||
pub dm_id: String,
|
||||
pub sender_id: String,
|
||||
pub content: String,
|
||||
pub timestamp: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct DmHistoryPayload {
|
||||
pub dm_id: String,
|
||||
#[serde(default)]
|
||||
pub messages: Vec<DmMessagePayload>,
|
||||
#[serde(default)]
|
||||
pub search_query: Option<String>,
|
||||
#[serde(default)]
|
||||
pub limit: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct FriendRequestPayload {
|
||||
pub to_user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct FriendAcceptPayload {
|
||||
pub from_user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct FriendDeclinePayload {
|
||||
pub from_user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct FriendRemovePayload {
|
||||
pub user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct FriendInfo {
|
||||
pub user_id: String,
|
||||
pub nickname: String,
|
||||
pub status: String,
|
||||
pub since: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct FriendListPayload {
|
||||
pub friends: Vec<FriendInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct BlockUserPayload {
|
||||
pub user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct UnblockUserPayload {
|
||||
pub user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct BlockListPayload {
|
||||
pub blocked: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct FriendEventPayload {
|
||||
pub event: String,
|
||||
pub user_id: String,
|
||||
pub nickname: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PresenceUpdatePayload {
|
||||
pub status: String,
|
||||
pub activity_type: Option<String>,
|
||||
pub activity_text: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct PresenceInfo {
|
||||
pub user_id: String,
|
||||
pub nickname: String,
|
||||
pub status: String,
|
||||
pub activity_type: Option<String>,
|
||||
pub activity_text: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PresenceSyncPayload {
|
||||
pub presences: Vec<PresenceInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct PresenceEventPayload {
|
||||
pub user_id: String,
|
||||
pub nickname: String,
|
||||
pub status: String,
|
||||
pub activity_type: Option<String>,
|
||||
pub activity_text: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ReadReceiptPayload {
|
||||
pub channel_id: String,
|
||||
pub last_read_message_id: String,
|
||||
pub user_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct TypingStartPayload {
|
||||
pub channel_id: String,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue