Giao diện
Network & Systems I/O Expert
Xây dựng hệ thống mạng từ tầng OS — Không library, chỉ có syscalls
Triết lý Module
"Don't use libraries; build them."
Module này deep-dive vào cách hệ thống mạng hoạt động ở mức kernel và hardware. Đây không phải hướng dẫn sử dụng Tokio hay Hyper — mà là hiểu cách chúng được xây dựng từ đầu.
⚠️ TARGET AUDIENCE
Module này dành cho Systems Architects và HFT (High-Frequency Trading) Engineers — những người cần hiểu từng microsecond latency và mỗi byte trong packet.
Kiến trúc Module
Cấu trúc Nội dung
📦 Raw Sockets & Packets
Tạo SOCK_RAW với libc, xây dựng Ethernet/IP/TCP headers bằng bitwise operations. Blueprint cho high-performance packet sniffer với zero-copy networking.
📡 Custom Protocols
Thiết kế binary protocol trên TCP. Framing strategies, endianness handling. Deep comparison: Protocol Buffers vs Cap'n Proto vs FlatBuffers với zero-copy deserialization.
⚙️ OS Event Queues
Phân tích epoll (Linux), kqueue (BSD/macOS), IOCP (Windows). Rust FFI với OS-level APIs. Mathematical breakdown của C10K Problem.
🔄 Async Runtime Internals
Xây dựng minimal async runtime từ scratch. Hiểu Waker, Executor, Reactor — những building blocks của Tokio.
Tại sao cần hiểu Low-Level Networking?
| Use Case | Vấn đề | Giải pháp Low-Level |
|---|---|---|
| HFT Systems | Mỗi μs đều quan trọng | Bypass kernel với AF_XDP, custom protocol |
| Network Security | Phân tích traffic raw | Raw sockets, packet inspection |
| Custom Load Balancers | HTTP overhead | Binary protocol, zero-copy forwarding |
| Game Servers | Low latency multiplayer | UDP với custom reliability layer |
| IoT/Embedded | Resource constraints | Minimal TCP stack, no allocations |
Prerequisites
Trước khi vào module này, đảm bảo đã hiểu:
- Rust Core: Memory Layout — Stack vs Heap
- Unsafe Rust: Unsafe — Raw pointers, FFI basics
- Async Basics: Async Runtime — Future trait, Pin
Learning Path
┌─────────────────────────────────────────────────────────────────────┐
│ │
│ 1. Raw Sockets 2. Custom Protocol 3. OS Event Queue │
│ ───────────── ─────────────────── ───────────────── │
│ • SOCK_RAW • Binary framing • epoll/kqueue │
│ • Packet headers • Serialization • Rust FFI │
│ • Zero-copy • Protobuf comparison • C10K math │
│ │
│ ↓ │
│ │
│ 4. Async Runtime Internals │
│ ────────────────────────── │
│ • Waker mechanism │
│ • Executor loop │
│ • Build your own runtime │
│ │
└─────────────────────────────────────────────────────────────────────┘Công cụ & Crates
| Crate | Mục đích | Trade-off |
|---|---|---|
libc | Raw syscall bindings | Manual, unsafe, full control |
socket2 | Socket abstraction | Safer, still low-level |
mio | Cross-platform event loop | Abstraction over epoll/kqueue/IOCP |
bytes | Zero-copy byte manipulation | Efficient buffer management |
💡 PHILOSOPHY
Trong module này, chúng ta ưu tiên sử dụng libc trực tiếp để hiểu OS-level operations. Các crates như mio sẽ được giải thích như abstraction layers.
"Any sufficiently advanced networking library is indistinguishable from an operating system."
— Hiểu OS để viết library tốt hơn.