relayclient

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package relayclient carries a sensor's platform requests through a sensor relay (api docs/rfcs/RFC-116-sensor-relay.md in openctemio/openctem; openctem research 194 §4).

Transport is an http.RoundTripper. Put it under the request signer (sensorsig.Transport's Base): each signed v2 request is sealed to the platform's ingest key (pkg/sealedmsg) and posted to the relay; the answer arrives on the sensor's relay mailbox, sealed to the sensor's encryption key and signed by the platform's response key, and is handed back as the request's http.Response. The relay can delay or drop traffic; it cannot read it, change it or answer in the platform's name.

Connection: TLS 1.3 to the relay, the relay's certificate checked by its SPKI pin from the pairing bundle (or by RootCAs when no pin is set), the sensor's identity key as the client certificate, and the platform-signed ticket on every request (Config.Ticket returns the current one; the sensor renews it through the relay itself).

Stability: Experimental (docs/STABILITY.md).

Index

Constants

View Source
const (
	DefaultResponseTimeout = 60 * time.Second
)

Defaults.

Variables

View Source
var (
	// ErrNoResponse: the platform's answer did not arrive in time (the
	// request may or may not have been processed; callers retry
	// idempotently, as for any lost response).
	ErrNoResponse = errors.New("relayclient: no response through the relay in time")
	// ErrTicket: the relay refused the ticket (expired, revoked, another
	// relay): renew it.
	ErrTicket = errors.New("relayclient: relay refused the ticket")
	// ErrPin: the relay's certificate does not match the pinned key.
	ErrPin = errors.New("relayclient: relay certificate does not match the pin")
)

Errors.

Functions

This section is empty.

Types

type Config

type Config struct {
	// RelayURL is the relay's base URL (https).
	RelayURL string
	// RelayPin is the SHA-256 of the relay certificate's
	// SubjectPublicKeyInfo (from the pairing bundle). When set, the
	// certificate chain is not used: the pin is the trust anchor.
	RelayPin []byte
	// RootCAs verifies the relay's certificate when no pin is set (nil:
	// the system roots).
	RootCAs *x509.CertPool
	// Identity is the sensor's Ed25519 identity key: the TLS client key the
	// ticket names.
	Identity ed25519.PrivateKey
	// Ticket returns the current relay ticket.
	Ticket func() string
	// Route is the sensor's realm and id (from its pairing).
	Route sealedmsg.Route
	// IngestKey is the platform's current ingest key.
	IngestKey *sealedmsg.PublicKey
	// ResponseKeys are the pinned platform response keys.
	ResponseKeys []ed25519.PublicKey
	// EncryptionKey is the sensor's own encryption key.
	EncryptionKey *sealedmsg.PrivateKey
	// Proxy is the control path's proxy (nil: none).
	Proxy func(*http.Request) (*url.URL, error)
	// ResponseTimeout bounds the wait for one answer (default 60 s).
	ResponseTimeout time.Duration
	// OnTicketRefused is called when the relay refuses the ticket.
	OnTicketRefused func()
	// Logf receives state changes (default: none).
	Logf func(format string, args ...any)
	// contains filtered or unexported fields
}

Config configures a Transport.

type Stats

type Stats struct {
	Sent            int64 `json:"sent"`
	Answered        int64 `json:"answered"`
	TimedOut        int64 `json:"timed_out"`
	DroppedForeign  int64 `json:"dropped_foreign"`  // responses that answered no outstanding request
	DroppedRefused  int64 `json:"dropped_refused"`  // envelopes that did not open or verify
	RelayThrottled  int64 `json:"relay_throttled"`  // 429 from the relay
	TicketRefusals  int64 `json:"ticket_refusals"`  // 401 from the relay
	PollErrors      int64 `json:"poll_errors"`      // failed mailbox polls
	PendingRequests int64 `json:"pending_requests"` // waiting for an answer now
}

Stats are the transport's counters.

type Transport

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

Transport is the relay round tripper.

func New

func New(cfg Config) (*Transport, error)

New checks the configuration and builds a Transport. Call Run to start receiving answers.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip seals the request, posts it to the relay and waits for the platform's answer.

func (*Transport) Run

func (t *Transport) Run(ctx context.Context)

Run polls the sensor's relay mailbox and hands answers to waiting requests until ctx ends. Failures back off with full jitter up to 60 s.

func (*Transport) Stats

func (t *Transport) Stats() Stats

Stats returns the counters.

Jump to

Keyboard shortcuts

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