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 ¶
- Variables
- type CertDetail
- type Manager
- func (m *Manager) AddPrivateServer(tag string, ip string, port int, accessToken string, ...) error
- func (m *Manager) AddServerBasedOnURLs(ctx context.Context, urls string, skipCertVerification bool) error
- func (m *Manager) AddServerWithSingboxJSON(ctx context.Context, value []byte) error
- func (m *Manager) AddServers(group ServerGroup, opts Options) error
- func (m *Manager) GetServerByTag(tag string) (Server, bool)
- func (m *Manager) InviteToPrivateServer(ip string, port int, accessToken string, inviteName string) (string, error)
- func (m *Manager) RemoveServer(tag string) error
- func (m *Manager) RevokePrivateServerInvite(ip string, port int, accessToken string, inviteName string) error
- func (m *Manager) Servers() Servers
- func (m *Manager) SetServers(group ServerGroup, options Options) error
- type Options
- type Server
- type ServerGroup
- type Servers
- type TrustFingerprintCB
Constants ¶
This section is empty.
Variables ¶
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 Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages server configurations, including endpoints and outbounds.
func NewManager ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 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.