Documentation
¶
Index ¶
- type Config
- type DNSInfo
- type DNSRecord
- type ExitNode
- type FetchOptions
- type FetchResponse
- type Network
- func (n *Network) Close() error
- func (n *Network) Dial(ctx context.Context, network, addr string) (net.Conn, error)
- func (n *Network) Fetch(ctx context.Context, rawURL string, opts FetchOptions) (*FetchResponse, error)
- func (n *Network) GetDNS() DNSInfo
- func (n *Network) GetLocalIPv4() string
- func (n *Network) GetLocalIPv6() string
- func (n *Network) GetPrefs() Prefs
- func (n *Network) GetRoutes() []*Route
- func (n *Network) ListExitNodes() []*ExitNode
- func (n *Network) Listen(port int) (net.Listener, error)
- func (n *Network) Ping(ctx context.Context, addr string) (*PingResult, error)
- func (n *Network) SetAcceptRoutes(accept bool) error
- func (n *Network) SetExitNode(id string) error
- type OnAuthComplete
- type OnAuthRequired
- type PingResult
- type Prefs
- type Route
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 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 ¶
FetchOptions mirrors the subset of the Fetch API init object we support.
type FetchResponse ¶
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) 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) GetLocalIPv4 ¶
GetLocalIPv4 returns the node's Tailscale IPv4 address, or empty string if unavailable.
func (*Network) GetLocalIPv6 ¶
GetLocalIPv6 returns the node's Tailscale IPv6 address, or empty string if unavailable.
func (*Network) GetRoutes ¶
GetRoutes returns the full routing table derived from the current network map.
func (*Network) ListExitNodes ¶
ListExitNodes returns all peers that advertise exit-node capability.
func (*Network) Listen ¶
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 ¶
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 ¶
SetAcceptRoutes enables or disables acceptance of subnet routes advertised by peers. This is equivalent to `tailscale set --accept-routes`.
func (*Network) SetExitNode ¶
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.