From d2fe46cdd0f506a7274ceed3c5aed96e7646777c Mon Sep 17 00:00:00 2001 From: ain ghazal Date: Tue, 23 Jan 2024 17:34:34 +0100 Subject: [PATCH] update architecture --- ARCHITECTURE.md | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index c6156eed..d3ab7134 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -12,7 +12,7 @@ * Finally, the [workers.Manager](https://github.com/ainghazal/minivpn/blob/main/internal/workers/workers.go) component deals with coordination among all the components. -## Implementation +## Services * Each layer is implemented as a service, that can be found under its own package under the [internal](https://github.com/ainghazal/minivpn/blob/main/internal) path. * Each service initializes and starts a number of workers (typicall two: one for moving data up the stack, and another one for moving data down). Some services implement only one worker, some do three. @@ -21,6 +21,7 @@ * The channels leaving and arriving each module can be seen in the diagram below: +``` ``` startShtdwn ┌───────────────────────────────────────────┬────────────►┌──────────────┐ @@ -29,60 +30,60 @@ │ │ Ready │ Manager │ └────▲───────┬──────────────────────────────┘◄────────────┤ │ │ │ │ │ - [10] │tunUp │tunDown │ │ + │tunUp │tunDown │ │ ┌────┴───────▼──────────────────────────────┐ │ │ │ │ shtdwn! │ │ │ datachannel │◄────────────┤ │ │ │ │ │ └───▲────────┬────────────────────────▲─────┘ │ │ - │ │ [1] keyUp │ shtdwn! │ │ + │ │ keyUp │ shtdwn! │ │ │ │ ┌────────────────┴─────┐◄────────────┤ │ │ │ │ │ │ │ - │ │ │ tlssession [1] ◄──┐ │ │ + │ │ │ tlssession ◄──┐ │ │ │ │ └───────▲──────────▲───┘ │ │ │ - │ │ tlsRec │ │ *notifyTLS │ │ + │ │ tlsRec │ │ notifyTLS │ │ muxerTo │ Down│ tlsRecUp notifyTLS │ │ │ Data │ │ │ │ │ │ │ │ │ ┌─▼─────┴──────────┴───┐ │ │ │ │ │ │ │ │ │ │ │ │ │ controlchannel │ │ │ │ │ │ └─┬─────▲──────────────┘ │ ◄────────┤ │ - │ │ ctrl │ │ notifyTLS │ shtdwn!│ │ - │ │ 2Rel │ rel2Ctrl │ │ │ │ - │ │ ┌─▼────────────────▼───┐ │ │ │ + │ │ ctrl │ │ │ shtdwn!│ │ + │ │ 2Rel │ rel2Ctrl │ │ │ + │ │ ┌─▼────────────────────┐ │ │ │ │ │ │ │ │ ◄────────┤ │ │ │ │ reliabletransport │ │ shtdwn!│ │ │ │ └───────▲──────────────┘ │ │ │ - │ *dataOrCtrlToMuxer │ muxerToReliable │ │ │ + │ dataOrCtrlToMuxer │ muxerToReliable │ │ │ │ │ │ │ │ │ │ ┌───┴────────▼─────────▼─────┴──────────────┐ │ │ │ hardReset│ │ │ │ │ - [1]────► packetkmuxer & HRESET ├──┘ │ │ + ────► packetkmuxer & HRESET ├──┘ │ │ │ │ │ │ └───────────────────┬────────▲──────────────┘◄────────────┤ │ - *muxerToNetwork│ │networkToMuxer shtdwn! │ │ - ┌─────[32]──────────▼────────┴──────────────┐ │ │ + muxerToNetwork│ │networkToMuxer shtdwn! │ │ + ┌───────────────────▼────────┴──────────────┐ │ │ │ │ │ │ │ network I/O │◄────────────┤ │ │ │ shtdwn! │ │ └───────────────────────────────────────────┘ └──────────────┘ ``` - - # Implementation and liveness analysis In the layered architecture detailed above, there are 12 different goroutines -that deal with moving data across the stack, in 7 services: +tasked with moving data across the stack, in 6 services: + +* 1. networkio: 2 workers (up/down). +* 2. packetmuxer: 2 workers (up/down). +* 3. reliabletransport: 2 workers (up/down). +* 4. controlchannel: 2 workers (up/down). +* 5. tlssession: 1 worker +* 6. datachannel: 3 workers (up/down/key). -* networkio: 2 workers (up/down). -* packetmuxer: 2 workers (up/down). -* reliabletransport: 2 workers (up/down). -* controlchannel: 2 workers (up/down). -* tlssession: 1 worker -* datachannel: 3 workers (up/down/key). +The `TUN` abstraction reads and writes to the `tunUp` and `tunDown` channels; TUN user is responsible for dialing the connection and passing a `networkio.FramingConn` to the `tun.StartTUN()` constructor. The TUN constructor will own the conn, and will also start an internal session.Manager and workers.Manager to deal with service coordination. -The channel communication is designed to be blocking, with unbuffered channels. +The channel communication between services is designed to be blocking, with unbuffered channels. ```mermaid stateDiagram-v2