config

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MPL-2.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AppConfigFilename         = "config_awl.json"
	AppDataDirectory          = "anywherelan"
	DhtPeerstoreDataDirectory = "peerstore"
	AppDataDirEnvKey          = "AWL_DATA_DIR"

	// TODO 8989 maybe?
	DefaultHTTPPort              = 8639
	AdminHttpServerDomainName    = "admin"
	AdminHttpServerIP            = "127.0.0.66"
	AdminHttpServerListenAddress = "127.0.0.66:80"

	DefaultPeerAlias = "peer"
)
View Source
const (
	DefaultVPNInterfaceName = "awl0"
	// TODO: generate subnets if this has already taken
	DefaultVPNNetworkSubnet = "10.66.0.1/16"
)
View Source
const DevVersion = "dev"

Variables

View Source
var (
	// set via ldflags
	Version         = DevVersion
	UserAgent       = UserAgentPrefix + SystemInfo + "/" + Version
	UserAgentPrefix = "awl/"
	SystemInfo      = runtime.GOOS + "-" + runtime.GOARCH
	// set via ldflags
	IsWindows7 = ""
)
View Source
var DefaultBootstrapPeers []multiaddr.Multiaddr
View Source
var LinuxFilesOwnerUID = os.Geteuid()

LinuxFilesOwnerUID is used to set correct files owner uid. This is needed because by default all files belong to root when we run as root, but they are stored in user's directory.

Functions

func CalcAppDataDir

func CalcAppDataDir() string

func ChownFileIfNeeded added in v0.9.0

func ChownFileIfNeeded(path string)

func ImportConfig

func ImportConfig(data []byte, directory string) error

func IsDevVersion added in v0.5.1

func IsDevVersion() bool

IsDevVersion Possible duplicate of *Config.DevMode() Based on build version (unchangeable after build, could be used only by developers)

func SystemInfoFromUserAgent added in v0.7.0

func SystemInfoFromUserAgent(userAgent string) (goos string, goarch string)

func VersionFromUserAgent

func VersionFromUserAgent(userAgent string) string

Types

type AppType added in v0.18.0

type AppType int
const (
	AppTypeAwl AppType = iota
	AppTypeAwlTray
	AppTypeAwlAndroid
)

type BlockedPeer

type BlockedPeer struct {
	// Hex-encoded multihash representing a peer ID
	PeerID      string `json:"peerId"`
	DisplayName string `json:"displayName"`
	// Time of adding to config (decline invitation/remove from KnownPeers)
	CreatedAt time.Time `json:"createdAt"`
}

type Config

type Config struct {
	sync.RWMutex `swaggerignore:"true"`

	Version               string                 `json:"version"`
	LoggerLevel           string                 `json:"loggerLevel"`
	HttpListenAddress     string                 `json:"httpListenAddress"`
	HttpListenOnAdminHost bool                   `json:"httpListenOnAdminHost"`
	HttpBasicAuth         HttpBasicAuthConfig    `json:"httpBasicAuth"`
	P2pNode               P2pNodeConfig          `json:"p2pNode"`
	VPNConfig             VPNConfig              `json:"vpn"`
	VPNGateway            VPNGatewayConfig       `json:"vpnGateway"`
	SOCKS5                SOCKS5Config           `json:"socks5"`
	DNS                   DNSConfig              `json:"dns"`
	KnownPeers            map[string]KnownPeer   `json:"knownPeers"`
	BlockedPeers          map[string]BlockedPeer `json:"blockedPeers"`
	Update                UpdateConfig           `json:"update"`
	// contains filtered or unexported fields
}

func LoadConfig

func LoadConfig(appType AppType, bus awlevent.Bus) (*Config, error)

func NewConfig

func NewConfig(appType AppType, bus awlevent.Bus) *Config

func (*Config) CheckIPUnique added in v0.15.0

func (c *Config) CheckIPUnique(checkIP string, exceptPeerID string) error

CheckIPUnique is not thread safe. Checks IP for: valid ip, unique across peers, in vpn net mask

func (*Config) DNSNamesMapping

func (c *Config) DNSNamesMapping() map[string]string

func (*Config) DataDir

func (c *Config) DataDir() string

func (*Config) DevMode

func (c *Config) DevMode() bool

DevMode Possible duplicate of IsDevVersion() Based on Config.LoggerLevel (could be used by any user)

func (*Config) Export

func (c *Config) Export() []byte

func (*Config) GenUniqPeerAlias added in v0.5.1

func (c *Config) GenUniqPeerAlias(name, alias string) string

func (*Config) GenUniqPeerAliasUnlocked added in v0.18.0

func (c *Config) GenUniqPeerAliasUnlocked(name, alias string) string

GenUniqPeerAliasUnlocked is GenUniqPeerAlias without locking; the caller must hold the lock.

func (*Config) GenerateNextIpAddr

func (c *Config) GenerateNextIpAddr() string

GenerateNextIpAddr is not thread safe.

func (*Config) GenerateNextIpAddrExcept added in v0.15.0

func (c *Config) GenerateNextIpAddrExcept(except []string) string

GenerateNextIpAddrExcept is not thread safe.

func (*Config) GetBlockedPeer

func (c *Config) GetBlockedPeer(peerID string) (BlockedPeer, bool)

func (*Config) GetBootstrapPeers

func (c *Config) GetBootstrapPeers() []peer.AddrInfo

func (*Config) GetListenAddresses

func (c *Config) GetListenAddresses() []multiaddr.Multiaddr

func (*Config) GetPeer

func (c *Config) GetPeer(peerID string) (KnownPeer, bool)

func (*Config) GetPeerUnlocked added in v0.18.0

func (c *Config) GetPeerUnlocked(peerID string) (KnownPeer, bool)

GetPeerUnlocked is GetPeer without locking; the caller must hold the lock.

func (*Config) IsUniqPeerAlias added in v0.5.1

func (c *Config) IsUniqPeerAlias(excludePeerID, alias string) bool

func (*Config) IsUniqPeerAliasUnlocked added in v0.18.0

func (c *Config) IsUniqPeerAliasUnlocked(excludePeerID, alias string) bool

IsUniqPeerAliasUnlocked is IsUniqPeerAlias without locking; the caller must hold the lock.

func (*Config) KnownPeersIds

func (c *Config) KnownPeersIds() []peer.ID

func (*Config) LogLevel

func (c *Config) LogLevel() zapcore.Level

func (*Config) NodeName added in v0.18.0

func (c *Config) NodeName() string

NodeName returns this node's name under the read lock. P2pNode.Name is mutated at runtime (UpdateMySettings), so it must not be read directly without the lock.

func (*Config) PeerstoreDir

func (c *Config) PeerstoreDir() string

func (*Config) PrivKey

func (c *Config) PrivKey() []byte

func (*Config) RemoveBlockedPeer

func (c *Config) RemoveBlockedPeer(peerID string)

func (*Config) RemovePeer

func (c *Config) RemovePeer(peerID string) (KnownPeer, bool)

func (*Config) Save

func (c *Config) Save()

func (*Config) SaveLocked added in v0.18.0

func (c *Config) SaveLocked()

SaveLocked persists the config without taking the lock. The caller must already hold c.Lock(). Use this when atomically batching mutations and persistence under a single critical section.

func (*Config) SetIdentity

func (c *Config) SetIdentity(key crypto.PrivKey, id peer.ID)

func (*Config) SetListenAddresses

func (c *Config) SetListenAddresses(multiaddrs []multiaddr.Multiaddr)

func (*Config) UpdatePeerFields added in v0.18.0

func (c *Config) UpdatePeerFields(peerID string, mutate func(*KnownPeer)) bool

UpdatePeerFields atomically applies mutate to the stored KnownPeer under the write lock and persists the change. It returns false if the peer is unknown.

mutate must only change the fields it owns and must NOT replace the struct wholesale, so that fields updated concurrently by other callers are not clobbered. mutate runs while the lock is held, so it must not call other Config methods that take the lock (use the *Unlocked variants instead).

func (*Config) UpdatePeerLastSeen

func (c *Config) UpdatePeerLastSeen(peerID string)

func (*Config) UpsertBlockedPeer

func (c *Config) UpsertBlockedPeer(peerID, displayName string)

func (*Config) UpsertPeer

func (c *Config) UpsertPeer(peer KnownPeer)

func (*Config) UpsertPeerUnlocked added in v0.15.0

func (c *Config) UpsertPeerUnlocked(peer KnownPeer)

func (*Config) VPNLocalIPMask

func (c *Config) VPNLocalIPMask() (net.IP, net.IPMask)

func (*Config) VPNLocalIPMaskUnlocked added in v0.15.0

func (c *Config) VPNLocalIPMaskUnlocked() (net.IP, net.IPMask)

type DNSConfig added in v0.16.0

type DNSConfig struct {
	DisableDNS    bool   `json:"disableDNS"`
	ListenAddress string `json:"listenAddress"`
	// UpstreamDNSAddress is the public resolver (host:port) that the awl
	// DNS resolver forwards non-.awl queries to. Used as a fallback when
	// the OS exposes no base nameserver, and forced as the sole upstream in
	// VPN gateway client mode so DNS traverses the tunnel and does not leak.
	// On Android the host reads this value to configure VpnService DNS.
	UpstreamDNSAddress string `json:"upstreamDNSAddress"`
}

type HttpBasicAuthConfig added in v0.17.0

type HttpBasicAuthConfig struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type KnownPeer

type KnownPeer struct {
	// Hex-encoded multihash representing a peer ID
	PeerID string `json:"peerId"`
	// Peer provided name
	Name string `json:"name"`
	// User provided name
	Alias string `json:"alias"`
	// IPAddr used for forwarding
	IPAddr string `json:"ipAddr"`
	// DomainName without zone suffix (.awl)
	DomainName string `json:"domainName"`
	// Time of adding to config (accept/invite)
	CreatedAt time.Time `json:"createdAt"`
	// Time of last connection
	LastSeen time.Time `json:"lastSeen"`
	// Has remote peer confirmed our invitation
	Confirmed bool `json:"confirmed"`
	// Has remote peer declined our invitation
	Declined               bool `json:"declined"`
	WeAllowUsingAsExitNode bool `json:"weAllowUsingAsExitNode"`
	AllowedUsingAsExitNode bool `json:"allowedUsingAsExitNode"`
	// RemoteVPNGatewayServerEnabled is the remote peer's VPNGatewayConfig.ServerEnabled
	// as advertised via the status protocol. Combined with AllowedUsingAsExitNode
	// (also from status) it determines whether this peer is currently a valid
	// VPN gateway target for us — see KnownPeer.CanUseAsVPNGateway.
	RemoteVPNGatewayServerEnabled bool `json:"remoteVPNGatewayServerEnabled"`
}

func (KnownPeer) CanUseAsVPNGateway added in v0.18.0

func (kp KnownPeer) CanUseAsVPNGateway() bool

CanUseAsVPNGateway reports whether this peer can currently be used as a VPN gateway. It requires both that the peer permits being used as an exit node (shared with SOCKS5 via AllowedUsingAsExitNode) and that the peer has VPN gateway server enabled on its side (RemoteVPNGatewayServerEnabled). Both flags are populated from the status protocol exchange in service/auth_status.go.

func (KnownPeer) DisplayName

func (kp KnownPeer) DisplayName() string

func (KnownPeer) PeerId

func (kp KnownPeer) PeerId() peer.ID

type P2pNodeConfig

type P2pNodeConfig struct {
	// Hex-encoded multihash representing a peer ID, calculated from Identity
	PeerID         string   `json:"peerId"`
	Name           string   `json:"name"`
	Identity       string   `json:"identity"`
	BootstrapPeers []string `json:"bootstrapPeers"`
	// With this option only BootstrapPeers from config will be used
	IgnoreDefaultBootstrapPeers *bool         `json:"ignoreDefaultBootstrapPeers,omitempty"`
	ListenAddresses             []string      `json:"listenAddresses"`
	ReconnectionIntervalSec     time.Duration `json:"reconnectionIntervalSec" swaggertype:"primitive,integer"` //nolint:staticcheck
	AutoAcceptAuthRequests      bool          `json:"autoAcceptAuthRequests"`

	UseDedicatedConnForEachStream bool `json:"useDedicatedConnForEachStream"`
	ParallelSendingStreamsCount   int  `json:"parallelSendingStreamsCount"`
}

type SOCKS5Config added in v0.12.0

type SOCKS5Config struct {
	ListenerEnabled bool `json:"listenerEnabled"`
	// allow using my host as proxy
	ProxyingEnabled bool   `json:"proxyingEnabled"`
	ListenAddress   string `json:"listenAddress"`
	// peer that is set as proxy
	UsingPeerID string `json:"usingPeerID"`
	// Optional local auth credentials. If both are set, SOCKS5 clients must authenticate.
	Username string `json:"username"`
	Password string `json:"password"`
}

type UpdateConfig

type UpdateConfig struct {
	LowestPriorityChan    string `json:"lowestPriorityChan"`
	UpdateServerURL       string `json:"updateServerURL"`
	TrayAutoCheckEnabled  bool   `json:"trayAutoCheckEnabled"`
	TrayAutoCheckInterval string `json:"trayAutoCheckInterval"`
}

type VPNConfig

type VPNConfig struct {
	DisableVPNInterface bool   `json:"disableVPNInterface"`
	InterfaceName       string `json:"interfaceName"`
	IPNet               string `json:"ipNet"`
}

type VPNGatewayConfig added in v0.18.0

type VPNGatewayConfig struct {
	// ClientEnabled — route all traffic through GatewayPeerID (client side).
	ClientEnabled bool `json:"clientEnabled"`
	// GatewayPeerID — selected gateway peer ID.
	GatewayPeerID string `json:"gatewayPeerID"`
	// ServerEnabled — this node serves as a VPN gateway for others.
	// Propagated via the status protocol so peers know whether to offer
	// this node as an option in their UI.
	ServerEnabled bool `json:"serverEnabled"`
}

VPNGatewayConfig configures full-tunnel VPN gateway mode.

VPN gateway is a separate feature from SOCKS5 exit-node: a peer can allow being used as a SOCKS5 exit (KnownPeer.AllowedUsingAsExitNode, propagated via the status protocol) without serving as a VPN gateway, and vice versa. KnownPeer.CanUseAsVPNGateway() combines both.

Jump to

Keyboard shortcuts

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