Help us shape the future of Go! Take the 2026 Go Developer Survey

tailnet

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: AGPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IP

func IP() netip.Addr

IP generates a new IP with a static service prefix.

func Logger

func Logger(logger slog.Logger) tslogger.Logf

Logger converts the Tailscale logging function to use slog.

func NewDERPMap

func NewDERPMap(ctx context.Context, region *tailcfg.DERPRegion, stunAddrs []string, remoteURL, localPath string) (*tailcfg.DERPMap, error)

NewDERPMap constructs a DERPMap from a set of STUN addresses and optionally a remote URL to fetch a mapping from e.g. https://controlplane.tailscale.com/derpmap/default.

func ServeCoordinator

func ServeCoordinator(conn net.Conn, updateNodes func(node []*Node) error) (func(node *Node), <-chan error)

ServeCoordinator matches the RW structure of a coordinator to exchange node messages.

Types

type Conn

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

Conn is an actively listening Wireguard connection.

func NewConn

func NewConn(options *Options) (*Conn, error)

NewConn constructs a new Wireguard server that will accept connections from the addresses provided.

func (*Conn) Close

func (c *Conn) Close() error

Close shuts down the Wireguard connection.

func (*Conn) Closed

func (c *Conn) Closed() <-chan struct{}

Closed is a channel that ends when the connection has been closed.

func (*Conn) DialContextTCP

func (c *Conn) DialContextTCP(ctx context.Context, ipp netip.AddrPort) (*gonet.TCPConn, error)

func (*Conn) DialContextUDP

func (c *Conn) DialContextUDP(ctx context.Context, ipp netip.AddrPort) (*gonet.UDPConn, error)

func (*Conn) Listen

func (c *Conn) Listen(network, addr string) (net.Listener, error)

Listen announces only on the Tailscale network. It will start the server if it has not been started yet.

func (*Conn) Ping

func (c *Conn) Ping(ip netip.Addr, pingType tailcfg.PingType, cb func(*ipnstate.PingResult))

Ping sends a ping to the Wireguard engine.

func (*Conn) SetDERPMap

func (c *Conn) SetDERPMap(derpMap *tailcfg.DERPMap)

SetDERPMap updates the DERPMap of a connection.

func (*Conn) SetForwardTCPCallback added in v0.8.12

func (c *Conn) SetForwardTCPCallback(callback func(conn net.Conn, listenerExists bool) net.Conn)

SetForwardTCPCallback is called every time a TCP connection is initiated inbound. listenerExists is true if a listener is registered for the target port. If there isn't one, traffic is forwarded to the local listening port.

This allows wrapping a Conn to track reads and writes.

func (*Conn) SetNodeCallback

func (c *Conn) SetNodeCallback(callback func(node *Node))

func (*Conn) Status

func (c *Conn) Status() *ipnstate.Status

Status returns the current ipnstate of a connection.

func (*Conn) UpdateNodes

func (c *Conn) UpdateNodes(nodes []*Node) error

UpdateNodes connects with a set of peers. This can be constantly updated, and peers will continually be reconnected as necessary.

type Coordinator

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

Coordinator exchanges nodes with agents to establish connections. ┌──────────────────┐ ┌────────────────────┐ ┌───────────────────┐ ┌──────────────────┐ │tailnet.Coordinate├──►│tailnet.AcceptClient│◄─►│tailnet.AcceptAgent│◄──┤tailnet.Coordinate│ └──────────────────┘ └────────────────────┘ └───────────────────┘ └──────────────────┘ This coordinator is incompatible with multiple Coder replicas as all node data is in-memory.

func NewCoordinator

func NewCoordinator() *Coordinator

NewCoordinator constructs a new in-memory connection coordinator.

func (*Coordinator) Node

func (c *Coordinator) Node(id uuid.UUID) *Node

Node returns an in-memory node by ID.

func (*Coordinator) ServeAgent

func (c *Coordinator) ServeAgent(conn net.Conn, id uuid.UUID) error

ServeAgent accepts a WebSocket connection to an agent that listens to incoming connections and publishes node updates.

func (*Coordinator) ServeClient

func (c *Coordinator) ServeClient(conn net.Conn, id uuid.UUID, agent uuid.UUID) error

ServeClient accepts a WebSocket connection that wants to connect to an agent with the specified ID.

type Node

type Node struct {
	ID            tailcfg.NodeID     `json:"id"`
	Key           key.NodePublic     `json:"key"`
	DiscoKey      key.DiscoPublic    `json:"disco"`
	PreferredDERP int                `json:"preferred_derp"`
	DERPLatency   map[string]float64 `json:"derp_latency"`
	Addresses     []netip.Prefix     `json:"addresses"`
	AllowedIPs    []netip.Prefix     `json:"allowed_ips"`
	Endpoints     []string           `json:"endpoints"`
}

Node represents a node in the network.

type Options

type Options struct {
	Addresses []netip.Prefix
	DERPMap   *tailcfg.DERPMap

	Logger slog.Logger
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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