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 ¶
- type Account
- type Device
- type Mullvad
- func (m *Mullvad) Account(ctx context.Context) (a Account, err error)
- func (m *Mullvad) Device(ctx context.Context, id string) (dev Device, err error)
- func (m *Mullvad) DeviceAdd(ctx context.Context, pubkey string, hijackDNS bool) (dev Device, err error)
- func (m *Mullvad) DeviceDel(ctx context.Context, id string) (err error)
- func (m *Mullvad) DeviceRotate(ctx context.Context, id, pubkey string) (dev Device, err error)
- func (m *Mullvad) Devices(ctx context.Context) (devices []Device, err error)
- func (m *Mullvad) RandomRelay(ctx context.Context, filter RelayFilter) (relay Relay, err error)
- func (m *Mullvad) Relays(ctx context.Context, filter RelayFilter) (relays []Relay, err error)
- func (m *Mullvad) ResolveDeviceID(ctx context.Context, target string) (id string, err error)
- type Relay
- type RelayFilter
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.
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.
type Mullvad ¶
type Mullvad struct {
// contains filtered or unexported fields
}
Mullvad is an API client bound to a single account number.
func New ¶
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) 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) DeviceRotate ¶
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) RandomRelay ¶
RandomRelay returns a random relay matching filter, considering only relays usable as a WireGuard endpoint (active, with a public key).
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.
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.