connector

package module
v0.2.29 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 10 Imported by: ? 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.

README

Open Machine network connector

github.com/OpenMachineLabs/openmachine/connector joins one device to a private network served by a Tailscale-protocol control server and carries TCP between the peers that server permits. It wraps the stock tsnet.Server; upstream details stay in internal/tailnet.

n, err := connector.Start(ctx, connector.Config{
	Dir:        stateDir,   // owner-only; holds the node identity
	ControlURL: controlURL, // required: there is no default control server
	Hostname:   "device",
	AuthKey:    oneUseKey,  // used only for the first registration
})
ln, err := n.Listen(port)           // Accept returns *connector.Conn
c, err := n.Dial(ctx, peerAddrPort) // only current peers are dialed
st, err := n.Status(ctx)            // self, peers, direct or relay path
err = n.Close()

The control server decides which peers and ports are reachable; the optional Config.Allow narrows that further. A node accepts or dials only connections whose remote end is a current, allowed peer, reports that peer from the control server's identity, including its verified NodeKey, and closes the connection when the peer leaves the network map or, after Revalidate, when Allow no longer permits it. A dial that upstream would hand to the host network, such as one racing a peer's removal, fails instead. Restarting from the same directory keeps the node's identity.

Importing the package disables Tailscale log upload and binds each dial to the interface that routes to its destination, so control and relays still work behind a VPN or proxy TUN. Both settings are process-wide and inherited by child processes: TS_NO_LOGS_NO_SUPPORT=true and TS_BIND_TO_INTERFACE_BY_ROUTE=true. The library does not use Server.Sys(), go:linkname, wgengine or magicsock directly, and enables no Funnel, Serve, exit node, subnet route or TUN device.

Test

The module builds and tests on its own, with no private sibling code:

go test ./...

test/proof_test.go runs two-node proofs against pinned, unmodified Headscale and DERP servers on loopback. Without OM_HEADSCALE and OM_DERPER set to those binaries, it is skipped and must be reported as not run. The proof uses Headscale v0.29.7 and derper at the tailscale.com version in go.mod:

bin="$(mktemp -d)"
GOBIN="$bin" go install github.com/juanfont/headscale/cmd/headscale@v0.29.7
GOBIN="$bin" go install "tailscale.com/cmd/derper@$(go list -m -f '{{.Version}}' tailscale.com)"
OM_HEADSCALE="$bin/headscale" OM_DERPER="$bin/derper" go test ./...

License

MIT; see LICENSE. Dependencies keep their own licenses; see third-party licenses.

Documentation

Overview

Package connector joins one Open Machine device to a private network served by a Tailscale-protocol control server, and carries TCP between peers that the control server permits.

The control server decides which peers and ports are reachable, and the caller may narrow that further. A Node only accepts or dials connections whose remote end is a current peer the caller allows, and closes them when that peer leaves the network map or the caller no longer allows it. Log upload to Tailscale is disabled for the whole process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Dir        string // private state directory; created owner-only if missing
	ControlURL string // http or https URL of the control server
	Hostname   string
	AuthKey    string               // one-use registration key; ignored once Dir holds an identity
	Logf       func(string, ...any) // optional; nil discards logs
	// Allow, if set, narrows what the control server permits: a connection
	// with peer is admitted and kept only while it returns true. Call
	// Revalidate after its answers change. It may be called concurrently and
	// should return quickly.
	Allow func(peer Peer) bool
}

Config describes one node.

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

Conn is a TCP connection to a verified peer.

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Peer

func (c *Conn) Peer() Peer

Peer returns the remote peer as identified by the control server.

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns the address the peer was verified at. Unlike the netstack's, it stays set once the connection is closed or reset.

type Node

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

Node is a running network node. Close it to leave the network.

func Start

func Start(ctx context.Context, c Config) (*Node, error)

Start registers or resumes the node and waits until it is connected.

func (*Node) Close

func (n *Node) Close() error

Close closes every connection and leaves the network. The node's identity stays in its state directory.

func (*Node) Dial

func (n *Node) Dial(ctx context.Context, addr netip.AddrPort) (*Conn, error)

Dial connects to a current peer that Allow permits. Addresses outside the network are refused rather than dialed through the host network.

func (*Node) Listen

func (n *Node) Listen(port uint16) (net.Listener, error)

Listen accepts TCP connections on port from current peers.

func (*Node) Revalidate

func (n *Node) Revalidate()

Revalidate closes the connections whose peer no longer owns the remote address or that Allow no longer permits. Removals from the network map are applied automatically.

func (*Node) Status

func (n *Node) Status(ctx context.Context) (Status, error)

Status reports this node's state and its current peers.

type Peer

type Peer = tailnet.Peer

type PeerStatus

type PeerStatus = tailnet.PeerStatus

type Status

type Status = tailnet.Status

Directories

Path Synopsis
internal
tailnet
Package tailnet adapts the stock tsnet.Server.
Package tailnet adapts the stock tsnet.Server.

Jump to

Keyboard shortcuts

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