How anywherelan/awl works
Project Type and Purpose
• This is a Go‑based, peer‑to‑peer mesh VPN application (awl). It combines a headless daemon (awl), a desktop system‑tray client (awl‑tray), a web‑based admin UI, and a CLI. Its purpose is to form a fully decentralized, encrypted VPN mesh using virtual network interfaces (tun/wintun) and libp2p (QUIC/TCP+TLS, DHT, bootstrap nodes) to connect peers directly or via relays, and optionally route traffic via SOCKS5 exit nodes.
File Structure Analysis
• Top‑level “cmd” contains two user‑facing executables:
• cmd/awl – headless daemon with embedded web UI and CLI subcommands
• cmd/awl‑tray – desktop system‑tray wrapper that embeds awl plus tray UI hooks
• “cli” package – implements the terminal‑based client interface used by both executables.
• “api” package – internal HTTP/RPC API layer (settings, peers, metrics).
• “service” package – business logic for tunnels, SOCKS5 service, auth.
• “p2p”, “protocol” – low‑level libp2p integration and wire‑protocol definitions.
• “vpn” & “awldns” – virtual interface management (platform‑specific) and DNS server.
• “socks5” – SOCKS5 proxy implementation.
• “config”, “entity” – configuration loading and domain models.
• “awlevent” – asynchronous event handling (notifications, status changes).
• “update” – self‑update mechanism.
• Test files in each package indicate unit tests for every component.
README Insights
• Libraries: tun/wintun driver, libp2p, QUIC/TCP+TLS, DHT, bootstrap nodes.
• Features: peer discovery via DHT, NAT traversal, relay fallback, built‑in DNS, SOCKS5 proxy, system‑tray and web UI.
• Platforms: Windows, Linux, macOS, Android.
• Interaction flows: user invokes CLI or clicks tray → communicates via local API → orchestrates p2p connections → configures virtual interface → routes traffic.
a. Main Components
• Clients: CLI, Tray UI, Web UI (browser)
• API Layer (http/json RPC)
• Core Daemon (application.go orchestrator)
• Services: VPN Engine, DNS Server, SOCKS5 Proxy, Update Manager, Event Dispatcher
• P2P Module (libp2p adapter, DHT, QUIC/TCP+TLS)
• Virtual Network Interface (tun/wintun driver)
• External Services: Bootstrap Nodes, Other Peers
• Operating System Network Stack
b. Relationships & Data Flows
1. User → CLI/Tray → local API → Core Daemon
2. Core → P2P Module → Bootstrap Nodes (initial registration)
3. Core → P2P Module ↔ Other Peers (peer‑to‑peer encrypted tunnels)
4. Core → VPN Engine → Virtual Interface → OS Network Stack
5. Core → DNS Server → resolves *.awl names → traffic via virtual interface
6. Core → SOCKS5 Service → forwards application traffic over P2P tunnels
7. Self‑Update: Core → Update Manager → GitHub Releases
c. Architectural Patterns & Principles
• Layered architecture: UI layer, API layer, core orchestration, adapter modules.
• Modular design: each functional area in its own Go package.
• Dependency injection: Core imports interfaces from service, p2p, vpn, socks5.
• Cross‑platform abstractions: vpn/iface_*.go, os_hacks_*.go under embeds.
• Asynchronous events: awlevent package for decoupling core logic and notifications.
d. Key Technologies
• Language: Go modules (go.mod)
• Networking: libp2p (QUIC/TCP + TLS), DHT, tun/wintun driver
• Web UI: embedded HTTP server in api + static assets from embeds
• CLI: urfave/cli (as seen in README examples)
• Testing: extensive _test.go files in every package