api

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package api is a small client for Mullvad's app API. A Mullvad value is created with New for a given account number; its methods exchange the account number for a short-lived bearer token (lazily, on first authenticated call) and then read or modify the account's devices, relays, and account data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID            string `json:"id"`
	Expiry        string `json:"expiry"`
	MaxDevices    int    `json:"max_devices"`
	CanAddDevices bool   `json:"can_add_devices"`
}

Account holds the account configuration returned by /accounts/v1/accounts/me. The API also returns has_payments and forwarded-port quotas, which the tool does not use and so does not decode.

func (Account) String

func (a Account) String() (out string)

String renders the account configuration as a human-readable block.

type Device

type Device struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Pubkey      string `json:"pubkey"`
	HijackDNS   bool   `json:"hijack_dns"`
	Created     string `json:"created"`
	IPv4Address string `json:"ipv4_address"`
	IPv6Address string `json:"ipv6_address"`
}

Device is a WireGuard device registered to the account.

func (Device) String

func (d Device) String() (out string)

String renders a device as a human-readable block.

type Mullvad

type Mullvad struct {
	// contains filtered or unexported fields
}

Mullvad is an API client bound to a single account number.

func New

func New(id string) (m *Mullvad)

New returns a Mullvad client for the given account number. The number is only required for authenticated calls — relay listing works with an empty id.

func (*Mullvad) Account

func (m *Mullvad) Account(ctx context.Context) (a Account, err error)

Account fetches the account's configuration (expiry, quotas, etc.).

func (*Mullvad) Device

func (m *Mullvad) Device(ctx context.Context, id string) (dev Device, err error)

Device fetches a single device by ID.

func (*Mullvad) DeviceAdd

func (m *Mullvad) DeviceAdd(ctx context.Context, pubkey string, hijackDNS bool) (dev Device, err error)

DeviceAdd registers a new device from a WireGuard public key. Mullvad assigns the name and tunnel addresses and returns the created device.

func (*Mullvad) DeviceDel

func (m *Mullvad) DeviceDel(ctx context.Context, id string) (err error)

DeviceDel deletes a device by ID.

func (*Mullvad) DeviceRotate

func (m *Mullvad) DeviceRotate(ctx context.Context, id, pubkey string) (dev Device, err error)

DeviceRotate replaces a device's public key in place. The device keeps its ID and name; Mullvad returns the updated device (its addresses may change).

func (*Mullvad) Devices

func (m *Mullvad) Devices(ctx context.Context) (devices []Device, err error)

Devices lists every device registered to the account.

func (*Mullvad) RandomRelay

func (m *Mullvad) RandomRelay(ctx context.Context, filter RelayFilter) (relay Relay, err error)

RandomRelay returns a random relay matching filter, considering only relays usable as a WireGuard endpoint (active, with a public key).

func (*Mullvad) Relays

func (m *Mullvad) Relays(ctx context.Context, filter RelayFilter) (relays []Relay, err error)

Relays fetches the public relay catalog, keeping only relays that match the filter. No authentication is required.

func (*Mullvad) ResolveDeviceID

func (m *Mullvad) ResolveDeviceID(ctx context.Context, target string) (id string, err error)

ResolveDeviceID maps target — which may be a device ID or a device name — to a device ID. A name matching more than one device is rejected as ambiguous.

type Relay

type Relay struct {
	Hostname         string `json:"hostname"`
	CountryCode      string `json:"country_code"`
	CountryName      string `json:"country_name"`
	CityCode         string `json:"city_code"`
	CityName         string `json:"city_name"`
	Active           bool   `json:"active"`
	Owned            bool   `json:"owned"`
	Provider         string `json:"provider"`
	IPv4AddrIn       string `json:"ipv4_addr_in"`
	IPv6AddrIn       string `json:"ipv6_addr_in"`
	NetworkPortSpeed int    `json:"network_port_speed"`
	Type             string `json:"type"`
	Daita            bool   `json:"daita"`
	Pubkey           string `json:"pubkey"`        // WireGuard relays only
	MultihopPort     int    `json:"multihop_port"` // entry port for multihop
	SocksName        string `json:"socks_name"`    // in-tunnel SOCKS5 proxy hostname
	SocksPort        int    `json:"socks_port"`    // in-tunnel SOCKS5 proxy port
}

Relay is a single Mullvad server from the public relay catalog.

func (Relay) Status

func (r Relay) Status() string

Status reports "up" or "DOWN" depending on the active flag. A DOWN relay is either offline or in maintenance — the public feed does not distinguish.

func (Relay) String

func (r Relay) String() (out string)

String renders a relay as a single human-readable line.

type RelayFilter

type RelayFilter struct {
	Country   string // country code, e.g. "us"
	City      string // city code, e.g. "nyc"
	Type      string // relay type, e.g. "wireguard" or "bridge"
	DownOnly  bool   // keep only inactive (down/maintenance) relays
	SocksOnly bool   // keep only relays exposing a SOCKS5 proxy
	OwnedOnly bool   // keep only Mullvad-owned relays
	DaitaOnly bool   // keep only DAITA-capable relays
}

RelayFilter narrows a relay list. Zero-value fields are ignored, so the empty filter matches everything; any set field must match (logical AND).

func (RelayFilter) Match

func (f RelayFilter) Match(r Relay) bool

Match reports whether r satisfies every set field of the filter. Country matches against either the country code (e.g. "us") or the country name (e.g. "USA"), case-insensitively.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL