How mas-bandwidth/netcode works
Main Components
• Client Component – Represented by files such as client.c, client_server.c, and profile.c, this part of the system handles the client-side connection initiation and communication. It also shows how a client retrieves a secure connect token (from an external REST API) and then establishes a connection.
• Server Component – Shown in server.c, the server is responsible for accepting client connections, managing a fixed pool of client slots, and handling secure communication. It uses a private key for encryption and decryption and coordinates client slots.
• Core Netcode Library – The core protocol logic is encapsulated in netcode.c/netcode.h. This includes the connection management, packet handling, and protocol states.
• Cryptographic Library (sodium) – The sodium subdirectory holds the extensive implementation of cryptography routines. This modular cryptography component is leveraged by the netcode library to provide encryption, signature verification, hash functions, and secure key exchange.
• Testing/Utility Components – Files like soak.c, test.cpp, and others serve for testing and benchmarking the network stability and performance.
• The communication channels should be depicted as unreliable UDP channels (unreliable and unordered), with an added layer providing encryption and signature validation.
• Interaction between the netcode protocol and the cryptography (sodium) module. You might show the netcode layer “calling” into sodium routines to perform encryption, hashing, or signing functions.
• If desired, also represent the interaction with an external REST API (for connect token generation) as an ancillary component that feeds into the client’s connection initiation process.
Architectural Patterns and Design Principles
• Connection-oriented over UDP: Emphasize that even though the underlying transport is UDP, the design offers features typically found in connection-oriented protocols, such as establishing sessions, reliable slot management, and secure client authentication.
• Modular Separation: The use of a dedicated cryptography module (sodium) indicates a clear separation of concerns. The network code leverages this module rather than implementing its own cryptography.
• Client Slot Management: The server holds a predefined number of client slots which is a notable architectural choice for managing simultaneous connections.
Relevant Technologies/Frameworks
• C Programming Language – The whole codebase is written in C, including manual memory management and using direct system calls (via sockets).
• UDP Sockets – As the network transport layer.
• Sodium Library – A well-known library for cryptographic functions (encryption, signing, etc.).
• CI/CD Tools – GitHub workflows for continuous integration, although not part of the runtime architecture, they are essential for development and build processes.