How warmcat/libwebsockets works
Main Components
a. Core Engine & Context Management – Represent the base “lib/core” and “lib/system” components that implement connection state, event handling, and resource management.
b. Protocol Implementations – Include distinct modules for HTTP (roles/h1, roles/h2, roles/http), WebSockets (roles/ws), MQTT (roles/mqtt) and other protocol-specific logic.
c. Secure Streams (SS) Layer – A higher-level abstraction sitting on top of the raw connections, defined in the “lib/secure-streams” section. Also include serialized secure streams and the SS Proxy component (ssproxy) to show how it abstractly manages policy, retries, and multiplexing.
d. TLS & Crypto Abstraction – Show the “lib/tls” subsystem which supports various TLS providers (OpenSSL, MbedTLS, etc.) and the cryptographic modules (e.g., in lib/cose, lib/jose) that work with crypto protocols.
g. Policy & Configuration – Emphasize the JSON-based “policy” portion that drives, for example, the vhost, secure streams settings, TLS validation details, connection retry/backoff, and protocol negotiation. This is key in the SS layer where endpoint, protocol, and metadata information are centralized.
h. Sample Applications and Plugins – Represent how minimal examples (in minimal-examples, test-apps) and plugins (both standalone and in the “plugins” folder) use the library. Indicate that these serve as both integration tests and “client/server” demonstrations.
Relationships and Interactions
• Secure streams layer as connecting upward from the low-level wsi APIs. Emphasize that policy JSON input drives SS behavior on top of the core connection management.
• How the event loops feed events into the core processing, and that TLS (and crypto) modules attach to every connection for security handling.
Design Patterns and Patterns to Highlight
• Modular design: the project is built in logical “modules” (or libraries) that can be independently built and configured using CMake.
• Separation of concerns: from low-level connection handling (wsi) to higher-level secure streams abstraction – with policy files governing behavior.
• Event-driven architecture: multiple event loop integrations are supported; display a central “event scheduler” receiving I/O events and dispatching them to protocol handlers.
• Configurability through JSON: show that many parameters (connection endpoints, TLS settings, retry policies) are externalized into policy files for both runtime adaptation and easy configuration.
• Portability: illustrate separate branches for platform-specific implementations, such as within lib/plat for UNIX, Windows, FreeRTOS, etc.
Technologies, Frameworks, and Tools
• CMake is used for building across platforms.
• Multiple crypto libraries (MbedTLS, OpenSSL) as indicated in lib/tls.
• Several event loop libraries (libuv, libev, glib, etc.) and plugins provide integration.
Extra Detail
• Subcomponents from directories such as “lib/drivers” (button, led, netdev, etc.) and “lib/event-libs” (showing different supported event libraries).
• That testing (CI and test-apps) and auxiliary scripts (in scripts/) support the development and build process but are not part of the runtime architecture.