Help us shape the future of Go! Take the 2026 Go Developer Survey

protocol

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package protocol pairs the reference and candidate traffic that protocol servers report, compares ingress responses, and replays egress responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Acceptor

type Acceptor interface {
	// ProcessRequest decides what a server does with a request. ignored explains why
	// ingress never compares its responses. An error means the request must not be sent.
	ProcessRequest(ctx context.Context, requestID Option[RequestID], route model.Route, ignored Option[string],
		request func(ctx context.Context) (Message, error)) (Decision, error)
	// ProcessResponse reports the response to a forwarded request. The engine owns
	// response.Raw from here on.
	ProcessResponse(ctx context.Context, exchange Exchange, response Response)
	// Unable ends a forwarded request whose response cannot be compared or replayed.
	// A cancelled ctx explains the failure, so it never quarantines the candidate.
	Unable(ctx context.Context, exchange Exchange, reason error)
}

Acceptor receives the requests and responses at one ingress or egress point, so servers never know whether they carry reference or candidate traffic.

type Config

type Config struct {
	// Comparison configures the scripts that normalise, compare, and hash payloads.
	Comparison comparison.Config `embed:""`
	// MatchWindow bounds how long an unused reference stays available, and how
	// long a candidate waits for one.
	MatchWindow time.Duration `default:"5s" help:"How long reference and candidate requests wait to be paired."`
}

Config contains the command-line configuration for pairing and comparison.

func NewConfig

func NewConfig() Config

NewConfig returns the default engine configuration.

func (Config) Validate

func (c Config) Validate() error

Validate checks that the engine configuration is usable.

type Content

type Content struct {
	// Status is absent only when Failure explains why.
	Status  Option[string]
	Message Option[Message]
	Failure Option[error]
}

Content is a response's comparable content. Comparison checks Status when both sides know it, then Failure, then Message.

type Decision

type Decision interface {
	// contains filtered or unexported methods
}

Decision tells a server what to do with a request.

type DecisionForward

type DecisionForward struct {
	RequestID Option[RequestID]
	Exchange  Exchange
}

DecisionForward sends the request on. The server reports the response under Exchange, and passes RequestID to a candidate when one is assigned.

type DecisionIntercept

type DecisionIntercept struct{ Raw Raw }

DecisionIntercept answers the request with Raw instead of sending it. The server releases Raw once replay finishes.

type Declaration

type Declaration interface {
	// contains filtered or unexported methods
}

Declaration is what a script declares for a protocol pattern.

type DeclarationIgnore

type DeclarationIgnore struct{ Reason string }

DeclarationIgnore skips comparison of ingress responses.

type DeclarationRequest

type DeclarationRequest struct{ Type schema.TypeRef }

DeclarationRequest types the requests that egress forwards to a dependency.

type DeclarationResponse

type DeclarationResponse struct{ Type schema.TypeRef }

DeclarationResponse types the responses that ingress compares.

type Engine

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

Engine owns the in-flight state that every Acceptor shares.

func NewEngine

func NewEngine(
	ctx context.Context,
	config Config,
	matchers map[model.Protocol]Matcher,
	quarantine Quarantiner,
) (*Engine, error)

NewEngine loads the scripts and passes each declaration to the matcher for its protocol. A script naming an unregistered protocol fails startup.

func (*Engine) EgressCandidate

func (e *Engine) EgressCandidate(protocol model.Protocol) Acceptor

EgressCandidate returns the acceptor for the candidate's dependency requests.

func (*Engine) EgressReference

func (e *Engine) EgressReference(protocol model.Protocol) Acceptor

EgressReference returns the acceptor for the reference's dependency requests.

func (*Engine) IngressCandidate

func (e *Engine) IngressCandidate(protocol model.Protocol) Acceptor

IngressCandidate returns the acceptor for mirrored requests to the candidate service.

func (*Engine) IngressReference

func (e *Engine) IngressReference(protocol model.Protocol) Acceptor

IngressReference returns the acceptor for requests to the reference service.

func (*Engine) Schema

func (e *Engine) Schema() *schema.Schema

Schema returns the types that servers decode messages as.

func (*Engine) Shutdown

func (e *Engine) Shutdown(ctx context.Context) error

Shutdown waits for background work on requests that have already been forwarded.

type Exchange

type Exchange struct {
	typeid.TypeID[exchangePrefix]
}

Exchange links a forwarded request to its response. It is unique within one engine, so it never leaves the process that forwarded the request.

type Matcher

type Matcher interface {
	Declare(pattern string, declaration Declaration) error
}

Matcher owns a protocol's pattern table. The engine passes it every script declaration for its protocol at startup, so invalid patterns fail startup.

type Message

type Message struct {
	Type  Option[schema.TypeRef]
	Value any
}

Message is a decoded payload. One without a Type is compared without normalisers.

type Quarantiner

type Quarantiner interface {
	Quarantine(ctx context.Context, reason model.QuarantineReason)
}

Quarantiner stops all candidate traffic.

type Raw

type Raw interface {
	Release()
}

Raw is a server's own record of a response, which an intercept replays. Release frees it, and must be safe to call more than once.

type RequestID

type RequestID struct {
	typeid.TypeID[requestPrefix]
}

RequestID links a mirrored inbound request to the operations it causes.

type Response

type Response struct {
	Raw Raw
	// Latency is the time to the first response byte, or zero if unmeasured.
	Latency time.Duration
	// Decode is called only to compare, on the candidate's time rather than the
	// reference's, and while the engine still holds Raw.
	Decode func() Content
}

Response is what a server received for a forwarded request.

Jump to

Keyboard shortcuts

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