Documentation
¶
Overview ¶
Package testclient is the shared connect/handshake/framing logic behind cmd/fakeagent and cmd/fakeclient — standalone processes that speak the real relay protocol (spec/PROTOCOL.md) for testing the relay, and later amallo and web, from outside the Go test binary. Nothing here is used by the relay server itself.
Index ¶
- Variables
- func RandomPairAndPSK() (pairID [16]byte, psk []byte, err error)
- type Transport
- func (t *Transport) Close() error
- func (t *Transport) Epoch() uint64
- func (t *Transport) RecvInner(ctx context.Context) (wire.InnerFrame, error)
- func (t *Transport) SendInner(ctx context.Context, f wire.InnerFrame) error
- func (t *Transport) SendInnerAt(ctx context.Context, epoch uint64, f wire.InnerFrame) error
- func (t *Transport) SendUnopenableCiphertext(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPeerOffline is returned from RecvInner once the relay reports the // other side has disconnected. The connection itself is still up: a // later peer_online starts a fresh session on it (spec §4.6), so a // caller that keeps reading recovers without reconnecting. ErrPeerOffline = errors.New("testclient: peer went offline") // ErrGoingAway is returned from RecvInner when the relay announces a // graceful shutdown. ErrGoingAway = errors.New("testclient: relay is going away") // ErrNoSession is returned by SendInner when there is no established // session to seal under — either none yet, or the one the caller // captured has since been replaced. ErrNoSession = errors.New("testclient: no established session") )
Functions ¶
func RandomPairAndPSK ¶
RandomPairAndPSK generates a fresh pair_id/psk (spec §4.2) — used when a caller wants fakeagent to mint new pairing material rather than reuse an existing one.
Types ¶
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is one connected session with the relay, from either role's perspective. The *connection* outlives any one session: a peer leaving retires the session, a peer arriving starts a new handshake on the same socket, and neither ends the connection (spec §4.6).
func Dial ¶
func Dial(ctx context.Context, relayURL string, role wire.Role, pairID [16]byte, psk []byte, insecure bool) (*Transport, error)
Dial connects to the relay and completes the control-channel hello.
For RoleClient it then waits for the peer and completes the first E2E handshake, so a caller can send the moment Dial returns. For RoleAgent it returns as soon as the relay acknowledges the hello — an agent is attached and useful before any browser exists, and its sessions come and go underneath (see RecvInner), which is what amallo does. In insecure mode channel 0x01 carries raw inner-frame bytes with no AEAD wrapping at all; that exists solely to exercise amallo's HTTP-bridge logic before its crypto is wired up, and must never be used against a production relay.
func (*Transport) Epoch ¶
Epoch identifies the current session. It changes whenever one is installed or retired, so a caller streaming a response can tell that the peer it was answering is gone — see SendInnerAt.
func (*Transport) RecvInner ¶
RecvInner returns the next inner frame, transparently handling multi-frame batched payloads (spec §6) by buffering, and carrying the session lifecycle underneath: `peer_online` starts a fresh handshake on this same socket, `peer_offline` retires the session and surfaces as a sentinel error the caller is expected to keep reading past.
func (*Transport) SendInner ¶
SendInner seals (or, in insecure mode, sends verbatim) a single inner frame under the current session. Safe for concurrent use — the internal mutex is exactly the single-sealing-point discipline spec §5.1 requires, made structurally hard to violate rather than merely documented.
func (*Transport) SendInnerAt ¶
SendInnerAt is SendInner, but only if the session is still the one the caller captured with Epoch(). A response being streamed for a request that arrived under an earlier session must not be sealed under the current one: the peer never sent that request and, worse, the frame consumes a counter the peer's opener is expecting for something else.
func (*Transport) SendUnopenableCiphertext ¶ added in v1.1.0
SendUnopenableCiphertext writes a channel-0x01 frame the peer's current session cannot open — the wire-level shape of "our keys and theirs have diverged", which is what a lost redial notification or a counter gap looks like from the other end.
It exists to test what that costs. The answer must be "the session", not "the connection": the peer retires its session, offers a fresh handshake, and everything else on that socket — the OpenAI endpoint's plain lane, the agent's registration — carries on untouched.