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

hostbridge

package
v1.3.104-alpha1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package hostbridge pkg/hostbridge/auth.go c3-vis-wasm

Package hostbridge pkg/hostbridge/client.go c3-vis-wasm

Package hostbridge pkg/hostbridge/proto.go c3-vis-wasm

Package hostbridge pkg/hostbridge/run.go c3-vis-wasm

Package hostbridge pkg/hostbridge/server.go c3-vis-wasm

Package hostbridge lends a browser visor the host's sockets. The tab dials the bridge over one WebSocket, both ends run yamux on it, and each stream asks the bridge to dial, listen on TCP, or bind UDP on the tab's behalf.

The bridge keeps no keys or state of its own, so the same small binary serves any visor that knows its token.

Package hostbridge pkg/hostbridge/tun_linux.go c3-vis-wasm

Package hostbridge pkg/hostbridge/ws.go c3-vis-wasm

Index

Constants

View Source
const DefaultAddr = "127.0.0.1:3438"

DefaultAddr is where the bridge listens for the tab.

View Source
const DefaultOrigin = "https://skywire.dev"

DefaultOrigin is the browser visor's page.

Variables

This section is empty.

Functions

func DefaultTokenFile

func DefaultTokenFile() string

DefaultTokenFile is where the bridge keeps its token, so the URL a visor saved still works after the bridge restarts. It is empty when the OS has no config directory.

func LoadToken

func LoadToken(path string) (string, error)

LoadToken reads the token in path, or writes a new one there.

func NewToken

func NewToken() (string, error)

NewToken returns a random 128-bit token in hex.

func PairFile

func PairFile(tokenFile string) string

PairFile is where the bridge keeps its paired visor: beside tokenFile, resolved as ResolveToken does, or in memory only when that is "none".

func ResolveToken

func ResolveToken(token, tokenFile string) (string, error)

ResolveToken returns token when set, else the one kept in tokenFile. An empty tokenFile means DefaultTokenFile, and "none" a new token each run.

func Run

func Run(addr string, cfg Config, ready func(url string)) error

Run listens on addr and serves tabs until the listener fails. ready gets the URL the tab connects to, token included.

func SplitOrigins

func SplitOrigins(s string) []string

SplitOrigins parses a comma separated origin list.

func Unpair

func Unpair(pairFile string) error

Unpair forgets the paired visor, so the next one to connect with the token pairs instead.

Types

type Client

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

Client is the tab end of the bridge. Its Dial, Listen and ListenPacket return the standard net types, backed by sockets on the bridge's host.

func NewClient

func NewClient(conn net.Conn, p *Pairing) (*Client, error)

NewClient runs the tab end over conn, the tab's WebSocket to the bridge, after pairing with it as p. When the bridge pairs for the first time it sets p.Secret, which the visor keeps for later sessions.

func (*Client) Close

func (c *Client) Close() error

Close ends the session and every socket opened through it.

func (*Client) Dial

func (c *Client) Dial(network, addr string) (net.Conn, error)

Dial opens a TCP connection from the bridge's host.

func (*Client) DialContext

func (c *Client) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext is Dial bounded by ctx.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done is closed when the session to the bridge ends.

func (*Client) Listen

func (c *Client) Listen(network, addr string) (net.Listener, error)

Listen listens on TCP on the bridge's host. Closing the listener closes the host socket.

func (*Client) ListenPacket

func (c *Client) ListenPacket(network, addr string) (net.PacketConn, error)

ListenPacket binds UDP on the bridge's host.

func (*Client) Net

func (c *Client) Net(ctx context.Context, cmd string, args ...string) (string, error)

Net sets up the bridge's host for a TUN: "gateway" returns the default gateway, "setup <tun> <cidr> <mtu>" addresses a TUN this bridge opened and brings it up, and "route add|change|del <dst> <gateway>" edits a route.

func (*Client) TUN

func (c *Client) TUN(ctx context.Context) (*TUN, error)

TUN opens a TUN device on the bridge's host. Each Read and Write moves one packet. Closing it deletes the device and the routes through it. The bridge needs CAP_NET_ADMIN, as a native vpn-client does.

type Config

type Config struct {
	// Token is the secret the tab puts in the WebSocket path.
	Token string
	// Origins are the pages allowed to connect. "*" allows any.
	Origins []string
	// PairFile keeps the visor the bridge paired with, so a restart serves
	// only that visor. Empty keeps the pairing in memory.
	PairFile string
	Logf     func(format string, args ...any)
}

Config is the bridge's access policy.

type Pairing

type Pairing struct {
	// PK is the visor's public key, in hex.
	PK string
	// Secret is the one the bridge gave this visor when they paired. Empty
	// asks to pair, which only an unpaired bridge accepts. NewClient sets it
	// when the bridge pairs.
	Secret string
}

Pairing is how a visor identifies itself to the bridge.

type Server

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

Server is the host end of the bridge.

func NewServer

func NewServer(cfg Config) (*Server, error)

NewServer returns a bridge with the given policy. An empty token is refused because any page could then use the host's sockets.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve accepts tab connections on l until it fails.

type TUN

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

TUN is a TUN device on the bridge's host.

func (*TUN) Close

func (t *TUN) Close() error

Close deletes the device.

func (*TUN) Name

func (t *TUN) Name() string

Name is the device's name on the host.

func (*TUN) Read

func (t *TUN) Read(p []byte) (int, error)

func (*TUN) Write

func (t *TUN) Write(p []byte) (int, error)

Directories

Path Synopsis
Package dist pkg/hostbridge/dist/dist.go c3-vis-wasm
Package dist pkg/hostbridge/dist/dist.go c3-vis-wasm

Jump to

Keyboard shortcuts

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