Initial commit: split VNOX monorepo into VNOX-Server
Unified server binary (vnox-serverd) combining: - Gateway (TCP, auth, channels, sessions, SQLite) - Voice-node (UDP relay, Opus, jitter buffer) Standalone gateway (vnox-gateway) and voice-node (vnox-voice-node) preserved as sub-crates.
This commit is contained in:
commit
e751e0bf5b
94 changed files with 9771 additions and 0 deletions
51
gateway/src/proto/crypto/cipher.rs
Normal file
51
gateway/src/proto/crypto/cipher.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use chacha20poly1305::{
|
||||
ChaCha20Poly1305, Key, KeyInit, Nonce,
|
||||
aead::{Aead, Payload},
|
||||
};
|
||||
|
||||
pub(super) fn make_nonce(cid: &[u8; 8], seq: u64) -> [u8; 12] {
|
||||
let mut nonce = [0u8; 12];
|
||||
nonce[..8].copy_from_slice(cid);
|
||||
nonce[8..12].copy_from_slice(&(seq as u32).to_le_bytes());
|
||||
nonce
|
||||
}
|
||||
|
||||
pub(super) fn encrypt_with_key(
|
||||
key: &[u8; 32],
|
||||
cid: &[u8; 8],
|
||||
seq: u64,
|
||||
plaintext: &[u8],
|
||||
) -> Vec<u8> {
|
||||
let cipher = ChaCha20Poly1305::new(Key::from_slice(key));
|
||||
let nonce_bytes = make_nonce(cid, seq);
|
||||
let nonce = Nonce::from_slice(&nonce_bytes);
|
||||
cipher
|
||||
.encrypt(
|
||||
nonce,
|
||||
Payload {
|
||||
msg: plaintext,
|
||||
aad: &[],
|
||||
},
|
||||
)
|
||||
.expect("ChaCha20-Poly1305 encryption is infallible")
|
||||
}
|
||||
|
||||
pub(super) fn decrypt_with_key(
|
||||
key: &[u8; 32],
|
||||
cid: &[u8; 8],
|
||||
seq: u64,
|
||||
ciphertext: &[u8],
|
||||
) -> anyhow::Result<Vec<u8>> {
|
||||
let cipher = ChaCha20Poly1305::new(Key::from_slice(key));
|
||||
let nonce_bytes = make_nonce(cid, seq);
|
||||
let nonce = Nonce::from_slice(&nonce_bytes);
|
||||
cipher
|
||||
.decrypt(
|
||||
nonce,
|
||||
Payload {
|
||||
msg: ciphertext,
|
||||
aad: &[],
|
||||
},
|
||||
)
|
||||
.map_err(|e| anyhow::anyhow!("decryption failed: {e:?}"))
|
||||
}
|
||||
112
gateway/src/proto/crypto/mod.rs
Normal file
112
gateway/src/proto/crypto/mod.rs
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
mod cipher;
|
||||
|
||||
use hkdf::Hkdf;
|
||||
use sha2::Sha256;
|
||||
use x25519_dalek::{EphemeralSecret, PublicKey, SharedSecret};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SessionCrypto {
|
||||
c2s_key: [u8; 32],
|
||||
s2c_key: [u8; 32],
|
||||
cid: [u8; 8],
|
||||
}
|
||||
|
||||
impl SessionCrypto {
|
||||
pub fn derive(shared_secret: &[u8; 32], session_id: &str) -> Self {
|
||||
let salt = b"VNOX-LNEx-KDF-v1";
|
||||
let hk = Hkdf::<Sha256>::new(Some(salt), shared_secret);
|
||||
|
||||
let mut keys = [0u8; 64];
|
||||
hk.expand(b"session-keys", &mut keys)
|
||||
.expect("64 bytes is within HKDF max");
|
||||
|
||||
let c2s_key: [u8; 32] = keys[..32].try_into().unwrap();
|
||||
let s2c_key: [u8; 32] = keys[32..64].try_into().unwrap();
|
||||
|
||||
use sha2::Digest;
|
||||
let hash = Sha256::digest(session_id.as_bytes());
|
||||
let cid: [u8; 8] = hash[..8].try_into().unwrap();
|
||||
|
||||
Self {
|
||||
c2s_key,
|
||||
s2c_key,
|
||||
cid,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn encrypt_s2c(&self, seq: u64, plaintext: &[u8]) -> Vec<u8> {
|
||||
cipher::encrypt_with_key(&self.s2c_key, &self.cid, seq, plaintext)
|
||||
}
|
||||
|
||||
pub fn decrypt_c2s(&self, seq: u64, ciphertext: &[u8]) -> anyhow::Result<Vec<u8>> {
|
||||
cipher::decrypt_with_key(&self.c2s_key, &self.cid, seq, ciphertext)
|
||||
}
|
||||
|
||||
pub fn new_ephemeral() -> (EphemeralSecret, PublicKey) {
|
||||
let mut rng = rand::thread_rng();
|
||||
let sk = EphemeralSecret::random_from_rng(&mut rng);
|
||||
let pk = PublicKey::from(&sk);
|
||||
(sk, pk)
|
||||
}
|
||||
|
||||
pub fn ecdh(secret: EphemeralSecret, peer_public: &PublicKey) -> SharedSecret {
|
||||
secret.diffie_hellman(peer_public)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn encrypt_then_decrypt_roundtrip() {
|
||||
let shared_secret = [0xABu8; 32];
|
||||
let crypto = SessionCrypto::derive(&shared_secret, "test-session-id");
|
||||
|
||||
let plaintext = b"hello encrypted world";
|
||||
let seq = 42;
|
||||
|
||||
let ciphertext = crypto.encrypt_s2c(seq, plaintext);
|
||||
assert_ne!(ciphertext, plaintext);
|
||||
assert!(ciphertext.len() > plaintext.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_keys_cannot_decrypt_each_other() {
|
||||
let shared_secret = [0xABu8; 32];
|
||||
let crypto = SessionCrypto::derive(&shared_secret, "test-session-id");
|
||||
|
||||
let s2c_ct = crypto.encrypt_s2c(0, b"server to client");
|
||||
let result = crypto.decrypt_c2s(0, &s2c_ct);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_keys_produce_different_ciphertexts() {
|
||||
let secret_a = [0xAAu8; 32];
|
||||
let secret_b = [0xBBu8; 32];
|
||||
let crypto_a = SessionCrypto::derive(&secret_a, "session-a");
|
||||
let crypto_b = SessionCrypto::derive(&secret_b, "session-b");
|
||||
|
||||
let plaintext = b"same plaintext";
|
||||
let ct_a = crypto_a.encrypt_s2c(0, plaintext);
|
||||
let ct_b = crypto_b.encrypt_s2c(0, plaintext);
|
||||
assert_ne!(ct_a, ct_b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ecdh_derives_same_secret_on_both_sides() {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let alice_sk = EphemeralSecret::random_from_rng(&mut rng);
|
||||
let alice_pk = PublicKey::from(&alice_sk);
|
||||
|
||||
let bob_sk = EphemeralSecret::random_from_rng(&mut rng);
|
||||
let bob_pk = PublicKey::from(&bob_sk);
|
||||
|
||||
let alice_shared = alice_sk.diffie_hellman(&bob_pk);
|
||||
let bob_shared = bob_sk.diffie_hellman(&alice_pk);
|
||||
|
||||
assert_eq!(alice_shared.as_bytes(), bob_shared.as_bytes());
|
||||
}
|
||||
}
|
||||
16
gateway/src/proto/framing.rs
Normal file
16
gateway/src/proto/framing.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use super::packet::{PacketHeader, PacketId};
|
||||
use serde::Serialize;
|
||||
|
||||
/// Encode a packet: header + JSON 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());
|
||||
out.extend_from_slice(&header.to_bytes());
|
||||
out.extend_from_slice(payload);
|
||||
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")
|
||||
}
|
||||
11
gateway/src/proto/mod.rs
Normal file
11
gateway/src/proto/mod.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
mod crypto;
|
||||
mod framing;
|
||||
mod packet;
|
||||
mod payloads;
|
||||
|
||||
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::*;
|
||||
6
gateway/src/proto/packet/flags.rs
Normal file
6
gateway/src/proto/packet/flags.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
pub const COMPRESSED: u16 = 1 << 0;
|
||||
pub const ENCRYPTED: u16 = 1 << 1;
|
||||
pub const FRAGMENTED: u16 = 1 << 2;
|
||||
pub const LAST_FRAG: u16 = 1 << 3;
|
||||
pub const ACK_REQ: u16 = 1 << 4;
|
||||
pub const KNOWN_MASK: u16 = COMPRESSED | ENCRYPTED | FRAGMENTED | LAST_FRAG | ACK_REQ;
|
||||
172
gateway/src/proto/packet/id.rs
Normal file
172
gateway/src/proto/packet/id.rs
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
#[repr(u16)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum PacketId {
|
||||
Hello = 0x0001,
|
||||
Auth = 0x0002,
|
||||
Session = 0x0003,
|
||||
Ping = 0x0004,
|
||||
Pong = 0x0005,
|
||||
VoicePacket = 0x0010,
|
||||
VoiceState = 0x0011,
|
||||
ChatMessage = 0x0020,
|
||||
ChatHistory = 0x0021,
|
||||
JoinChannel = 0x0030,
|
||||
LeaveChannel = 0x0031,
|
||||
ChannelState = 0x0032,
|
||||
ChannelCreate = 0x0033,
|
||||
ChannelDelete = 0x0034,
|
||||
ChannelList = 0x0035,
|
||||
UserJoin = 0x0040,
|
||||
UserLeave = 0x0041,
|
||||
PermissionCheck = 0x0050,
|
||||
PermissionDeny = 0x0051,
|
||||
DmStart = 0x0060,
|
||||
DmMessage = 0x0061,
|
||||
DmHistory = 0x0062,
|
||||
DmReadAck = 0x0063,
|
||||
ReadReceipt = 0x0064,
|
||||
ReadReceiptBroadcast = 0x0065,
|
||||
MessageReactionAdd = 0x0066,
|
||||
MessageReactionRemove = 0x0067,
|
||||
MessageEdit = 0x0068,
|
||||
MessageDelete = 0x0069,
|
||||
TypingStart = 0x0070,
|
||||
GuildCreate = 0x0100,
|
||||
GuildDelete = 0x0101,
|
||||
GuildList = 0x0102,
|
||||
GuildMemberJoin = 0x0103,
|
||||
GuildMemberLeave = 0x0104,
|
||||
GuildMemberKick = 0x0105,
|
||||
RoleCreate = 0x0106,
|
||||
RoleDelete = 0x0107,
|
||||
InviteCreate = 0x0108,
|
||||
InviteAccept = 0x0109,
|
||||
InviteDelete = 0x010A,
|
||||
UserRoleUpdate = 0x010B,
|
||||
GuildAuditLogFetch = 0x010C,
|
||||
GuildAuditLog = 0x010D,
|
||||
GuildMemberListFetch = 0x010E,
|
||||
GuildMemberList = 0x010F,
|
||||
GuildRoleAssign = 0x0110,
|
||||
GuildRoleUnassign = 0x0111,
|
||||
GuildRoleListFetch = 0x0112,
|
||||
GuildRoleList = 0x0113,
|
||||
PresenceUpdate = 0x0140,
|
||||
PresenceSync = 0x0141,
|
||||
PresenceEvent = 0x0142,
|
||||
FriendRequest = 0x0150,
|
||||
FriendAccept = 0x0151,
|
||||
FriendDecline = 0x0152,
|
||||
FriendRemove = 0x0153,
|
||||
FriendList = 0x0154,
|
||||
BlockUser = 0x0155,
|
||||
UnblockUser = 0x0156,
|
||||
BlockList = 0x0157,
|
||||
Error = 0x00F0,
|
||||
Disconnect = 0x00FF,
|
||||
}
|
||||
|
||||
impl PacketId {
|
||||
pub fn from_u16(v: u16) -> Option<Self> {
|
||||
match v {
|
||||
0x0001 => Some(Self::Hello),
|
||||
0x0002 => Some(Self::Auth),
|
||||
0x0003 => Some(Self::Session),
|
||||
0x0004 => Some(Self::Ping),
|
||||
0x0005 => Some(Self::Pong),
|
||||
0x0010 => Some(Self::VoicePacket),
|
||||
0x0011 => Some(Self::VoiceState),
|
||||
0x0020 => Some(Self::ChatMessage),
|
||||
0x0021 => Some(Self::ChatHistory),
|
||||
0x0030 => Some(Self::JoinChannel),
|
||||
0x0031 => Some(Self::LeaveChannel),
|
||||
0x0032 => Some(Self::ChannelState),
|
||||
0x0033 => Some(Self::ChannelCreate),
|
||||
0x0034 => Some(Self::ChannelDelete),
|
||||
0x0035 => Some(Self::ChannelList),
|
||||
0x0040 => Some(Self::UserJoin),
|
||||
0x0041 => Some(Self::UserLeave),
|
||||
0x0050 => Some(Self::PermissionCheck),
|
||||
0x0051 => Some(Self::PermissionDeny),
|
||||
0x0060 => Some(Self::DmStart),
|
||||
0x0061 => Some(Self::DmMessage),
|
||||
0x0062 => Some(Self::DmHistory),
|
||||
0x0063 => Some(Self::DmReadAck),
|
||||
0x0064 => Some(Self::ReadReceipt),
|
||||
0x0065 => Some(Self::ReadReceiptBroadcast),
|
||||
0x0066 => Some(Self::MessageReactionAdd),
|
||||
0x0067 => Some(Self::MessageReactionRemove),
|
||||
0x0068 => Some(Self::MessageEdit),
|
||||
0x0069 => Some(Self::MessageDelete),
|
||||
0x0070 => Some(Self::TypingStart),
|
||||
0x0100 => Some(Self::GuildCreate),
|
||||
0x0101 => Some(Self::GuildDelete),
|
||||
0x0102 => Some(Self::GuildList),
|
||||
0x0103 => Some(Self::GuildMemberJoin),
|
||||
0x0104 => Some(Self::GuildMemberLeave),
|
||||
0x0105 => Some(Self::GuildMemberKick),
|
||||
0x0106 => Some(Self::RoleCreate),
|
||||
0x0107 => Some(Self::RoleDelete),
|
||||
0x0108 => Some(Self::InviteCreate),
|
||||
0x0109 => Some(Self::InviteAccept),
|
||||
0x010A => Some(Self::InviteDelete),
|
||||
0x010B => Some(Self::UserRoleUpdate),
|
||||
0x010C => Some(Self::GuildAuditLogFetch),
|
||||
0x010D => Some(Self::GuildAuditLog),
|
||||
0x010E => Some(Self::GuildMemberListFetch),
|
||||
0x010F => Some(Self::GuildMemberList),
|
||||
0x0110 => Some(Self::GuildRoleAssign),
|
||||
0x0111 => Some(Self::GuildRoleUnassign),
|
||||
0x0112 => Some(Self::GuildRoleListFetch),
|
||||
0x0113 => Some(Self::GuildRoleList),
|
||||
0x0140 => Some(Self::PresenceUpdate),
|
||||
0x0141 => Some(Self::PresenceSync),
|
||||
0x0142 => Some(Self::PresenceEvent),
|
||||
0x0150 => Some(Self::FriendRequest),
|
||||
0x0151 => Some(Self::FriendAccept),
|
||||
0x0152 => Some(Self::FriendDecline),
|
||||
0x0153 => Some(Self::FriendRemove),
|
||||
0x0154 => Some(Self::FriendList),
|
||||
0x0155 => Some(Self::BlockUser),
|
||||
0x0156 => Some(Self::UnblockUser),
|
||||
0x0157 => Some(Self::BlockList),
|
||||
0x00F0 => Some(Self::Error),
|
||||
0x00FF => Some(Self::Disconnect),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[repr(u8)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ErrorCode {
|
||||
VersionMismatch = 0x01,
|
||||
AuthFailed = 0x02,
|
||||
SessionExpired = 0x03,
|
||||
PermissionDenied = 0x04,
|
||||
ChannelNotFound = 0x05,
|
||||
RateLimited = 0x06,
|
||||
InvalidPacket = 0x07,
|
||||
NodeUnavailable = 0x08,
|
||||
GuildNotFound = 0x09,
|
||||
Blocked = 0x0A,
|
||||
Internal = 0xFF,
|
||||
}
|
||||
|
||||
impl ErrorCode {
|
||||
pub fn from_u32(v: u32) -> Option<Self> {
|
||||
match v {
|
||||
0x01 => Some(Self::VersionMismatch),
|
||||
0x02 => Some(Self::AuthFailed),
|
||||
0x03 => Some(Self::SessionExpired),
|
||||
0x04 => Some(Self::PermissionDenied),
|
||||
0x05 => Some(Self::ChannelNotFound),
|
||||
0x06 => Some(Self::RateLimited),
|
||||
0x07 => Some(Self::InvalidPacket),
|
||||
0x08 => Some(Self::NodeUnavailable),
|
||||
0x09 => Some(Self::GuildNotFound),
|
||||
0x0A => Some(Self::Blocked),
|
||||
0xFF => Some(Self::Internal),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
43
gateway/src/proto/packet/mod.rs
Normal file
43
gateway/src/proto/packet/mod.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
pub mod flags;
|
||||
mod id;
|
||||
|
||||
pub use id::{ErrorCode, PacketId};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PacketHeader {
|
||||
pub packet_id: u16,
|
||||
pub flags: u16,
|
||||
pub sequence: u32,
|
||||
pub payload_length: u32,
|
||||
}
|
||||
|
||||
impl PacketHeader {
|
||||
pub const SIZE: usize = 12;
|
||||
|
||||
pub fn new(packet_id: PacketId, sequence: u32, payload_length: u32) -> Self {
|
||||
Self {
|
||||
packet_id: packet_id as u16,
|
||||
flags: 0,
|
||||
sequence,
|
||||
payload_length,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_bytes(&self) -> [u8; Self::SIZE] {
|
||||
let mut buf = [0u8; Self::SIZE];
|
||||
buf[0..2].copy_from_slice(&self.packet_id.to_be_bytes());
|
||||
buf[2..4].copy_from_slice(&self.flags.to_be_bytes());
|
||||
buf[4..8].copy_from_slice(&self.sequence.to_be_bytes());
|
||||
buf[8..12].copy_from_slice(&self.payload_length.to_be_bytes());
|
||||
buf
|
||||
}
|
||||
|
||||
pub fn from_bytes(buf: &[u8; Self::SIZE]) -> Self {
|
||||
Self {
|
||||
packet_id: u16::from_be_bytes([buf[0], buf[1]]),
|
||||
flags: u16::from_be_bytes([buf[2], buf[3]]),
|
||||
sequence: u32::from_be_bytes([buf[4], buf[5], buf[6], buf[7]]),
|
||||
payload_length: u32::from_be_bytes([buf[8], buf[9], buf[10], buf[11]]),
|
||||
}
|
||||
}
|
||||
}
|
||||
157
gateway/src/proto/payloads/channel.rs
Normal file
157
gateway/src/proto/payloads/channel.rs
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
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,
|
||||
}
|
||||
161
gateway/src/proto/payloads/guild.rs
Normal file
161
gateway/src/proto/payloads/guild.rs
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
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>,
|
||||
}
|
||||
7
gateway/src/proto/payloads/mod.rs
Normal file
7
gateway/src/proto/payloads/mod.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
mod channel;
|
||||
mod guild;
|
||||
mod social;
|
||||
|
||||
pub use channel::*;
|
||||
pub use guild::*;
|
||||
pub use social::*;
|
||||
132
gateway/src/proto/payloads/social.rs
Normal file
132
gateway/src/proto/payloads/social.rs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
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