remote

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package remote connects this daemon to the daemon on another of the owner's devices (see package share for the other side). While connected it relays the dashboard's API calls and WebSockets, serves the remote servers at http://<name>.<computer>.localhost through this daemon's proxy, and forwards each running remote server's port to the same port here, so links such as http://127.0.0.1:5173 open as if the servers ran on this machine, except ports the user turned off for that computer (mirrors.go).

All traffic travels over the tailnet as HTTP to Tailscale Serve on the other device; raw TCP for ports is carried in WebSockets to /api/tunnel.

Index

Constants

View Source
const (
	CodePairingRequired = "pairing_required"
	CodePairingFailed   = "pairing_failed"
	// CodeUnverified: something answered on the device's address but could
	// not prove it holds the pairing key. Pairing again would not help.
	CodeUnverified = "unverified"
)

Codes of Error.

View Source
const (
	Connecting   = "connecting"
	Open         = "open"
	Reconnecting = "reconnecting"
)

Connection states.

View Source
const PathPrefix = "/api/peer"

PathPrefix is where the dashboard reaches the remote daemon's API, as PathPrefix/<DNS name of the device it expects>/...

Variables

View Source
var ErrForwardingOff = errors.New("forwarding is off")

ErrForwardingOff is returned for a server whose port the user turned off.

View Source
var ErrNotConnected = errors.New("not connected")

ErrNotConnected is returned when no remote is connected, or another one is.

View Source
var ErrUnknownServer = errors.New("unknown server")

ErrUnknownServer is returned for a server the remote does not have.

Functions

func Bind

func Bind(r *http.Request, life context.Context) (*http.Request, func())

Bind returns r with a context that also ends when life does, and a function that releases the link. A reverse proxy closes an upgraded connection when its request context ends.

Types

type Counts

type Counts struct {
	Total   int `json:"total"`
	Running int `json:"running"`
}

Counts summarises a peer's servers.

type Discovery

type Discovery struct {
	Tailnet struct {
		Available bool   `json:"available"`
		Error     string `json:"error,omitempty"`
		Problem   string `json:"problem,omitempty"` // tailnet.Problem of Error
		Self      string `json:"self,omitempty"`
	} `json:"tailnet"`
	Peers []Peer `json:"peers"`
}

Discovery is the answer to a scan of the tailnet.

type Error

type Error struct {
	Status int
	Code   string
	Msg    string
}

Error carries the HTTP status and machine-readable code a failure maps to.

func (*Error) Error

func (e *Error) Error() string

type Info

type Info struct {
	Peer    tailnet.Node `json:"peer"`
	Status  string       `json:"status"`
	Error   string       `json:"error,omitempty"`
	Version string       `json:"version,omitempty"`
	// LocalPort is this daemon's port, used in *.localhost URLs.
	LocalPort int       `json:"localPort"`
	Mirrors   []Mirror  `json:"mirrors"`
	Since     time.Time `json:"since"`
}

Info describes the connection for the dashboard.

type Manager

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

Manager holds at most one connection.

func New

func New(localPort int, stateDir string, ts *tailnet.Cache) *Manager

New creates a manager for the daemon listening on localPort that keeps its pairings in stateDir.

func (*Manager) Close

func (m *Manager) Close()

Close ends the current connection as the daemon stops; the next daemon resumes it.

func (*Manager) Connect

func (m *Manager) Connect(ctx context.Context, target string) (Info, error)

Connect connects to the device called target ("name" or "name:port"), replacing any current connection. A Connect, Disconnect or Close that begins while it reaches the device wins: this one then installs nothing.

func (*Manager) Disconnect

func (m *Manager) Disconnect()

Disconnect ends the current connection, and the daemon no longer resumes it when it starts.

func (*Manager) Discover

func (m *Manager) Discover(ctx context.Context) Discovery

Discover lists the owner's online devices whose daemon is shared.

func (*Manager) Forwarded

func (m *Manager) Forwarded(port int) (string, bool)

Forwarded reports whether local port currently forwards to the connected computer, with that computer's name. A connection to the port reaches the other computer, not a process here.

func (*Manager) Info

func (m *Manager) Info() *Info

Info describes the current connection, or nil.

func (*Manager) Pair

func (m *Manager) Pair(ctx context.Context, target, code string) (Info, error)

Pair redeems a pairing code shown on the device called target, keeps the token it issues, and connects.

func (*Manager) Release

func (m *Manager) Release(port int)

Release frees local port for a local server about to start, and keeps it free long enough for that server to bind it.

func (*Manager) Resume

func (m *Manager) Resume(ctx context.Context)

Resume reconnects, in the background, to the computer this daemon was connected to when it stopped. The connection shows as connecting and retries until the other computer answers, the user disconnects, or the other computer no longer accepts this one's pairing.

func (*Manager) Route

func (m *Manager) Route(name, label string) (Route, error)

Route finds the remote server called name. label, when set, must be the connected device's DNS label. A server whose port is turned off gets ErrForwardingOff, with Peer and Port set for the answer.

func (*Manager) ServeAPI

func (m *Manager) ServeAPI(w http.ResponseWriter, r *http.Request)

ServeAPI relays a request for PathPrefix/<DNS name>/... to the remote daemon's /api/..., refusing it when the named device is not the connected one, so a request made while a window showed another computer never runs on this one. The caller has already authenticated the request.

func (*Manager) SetForwarding added in v0.4.0

func (m *Manager) SetForwarding(port int, on bool) (Info, error)

SetForwarding turns forwarding of the connected computer's port on or off. Off closes the port's listeners here and its open connections, and <name>.<computer>.localhost no longer reaches a server on it; the port is still listed so it can be turned on again. The choice is kept for that computer. Turning off a port that computer does not forward is refused.

func (*Manager) SetLocalPort

func (m *Manager) SetLocalPort(port, local int) (Info, error)

SetLocalPort forwards the connected computer's port to local on this computer instead of the same number, or to the same number again when local is 0 or port. The choice is kept for that computer.

func (*Manager) SetLocalWant

func (m *Manager) SetLocalWant(fn func(port int) bool)

SetLocalWant registers fn, which reports a port a server on this computer is starting or running on. Such a port is not forwarded even once a Release has expired, so a server that binds late is not reached through the other computer. fn is called with the manager's lock held and must not call into the manager.

func (*Manager) Subscribe

func (m *Manager) Subscribe() chan struct{}

Subscribe returns a channel signalled on every change, including each new remote state. SubscribeInfo is signalled only when Info changes.

func (*Manager) SubscribeInfo

func (m *Manager) SubscribeInfo() chan struct{}

func (*Manager) Unsubscribe

func (m *Manager) Unsubscribe(ch chan struct{})

Unsubscribe removes a channel from either set.

type Mirror

type Mirror struct {
	Port      int    `json:"port"`
	Local     int    `json:"local,omitempty"`
	Server    string `json:"server,omitempty"`
	Container string `json:"container,omitempty"`
	// State is "mirrored", "busy" when the port is taken here, "off" when
	// the user turned its forwarding off, or "limit" when more ports are
	// forwarded than this computer allows (forwardLimit).
	State string `json:"state"`
}

Mirror is a remote port forwarded to this machine: to the same port, or to Local when the user chose another one.

type Peer

type Peer struct {
	tailnet.Node
	Version string `json:"version"`
	Paired  bool   `json:"paired"`
	// Servers is known only once paired.
	Servers   *Counts `json:"servers,omitempty"`
	Connected bool    `json:"connected"`
}

Peer is a device that shares its daemon.

type Route

type Route struct {
	Peer      string
	Port      int
	Transport http.RoundTripper
	// Done ends with the connection; requests through the route, upgraded
	// WebSockets included, must end with it.
	Done context.Context
}

Route is how to reach a remote server: dial 127.0.0.1:Port through Transport.

Jump to

Keyboard shortcuts

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