libts

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanWrite

func CanWrite(ctx context.Context) bool

Returns true if the user has write permissions to the Tailscale config. If false, the user may have to run tsui with sudo.

func Down

func Down(ctx context.Context) error

Stop the Tailscale daemon.

func EditPrefs

func EditPrefs(ctx context.Context, maskedPrefs *ipn.MaskedPrefs) error

Update preferences.

func LockStatus

func LockStatus(ctx context.Context) (*ipnstate.NetworkLockStatus, error)

Return the tailnet lock status of the current node.

func Logout

func Logout(ctx context.Context) error

Logs you out.

func NewIPNStateFromString added in v0.2.0

func NewIPNStateFromString(v string) (ipn.State, error)

Create an ipn.State from the string representation.

This string representation comes from Tailscale's API and, because Go does not have proper enums, this is the best way to convert it back to a "typed" representation.

func PeerName

func PeerName(peer *ipnstate.PeerStatus) string

Get the user-friendly name of a Tailscale peer such as "foobar-router-2". This is distinct from the device name, which can have duplicates on the network, and from the DNS name, which includes the tailnet suffix.

func PingPeer

func PingPeer(ctx context.Context, peer *ipnstate.PeerStatus) (*ipnstate.PingResult, error)

Ping a peer.

func Prefs

func Prefs(ctx context.Context) (*ipn.Prefs, error)

Get current preferences.

func SetExitNode

func SetExitNode(ctx context.Context, peer *ipnstate.PeerStatus) error

Set the exit node to the given peer, or clear the exit node if peer is nil.

func StartLoginInteractive

func StartLoginInteractive(ctx context.Context) error

Start an interactive login flow. On macOS, this will automatically open the user's web browser.

func StartLoginInteractiveWillOpenBrowser added in v0.2.0

func StartLoginInteractiveWillOpenBrowser() bool

Returns true if StartLoginInteractive will (probably) open the user's web browser. Can be used to decide whether to display UI elements related to interactive login.

func Status

func Status(ctx context.Context) (*ipnstate.Status, error)

Return the Tailscale daemon status. Returns an error if the daemon is not running.

func Up

func Up(ctx context.Context) error

Start the Tailscale daemon.

Types

type State

type State struct {
	// Tailscale preferences.
	Prefs *ipn.Prefs

	// Current Tailscale backend state.
	BackendState ipn.State

	// Current Tailscale version. This is a shortened version string like "1.70.0".
	TSVersion string

	// Auth URL. Empty if the user doesn't need to be authenticated.
	AuthURL string
	// User profile of the currently logged in user or nil if unknown.
	User *tailcfg.UserProfile

	// Peer status of the local node.
	Self *ipnstate.PeerStatus

	// Tailnet lock key. Nil if not enabled.
	LockKey *key.NLPublic
	// True if the node is locked out by tailnet lock.
	IsLockedOut bool

	// Exit node peers sorted by PeerName.
	ExitNodes []*ipnstate.PeerStatus
	// Peers owned by the user sorted by PeerName.
	MyNodes []*ipnstate.PeerStatus
	// Tagged peers sorted by PeerName.
	TaggedNodes []*ipnstate.PeerStatus
	// Alphabetically sorted keys of AccountNodes.
	OwnedNodeKeys []string
	// Peers owned by other accoutns, sorted by PeerName, and keyed by account name.
	OwnedNodes map[string][]*ipnstate.PeerStatus

	// ID of the currently selected exit node or nil if none is selected.
	CurrentExitNode *tailcfg.StableNodeID
	// Name of the currently selected exit node or an empty string if none is selected.
	CurrentExitNodeName string

	// Total bytes received from peers.
	RxBytes int64
	// Total bytes sent to peers.
	TxBytes int64
}

Opinionated, sanitized subset of Tailscale state.

func GetState

func GetState(ctx context.Context) (State, error)

Make a current State by making necessary Tailscale API calls.

Jump to

Keyboard shortcuts

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