ts2021
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package ts2021 handles the details of the Tailscale 2021 control protocolthat are after (above) the Noise layer. In particular, the"tailcfg.EarlyNoise" message and the subsequent HTTP/2 connection.
Index¶
Constants¶
const EarlyPayloadMagic = "\xff\xff\xffTS"EarlyPayloadMagic is the 5-byte magic prefix that indicates an early payload.
Variables¶
This section is empty.
Functions¶
funcAddLBHeader¶
func AddLBHeader(req *http.Request, nodeKeykey.NodePublic)
AddLBHeader adds the load balancer header to req if nodeKey is non-zero.
Types¶
typeClient¶
type Client struct {// Client is an HTTP client to talk to the coordination server.// It automatically makes a new Noise connection as needed.*http.Client// contains filtered or unexported fields}Client provides a http.Client to connect to tailcontrol overthe ts2021 protocol.
funcNewClient¶
func NewClient(optsClientOpts) (*Client,error)
NewClient returns a new noiseClient for the provided server and machine key.
netMon may be nil, if non-nil it's used to do faster interface lookups.dialPlan may be nil
func (*Client)Close¶
Close closes all the underlying noise connections.It is a no-op and returns nil if the connection is already closed.
func (*Client)DoWithBody¶
typeClientOpts¶
type ClientOpts struct {// ServerURL is the URL of the server to connect to.ServerURLstring// PrivKey is this node's private key.PrivKeykey.MachinePrivate// ServerPubKey is the public key of the server.// It is of the form https://<host>:<port> (no trailing slash).ServerPubKeykey.MachinePublic// Dialer's SystemDial function is used to connect to the server.Dialer *tsdial.Dialer// Logf is the log function to use.// If nil, log.Printf is used.Logflogger.Logf// NetMon is the network monitor that will be used to get the// network interface state. This field can be nil; if so, the current// state will be looked up dynamically.NetMon *netmon.Monitor// DNSCache is the caching Resolver to use to connect to the server.//// This field can be nil.DNSCache *dnscache.Resolver// HealthTracker, if non-nil, is the health tracker to use.HealthTracker *health.Tracker// DialPlan, if set, is a function that should return an explicit plan// on how to connect to the server.DialPlan func() *tailcfg.ControlDialPlan// ProtocolVersion, if non-zero, specifies an alternate// protocol version to use instead of the default,// of [tailcfg.CurrentCapabilityVersion].ProtocolVersionuint16}ClientOpts contains options for theNewClient function. All fields arerequired unless otherwise specified.
typeConn¶
type Conn struct {*controlbase.Conn// contains filtered or unexported fields}Conn is a wrapper around controlbase.Conn.
It allows attaching an ID to a connection to allow cleaning up references inthe pool when the connection is closed, properly handles an optional "earlypayload" that's sent prior to beginning the HTTP/2 session, and provides away to return a connection to a pool when the connection is closed.
UseNewConn to build a new Conn if you wantConn.GetEarlyPayload to work.Otherwise making a Conn directly, only setting Conn, is fine.
funcNewConn¶
func NewConn(conn *controlbase.Conn, onClose func()) *Conn
NewConn creates a new Conn that wraps the given controlbase.Conn.
h2t is the HTTP/2 transport to use for the connection; a newhttp2.ClientConn will be created that reads from the returned Conn.
connID should be a unique ID for this connection. When the Conn is closed,the onClose function will be called if it is non-nil.
func (*Conn)GetEarlyPayload¶
GetEarlyPayload waits for the early Noise payload to arrive.It may return (nil, nil) if the server begins HTTP/2 without one.
It is safe to call this multiple times; all callers will block until theearly Noise payload is ready (if any) and will return the same result forthe lifetime of the Conn.