Documentation
¶
Overview ¶
Package wgclient encapsulates the goloom client-side tunnel (Telemost / WB-Stream LiveKit → local UDP for WireGuard userspace) behind an event-driven Service API. The same package backs both the CLI (cmd/goloom-wg-client) and the GUI (cmd/goloom-wg-gui), so client behaviour stays in one place.
Lifecycle:
svc := wgclient.New()
defer svc.Stop()
events, cancel := svc.Subscribe()
defer cancel()
go func() {
for ev := range events {
// ev.Status — phase/transport/tx/rx changes
// ev.Log — log lines emitted by the running session
}
}()
svc.Start(ctx, cfg) // returns immediately; runs in background
<-ctx.Done() // user wants to quit
svc.Stop() // graceful tunnel teardown
Concurrency: all public methods are safe to call from any goroutine. Subscribe channels are non-blocking — slow consumers drop events rather than back-pressure the producer.
Index ¶
- Variables
- type Config
- type Event
- type EventKind
- type LogLine
- type Phase
- type Service
- func (s *Service) BridgeStats() string
- func (s *Service) Logger() *log.Logger
- func (s *Service) RecentLogs(limit int) []LogLine
- func (s *Service) SetVerbose(on bool)
- func (s *Service) Start(ctx context.Context, cfg Config) error
- func (s *Service) Status() Status
- func (s *Service) Stop()
- func (s *Service) Subscribe() (<-chan Event, func())
- func (s *Service) Verbose() bool
- type Status
- type WGParams
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyRunning = errors.New("wgclient: session already running")
ErrAlreadyRunning is returned by Service.Start when a session is already active. Stop the existing session first.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Transport string `json:"transport"` // empty == "telemost"
Meeting string `json:"meeting"`
LiveKitRoomURL string `json:"livekit_room_url"`
LiveKitAccessToken string `json:"livekit_access_token"`
LiveKitCookies string `json:"livekit_cookies"`
VKCallsRole string `json:"vk_calls_role"` // empty == "caller" for clients
VKCallsCodec string `json:"vk_calls_codec"`
DisplayName string `json:"display_name"`
ListenAddr string `json:"listen_addr"` // default 127.0.0.1:51820
// LobbyMeetingURL + Bearer — in-band lobby bootstrap для VK
// client-meeting (S2/S3). Клиент peer-join'ится в LobbyMeetingURL,
// шлёт goloom_ctrl DIAL{meeting,bearer} серверу через
// transmit-data, ждёт DIAL_OK, leave'ит lobby и идёт в target
// meeting. Bootstrap полностью через VK SFU.
LobbyMeetingURL string `json:"lobby_meeting_url,omitempty"`
Bearer string `json:"bearer,omitempty"`
// AutoWG, when true and WG is populated, makes the service bring
// up a wintun adapter and run a wireguard-go userspace tunnel
// itself instead of expecting an external WireGuard for Windows
// install to dial 127.0.0.1:51820. Implemented on Windows only.
AutoWG bool `json:"auto_wg"`
// WG carries the per-client WireGuard parameters that the admin
// panel embeds in a connstr. Used only when AutoWG is on; the
// classic flow still works without these because the user's own
// WG client knows the keys via the wg.conf they downloaded.
WG WGParams `json:"wg"`
}
Config is the input to Service.Start. Mirrors the YAML/connstr schema used by the standalone client. Per Transport:
"telemost" — Meeting required
"livekit-wb-stream" — LiveKit* fields required (run admin webview-auth)
"vk-calls" — Meeting required (VK call link); VKCallsRole
optional ("caller" default for clients).
В client-meeting режиме (S2/S3) Meeting
приходит из локального GUI/CLI ввода,
а CtrlURL/Bearer/InboundID — из connstr.
ListenAddr defaults to 127.0.0.1:51820.
func FromConnStr ¶
FromConnStr decodes a goloom:// connection string into a Config. Connstrs created before multi-transport implicitly resolve to transport=telemost (Params.Transport == ""); newer connstrs carry the transport explicitly. WB-Stream credentials still arrive out-of-band (admin webview-auth flow) — they're never embedded in the connstr.
If the connstr embeds WG client params (admin panel's auto-provision flow), they're carried into Config.WG so the GUI can offer auto-WG without requiring a separate wg.conf import.
type Event ¶
type Event struct {
Kind EventKind `json:"kind"`
Status *Status `json:"status,omitempty"`
Log *LogLine `json:"log,omitempty"`
}
Event is the wire format pushed to subscribers. Exactly one of Status / Log is non-nil per event.
type LogLine ¶
type LogLine struct {
Time time.Time `json:"time"`
Level string `json:"level"` // "info" | "warn" | "error"
Text string `json:"text"`
}
LogLine is one line captured from the underlying session logger.
type Phase ¶
type Phase string
Phase is a coarse-grained tunnel state suitable for surfacing in a UI.
const ( PhaseIdle Phase = "idle" // never started, or after Stop() PhaseConnecting Phase = "connecting" // transport.Connect in flight PhaseHandshaking Phase = "handshaking" // peer found, in-band handshake PhaseRelaying Phase = "relaying" // bridge.Run live PhaseReconnecting Phase = "reconnecting" // backoff window between sessions PhaseError Phase = "error" // fatal: bad config, no transport, etc. )
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages a single tunnel session lifecycle. Construct one per process — concurrent sessions aren't supported (one bridge, one local UDP port).
func (*Service) BridgeStats ¶
BridgeStats returns the live SFU bridge counters as a one-liner suitable for log diagnostics. "" if no bridge is currently active.
func (*Service) Logger ¶
Logger exposes the captured *log.Logger so external code can pipe through the same capture pipeline (e.g. the CLI tool reusing this package).
func (*Service) RecentLogs ¶
RecentLogs returns the last `limit` captured log lines (newest last). limit ≤ 0 means "all".
func (*Service) SetVerbose ¶
SetVerbose toggles whether trace-classified lines flow through the log pipeline. When false (default), they're dropped at the entry point — no ring-buffer growth, no event broadcast, zero CPU spent formatting them per line. When true, every captured line goes through normally.
Switching the flag at runtime affects only future lines; lines already in the ring buffer keep their original level so a later RecentLogs call still surfaces what was captured at that level.
func (*Service) Start ¶
Start spawns the supervise loop in the background. Returns immediately. Subsequent Start calls while a session is active are rejected with ErrAlreadyRunning.
func (*Service) Status ¶
Status returns a snapshot of the current state, augmented with live byte counters from the running bridge if any.
func (*Service) Stop ¶
func (s *Service) Stop()
Stop signals graceful shutdown of any running session and blocks until the supervise loop has exited. Safe to call when idle.
type Status ¶
type Status struct {
Phase Phase `json:"phase"`
// SubPhase — finer-grained step внутри coarse Phase. Например
// под Phase=Connecting может быть SubPhase="lobby_dial" или
// "captcha". UI рендерит как secondary caption рядом с phase chip.
// Совпадает по семантике с mobile/api.go::emitPhase.
SubPhase string `json:"sub_phase,omitempty"`
Detail string `json:"detail,omitempty"`
Transport string `json:"transport"` // "telemost" | "livekit-wb-stream"
Meeting string `json:"meeting,omitempty"`
PeerID string `json:"peer_id,omitempty"`
LocalAddr string `json:"local_addr,omitempty"` // "127.0.0.1:51820"
StartedAt time.Time `json:"started_at,omitempty"`
LastError string `json:"last_error,omitempty"`
TxPackets uint64 `json:"tx_packets"`
TxBytes uint64 `json:"tx_bytes"`
RxPackets uint64 `json:"rx_packets"`
RxBytes uint64 `json:"rx_bytes"`
}
Status snapshots the running session. Returned by Service.Status and pushed inside Event.Status on every change.
type WGParams ¶
type WGParams struct {
ClientPrivateKey string `json:"client_private_key"` // base64
ServerPublicKey string `json:"server_public_key"` // base64
ClientAddr string `json:"client_addr"` // CIDR like 10.66.1.2/24
Endpoint string `json:"endpoint"` // typically same as ListenAddr
DNS []string `json:"dns,omitempty"` // ["1.1.1.1","8.8.8.8"]
}
WGParams is the embedded WireGuard config for the auto-WG path. Field names match the connstr schema in internal/connstr.