network

package
v0.0.0-...-529d744 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Hostname is the name this device will appear as on the tailnet.
	Hostname string

	// StoragePrefix is the key namespace used by the default localStorage store.
	// Defaults to "tailscale-web". Keys are written as "{prefix}_{stateKey}".
	// Ignored when Store is set explicitly.
	StoragePrefix string

	// ControlURL overrides the Tailscale coordination server URL.
	// Defaults to the public Tailscale control server.
	ControlURL string

	// Store is the state store to use. If nil, defaults to localStorage when
	// available (browser), or an in-memory store otherwise.
	Store ipn.StateStore
}

Config holds configuration for the Tailscale node.

type DNSInfo

type DNSInfo struct {
	// Resolvers are the global nameservers.
	Resolvers []string
	// Routes maps DNS search suffixes to their dedicated resolvers.
	// A nil/empty resolver list means "use the built-in MagicDNS resolver".
	Routes map[string][]string
	// Domains are the search/split-DNS domains.
	Domains []string
	// ExtraRecords are custom DNS records pushed by the control plane.
	ExtraRecords []DNSRecord
	// MagicDNS reports whether MagicDNS (proxied resolution) is enabled.
	MagicDNS bool
}

DNSInfo holds the Tailscale-managed DNS configuration.

type DNSRecord

type DNSRecord struct {
	Name  string
	Type  string
	Value string
}

DNSRecord is a single custom DNS record.

type ExitNode

type ExitNode struct {
	// ID is the stable node ID; pass to SetExitNode to activate it.
	ID string
	// HostName is the machine's hostname.
	HostName string
	// DNSName is the MagicDNS FQDN (ends with a dot).
	DNSName string
	// TailscaleIP is the primary Tailscale IPv4 address of the node.
	TailscaleIP string
	// Active reports whether this node is the currently selected exit node.
	Active bool
	// Online reports whether the node is currently reachable.
	Online bool
}

ExitNode represents a peer that is advertising exit-node capability.

type FetchOptions

type FetchOptions struct {
	Method    string
	Headers   map[string]string
	BodyBytes []byte
}

FetchOptions mirrors the subset of the Fetch API init object we support.

type FetchResponse

type FetchResponse struct {
	Status     int
	StatusText string
	Headers    map[string]string
	Body       []byte
}

FetchResponse is the result of a Fetch call.

type Network

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

Network manages a Tailscale node running in the browser.

func Connect

func Connect(ctx context.Context, cfg Config, onAuthRequired OnAuthRequired, onAuthComplete OnAuthComplete) (*Network, error)

Connect starts a Tailscale node and returns a ready Network. If the node has persisted state from a previous session it reconnects automatically; otherwise it triggers the OAuth flow via onAuthRequired.

func (*Network) Close

func (n *Network) Close() error

Close shuts down the Tailscale node.

func (*Network) Dial

func (n *Network) Dial(ctx context.Context, network, addr string) (net.Conn, error)

Dial opens a TCP connection through the Tailscale network.

func (*Network) Fetch

func (n *Network) Fetch(ctx context.Context, rawURL string, opts FetchOptions) (*FetchResponse, error)

Fetch makes an HTTP request through the Tailscale network.

func (*Network) GetDNS

func (n *Network) GetDNS() DNSInfo

GetDNS returns the Tailscale-managed DNS configuration.

func (*Network) GetLocalIPv4

func (n *Network) GetLocalIPv4() string

GetLocalIPv4 returns the node's Tailscale IPv4 address, or empty string if unavailable.

func (*Network) GetLocalIPv6

func (n *Network) GetLocalIPv6() string

GetLocalIPv6 returns the node's Tailscale IPv6 address, or empty string if unavailable.

func (*Network) GetPrefs

func (n *Network) GetPrefs() Prefs

GetPrefs returns the current relevant preferences.

func (*Network) GetRoutes

func (n *Network) GetRoutes() []*Route

GetRoutes returns the full routing table derived from the current network map.

func (*Network) ListExitNodes

func (n *Network) ListExitNodes() []*ExitNode

ListExitNodes returns all peers that advertise exit-node capability.

func (*Network) Listen

func (n *Network) Listen(port int) (net.Listener, error)

Listen opens a TCP listener on the Tailscale network for inbound connections from peers. Pass port 0 to have an ephemeral port assigned automatically.

func (*Network) Ping

func (n *Network) Ping(ctx context.Context, addr string) (*PingResult, error)

Ping sends an ICMP echo request to addr and measures round-trip time. addr may be a Tailscale IP address, a MagicDNS hostname (full or short), or a machine hostname. Any port suffix is stripped and ignored.

func (*Network) SetAcceptRoutes

func (n *Network) SetAcceptRoutes(accept bool) error

SetAcceptRoutes enables or disables acceptance of subnet routes advertised by peers. This is equivalent to `tailscale set --accept-routes`.

func (*Network) SetExitNode

func (n *Network) SetExitNode(id string) error

SetExitNode activates the exit node with the given stable node ID. Pass an empty string to clear the exit node.

type OnAuthComplete

type OnAuthComplete func()

OnAuthComplete is called once the device is authenticated and connected.

type OnAuthRequired

type OnAuthRequired func(url string)

OnAuthRequired is called with the OAuth URL when interactive login is needed.

type PingResult

type PingResult struct {
	Alive bool
	RttMs float64
	// NodeName is the MagicDNS name of the destination peer.
	NodeName string
	// NodeIP is the Tailscale IP of the destination.
	NodeIP string
	// Endpoint is the direct UDP endpoint used, if a direct path was established.
	Endpoint string
	// DERPRegionCode is the DERP relay region (e.g. "nyc") if traffic was relayed.
	DERPRegionCode string
	// Err holds the error reason when Alive is false.
	Err string
}

PingResult is the result of an ICMP connectivity probe.

type Prefs

type Prefs struct {
	// AcceptRoutes reports whether subnet routes advertised by peers are accepted.
	AcceptRoutes bool
	// ExitNodeID is the stable node ID of the currently selected exit node,
	// or empty if no exit node is active.
	ExitNodeID string
}

Prefs contains the subset of Tailscale preferences exposed by this library.

type Route

type Route struct {
	// Prefix is the CIDR being routed (e.g. "10.0.0.0/24" or "0.0.0.0/0").
	Prefix string
	// Via is the display name of the node advertising this route,
	// or "self" for routes owned by this node.
	Via string
	// IsPrimary reports whether this node is the primary (active) router
	// for the prefix. For self-routes this is always true.
	IsPrimary bool
	// IsExitRoute reports whether this is a default/exit route (0.0.0.0/0 or ::/0).
	IsExitRoute bool
}

Route represents a single entry in the routing table.

Jump to

Keyboard shortcuts

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