agent

package
v0.1.125 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSuchHost        = errors.New("host was not found in DNS")
	ErrTunnelUnavailable = errors.New("tunnel unavailable")
)
View Source
var ErrAgentNotRunning = errors.New("agent not running")

Functions

func DialerWithContext added in v0.0.367

func DialerWithContext(ctx context.Context, dialer Dialer) context.Context

func PathToSocket

func PathToSocket() string

TODO: deprecate

func SetSysProcAttributes added in v0.1.117

func SetSysProcAttributes(cmd *exec.Cmd)

Types

type Client

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

func DefaultClient

func DefaultClient(ctx context.Context) (*Client, error)

func Dial

func Dial(ctx context.Context, network, addr string) (*Client, error)

func Establish

func Establish(ctx context.Context, apiClient *api.Client) (*Client, error)

Establish starts the daemon, if necessary, and returns a client to it.

func StartDaemon

func StartDaemon(ctx context.Context) (*Client, error)

func (*Client) ConnectToTunnel

func (c *Client) ConnectToTunnel(ctx context.Context, slug string) (d Dialer, err error)

ConnectToTunnel is a convenience method for connect to a wireguard tunnel and returning a Dialer. Only suitable for use in the new CLI commands.

func (*Client) Dialer

func (c *Client) Dialer(ctx context.Context, slug string) (d Dialer, err error)

Dialer establishes a connection to the wireguard agent and return a dialier for use in subsequent actions, such as running ssh commands or opening proxies

func (*Client) Establish

func (c *Client) Establish(ctx context.Context, slug string) (res *EstablishResponse, err error)

func (*Client) Instances

func (c *Client) Instances(ctx context.Context, org, app string) (instances Instances, err error)

func (*Client) Kill

func (c *Client) Kill(ctx context.Context) error

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) (res PingResponse, err error)

func (*Client) Pinger

func (c *Client) Pinger(ctx context.Context, slug string) (p *Pinger, err error)

Pinger creates a Pinger struct. It does this by first ensuring a WireGuard session exists for the specified org, and then opening an additional connection to the agent, which is upgraded to a Pinger connection by sending the "ping6" command. Call "Close" on a Pinger when you're done pinging things.

func (*Client) Probe

func (c *Client) Probe(ctx context.Context, slug string) error

func (*Client) Reestablish

func (c *Client) Reestablish(ctx context.Context, slug string) (res *EstablishResponse, err error)

func (*Client) Resolve

func (c *Client) Resolve(ctx context.Context, slug, host string) (addr string, err error)

func (*Client) WaitForDNS

func (c *Client) WaitForDNS(parent context.Context, dialer Dialer, slug string, host string) (err error)

WaitForDNS waits for a Fly host internal DNS entry to register

func (*Client) WaitForTunnel

func (c *Client) WaitForTunnel(parent context.Context, slug string) (err error)

WaitForTunnel waits for a tunnel to the given org slug to become available in the next four minutes.

type Dialer

type Dialer interface {
	State() *wg.WireGuardState
	Config() *wg.Config
	DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}

TODO: refactor to struct

func DialerFromContext added in v0.0.367

func DialerFromContext(ctx context.Context) Dialer

type EstablishResponse

type EstablishResponse struct {
	WireGuardState *wg.WireGuardState
	TunnelConfig   *wg.Config
}

type Instances

type Instances struct {
	Labels    []string
	Addresses []string
}

type PingResponse

type PingResponse struct {
	PID        int
	Version    string
	Background bool
}

type Pinger

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

Pinger wraps a connection to the flyctl agent over which ICMP requests and replies are written. There's a simple protocol for encapsulating requests and responses; drive it with the Pinger member functions. Pinger implements most of net.PacketConn but is not really intended as such.

func (*Pinger) Close

func (p *Pinger) Close() error

func (*Pinger) Err

func (p *Pinger) Err() error

Err returns any non-recoverable error seen on this Pinger connection; WriteTo and ReadFrom on a Pinger will not function if Err returns non-nil.

func (*Pinger) ReadFrom

func (p *Pinger) ReadFrom(buf []byte) (int64, net.Addr, error)

ReadFrom reads an ICMP message from a Pinger, using the same protocol as WriteTo. Call `SetReadDeadline` to poll this interface while watching channels or whatever.

func (*Pinger) SetReadDeadline

func (p *Pinger) SetReadDeadline(t time.Time) error

func (*Pinger) WriteTo

func (p *Pinger) WriteTo(buf []byte, addr net.Addr) (int64, error)

WriteTo writes an ICMP message, including headers, to the specified address. `addr` should always be an IPv6 net.IPAddr beginning with `fdaa` --- you cannot ping random hosts on the Internet with this interface. See golang/x/net/icmp for message construction details; this interface uses gVisor netstack, which is fussy about ICMP, and will only allow icmp.Echo messages with a code of 0.

Pinger runs a trivial protocol to encapsulate ICMP messages over agent connections: each message is a 16-byte IPv6 address, followed by an NBO u16 length, followed by the ICMP message bytes, which again must begin with an ICMP header. Checksums are performed by netstack; don't bother with them.

Directories

Path Synopsis
internal
proto
Package proto implements the agent's protocol.
Package proto implements the agent's protocol.

Jump to

Keyboard shortcuts

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