Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
README

CI Code Quality Coverage codecov Documentation License

Network System

Language: English | ํ•œ๊ตญ์–ด

Table of Contents

  • Overview
  • Quick Start
  • Requirements
  • Installation via vcpkg
  • Modular Architecture
  • Core Features
  • Performance Highlights
  • Architecture Overview
  • Ecosystem Integration
  • Documentation
  • Platform Support
  • Production Quality
  • Build Options
  • Examples
  • Roadmap
  • Contributing
  • License

Overview

A modern C++20 asynchronous network library providing reusable transport primitives for distributed systems and messaging applications. Originally extracted from messaging_system for enhanced modularity and ecosystem-wide reusability.

Key Characteristics:

  • ๐Ÿ—๏ธ Modular Architecture: Coroutine-friendly async I/O with pluggable protocol stack
  • โšก High Performance: ASIO-based non-blocking operations with synthetic benchmarks showing ~769K msg/s for small payloads
  • ๐Ÿ›ก๏ธ Production Grade: Comprehensive sanitizer coverage (TSAN/ASAN/UBSAN clean), RAII Grade A, multi-platform CI/CD
  • ๐Ÿ”’ Secure: TLS 1.2/1.3 support, certificate validation, modern cipher suites
  • ๐ŸŒ Cross-Platform: Ubuntu, Windows, macOS with GCC, Clang, MSVC support

Installation via vcpkg

Quick Start

# Using overlay ports from the kcenon vcpkg registry
vcpkg install kcenon-network-system \
--overlay-ports=path/to/kcenon/vcpkg-registry/ports
# With SSL and ecosystem features enabled
vcpkg install kcenon-network-system[ssl,ecosystem] \
--overlay-ports=path/to/kcenon/vcpkg-registry/ports

Registry-based consumption: For projects already using kcenon/vcpkg-registry, add the registry to your vcpkg-configuration.json and install without --overlay-ports.

Feature Matrix

Feature Default Description Transitive Dependencies
(core) always Async TCP/UDP, WebSocket, HTTP/1.1, TLS common_system, thread_system, asio, openssl, zlib
ssl off Explicit SSL/TLS support flag openssl >= 3.0.0
ecosystem off Logger and container integration logger_system, container_system
testing off Unit tests and benchmarks gtest, benchmark
samples off Sample applications โ€”
docs off Doxygen documentation โ€”

CMake Integration

find_package(network_system CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE network_system::network_system)

Minimal Example

#include <iostream>
int main() {
auto server = kcenon::network::tcp_facade::create_server({
.port = 9090,
.on_message = [](auto session, auto data) {
std::cout << "Received: " << data << std::endl;
}
});
server->start();
return 0;
}
int main()
@ server
Server-side handling of a request.
Simplified facade for creating TCP clients and servers.

Requirements

Dependency Version Required Description
C++20 Compiler GCC 13+ / Clang 17+ / MSVC 2022+ / Apple Clang 14+ Yes Higher requirements due to thread_system dependency
CMake 3.20+ Yes Build system
ASIO latest Yes Asynchronous I/O (standalone)
OpenSSL 3.x (recommended) / 1.1.1 (minimum) Yes TLS/SSL support
common_system latest Yes Common interfaces and Result<T>
thread_system latest Yes Thread pool and async operations
logger_system latest Yes Logging infrastructure
container_system latest Yes Data container operations

OpenSSL Version Note: OpenSSL 1.1.1 reached End-of-Life on September 11, 2023. We strongly recommend upgrading to OpenSSL 3.x for continued security support. The build system will display a warning if OpenSSL 1.1.1 is detected.

Dependency Flow

network_system
โ”œโ”€โ”€ common_system (required)
โ”œโ”€โ”€ thread_system (required)
โ”‚ โ””โ”€โ”€ common_system
โ”œโ”€โ”€ logger_system (required)
โ”‚ โ””โ”€โ”€ common_system
โ””โ”€โ”€ container_system (required)
โ””โ”€โ”€ common_system

Note: Unlike database_system, network_system does not have a compile-time dependency on monitoring_system. For observability, network_system uses EventBus-based metric publishing via common_system. External monitoring consumers (including monitoring_system) can subscribe to network_metric_event for metrics collection. See Monitoring Integration Guide for details.

Building with Dependencies

# Clone all dependencies
git clone https://github.com/kcenon/common_system.git
git clone https://github.com/kcenon/thread_system.git
git clone https://github.com/kcenon/logger_system.git
git clone https://github.com/kcenon/container_system.git
git clone https://github.com/kcenon/network_system.git
# Build network_system
cd network_system
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build

๐Ÿ“– Quick Start Guide โ†’


Quick Start

Prerequisites

Ubuntu/Debian (Ubuntu 22.04+ provides OpenSSL 3.x by default):

sudo apt update
sudo apt install -y cmake ninja-build libasio-dev libssl-dev liblz4-dev zlib1g-dev

macOS (OpenSSL 3.x via Homebrew):

brew install cmake ninja asio openssl@3 lz4 zlib

Windows (vcpkg):

# vcpkg provides OpenSSL 3.x
vcpkg install openssl asio lz4 zlib --triplet x64-windows

Windows (MSYS2):

pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja \
mingw-w64-x86_64-asio mingw-w64-x86_64-openssl

Build

git clone https://github.com/kcenon/network_system.git
cd network_system
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build -j

C++20 Module Build (Experimental)

For C++20 module support (requires CMake 3.28+ and compatible compiler):

cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DNETWORK_BUILD_MODULES=ON
cmake --build build -j

Usage with modules:

int main() {
auto server = std::make_unique<kcenon::network::core::messaging_server>("MyServer");
server->start_server(8080);
server->wait_for_stop();
}

Your First Server (60 seconds)

#include <kcenon/network/core/messaging_server.h>
#include <iostream>
int main() {
auto server = std::make_shared<kcenon::network::core::messaging_server>("MyServer");
auto result = server->start_server(8080);
if (result.is_err()) {
const auto& err = result.error();
std::cerr << "Failed to start: " << err.message
<< " (code: " << err.code << ")" << std::endl;
return -1;
}
std::cout << "Server running on port 8080..." << std::endl;
server->wait_for_stop();
return 0;
}

Your First Client

#include <kcenon/network/core/messaging_client.h>
#include <iostream>
int main() {
auto client = std::make_shared<kcenon::network::core::messaging_client>("MyClient");
auto result = client->start_client("localhost", 8080);
if (result.is_err()) {
const auto& err = result.error();
std::cerr << "Failed to connect: " << err.message
<< " (code: " << err.code << ")" << std::endl;
return -1;
}
// Send message (std::move avoids extra copies)
std::string message = "Hello, Network System!";
std::vector<uint8_t> data(message.begin(), message.end());
auto send_result = client->send_packet(std::move(data));
if (send_result.is_err()) {
const auto& err = send_result.error();
std::cerr << "Failed to send: " << err.message
<< " (code: " << err.code << ")" << std::endl;
}
client->wait_for_stop();
return 0;
}

Simplified Facade API (NEW in v2.0)

For even simpler usage, use the Facade API that hides template complexity:

#include <iostream>
int main() {
using namespace kcenon::network;
// Create server with declarative configuration
auto server = facade.create_server({
.port = 8080,
.server_id = "MyServer"
});
// Set callbacks
server->set_receive_callback([&](auto session_id, const auto& data) {
std::cout << "Received " << data.size() << " bytes\n";
// Echo back
server->send(session_id, data);
});
// Start server
auto result = server->start(8080);
if (result.is_err()) {
std::cerr << "Failed: " << result.error().message << "\n";
return -1;
}
std::cout << "Server running on port 8080...\n";
server->wait_for_stop();
return 0;
}
Simplified facade for creating TCP clients and servers.
Definition tcp_facade.h:95
auto create_server(const server_config &config) const -> Result< std::shared_ptr< interfaces::i_protocol_server > >
Creates a TCP server with the specified configuration.
Main namespace for all Network System components.

Benefits:

  • โœ… No template parameters
  • โœ… Clear configuration struct
  • โœ… Protocol-agnostic interface
  • โœ… Same performance as direct API

๐Ÿ“– Full Facade Documentation โ†’


Modular Architecture (NEW)

Starting with v2.0, network_system is organized into protocol-specific libraries for improved maintainability and selective linking.

Library Overview

Library Description Dependencies
network-core Core interfaces and session management None
network-tcp TCP protocol with SSL/TLS support network-core, ASIO, OpenSSL
network-udp UDP datagram protocol network-core, ASIO
network-websocket WebSocket (RFC 6455) network-tcp
network-http2 HTTP/2 multiplexed protocol network-websocket
network-quic QUIC (RFC 9000) network-udp, OpenSSL
network-grpc gRPC high-performance RPC network-quic
network-all Umbrella package (all protocols) All above

Dependency Graph

network-core
/ | \
/ | \
network-tcp | network-udp
| | |
network-websocket network-quic
| |
network-http2 network-grpc

Selective Linking

Link only the protocols your application needs:

# Option 1: All protocols (simple, larger binary)
find_package(network-all REQUIRED)
target_link_libraries(my_app PRIVATE kcenon::network-all)
# Option 2: Specific protocols (smaller binary)
find_package(network-tcp REQUIRED)
find_package(network-udp REQUIRED)
target_link_libraries(my_app PRIVATE
kcenon::network-tcp
kcenon::network-udp
)

Umbrella Header

Include all protocols with a single header:

#include <network_all/network.h>
// Check protocol availability at compile time
#if NETWORK_ALL_HAS_QUIC
auto quic_conn = protocol::quic::connect({...});
#endif

๐Ÿ“– Migration Guide โ†’ | Library READMEs


Core Features

Protocols

  • TCP: Asynchronous TCP server/client with lifecycle management
    • Non-blocking I/O, automatic reconnection, health monitoring
    • Multi-threaded message processing, session management
  • UDP: Connectionless UDP for real-time applications
    • Low-latency datagram transmission, broadcast/multicast support
  • TLS/SSL: Secure communication (TLS 1.2/1.3)
    • Modern cipher suites (AES-GCM, ChaCha20-Poly1305)
    • Certificate validation, forward secrecy (ECDHE)
  • WebSocket: RFC 6455 compliant
    • Text and binary message framing, ping/pong keepalive
    • Fragmentation/reassembly, graceful connection lifecycle
  • HTTP/1.1: Server and client with advanced features
    • Routing, cookies, multipart/form-data, chunked encoding
    • Automatic compression (gzip/deflate)
  • QUIC: RFC 9000/9001/9002 compliant
    • UDP-based multiplexed transport with TLS 1.3 encryption
    • Stream multiplexing, 0-RTT connection resumption
    • Loss detection and congestion control
    • Connection migration support
  • gRPC: High-performance RPC framework (NEW)
    • Official gRPC library wrapper with network_system integration
    • Service registry with dynamic method registration
    • All streaming modes (unary, server, client, bidirectional)
    • Health checking and reflection support
    • Result<T> to gRPC Status conversion

๐Ÿ“– Detailed Protocol Documentation โ†’ ๐Ÿ“– gRPC Guide โ†’

Distributed Tracing

OpenTelemetry-compatible distributed tracing for observability:

  • W3C Trace Context: Standard context propagation across service boundaries
  • RAII Spans: Automatic span lifecycle management with NETWORK_TRACE_SPAN macro
  • Multiple Exporters: Console, OTLP HTTP/gRPC, Jaeger, Zipkin support
  • Sampling: Always-on, always-off, trace-id-based, parent-based samplers
  • Rich Attributes: String, integer, double, boolean attributes and events
#include <kcenon/network/tracing/tracing_config.h>
#include <kcenon/network/tracing/trace_context.h>
// Configure tracing (once at startup)
auto config = tracing_config::otlp_http("http://localhost:4318/v1/traces");
config.service_name = "my-service";
configure_tracing(config);
// Create spans using RAII
void process_request() {
NETWORK_TRACE_SPAN("http.request.process");
_span.set_attribute("http.method", "POST");
_span.set_attribute("http.url", "/api/orders");
// Child spans inherit trace context
{
auto db_span = trace_context::current().create_child_span("database.query");
db_span.set_attribute("db.system", "postgresql");
// ... perform database operation
db_span.set_status(span_status::ok);
}
_span.set_status(span_status::ok);
}
tracing_config config
Definition exporters.cpp:29
#define NETWORK_TRACE_SPAN(name)
RAII helper macro for creating spans.
Definition span.h:305

๐Ÿ“– Tracing Guide โ†’

Asynchronous Model

  • ASIO-Based: Non-blocking event loop with async operations
  • C++20 Coroutines: Optional coroutine-based async helpers
  • C++20 Concepts: Compile-time type validation with clear error messages
  • Pipeline Architecture: Message transformation with compression/encryption hooks
  • Move Semantics: Zero-copy friendly APIs (move-aware buffer handling)

Failure Handling

  • All server/client start helpers return Result<void>; check result.is_err() before continuing and log result.error().message.
  • For historical fixes (session cleanup, backpressure, TLS rollout), review IMPROVEMENTS.md to understand the safeguards already in place and how to react if regression symptoms reappear.
  • When building higher-level services, propagate common::error_info up the stack so monitoring and alerting pipelines can correlate failures across tiers.

Error Handling

Result<T> Pattern (75-80% migrated):

auto result = server->start_server(8080);
if (result.is_err()) {
const auto& err = result.error();
std::cerr << "Error: " << err.message
<< " (code: " << err.code << ")\n";
return -1;
}

Error Codes (-600 to -699):

  • Connection (-600 to -619): connection_failed, connection_refused, connection_timeout
  • Session (-620 to -639): session_not_found, session_expired
  • Send/Receive (-640 to -659): send_failed, receive_failed, message_too_large
  • Server (-660 to -679): server_not_started, server_already_running, bind_failed

Performance Highlights

Synthetic Benchmarks (Intel i7-12700K, Ubuntu 22.04, GCC 11, -O3)

Payload Throughput Latency (ns/op) Scope
64 bytes ~769K msg/s 1,300 CPU-only (allocation + memcpy)
256 bytes ~305K msg/s 3,270 CPU-only (allocation + memcpy)
1 KB ~128K msg/s 7,803 CPU-only (allocation + memcpy)
8 KB ~21K msg/s 48,000 CPU-only (allocation + memcpy)

Real I/O Benchmarks (Loopback TCP)

Benchmark Payload Scope
TCP Connection Establish N/A Connect + disconnect via loopback
TCP Echo Roundtrip 64B, 1KB, 8KB Send + receive through kernel TCP stack
TCP Stream Throughput 1KB, 64KB Sustained bytes/sec over loopback

Note: Synthetic benchmarks measure CPU-only operations without real network I/O. Real I/O benchmarks use a TCP echo server on the loopback interface to measure actual kernel TCP stack overhead.

Reproducing Benchmarks

# Build with benchmarks
cmake -B build -DCMAKE_BUILD_TYPE=Release -DNETWORK_BUILD_BENCHMARKS=ON
cmake --build build -j
# Run all benchmarks
./build/benchmarks/network_benchmarks
# Run synthetic benchmarks only
./build/benchmarks/network_benchmarks --benchmark_filter=MessageThroughput
# Run real I/O benchmarks only
./build/benchmarks/network_benchmarks --benchmark_filter=TCP

โšก Full Benchmarks & Load Testing โ†’

Platform: Apple M1 @ 3.2GHz (when tested on Apple Silicon)


Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Network System Architecture โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Public API Layer โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ messaging โ”‚ โ”‚ messaging โ”‚ โ”‚ messaging_ws โ”‚ โ”‚
โ”‚ โ”‚ _server โ”‚ โ”‚ _client โ”‚ โ”‚ _server / _client โ”‚ โ”‚
โ”‚ โ”‚ (TCP) โ”‚ โ”‚ (TCP) โ”‚ โ”‚ (WebSocket) โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ secure_messaging โ”‚ โ”‚ secure_messaging โ”‚ โ”‚
โ”‚ โ”‚ _server (TLS/SSL) โ”‚ โ”‚ _client (TLS/SSL) โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ messaging_quic โ”‚ โ”‚ messaging_quic โ”‚ โ”‚
โ”‚ โ”‚ _server (QUIC) โ”‚ โ”‚ _client (QUIC) โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Protocol Layer โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ tcp_socket โ”‚ โ”‚ udp_socket โ”‚ โ”‚ websocket_socket โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ secure_tcp_socket โ”‚ โ”‚ websocket_protocol โ”‚ โ”‚
โ”‚ โ”‚ (SSL stream wrapper) โ”‚ โ”‚ (frame/handshake/msg handle) โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ protocols/quic/ (RFC 9000/9001/9002) โ”‚ โ”‚
โ”‚ โ”‚ connection, stream, packet, frame, crypto, varint โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Session Management Layer โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ messaging โ”‚ โ”‚ secure โ”‚ โ”‚ ws_session_manager โ”‚ โ”‚
โ”‚ โ”‚ _session โ”‚ โ”‚ _session โ”‚ โ”‚ (WebSocket mgmt) โ”‚ โ”‚
โ”‚ โ”‚ (TCP) โ”‚ โ”‚ (TLS/SSL) โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
โ”‚ โ”‚ quic_session (QUIC session management) โ”‚โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Core Network Engine (ASIO-based) โ”‚
โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ”‚ io_context โ”‚ โ”‚ async โ”‚ โ”‚ Result<T> โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ โ”‚ operations โ”‚ โ”‚ pattern โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Design Patterns: Factory, Observer, Strategy, RAII, Template Metaprogramming

๐Ÿ›๏ธ Detailed Architecture Guide โ†’


Ecosystem Integration

Ecosystem Dependency Map

graph TD
A[common_system] --> B[thread_system]
A --> C[container_system]
B --> D[logger_system]
B --> E[monitoring_system]
D --> F[database_system]
E --> F
F --> G[network_system]
G --> H[pacs_system]
style G fill:#f9f,stroke:#333,stroke-width:3px

Ecosystem reference: common_system โ€” Result<T>, interfaces, and shared utilities thread_system โ€” Thread pool and async execution primitives container_system โ€” Type-safe data serialization logger_system โ€” Logging infrastructure database_system โ€” Database operations (depends on network_system) pacs_system โ€” DICOM/PACS system (consumes network_system)

Related Projects

This system integrates seamlessly with:

Integration Example

#include <kcenon/network/core/messaging_server.h>
#include <kcenon/network/integration/thread_system_adapter.h>
using namespace kcenon::network;
int main() {
// Bind thread_system for unified thread management
#if KCENON_WITH_THREAD_SYSTEM
integration::bind_thread_system_pool_into_manager("network_pool");
#endif
// Create and start server
auto server = std::make_shared<core::messaging_server>("IntegratedServer");
auto result = server->start_server(8080);
if (result.is_err()) {
std::cerr << "Failed: " << result.error().message << std::endl;
return -1;
}
// Get thread pool metrics
auto& manager = integration::thread_integration_manager::instance();
auto metrics = manager.get_metrics();
std::cout << "Workers: " << metrics.worker_threads << std::endl;
server->wait_for_stop();
return 0;
}

Thread Pool Adapters

Bidirectional adapters enable interoperability between network_system's thread pool and common_system's executor:

#include <kcenon/network/integration/thread_pool_adapters.h>
// Use network_system pool where IExecutor is expected
auto network_pool = thread_integration_manager::instance().get_thread_pool();
auto executor = std::make_shared<network_to_common_thread_adapter>(network_pool);
// Pass executor to messaging_system, database_system, etc.
// Use external IExecutor in network_system
auto external_executor = container.resolve<common::interfaces::IExecutor>();
auto adapted = std::make_shared<common_to_network_thread_adapter>(external_executor);
thread_integration_manager::instance().set_thread_pool(adapted);

๐ŸŒ Full Integration Guide โ†’


Documentation

Getting Started

  • ๐Ÿ“– Features Guide - Comprehensive feature descriptions
  • ๐Ÿ—๏ธ Architecture - System design and patterns
  • ๐Ÿ“˜ API Reference - Complete API documentation
  • ๐Ÿ”ง Build Guide - Detailed build instructions
  • ๐Ÿš€ Migration Guide - Migrating from messaging_system

Advanced Topics

  • โšก Performance & Benchmarks - Performance metrics and testing
  • ๐Ÿญ Production Quality - CI/CD, security, quality assurance
  • ๐Ÿ“ Project Structure - Directory organization and modules
  • ๐Ÿงฉ C++20 Concepts - Compile-time type validation
  • ๐Ÿ”’ TLS Setup Guide - TLS/SSL configuration
  • ๐Ÿ” Troubleshooting - Common issues and solutions
  • ๐Ÿงช Load Test Guide - Load testing procedures
  • ๐Ÿ“ Design Decisions - Architectural patterns and rationale

Development

  • ๐Ÿ”„ Integration Guide - Ecosystem integration patterns
  • ๐Ÿ“Š Operations Guide - Deployment and operations
  • ๐Ÿ“‹ Changelog - Version history and updates

Platform Support

Platform Compiler Architecture Support Level
Ubuntu 22.04+ GCC 13+ x86_64, ARM64 โœ… Full Support
Ubuntu 22.04+ Clang 17+ x86_64, ARM64 โœ… Full Support
Windows 2022+ MSVC 2022+ x86_64 โœ… Full Support
Windows 2022+ MinGW64 x86_64 โœ… Full Support
macOS 12+ Apple Clang 14+ x86_64, ARM64 โœ… Full Support

Production Quality

CI/CD Infrastructure

Comprehensive Multi-Platform Testing:

  • โœ… Sanitizer Coverage: ThreadSanitizer, AddressSanitizer, UBSanitizer
  • โœ… Multi-Platform: Ubuntu (GCC/Clang), Windows (MSVC/MinGW), macOS
  • โœ… Performance Gates: Automated regression detection
  • โœ… Static Analysis: clang-tidy, cppcheck with modernize checks
  • โœ… Code Coverage: ~80% with Codecov integration

Security

TLS/SSL Implementation:

  • TLS 1.2/1.3 protocol support
  • Modern cipher suites (AES-GCM, ChaCha20-Poly1305)
  • Forward secrecy (ECDHE), certificate validation
  • Hostname verification, optional certificate pinning

Additional Security:

  • Input validation and buffer overflow protection
  • WebSocket origin validation and frame masking
  • HTTP request size limits and path traversal protection
  • Cookie security (HttpOnly, Secure, SameSite)

Thread Safety & Memory Safety

Thread Safety:

  • โœ… Comprehensive synchronization (mutex, atomic, shared_mutex)
  • โœ… ThreadSanitizer clean (zero data races)
  • โœ… Concurrent session handling tested

Memory Safety (RAII Grade A):

  • โœ… 100% smart pointer usage (std::shared_ptr, std::unique_ptr)
  • โœ… Zero manual memory management
  • โœ… AddressSanitizer clean (zero leaks, zero buffer overflows)
  • โœ… Automatic resource cleanup via RAII

๐Ÿ›ก๏ธ Complete Production Quality Guide โ†’


Dependencies

Required

  • C++20 compatible compiler (GCC 13+, Clang 17+, MSVC 2022+, Apple Clang 14+)

Note: The higher GCC/Clang requirements come from the thread_system dependency, which requires GCC 13+ and Clang 17+ for full C++20 feature support.

  • CMake 3.20+
  • ASIO or Boost.ASIO 1.28+
  • OpenSSL 3.x recommended / 1.1.1+ minimum (for TLS/SSL and WebSocket)
  • common_system (Result<T> pattern, common interfaces)
  • thread_system (thread pool integration)
  • logger_system (structured logging)
  • container_system (data container operations)
  • fmt 10.0.0+ (formatting library)
  • zlib (compression support)

Build Options

Using CMake Presets (Recommended)

CMake presets provide standardized build configurations:

# List available presets
cmake --list-presets
# Configure with a preset
cmake --preset debug # Debug build
cmake --preset release # Release build
cmake --preset asan # AddressSanitizer
cmake --preset tsan # ThreadSanitizer
cmake --preset ubsan # UndefinedBehaviorSanitizer
cmake --preset coverage # Code coverage
# Build
cmake --build --preset debug
# Test with sanitizer-specific environment
ctest --preset asan # Runs with ASAN_OPTIONS configured
ctest --preset tsan # Runs with TSAN_OPTIONS configured

Manual CMake Configuration

# Basic build
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
# With sanitizers (mutually exclusive)
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON # AddressSanitizer
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_TSAN=ON # ThreadSanitizer
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DENABLE_UBSAN=ON # UndefinedBehaviorSanitizer
# With benchmarks
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DNETWORK_BUILD_BENCHMARKS=ON
# With tests
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTS=ON
# With optional integrations
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DBUILD_WITH_THREAD_SYSTEM=ON \
-DBUILD_WITH_LOGGER_SYSTEM=ON \
-DBUILD_WITH_CONTAINER_SYSTEM=ON
# Build and run tests
cmake --build build -j
cd build && ctest --output-on-failure

Cleaning Build Directories

To remove all build directories at once:

./scripts/clean.sh

Tip: Prefer cmake --preset <name> over manual mkdir build_* directories. Named presets produce consistent, reproducible builds and avoid build directory proliferation.

Available CMake Options

Option Default Description
BUILD_TESTS ON Build unit tests
BUILD_SAMPLES ON Build sample applications
BUILD_TLS_SUPPORT ON Enable TLS/SSL support
BUILD_WEBSOCKET_SUPPORT ON Enable WebSocket protocol
NETWORK_BUILD_BENCHMARKS OFF Build performance benchmarks
ENABLE_ASAN OFF Enable AddressSanitizer
ENABLE_TSAN OFF Enable ThreadSanitizer
ENABLE_UBSAN OFF Enable UndefinedBehaviorSanitizer
ENABLE_COVERAGE OFF Enable code coverage
NETWORK_ENABLE_GRPC_OFFICIAL OFF Use official gRPC library

Examples

Complete examples are available in the samples/ directory:

  • basic_usage.cpp - Basic TCP client/server
  • simple_tcp_server.cpp - TCP server with session management
  • simple_tcp_client.cpp - TCP client with reconnection
  • simple_http_server.cpp - HTTP server with routing
  • simple_http_client.cpp - HTTP client with various request types
  • websocket_example.cpp - WebSocket server and client
  • quic_server_example.cpp - QUIC server with multi-stream support
  • quic_client_example.cpp - QUIC client with stream multiplexing
  • grpc_service_example.cpp - gRPC service registration and management

Build and run examples:

cmake --build build --target samples
./build/bin/simple_tcp_server
./build/bin/simple_tcp_client

Roadmap

Recently Completed

  • โœ… QUIC Protocol Support: RFC 9000/9001/9002 compliant implementation
  • โœ… gRPC Integration: Official gRPC library wrapper with full streaming support

Current Focus

  • ๐Ÿšง Real network load test validation and baseline establishment
  • ๐Ÿšง Complete Result<T> migration (currently 75-80%)
  • ๐Ÿšง Documentation examples update

Planned Features

  • ๐Ÿšง Connection Pooling: Enterprise-grade connection management
  • ๐Ÿšง Zero-Copy Pipelines: Eliminate unnecessary buffer copies
  • ๐Ÿšง HTTP/2 Client: Modern HTTP/2 protocol support

See IMPROVEMENTS.md for detailed roadmap and tracking.


Contributing

Contributions are welcome! Please see our Contributing Guide for detailed guidelines.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Follow the Coding Style Rules
  4. Commit changes with conventional commits
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

Before submitting:

  • Ensure all tests pass (ctest)
  • Run sanitizers (TSAN, ASAN, UBSAN)
  • Check code formatting (clang-format)
  • Update documentation as needed

License

This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details.


Contact & Support

Contact Type Details
Project Owner kcenon (kceno.nosp@m.n@na.nosp@m.ver.c.nosp@m.om)
Repository https://github.com/kcenon/network_system
Issues & Bug Reports https://github.com/kcenon/network_system/issues
Discussions & Questions https://github.com/kcenon/network_system/discussions

Acknowledgments

Core Dependencies

  • ASIO Library Team: Foundation of asynchronous network programming
  • C++ Standards Committee: C++20 features enabling modern networking

Ecosystem Integration

  • Thread System: Seamless thread pool integration
  • Logger System: Comprehensive logging and debugging
  • Container System: Advanced serialization support
  • Database System: Network-database integration patterns
  • Monitoring System: Performance metrics and observability

Made with โค๏ธ by ๐Ÿ€โ˜€๐ŸŒ•๐ŸŒฅ ๐ŸŒŠ