Replace the X25519/HKDF/ChaCha20 TCP layer with rustls TLS 1.3 (ALPN vnox-lnex/3). Auto-generate a self-signed certificate keyed by the server identity or load an operator certificate, publish the SPKI fingerprint, bind HELLO and AUTH signatures to the TLS exporter, reject plaintext, TLS 1.2 and LNEx v2 peers with an explicit error. BREAKING: protocol v3. Claude-Session: https://claude.ai/code/session_01GDjxLvBcnJqniFQGUGb1V4
45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
use anyhow::Result;
|
|
use tokio::io::{AsyncRead, AsyncWrite};
|
|
|
|
use crate::{
|
|
domain::session,
|
|
net::{io, state::State},
|
|
proto::{FriendInfo, FriendListPayload, PacketId, to_payload},
|
|
};
|
|
|
|
pub async fn handle_friend_list(
|
|
stream: &mut (impl AsyncRead + AsyncWrite + Unpin),
|
|
seq: &mut u32,
|
|
session_id: &str,
|
|
state: &State,
|
|
) -> Result<()> {
|
|
let sess = session::get(&state.sessions, session_id)
|
|
.await
|
|
.ok_or_else(|| anyhow::anyhow!("session not found"))?;
|
|
|
|
let friend_ids = state.storage.list_friends(&sess.user_id).await?;
|
|
let mut friends = Vec::new();
|
|
let presences = state.presences.read().await;
|
|
|
|
for fid in &friend_ids {
|
|
let nick = state.storage.get_nickname(fid).await?.unwrap_or_default();
|
|
let presence = presences.get(fid);
|
|
friends.push(FriendInfo {
|
|
user_id: fid.clone(),
|
|
nickname: nick,
|
|
status: presence
|
|
.map(|p| p.status.clone())
|
|
.unwrap_or_else(|| "OFFLINE".into()),
|
|
since: 0,
|
|
});
|
|
}
|
|
|
|
io::send_frame(
|
|
stream,
|
|
PacketId::FriendList,
|
|
seq,
|
|
&to_payload(&FriendListPayload { friends }),
|
|
)
|
|
.await?;
|
|
Ok(())
|
|
}
|