# mannava-daasaradhi/tcp-stack architecture

> Architecture diagram of the GitHub repository mannava-daasaradhi/tcp-stack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mannava-daasaradhi/tcp-stack
- Repository: https://github.com/mannava-daasaradhi/tcp-stack

## Overview

tcp-stack is a userspace IPv4/TCP stack over Linux TUN, with ICMP and UDP echo plus TCP echo and HTTP server applications. The principal workflow is peer packets entering TUN, main dispatching by IP protocol, TCP maintaining per-connection state and delivering ordered data to an application, then transmitting replies through TUN. TCP’s internal mechanisms include reassembly, sequence arithmetic, RTT estimation, and selectable congestion control. README documents additional TCP lifecycle, recovery, options, and socket capabilities; the excerpts do not expose every internal call, so only documented or sampled wiring is shown.

Main entry points: [`src/main.rs`](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/main.rs) (Event Loop), [`src/tcp.rs`](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/tcp.rs) (TCP Connection), [`src/ip.rs`](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/ip.rs) (IPv4), [`src/icmp.rs`](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/icmp.rs) (ICMP Echo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Packet Runtime"]
  node_main["Event Loop<br/>[main.rs]"]
end

subgraph group_protocols["IP Protocols"]
  node_ip["IPv4<br/>[ip.rs]"]
  node_icmp["ICMP Echo<br/>[icmp.rs]"]
  node_udp["UDP Echo<br/>[udp.rs]"]
  node_checksum["Internet Checksum<br/>[utils.rs]"]
end

subgraph group_tcp_core["TCP Core"]
  node_tcp["TCP Connection<br/>[tcp.rs]"]
  node_seq["Sequence Arithmetic<br/>[seq.rs]"]
end

subgraph group_reliability["Reliability Control"]
  node_reassembly["Receive Reassembly<br/>[reassembly.rs]"]
  node_rtt["RTT Estimator<br/>[rtt.rs]"]
  node_congestion["CUBIC Control<br/>[congestion.rs]"]
  node_bbr["BBR Control<br/>[bbr.rs]"]
end

subgraph group_apps["Applications"]
  node_http["HTTP Responder<br/>[http.rs]"]
  node_socket["Socket API<br/>[socket.rs]"]
end

node_peers(("Network Peers"))
node_tun["Linux TUN"]

node_peers -->|"send packets"| node_tun
node_tun -->|"receive packets"| node_main
node_main -->|"send packets"| node_tun
node_tun -->|"deliver packets"| node_peers
node_main -->|"parse IPv4"| node_ip
node_main -->|"dispatch ICMP"| node_icmp
node_main -->|"dispatch UDP"| node_udp
node_main -->|"dispatch TCP"| node_tcp
node_icmp -->|"update header"| node_ip
node_icmp -->|"compute checksum"| node_checksum
node_udp -->|"update header"| node_ip
node_udp -->|"compute checksum"| node_checksum
node_ip -->|"compute checksum"| node_checksum
node_tcp -->|"compare sequences"| node_seq
node_tcp -->|"reassemble data"| node_reassembly
node_tcp -->|"sample RTT"| node_rtt
node_tcp -->|"update control"| node_congestion
node_tcp -->|"update control"| node_bbr
node_main -->|"parse and respond"| node_http
node_socket -->|"drive connections"| node_tcp

click node_main "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/main.rs"
click node_ip "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/ip.rs"
click node_icmp "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/icmp.rs"
click node_udp "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/udp.rs"
click node_checksum "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/utils.rs"
click node_tcp "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/tcp.rs"
click node_seq "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/seq.rs"
click node_reassembly "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/reassembly.rs"
click node_rtt "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/rtt.rs"
click node_congestion "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/congestion.rs"
click node_bbr "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/bbr.rs"
click node_http "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/http.rs"
click node_socket "https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/socket.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main toneBlue
class node_ip,node_icmp,node_udp,node_checksum toneAmber
class node_tcp,node_seq toneMint
class node_reassembly,node_rtt,node_congestion,node_bbr toneRose
class node_http,node_socket,node_peers,node_tun toneIndigo
```

## Components

### Packet Runtime

- [Event Loop](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/main.rs): `src/main.rs`

### IP Protocols

- [IPv4](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/ip.rs): `src/ip.rs`
- [ICMP Echo](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/icmp.rs): `src/icmp.rs`
- [UDP Echo](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/udp.rs): `src/udp.rs`
- [Internet Checksum](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/utils.rs): `src/utils.rs`

### TCP Core

- [TCP Connection](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/tcp.rs): `src/tcp.rs`
- [Sequence Arithmetic](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/seq.rs): `src/seq.rs`

### Reliability Control

- [Receive Reassembly](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/reassembly.rs): `src/reassembly.rs`
- [RTT Estimator](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/rtt.rs): `src/rtt.rs`
- [CUBIC Control](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/congestion.rs): `src/congestion.rs`
- [BBR Control](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/bbr.rs): `src/bbr.rs`

### Applications

- [HTTP Responder](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/http.rs): `src/http.rs`
- [Socket API](https://github.com/mannava-daasaradhi/tcp-stack/blob/main/src/socket.rs): `src/socket.rs`

### Other components

- **Network Peers**
- **Linux TUN**

## Connections

- Network Peers → Linux TUN: send packets
- Linux TUN → Event Loop: receive packets
- Event Loop → Linux TUN: send packets
- Linux TUN → Network Peers: deliver packets
- Event Loop → IPv4: parse IPv4
- Event Loop → ICMP Echo: dispatch ICMP
- Event Loop → UDP Echo: dispatch UDP
- Event Loop → TCP Connection: dispatch TCP
- ICMP Echo → IPv4: update header
- ICMP Echo → Internet Checksum: compute checksum
- UDP Echo → IPv4: update header
- UDP Echo → Internet Checksum: compute checksum
- IPv4 → Internet Checksum: compute checksum
- TCP Connection → Sequence Arithmetic: compare sequences
- TCP Connection → Receive Reassembly: reassemble data
- TCP Connection → RTT Estimator: sample RTT
- TCP Connection → CUBIC Control: update control
- TCP Connection → BBR Control: update control
- Event Loop → HTTP Responder: parse and respond
- Socket API → TCP Connection: drive connections
