2.9 KiB
2.9 KiB
Milestone 1: The Foundation (The Skeleton)
Goal: Initialize the project and establish the shared language between client and server.
1. Workspace Setup
- Initialize the root Cargo workspace:
cargo init --vcs none(deletesrc/). Create a rootCargo.tomlwith[workspace] members = ["core_protocol", "server_node", "client_node"]. - Create crates:
cargo new --lib core_protocol,cargo new --bin server_node,cargo new --bin client_node. - Add strict lints (
#![forbid(unsafe_code)], etc.) to the root workspace or individuallib.rs/main.rsfiles. - Dependencies (
core_protocol): Addserde,bincode,uuid,chrono,thiserror,secrecy(for zeroing sensitive keys). - Dependencies (
server_node): Addtokio(full),tracing,tracing-subscriber,anyhow,dashmap. - Dependencies (
client_node): Addtokio(rt-multi-thread),tracing,tracing-subscriber,anyhow.
2. Protocol Definitions (core_protocol)
- Create
src/tcp_events.rs. Defineenum TcpEvent { AuthRequest { username: String, ... }, AuthResponse { session_token: u32, ... }, ChannelJoin { ... }, ChatMessage { ... } }with#[derive(Serialize, Deserialize)]. - Create
src/udp_packets.rs. Definestruct VoicePacketHeader { pub session_token: u32, pub sequence_num: u64, pub timestamp: u64 }with#[derive(Serialize, Deserialize)]. - Create
src/constants.rs. Definepub const SAMPLE_RATE: u32 = 48000;,pub const FRAME_SIZE: usize = 960;,pub const TCP_PORT: u16 = 8080;.
3. TCP Handshake (server_node & client_node)
- Server: In
server_node/src/main.rs, initializetokio::net::TcpListener::bind("0.0.0.0:8080"). - Server: Spawn a new
tokio::spawn(async move { ... })for each incomingTcpStream. - Client: In
client_node/src/network/control.rs, implementTcpStream::connect("127.0.0.1:8080"). - Shared: Implement a framing mechanism (e.g., sending a
u32length prefix before thebincodeserializedTcpEvent) to prevent TCP stream fragmentation.
4. Login Logic & State
- Server State: Create
server_node/src/state.rs. Define aDashMap<u32, UserState>to store active session tokens. - Authentication Flow: Client sends
TcpEvent::AuthRequest. Server generates a randomu32session token, stores it inDashMap, and returnsTcpEvent::AuthResponse. - Validation: Ensure the server actively drops the connection if the client sends invalid or excessively large payloads.
5. Observability (Logging)
- Initialization: In both binaries'
main.rs, calltracing_subscriber::fmt::init(). - Implementation: Replace all
println!calls withtracing::info!,tracing::warn!, ortracing::error!. - Tracing Context: Use
#[tracing::instrument]on core TCP handler functions to automatically log client IPs and session IDs.