Overview
The Mullvad VPN application is architecturally divided into two distinct layers:- Talpid: A generic, provider-agnostic VPN core library
- Mullvad: The Mullvad-specific business logic and features
Talpid Layer
Purpose
Talpid (from Swedish “talpid” meaning “patient”) is the foundational VPN core that handles:- Tunnel state machine coordination
- Operating system integration (firewall, DNS, routing)
- Platform-specific implementations for Windows, Linux, macOS, Android, and iOS
- Generic VPN connection logic
- Security policy enforcement
Key Components
Tunnel State Machine
The tunnel state machine (talpid-core/src/tunnel_state_machine) is the core of Talpid. It coordinates VPN connection establishment and manages state transitions:
- Disconnected: Initial state, no system modifications
- Connecting: Configuring OS and establishing VPN connection
- Connected: Tunnel verified and working
- Disconnecting: Closing connection and restoring OS configuration
- Error: Blocking all connections to prevent leaks
talpid-core/src/tunnel_state_machine/mod.rs
System Integration
Talpid provides abstractions for:-
Firewall Integration: Platform-specific firewall implementations (
talpid-core/src/firewall)- Windows: WFP (Windows Filtering Platform) via
windows/winfw - Linux: nftables/iptables
- macOS: PF (Packet Filter)
- Windows: WFP (Windows Filtering Platform) via
-
DNS Management: System DNS configuration (
talpid-dns) -
Routing: Route table manipulation (
talpid-routing) -
Offline Detection: Network connectivity monitoring (
talpid-core/src/offline) - see Offline Detection
Platform-Specific Crates
talpid-windows: Windows-specific utilitiestalpid-macos: macOS-specific utilitiestalpid-core: Cross-platform core logictalpid-types: Common type definitionstalpid-wireguard: WireGuard integration
State Machine Inputs
The tunnel state machine responds to: Commands:Connect: Establish secure VPN connectionDisconnect: Tear down connection and restore OS stateAllow LAN: Enable/disable local network sharingBlock when disconnected: Apply security policy in disconnected state
Tunnel is Up: Monitor confirms tunnel is workingTunnel is Down: Monitor detects tunnel disconnectTunnel monitor stopped: Lost communication with monitorIs offline: OS network connectivity status changed
State Machine Outputs
Every state transition emits aTunnelStateTransition:
- Disconnected: No active tunnel
- Connecting: Includes target endpoint information
- Connected: Includes connected endpoint information
- Disconnecting: Includes next action (Nothing, Block, or Reconnect)
- Error: Includes error cause and blocking status
Mullvad Layer
Purpose
The Mullvad layer (mullvad-daemon) contains all Mullvad-specific functionality:
- API communication with
api.mullvad.net - Account and device management
- Relay selection algorithm
- User settings and preferences
- Management interface (gRPC API)
- Custom Mullvad features (DAITA, multihop, etc.)
Key Components
Daemon
The daemon (mullvad-daemon/src/lib.rs) is the main system service that:
- Receives commands from frontends (GUI, CLI) via management interface
- Manages tunnel state through Talpid
- Handles API communication
- Persists settings and state
- Coordinates asynchronous operations across components
mullvad-daemon/src/lib.rs
API Communication
The Mullvad layer handles all communication with Mullvad’s API:- REST API requests to
api.mullvad.net - Account operations (create, login, voucher redemption)
- Device management
- Relay list updates
- Version checks and app updates
mullvad-daemon/src/api.rs
Relay Selection
The relay selector (mullvad-relay-selector) implements Mullvad’s specific relay selection logic:
- Filtering relays by location, provider, ownership
- Constraint evaluation
- Weighted random selection
- DAITA compatibility checks
- Multihop configuration
mullvad-relay-selector/src/relay_selector.rs
Management Interface
The gRPC management interface exposes daemon functionality to frontends:- Tunnel control (connect, disconnect, reconnect)
- Settings management
- Account and device operations
- Event streaming
- Split tunneling configuration
mullvad-management-interface/proto/management_interface.proto
Mullvad-Specific Features
- DAITA (Defense Against AI-guided Traffic Analysis): Traffic analysis resistance
- Quantum-resistant tunnels: Post-quantum key encapsulation
- Multihop: Multiple relay hops for enhanced privacy
- Custom lists: User-defined relay groupings
- Access methods: API censorship circumvention
- Lockdown mode: Block all traffic when not connected
Interaction Between Layers
Command Flow
- Frontend → Management Interface: User action (e.g., “Connect”)
- Management Interface → Daemon: gRPC request processed
- Daemon → Relay Selector: Select appropriate relay
- Daemon → API: Fetch latest relay list if needed
- Daemon → Talpid: Send
TunnelCommand::Connectwith parameters - Talpid: Execute tunnel state machine transitions
- Talpid → Daemon: Emit
TunnelStateTransitionevents - Daemon → Frontend: Stream state updates via management interface
Data Flow
- Settings: Stored by Mullvad layer, used to configure Talpid operations
- Relay List: Fetched from Mullvad API, processed by relay selector, passed to Talpid
- Tunnel Parameters: Generated by Mullvad, executed by Talpid
- State Transitions: Emitted by Talpid, processed and broadcast by Mullvad
Why This Separation?
Benefits
- Modularity: Talpid can be used independently or with other VPN providers
- Testability: Generic VPN logic can be tested separately from Mullvad-specific features
- Security: Clear boundaries between trusted system-level operations and business logic
- Maintainability: Changes to Mullvad features don’t affect core VPN functionality
- Platform Support: Talpid provides unified abstractions across different operating systems
Design Principles
- Talpid knows nothing about Mullvad: It receives generic tunnel parameters
- Mullvad knows about Talpid: It orchestrates Talpid to implement Mullvad features
- Single responsibility: Each layer has clearly defined responsibilities
- Loose coupling: Layers communicate through well-defined interfaces
Code Organization
Talpid Crates
Mullvad Crates
Related Documentation
- Management Interface
- Relay Selector
- API Communication
- Offline Detection
- Architecture Overview (source repository)