tailnet

package
v0.0.0-...-560f09a Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: AGPL-3.0 Imports: 44 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.

Documentation

Index

Constants

View Source
const (
	// AgentPrefix is the prefix key that is used to save an agent's tailnet node information to the cluster state
	AgentPrefix = "ts/coord/agent"
	// ServerPrefix is the prefix key that is used to save a server's tailnet node information to the cluster state
	ServerPrefix = "ts/coord/server"
	// ConnectionPrefix is the prefix key that is used to save a connection's tailnet information to the cluster state
	ConnectionPrefix = "ts/coord/connection"
)

Variables

This section is empty.

Functions

func IP

func IP() netip.Addr

IP generates a new IP with a static service prefix.

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.

Types

type AgentConnMsg

type AgentConnMsg struct {
	Type    AgentConnMsgType `json:"type"`
	AgentID int64            `json:"agent_id"`
	Node    Node             `json:"node"`
}

AgentConnMsg is the metadata of an agent

type AgentConnMsgType

type AgentConnMsgType int
const (
	AgentConnMsgTypeAdd AgentConnMsgType = iota
	AgentConnMsgTypeRemove
)

type Conn

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

Conn is an actively listening Wireguard connection.

func NewConn

func NewConn(connType ConnType, options *Options, logger logging.Logger) (*Conn, error)

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

func (*Conn) AwaitReachable

func (c *Conn) AwaitReachable(ctx context.Context, ip netip.Addr) bool

AwaitReachable pings the provided IP continually until the address is reachable. It's the callers responsibility to provide a timeout, otherwise this function will block forever.

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) ConnectToCoordinator

func (c *Conn) ConnectToCoordinator(conn net.Conn) <-chan error

ConnectToCoordinator Connects the connection to the provided coordinator connection and processes network updates automatically.

func (*Conn) DERPMap

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

DERPMap returns the currently set DERP mapping.

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) Node

func (c *Conn) Node() *Node

Node returns the last node that was sent to the node callback.

func (*Conn) Ping

Ping sends a Disco ping to the Wireguard engine. The bool returned is true if the ping was performed P2P.

func (*Conn) RemoveAllPeers

func (c *Conn) RemoveAllPeers() error

RemoveAllPeers

Clears all current peers from a tailnet connection

func (*Conn) SetConnStatsCallback

func (c *Conn) SetConnStatsCallback(maxPeriod time.Duration, maxConns int, dump func(start, end time.Time, virtual, physical map[netlogtype.Connection]netlogtype.Counts))

SetConnStatsCallback sets a callback to be called after maxPeriod or maxConns, whichever comes first. Multiple calls overwrites the callback.

func (*Conn) SetDERPMap

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

SetDERPMap updates the DERPMap of a connection.

func (*Conn) SetForwardTCPCallback

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.

func (*Conn) UpdateNodesClear

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

UpdateNodesClear removes all peers and then adds the provided peers.

type ConnType

type ConnType int
const (
	ConnTypeServer ConnType = iota
	ConnTypeAgent
)

type ConnectionMetadata

type ConnectionMetadata struct {
	// ID is the unique ID of the connection
	ID int64 `json:"_id"`
	// AgentID is the unique ID of the agent
	AgentID int64 `json:"agent_id"`
	// ServerID is the unique ID of the server
	ServerID int64 `json:"server_id"`
	// CreatedAt is the time the connection was created
	CreatedAt time.Time `json:"created_at"`
}

ConnectionMetadata is the metadata associated with a connection

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│ └──────────────────┘ └────────────────────┘ └───────────────────┘ └──────────────────┘

func NewCoordinator

func NewCoordinator(clusterNode cluster.Node, jsClient *mq.JetstreamClient, logger logging.Logger) (*Coordinator, error)

NewCoordinator constructs a new in-memory connection Coordinator. This Coordinator is incompatible with multiple Coder replicas as all node data is in-memory.

func (*Coordinator) Agent

func (c *Coordinator) Agent(id int64) (*Node, error)

Agent

Returns the tailscale node for the passed agent ID.
If the agent does not exist, nil is returned.

func (*Coordinator) Close

func (c *Coordinator) Close() error

Close closes all of the open connections in the Coordinator and stops the Coordinator from accepting new connections.

func (*Coordinator) ServeAgent

func (c *Coordinator) ServeAgent(conn net.Conn, agent int64) 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, connectionID int64, agent int64) error

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

func (*Coordinator) Server

func (c *Coordinator) Server(id int64) (*Node, error)

Server

Returns the tailscale node for the passed server ID.
If the server does not exist, nil is returned.

type Node

type Node struct {
	// ID is used to identify the connection.
	ID tailcfg.NodeID `json:"id"`
	// AsOf is the time the node was created.
	AsOf time.Time `json:"as_of"`
	// Key is the Wireguard public key of the node.
	Key key.NodePublic `json:"key"`
	// DiscoKey is used for discovery messages over DERP to establish peer-to-peer connections.
	DiscoKey key.DiscoPublic `json:"disco"`
	// PreferredDERP is the DERP server that peered connections
	// should meet at to establish.
	PreferredDERP int `json:"preferred_derp"`
	// DERPLatency is the latency in seconds to each DERP server.
	DERPLatency map[string]float64 `json:"derp_latency"`
	// Addresses are the IP address ranges this connection exposes.
	Addresses []netip.Prefix `json:"addresses"`
	// AllowedIPs specify what addresses can dial the connection.
	// We allow all by default.
	AllowedIPs []netip.Prefix `json:"allowed_ips"`
	// Endpoints are ip:port combinations that can be used to establish
	// peer-to-peer connections.
	Endpoints []string `json:"endpoints"`
}

Node represents a node in the network.

type Options

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

	// BlockEndpoints specifies whether P2P endpoints are blocked.
	// If so, only DERPs can establish connections.
	BlockEndpoints bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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