safesocket

package
v1.50.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: BSD-3-Clause Imports: 11 Imported by: 28

Documentation

Overview

Package safesocket creates either a Unix socket, if possible, or otherwise a localhost TCP connection.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenNotFound = errors.New("no token found")
	ErrNoTokenOnOS   = errors.New("no token on " + runtime.GOOS)
)

Functions

func ConnCloseRead

func ConnCloseRead(c net.Conn) error

ConnCloseRead calls c's CloseRead method. c is expected to be either a UnixConn or TCPConn as returned from this package.

func ConnCloseWrite

func ConnCloseWrite(c net.Conn) error

ConnCloseWrite calls c's CloseWrite method. c is expected to be either a UnixConn or TCPConn as returned from this package.

func Connect

func Connect(s *ConnectionStrategy) (net.Conn, error)

Connect connects to tailscaled using s

func GOOSUsesPeerCreds added in v1.8.0

func GOOSUsesPeerCreds(goos string) bool

GOOSUsesPeerCreds is like PlatformUsesPeerCreds but takes a runtime.GOOS value instead of using the current one.

func Listen

func Listen(path string) (net.Listener, error)

Listen returns a listener either on Unix socket path (on Unix), or the NamedPipe path (on Windows).

func LocalTCPPortAndToken added in v1.6.0

func LocalTCPPortAndToken() (port int, token string, err error)

LocalTCPPortAndToken returns the port number and auth token to connect to the local Tailscale daemon. It's currently only applicable on macOS when tailscaled is being run in the Mac Sandbox from the App Store version of Tailscale.

func PlatformUsesPeerCreds added in v1.6.0

func PlatformUsesPeerCreds() bool

PlatformUsesPeerCreds reports whether the current platform uses peer credentials to authenticate connections.

Types

type ConnectionStrategy added in v1.20.0

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

A ConnectionStrategy is a plan for how to connect to tailscaled or equivalent (e.g. IPNExtension on macOS).

This is a struct because prior to Tailscale 1.34.0 it was more complicated and there were multiple protocols that could be used. See LocalClient's dialer for what happens in practice these days (2022-11-28).

TODO(bradfitz): we can remove this struct now and revert this package closer to its original smaller API.

func DefaultConnectionStrategy added in v1.20.0

func DefaultConnectionStrategy(path string) *ConnectionStrategy

DefaultConnectionStrategy returns a default connection strategy. The default strategy is to attempt to connect in as many ways as possible. It uses path as the unix socket path, when applicable, and defaults to WindowsLocalPort for the TCP port when applicable. It falls back to auto-discovery across sandbox boundaries on macOS. TODO: maybe take no arguments, since path is irrelevant on Windows? Discussion in PR 3499.

Jump to

Keyboard shortcuts

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