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:
Loki 2026-07-09 13:04:22 +02:00
parent 5534cd01f7
commit 9821814240
Signed by: boba
GPG key ID: 253067914055423B
31 changed files with 719 additions and 661 deletions

View file

@ -1,10 +1,11 @@
use anyhow::Result;
use prost::Message;
use tokio::io::{AsyncRead, AsyncWrite};
use crate::{
domain::session,
net::io,
proto::{FriendDeclinePayload, PacketId, SessionCrypto, to_payload},
proto::{FriendDeclinePayload, PacketId, SessionCrypto, SimpleResponsePayload, to_payload},
};
pub async fn handle_friend_decline(
@ -15,7 +16,7 @@ pub async fn handle_friend_decline(
crypto: &SessionCrypto,
state: &crate::net::state::State,
) -> Result<()> {
let req: FriendDeclinePayload = serde_json::from_slice(payload)?;
let req = FriendDeclinePayload::decode(payload)?;
let sess = session::get(&state.sessions, session_id)
.await
.ok_or_else(|| anyhow::anyhow!("session not found"))?;
@ -29,7 +30,7 @@ pub async fn handle_friend_decline(
stream,
PacketId::FriendDecline,
seq,
&to_payload(&serde_json::json!({"status": "DECLINED"})),
&to_payload(&SimpleResponsePayload { ok: true, user_id: None, role_id: None }),
crypto,
)
.await?;

View file

@ -1,4 +1,5 @@
use anyhow::Result;
use prost::Message;
use tokio::io::{AsyncRead, AsyncWrite};
use crate::{
@ -6,7 +7,7 @@ use crate::{
net::{io, state::State},
proto::{
BlockListPayload, BlockUserPayload, FriendRemovePayload, PacketId, SessionCrypto,
UnblockUserPayload, to_payload,
SimpleResponsePayload, UnblockUserPayload, to_payload,
},
};
@ -18,7 +19,7 @@ pub async fn handle_friend_remove(
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req: FriendRemovePayload = serde_json::from_slice(payload)?;
let req = FriendRemovePayload::decode(payload)?;
let sess = session::get(&state.sessions, session_id)
.await
.ok_or_else(|| anyhow::anyhow!("session not found"))?;
@ -32,7 +33,7 @@ pub async fn handle_friend_remove(
stream,
PacketId::FriendRemove,
seq,
&to_payload(&serde_json::json!({"removed": true})),
&to_payload(&SimpleResponsePayload { ok: true, user_id: None, role_id: None }),
crypto,
)
.await?;
@ -47,7 +48,7 @@ pub async fn handle_block_user(
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req: BlockUserPayload = serde_json::from_slice(payload)?;
let req = BlockUserPayload::decode(payload)?;
let sess = session::get(&state.sessions, session_id)
.await
.ok_or_else(|| anyhow::anyhow!("session not found"))?;
@ -61,7 +62,7 @@ pub async fn handle_block_user(
stream,
PacketId::BlockUser,
seq,
&to_payload(&serde_json::json!({"blocked": true})),
&to_payload(&SimpleResponsePayload { ok: true, user_id: None, role_id: None }),
crypto,
)
.await?;
@ -76,7 +77,7 @@ pub async fn handle_unblock_user(
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req: UnblockUserPayload = serde_json::from_slice(payload)?;
let req = UnblockUserPayload::decode(payload)?;
let sess = session::get(&state.sessions, session_id)
.await
.ok_or_else(|| anyhow::anyhow!("session not found"))?;
@ -90,7 +91,7 @@ pub async fn handle_unblock_user(
stream,
PacketId::UnblockUser,
seq,
&to_payload(&serde_json::json!({"unblocked": true})),
&to_payload(&SimpleResponsePayload { ok: true, user_id: None, role_id: None }),
crypto,
)
.await?;

View file

@ -1,4 +1,5 @@
use anyhow::Result;
use prost::Message;
use tokio::io::{AsyncRead, AsyncWrite};
use crate::{
@ -23,7 +24,7 @@ pub async fn handle_friend_request(
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req: FriendRequestPayload = serde_json::from_slice(payload)?;
let req = FriendRequestPayload::decode(payload)?;
let sess = session::get(&state.sessions, session_id)
.await
.ok_or_else(|| anyhow::anyhow!("session not found"))?;
@ -92,7 +93,9 @@ pub async fn handle_friend_request(
stream,
PacketId::FriendRequest,
seq,
&to_payload(&serde_json::json!({"status": "PENDING", "to_user_id": req.to_user_id})),
&to_payload(&FriendRequestPayload {
to_user_id: req.to_user_id.clone(),
}),
crypto,
)
.await?;
@ -107,7 +110,7 @@ pub async fn handle_friend_accept(
crypto: &SessionCrypto,
state: &State,
) -> Result<()> {
let req: FriendAcceptPayload = serde_json::from_slice(payload)?;
let req = FriendAcceptPayload::decode(payload)?;
let sess = session::get(&state.sessions, session_id)
.await
.ok_or_else(|| anyhow::anyhow!("session not found"))?;
@ -144,7 +147,9 @@ pub async fn handle_friend_accept(
stream,
PacketId::FriendAccept,
seq,
&to_payload(&serde_json::json!({"status": "ACCEPTED", "from_user_id": req.from_user_id})),
&to_payload(&FriendAcceptPayload {
from_user_id: req.from_user_id.clone(),
}),
crypto,
)
.await?;