Help us shape the future of Go! Take the 2026 Go Developer Survey

servers

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

Package servers provides management of server configurations, such as option.Endpoints and option.Outbounds,and integration with remote server managers for adding, inviting, and revoking private servers with trust-on-first-use (TOFU) fingerprint verification.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMatchingFingerprint = errors.New("server certificate(s) didn't match trusted fingerprint")
	ErrCertExpired           = errors.New("server certificate has expired")
	ErrCertNotYetValid       = errors.New("server certificate is not yet valid")
	ErrNoCertsDetected       = errors.New("no server certificates detected")
	ErrTrustCancelled        = errors.New("user cancelled the trust dialog")
)

this file contains the code for Trust On First Use (TOFU) when accessing lantern server manager

Functions

This section is empty.

Types

type CertDetail

type CertDetail struct {
	Subject     string
	Issuer      string
	Fingerprint string
}

type Manager

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

Manager manages server configurations, including endpoints and outbounds.

func NewManager

func NewManager(dataPath string) (*Manager, error)

NewManager creates a new Manager instance, loading server options from disk.

func (*Manager) AddPrivateServer

func (m *Manager) AddPrivateServer(tag string, ip string, port int, accessToken string, trustFingerprintCB TrustFingerprintCB) error

AddPrivateServer fetches VPN connection info from a remote server manager and adds it as a server. Requires a trust fingerprint callback for certificate verification. If one isn't provided, it will prompt the user to trust the fingerprint.

func (*Manager) AddServerBasedOnURLs

func (m *Manager) AddServerBasedOnURLs(ctx context.Context, urls string, skipCertVerification bool) error

AddServerBasedOnURLs adds a server(s) based on the provided URL string. The URL can be comma-separated list of URLs or URLs separated by new lines.

func (*Manager) AddServerWithSingboxJSON

func (m *Manager) AddServerWithSingboxJSON(ctx context.Context, value []byte) error

AddServerWithSingboxJSON parse a value that can be a JSON sing-box config. It parses the config into a sing-box config and add it to the user managed group.

func (*Manager) AddServers

func (m *Manager) AddServers(group ServerGroup, opts Options) error

AddServers adds new servers to the specified group. If a server with the same tag already exists, it will be skipped.

func (*Manager) GetServerByTag

func (m *Manager) GetServerByTag(tag string) (Server, bool)

GetServerByTag returns the server configuration for a given tag and a boolean indicating whether the server was found.

func (*Manager) InviteToPrivateServer

func (m *Manager) InviteToPrivateServer(ip string, port int, accessToken string, inviteName string) (string, error)

InviteToPrivateServer invites another user to the server manager instance and returns a connection token. The server must be added to the user's servers first and have a trusted fingerprint.

func (*Manager) RemoveServer

func (m *Manager) RemoveServer(tag string) error

RemoveServer removes a server config by its tag.

func (*Manager) RevokePrivateServerInvite

func (m *Manager) RevokePrivateServerInvite(ip string, port int, accessToken string, inviteName string) error

RevokePrivateServerInvite will revoke an invite to the server manager instance. The server must be added to the user's servers first and have a trusted fingerprint.

func (*Manager) Servers

func (m *Manager) Servers() Servers

Servers returns the current server configurations for both groups (SGLantern and SGUser).

func (*Manager) SetServers

func (m *Manager) SetServers(group ServerGroup, options Options) error

SetServers sets the server options for a specific group. Important: this will overwrite any existing servers for that group. To add new servers without overwriting existing ones, use [AddServers] instead.

type Options

type Options struct {
	Outbounds []option.Outbound           `json:"outbounds,omitempty"`
	Endpoints []option.Endpoint           `json:"endpoints,omitempty"`
	Locations map[string]C.ServerLocation `json:"locations,omitempty"`
}

func (Options) AllTags

func (o Options) AllTags() []string

AllTags returns a slice of all tags from both endpoints and outbounds in the Options.

type Server

type Server struct {
	Group    ServerGroup
	Tag      string
	Type     string
	Options  any // will be either [option.Endpoint] or [option.Outbound]
	Location C.ServerLocation
}

type ServerGroup

type ServerGroup = string
const (
	SGLantern ServerGroup = "lantern"
	SGUser    ServerGroup = "user"
)

type Servers

type Servers map[ServerGroup]Options

type TrustFingerprintCB

type TrustFingerprintCB func(ip string, details []CertDetail) *CertDetail

TrustFingerprintCB is a callback function that is called when a server's certificate fingerprint is detected. It receives the server's IP address and the certificate details. The responder can return a CertDetail to be used as the trusted fingerprint. If the returned CertDetail is nil, the connection will be rejected.

Jump to

Keyboard shortcuts

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