mullvad

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 12 Imported by: 0

README

go-mullvad-proxy

Documentation

Overview

Copyright © 2026 fakeapate <fakeapate@pm.me>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2026 fakeapate <fakeapate@pm.me>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2026 fakeapate <fakeapate@pm.me>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConnected

func IsConnected() (bool, error)

func SelectProxies

func SelectProxies(cfg MullvadConfig, limit int, filter RelayFilter) ([]string, error)

SelectProxies returns up to limit proxy strings for relays matching filter, formatted as socks5://hostname:<port> for use with colly's proxy switcher. limit <= 0 means no limit. Reports an error if the relay list is not loaded.

func StartUpdater

func StartUpdater(cfg MullvadConfig)

StartUpdater performs an initial relay list update and then checks for updates at the interval specified by cfg.UpdateInterval. It returns immediately after the first update; subsequent checks run in the background.

Types

type AmIConnected

type AmIConnected struct {
	// Ip corresponds to the JSON schema field "ip".
	Ip *string `json:"ip,omitempty,omitzero" yaml:"ip,omitempty" mapstructure:"ip,omitempty"`

	// MullvadExitIp corresponds to the JSON schema field "mullvad_exit_ip".
	MullvadExitIp bool `json:"mullvad_exit_ip" yaml:"mullvad_exit_ip" mapstructure:"mullvad_exit_ip"`

	// MullvadExitIpHostname corresponds to the JSON schema field
	// "mullvad_exit_ip_hostname".
	MullvadExitIpHostname *string `` /* 142-byte string literal not displayed */

	AdditionalProperties interface{} `mapstructure:",remain"`
}

func (*AmIConnected) UnmarshalJSON

func (j *AmIConnected) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Location

type Location struct {
	// City corresponds to the JSON schema field "city".
	City string `json:"city" yaml:"city" mapstructure:"city"`

	// Country corresponds to the JSON schema field "country".
	Country string `json:"country" yaml:"country" mapstructure:"country"`

	// Latitude corresponds to the JSON schema field "latitude".
	Latitude float64 `json:"latitude" yaml:"latitude" mapstructure:"latitude"`

	// Longitude corresponds to the JSON schema field "longitude".
	Longitude float64 `json:"longitude" yaml:"longitude" mapstructure:"longitude"`
}

func (*Location) UnmarshalJSON

func (j *Location) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

type MullvadConfig

type MullvadConfig struct {
	RelayURL       string        `toml:"relay_url"`       // Mullvad wireguard relay list API endpoint
	DataFile       string        `toml:"data_file"`       // path to the cached relay list on disk
	MetaFile       string        `toml:"meta_file"`       // path to the cached relay list metadata on disk
	ProxyPort      int           `toml:"proxy_port"`      // SOCKS5 port on Mullvad relay hosts
	UpdateInterval time.Duration `toml:"update_interval"` // how often to refresh the relay list
}

MullvadConfig holds all Mullvad VPN configuration.

func DefaultMullvadConfig

func DefaultMullvadConfig() MullvadConfig

DefaultMullvadConfig returns a MullvadConfig with sensible defaults.

type MullvadRelays

type MullvadRelays struct {
	// Locations corresponds to the JSON schema field "locations".
	Locations MullvadRelaysLocations `json:"locations" yaml:"locations" mapstructure:"locations"`

	// Wireguard corresponds to the JSON schema field "wireguard".
	Wireguard WireguardEndpoints `json:"wireguard" yaml:"wireguard" mapstructure:"wireguard"`
}
var Relays *MullvadRelays

Relays holds the most recently loaded Mullvad relay list. It is nil until the first successful parse completes.

func (*MullvadRelays) UnmarshalJSON

func (j *MullvadRelays) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

type MullvadRelaysLocations

type MullvadRelaysLocations map[string]Location

type Relay

type Relay struct {
	// Active corresponds to the JSON schema field "active".
	Active bool `json:"active" yaml:"active" mapstructure:"active"`

	// Hostname corresponds to the JSON schema field "hostname".
	Hostname string `json:"hostname" yaml:"hostname" mapstructure:"hostname"`

	// IncludeInCountry corresponds to the JSON schema field "include_in_country".
	IncludeInCountry bool `json:"include_in_country" yaml:"include_in_country" mapstructure:"include_in_country"`

	// Ipv4AddrIn corresponds to the JSON schema field "ipv4_addr_in".
	Ipv4AddrIn string `json:"ipv4_addr_in" yaml:"ipv4_addr_in" mapstructure:"ipv4_addr_in"`

	// Ipv6AddrIn corresponds to the JSON schema field "ipv6_addr_in".
	Ipv6AddrIn string `json:"ipv6_addr_in" yaml:"ipv6_addr_in" mapstructure:"ipv6_addr_in"`

	// Location corresponds to the JSON schema field "location".
	Location string `json:"location" yaml:"location" mapstructure:"location"`

	// PublicKey corresponds to the JSON schema field "public_key".
	PublicKey string `json:"public_key" yaml:"public_key" mapstructure:"public_key"`

	// Weight corresponds to the JSON schema field "weight".
	Weight int `json:"weight" yaml:"weight" mapstructure:"weight"`

	AdditionalProperties interface{} `mapstructure:",remain"`
}

func (*Relay) UnmarshalJSON

func (j *Relay) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

type RelayFilter

type RelayFilter struct {
	Location *regexp.Regexp // match relay.Location against pattern; nil = any
	Owned    *bool          // nil = any, true = owned only, false = non-owned only
	Weight   func(int) bool // nil = no weight filter
}

RelayFilter specifies which relays SelectProxies should include. Zero values impose no constraint for that field. Active and IncludeInCountry are always required to be true and are not exposed.

type WireguardEndpoints

type WireguardEndpoints struct {
	// Ipv4Gateway corresponds to the JSON schema field "ipv4_gateway".
	Ipv4Gateway string `json:"ipv4_gateway" yaml:"ipv4_gateway" mapstructure:"ipv4_gateway"`

	// Ipv6Gateway corresponds to the JSON schema field "ipv6_gateway".
	Ipv6Gateway string `json:"ipv6_gateway" yaml:"ipv6_gateway" mapstructure:"ipv6_gateway"`

	// PortRanges corresponds to the JSON schema field "port_ranges".
	PortRanges [][]int `json:"port_ranges" yaml:"port_ranges" mapstructure:"port_ranges"`

	// Relays corresponds to the JSON schema field "relays".
	Relays []Relay `json:"relays" yaml:"relays" mapstructure:"relays"`
}

func (*WireguardEndpoints) UnmarshalJSON

func (j *WireguardEndpoints) UnmarshalJSON(value []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

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