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.
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
- Variables
- func Bind(r *http.Request, life context.Context) (*http.Request, func())
- type Counts
- type Discovery
- type Error
- type Info
- type Manager
- func (m *Manager) Close()
- func (m *Manager) Connect(ctx context.Context, target string) (Info, error)
- func (m *Manager) Disconnect()
- func (m *Manager) Discover(ctx context.Context) Discovery
- func (m *Manager) Forwarded(port int) (string, bool)
- func (m *Manager) Info() *Info
- func (m *Manager) Pair(ctx context.Context, target, code string) (Info, error)
- func (m *Manager) Release(port int)
- func (m *Manager) Resume(ctx context.Context)
- func (m *Manager) Route(name, label string) (Route, error)
- func (m *Manager) ServeAPI(w http.ResponseWriter, r *http.Request)
- func (m *Manager) SetLocalPort(port, local int) (Info, error)
- func (m *Manager) SetLocalWant(fn func(port int) bool)
- func (m *Manager) Subscribe() chan struct{}
- func (m *Manager) SubscribeInfo() chan struct{}
- func (m *Manager) Unsubscribe(ch chan struct{})
- type Mirror
- type Peer
- type Route
Constants ¶
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.
const ( Connecting = "connecting" Open = "open" Reconnecting = "reconnecting" )
Connection states.
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 ¶
var ErrNotConnected = errors.New("not connected")
ErrNotConnected is returned when no remote is connected, or another one is.
var ErrUnknownServer = errors.New("unknown server")
ErrUnknownServer is returned for a server the remote does not have.
Functions ¶
Types ¶
type Discovery ¶
type Discovery struct {
Tailnet struct {
Available bool `json:"available"`
Error string `json:"error,omitempty"`
Self string `json:"self,omitempty"`
} `json:"tailnet"`
Peers []Peer `json:"peers"`
}
Discovery is the answer to a scan of the tailnet.
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 ¶
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 ¶
Connect connects to the device called target ("name" or "name:port"), replacing any current connection.
func (*Manager) Disconnect ¶
func (m *Manager) Disconnect()
Disconnect ends the current connection, and the daemon no longer resumes it when it starts.
func (*Manager) Forwarded ¶
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) Pair ¶
Pair redeems a pairing code shown on the device called target, keeps the token it issues, and connects.
func (*Manager) Release ¶
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 ¶
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 ¶
Route finds the remote server called name. label, when set, must be the connected device's DNS label.
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) SetLocalPort ¶
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 ¶
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", or "busy" when the port is taken here.
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.