Documentation
¶
Overview ¶
Package broker implements the in-memory router that sits between intercom shims on a single host. One broker process serves all sessions; it is auto-spawned by the first shim and exits cleanly after a configurable idle period with no peers.
Wire protocol: see github.com/dpemmons/intercom/internal/wire. The broker is the server side; shims are clients.
Index ¶
Constants ¶
const ( DefaultIdleAfter = 10 * time.Minute IdleExitDisabled = -1 * time.Nanosecond DefaultHelloDeadline = 5 * time.Second DefaultDeliverDeadline = 5 * time.Second )
Defaults document tunable behavior. Tests use Options to override.
Variables ¶
var ErrLockHeld = errors.New("broker: another process holds the lock")
ErrLockHeld is returned when another broker process holds the singleton lock. Callers (typically the shim's auto-spawn path) should treat this as a success: another broker is already serving, so we should connect to it rather than start our own.
Functions ¶
func Run ¶
Run is the top-level entry point. It acquires the singleton lock, opens the listener, serves until ctx is cancelled or the idle timer fires, and cleans up on the way out. Returns nil for clean shutdown, ErrLockHeld if another broker is already running, or a non-nil error for any other startup failure.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker is the runtime state of a single broker process.
type Options ¶
type Options struct {
// SocketPath is the Unix socket path the broker listens on.
SocketPath string
// LockPath is the flock sentinel used to ensure only one broker runs at a
// time. If empty, defaults to SocketPath + ".lock".
LockPath string
// IdleAfter is how long the broker waits with zero peers before exiting.
// Zero selects DefaultIdleAfter; a negative duration disables idle exit.
// The CLI maps its user-facing --idle-after=0 value to IdleExitDisabled.
IdleAfter time.Duration
// HelloDeadline bounds how long a connection has to send its first
// frame. Zero selects DefaultHelloDeadline; a negative duration disables
// the deadline (not recommended).
HelloDeadline time.Duration
// DeliverDeadline bounds how long a deliver write to a peer may block
// before the peer is dropped as unresponsive. Zero selects
// DefaultDeliverDeadline; a negative duration disables the deadline.
DeliverDeadline time.Duration
// Logger receives structured log events. Required.
Logger *slog.Logger
}
Options configures a Broker.