Skip to content

Decouple TLS from Transport using Decorator Pattern #201

@mrabine

Description

@mrabine

Description:

The current socket inheritance-based design (Tls Socket -> Stream Socket -> Datagram Socket -> Basic Socket) creates tight coupling, violates the Liskov Substitution Principle (LSP), and restricts protocol combinations.

To improve maintainability, facilitate upcoming asynchronous APIs, and enable cleaner code separation, we need to refactor the architecture using the Decorator Pattern (static polymorphism via templates). We will also isolate TLS configuration management into its own dedicated context class.

We will break the inheritance chain:

  • Separate Stream Socket and Datagram Socket. Share common system resource logic (like file descriptor management) via a common base class (e.g., BasicSocket).
  • Introduce TlsStream, A template-based decorator that owns the underlying socket by value/move, handling encryption/decryption layers transparently.
  • Extract TlsContext: A standalone class to manage SSL_CTX lifecycle and certificate configuration, independent of individual socket connections.

Acceptance Criteria:

  • Compile-Time Composition: TlsStream can wrap any transport layer (e.g., TlsStream, TlsStream) without dynamic dispatch costs.
  • Separation of Concerns: TlsContext handles global TLS configuration and can be safely shared across multiple connections.
  • Resource Management (RAII): Sockets and TLS streams correctly manage their lifecycles via move-only semantics (C++14 compatible).

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request
No fields configured for Feature.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions