Documentation
¶
Overview ¶
Package client reaches an agent through a relay, or directly when it can, over an end-to-end encrypted session.
The short version:
c, _ := client.New("https://relay.example.com/#k=…", nil)
resp, _ := c.HTTPClient().Get("http://agent/api/status")
Client picks the fastest path (direct candidates race the relay), redials when the connection drops, and upgrades from the relay to a direct path in the background when one becomes reachable.
Index ¶
- Variables
- func StreamConn(st *mux.Stream, path string) net.Conn
- type Client
- func (c *Client) Close() error
- func (c *Client) Conn(ctx context.Context) (*Conn, error)
- func (c *Client) DialTCP(ctx context.Context, target string) (net.Conn, error)
- func (c *Client) DialWebSocket(ctx context.Context, path string, protocols ...string) (*wskind.Conn, string, error)
- func (c *Client) HTTPClient() *http.Client
- func (c *Client) Open(ctx context.Context, kind string, meta any) (*mux.Stream, error)
- func (c *Client) Path() string
- func (c *Client) Transport() http.RoundTripper
- type Conn
- type Mode
- type Options
Constants ¶
This section is empty.
Variables ¶
var ErrAgentOffline = errors.New("client: agent is offline, or the code is wrong")
ErrAgentOffline is returned when the relay has no agent for this code. A wrong code looks the same as an offline agent: the relay only sees hashes.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client keeps one live encrypted session to an agent.
func New ¶
New parses a connection string and returns a Client. It does not dial until the first use.
func (*Client) DialTCP ¶
DialTCP opens a raw byte stream to one of the agent's named TCP targets ("" is the default target).
func (*Client) DialWebSocket ¶
func (c *Client) DialWebSocket(ctx context.Context, path string, protocols ...string) (*wskind.Conn, string, error)
DialWebSocket opens a WebSocket to path on the agent.
func (*Client) HTTPClient ¶
HTTPClient returns an http.Client whose requests travel over the session. The URL's scheme and host are ignored; only path and query are sent. Each request redials if the session is gone.
func (*Client) Transport ¶
func (c *Client) Transport() http.RoundTripper
Transport is the http.RoundTripper behind HTTPClient.
type Conn ¶
type Conn struct {
Session *mux.Session
Path string
Hello *e2e.AgentHello
}
Conn is one established session.
type Options ¶
type Options struct {
Name string // sent to the agent inside the encrypted hello
Mode Mode // path selection, Auto by default
Direct []string // extra direct candidates (ws:// or wss:// URLs)
// RelayDelay is how long direct candidates get a head start (default 250ms).
RelayDelay time.Duration
// DirectTimeout bounds one direct attempt (default 2s).
DirectTimeout time.Duration
// UpgradeInterval is how often a relayed client probes direct
// candidates (default 30s; negative disables).
UpgradeInterval time.Duration
HTTPClient *http.Client
Logger *slog.Logger
// OnPath is called whenever the active path changes.
OnPath func(path string)
// Accept handles streams the agent opens toward this client. Optional.
Accept func(ctx context.Context, st *mux.Stream)
}
Options configure a Client. All fields are optional.