Files
Nikita Gorskikh 3c93077f4c Pull request 682: Add an "easy" Windows service interface for TrustTunnel GUI clients
Squashed commit of the following:

commit e262ed1da2c2aef6a5c5a45ec5d41066ba44979f
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Sun Apr 26 18:13:02 2026 +0300

    Return more correct error code

commit 4a9b56b2b4e746b59e559ec6ce689f961ddd9e2b
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Sat Apr 25 00:18:15 2026 +0300

    Cleanup

commit 7884c91e0e869b9c5bc4b83548aa18cf487d7af2
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Sat Apr 25 00:06:10 2026 +0300

    Cleanup + run clang-format

commit 7973e7aa5cabbb2e02ee559ea3e7bf9f073d3430
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Fri Apr 24 23:28:24 2026 +0300

    Cleanup

commit 53e982d626ebe841a8d27bb6dd96cc2ace05d0c4
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Fri Apr 24 22:42:27 2026 +0300

    Vibe test

commit d4fab62e2838dbecb7d04f811b62d6c4efad6440
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Fri Apr 24 22:24:00 2026 +0300

    Service interface and test

commit 5a84e3b0216ab0ce4cedcd65cc620e82d5426cd5
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Fri Apr 24 20:29:07 2026 +0300

    Allow authenticated users to start/stop service

commit 85238d526d447547d42cfe689952315de76b2869
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Fri Apr 24 17:59:13 2026 +0300

    Fix vibe code

commit 79df07013043a16ca1fad3a9ea4b01af7af314e9
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Fri Apr 24 14:12:47 2026 +0300

    Fix vibe code

commit e8ced6e1c76f519983ac756ea091ecc04332e33f
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Thu Apr 23 22:10:38 2026 +0300

    Vibe code more

commit af1d789c08f6bf27bed7510b4644ad5e17d3e709
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Thu Apr 23 19:28:20 2026 +0300

    Vibe-update AGENTS.md

commit b34813d984ca927f8e427b551ed787f036386557
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Thu Apr 23 19:28:09 2026 +0300

    Remove non-vibe-coded

commit 496dc4057e5e7db21e12f4b5d9ef0f9c9e22df5f
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Thu Apr 23 18:52:33 2026 +0300

    Vibe test

commit a1877a026496dc5919c72d44c7e8d971cda18d8f
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Thu Apr 23 15:31:38 2026 +0300

    Vibe code

commit 9e706843376b71cbf4160fe9edcff62ee9652b8f
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Thu Apr 23 00:13:18 2026 +0300

    Vibe code

commit a641c864fde194f9cb7c7001487801842b1d56b9
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Wed Apr 22 22:58:12 2026 +0300

    Vibe code

commit 9edb4183a2173154502b00aa63b6f7af688b9624
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Wed Apr 22 22:37:20 2026 +0300

    Vibe code

commit f3a7b059e8e2bce823410d7c6efcc521a48027fd
Author: Nikita Gorskikh <n.gorskikh@adguard.com>
Date:   Tue Mar 31 20:54:15 2026 +0300

    WIP
2026-05-04 14:12:30 +00:00

9.7 KiB

AGENTS.md — Project Guide for AI Coding Agents

Project Overview

This is reposoitory TrustTunnelClient, which contains libraries and command-line client for TrustTunnel protocol. The protocol is compatible with HTTP/1.1, HTTP/2, and QUIC, and supports tunneling TCP, UDP, and ICMP traffic. The libraries run on Linux, macOS, and Windows.

See README.md for full product details and DEVELOPMENT.md for prerequisite setup.

Tech Stack

  • C++20 (primary), C11 — core libraries
  • Rust 1.85trusttunnel/setup_wizard/, trusttunnel/settings/, trusttunnel/deeplink-ffi/
  • Kotlin — Android platform adapter
  • Swift / Objective-C — Apple platform adapter
  • Dart (Flutter) — test app (platform/testapp/)
  • CMake 3.24+ — build system
  • Conan 2.0.5+ — C++ package manager
  • Ninja — build backend
  • Clang / LLVM 17+ (LLVM 19 on macOS) — compiler and tooling (Windows builds use MSVC cl.exe, not clang)
  • clang-format 21+ — required by make lint-cpp / make clang-format
  • Python 3scripts/bootstrap_conan_deps.py, Conan wrappers (requirements.txt)
  • Ruby / Fastlane — iOS/Android release automation (Gemfile, fastlane/)

Directory Structure

Directory Purpose
common/ Shared utilities used across all modules: FSM, event loop, platform abstractions, settings
core/ Core VPN logic: tunnel, upstream connectors (HTTP/2, HTTP/3), DNS, SOCKS listener, TUN device
net/ Network layer: HTTP sessions, TLS, QUIC, sockets, OS tunnel, DNS management, pinger
tcpip/ TCP/IP stack: lwIP integration, TCP/UDP/ICMP raw handling, packet pool
trusttunnel/ CLI client app, config parsing; contains Rust sub-crates: deeplink-ffi/, settings/, setup_wizard/
platform/android/ Android adapter (Kotlin/Gradle)
platform/apple/ Apple adapter (Swift/ObjC, CocoaPods, XCFramework)
platform/windows/ Windows adapter (C++/CMake)
platform/testapp/ Flutter test application for platform adapters
third-party/ Vendored dependencies: lwip, pcap_savefile, wintun
scripts/ Build helpers, Conan export, version increment, git hooks
cmake/ CMake modules: unit test helper, Conan bootstrapping/provider
bamboo-specs/ CI/CD pipeline definitions (Bamboo)
integration-tests/ Docker-based integration test harness
conan/ Conan user settings and build profiles
fastlane/ iOS/Android release automation (Fastfile, Matchfile)
.devcontainer/ Docker-based remote debugging environment (see below)
.github/ GitHub Actions workflows and PR/issue templates

Module Dependency Flow

common ← core ← trusttunnel (CLI client)
common ← net  ← core
common ← tcpip ← core

platform/* adapters wrap core for their respective OS.

Build Commands

Run make init once after cloning to set up git hooks. Running make with no arguments runs the init target — use make all (or make build_libs) to actually build.

Command What It Does
make init Configure git hooks path to ./scripts/hooks
make bootstrap_deps Export AdGuard Conan recipes to local cache (prerequisite of most build targets)
make setup_cmake CMake configure only (accepts SKIP_BOOTSTRAP=1)
make build_libs Bootstrap Conan deps → CMake configure → build vpnlibs_core
make build_trusttunnel_client Build the CLI client binary (depends on build_libs)
make build_wizard Build the setup wizard binary
make build_and_export_bin Build binaries and copy to $(EXPORT_DIR) (default bin/)
make all Build all binaries (client + wizard)
make test Run all tests (test-cpp + test-rust)
make test-cpp Build libs → build test targets → run ctest
make test-rust cargo test on the setup_wizard workspace
make lint Run all linters (lint-md + lint-rust + lint-cpp)
make lint-cpp clang-format check + clangd-tidy
make clang-format Explicit clang-format check only
make clang-tidy / make clangd-tidy Run C++ static analysis only
make lint-rust cargo clippy + cargo fmt --check
make lint-md markdownlint .
make lint-fix Auto-fix all fixable linter issues
make lint-fix-cpp / lint-fix-rust / lint-fix-md Granular auto-fix targets
make list-deps-dirs List Conan package directories (for finding dep headers)
make compile_commands Generate compile_commands.json for IDE integration
make clean Clean build artifacts

Set BUILD_TYPE=debug for debug builds (default is releaseRelWithDebInfo).

Code Style

C++

  • LLVM-based style, 4-space indent, 120-column limit (see .clang-format)
  • Pointers and references: * and & bind to the identifier (right side), e.g. int *ptr, const std::string &ref (LLVM convention)
  • Line continuations (wrapped arguments, conditions) indent 8 spaces
  • No short functions/blocks on a single line
  • Constructor initializers break before comma
  • Binary operators break before the operator (non-assignment)
  • Extensive static analysis via .clang-tidy, all warnings are errors
  • Naming conventions (from .clang-tidy):
    • lower_case: variables, functions, methods, namespaces
    • CamelCase: classes, structs, enums, typedefs, template type parameters
    • UPPER_CASE: constants, constexpr locals, static constants
    • Private/protected members prefixed with m_, globals with g_
  • Use libc++ (not libstdc++)
  • Use static storage duration instead of anonymous namespaces for internal linkage where possible
    • (e.g. static const int VALUE = 42; instead of putting it in an anonymous namespace)
  • Function descriptions are written in imperative language
    • e.g. "Calculate the sum of two numbers" instead of "Calculates the sum of two numbers"

Rust

  • Standard rustfmt formatting, enforced by cargo fmt
  • clippy with -D warnings (all warnings are errors)

Markdown

  • Linted with markdownlint (config in .markdownlint.json)

  • Unordered lists use dashes (-), indented 4 spaces

  • No line-length limit

  • Markdown table formatting (MD060): When the Markdownlint MD060 rule triggers, switch to tight table formatting with spaces. Example:

    | Column1 | Column2 |
    | --- | --- |
    | Value 1 | Value 2 |
    

    Do NOT use extra padding or alignment characters beyond single spaces.

General

  • Prefer existing patterns over inventing new ones
  • Keep changes minimal and focused
  • Tests live in test/ subdirectories alongside the module they cover
  • Logging guidelines:
    • Use DEBUG level for verbose debug info, INFO for high-level events, WARN for recoverable issues, and ERROR for critical (unrecoverable) errors
    • Very frequent events (e.g. every packet) should be logged at DEBUG level, while important state changes (e.g. connection established, error occurred) should be at INFO or higher
    • Include relevant context in log messages (e.g. connection ID, error code)
    • Avoid logging sensitive information (e.g. IP addresses, payload data)

Docker Debug Environment

The .devcontainer/ directory provides a Docker-based remote debugging setup (copy devcontainer.json.example to devcontainer.json to enable it).

  • Image: Ubuntu 24.04 with clang, cmake, ninja, rust, conan, lldb
  • Purpose: Remote LLDB debugging, especially for Linux debugging from macOS
  • Start: docker-compose -f .devcontainer/docker-compose.yml up -d --build
  • Build inside: docker-compose -f .devcontainer/docker-compose.yml exec trusttunnel-debug bash -c "cd /workspace && SKIP_VENV=1 BUILD_TYPE=debug make build_trusttunnel_client build_wizard"
  • Debug: Connect to lldb-server on port 12345

See DEVELOPMENT.md for full instructions.

Dependencies

Managed via Conan. Key libraries:

  • dns-libs, native_libs_common — AdGuard shared libraries
  • libevent — async event loop
  • nghttp2 — HTTP/2
  • quiche — HTTP/3 / QUIC (disabled on MIPS)
  • openssl (BoringSSL; MIPS falls back to openssl/3.1.5-quic1@adguard/oss) — TLS
  • nlohmann_json, tomlplusplus — config parsing
  • cxxopts — CLI argument parsing
  • magic_enum — enum reflection
  • gtest — unit testing

Local conan cache is populated by make bootstrap_deps which is dependency for many other make commands.

To find headers for dns-libs and native_libs_common (e.g. when resolving symbols or includes), run make list-deps-dirs to list Conan package directories, then look in each directory's include/ subdirectory.

Mandatory Task Rules

You MUST follow the following rules for EVERY task that you perform:

  • You MUST verify it with linter, formatter, and C++/Rust compilers.

    Use the following commands:

    • make all to check if code builds (bare make only runs init)
    • make test to build and run unit tests
    • make lint to run the linters
    • make lint-fix to fix linting issues that can be fixed automatically
    • make clang-format to check the formatting
  • You MUST update the unit tests for changed code.

  • You MUST run tests with the make test script to verify that your changes do not break existing functionality.

  • When making changes to the project structure, ensure the Project structure section in AGENTS.md is updated and remains valid.

  • If the prompt essentially asks you to refactor or improve existing code, check if you can phrase it as a code guideline. If it's possible, add it to the relevant Code Guidelines section in AGENTS.md.

  • After completing the task you MUST verify that the code you've written follows the Code Guidelines in this file.