internalrpc

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package internalrpc is the server-to-server RPC plumbing for the fleet: a per-peer connection pool, API-key authentication for internal-only endpoints, and helpers for forwarding a request to the member that owns its key. It carries no domain knowledge — event forwarding and cluster ownership forwarding ride the same machinery.

Index

Constants

View Source
const APIKeyHeaderName = "x-flipcash-internal-rpc-api-key"

APIKeyHeaderName carries the internal RPC API key. Internal endpoints are reachable on the public gRPC surface, so every internal RPC must present a key and every internal handler must verify one.

Variables

View Source
var ErrPoolClosed = errors.New("internal rpc connection pool is closed")

ErrPoolClosed is returned by Conn after Close: a connection created past Close would never be closed or reaped.

Functions

func RedirectAddress

func RedirectAddress(err error) (address string, ok bool)

RedirectAddress extracts the forwarding target from an Ownership.Do error. ok is true only when the error is a NotOwnerError naming a member: forward the request to the returned address (and report a failed forward via Ownership.NoteUnreachable). ok is false for a redirect-less NotOwnerError — no healthy owner is known, so use the store-serialized fallback — and for every other error.

func WithAPIKey

func WithAPIKey(ctx context.Context, apiKey string) (context.Context, error)

WithAPIKey returns ctx with headers initialized (if they aren't already) and the internal API key header set — the client side of internal RPC auth.

Types

type Authenticator

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

Authenticator verifies internal API keys on incoming RPCs. It holds the set of currently accepted keys, which may exceed one so keys can be rotated across a deploy without rejecting in-flight traffic.

func NewAuthenticator

func NewAuthenticator(apiKeys ...string) *Authenticator

NewAuthenticator creates an authenticator accepting the given keys. Empty keys are discarded: an absent header reads back as the empty string, so accepting "" (e.g. from an unset config value) would leave internal endpoints open to unauthenticated callers on the public gRPC surface. An authenticator left with no keys denies everything — a misconfiguration fails closed and loud, never open.

func (*Authenticator) Allow

func (a *Authenticator) Allow(ctx context.Context) (bool, error)

Allow reports whether the RPC presented an accepted internal API key. A malformed header is an error; an absent header (which reads as "") or a well-formed but unaccepted key is (false, nil) so handlers can return their endpoint's denial shape.

type Pool

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

Pool caches one gRPC client connection per peer address. Connections are created lazily, shared by all callers, and reaped only once they report broken (peer addresses die with their instances, so idle-but-healthy conns are cheap and worth keeping).

func NewPool

func NewPool(log *zap.Logger) *Pool

NewPool creates a connection pool and starts its background reaper.

func (*Pool) Close

func (p *Pool) Close()

Close shuts down every pooled connection and stops the reaper. Subsequent (or racing) Conn calls return ErrPoolClosed.

func (*Pool) Conn

func (p *Pool) Conn(address string) (*grpc.ClientConn, error)

Conn returns the pooled connection for the address, creating it if needed.

Jump to

Keyboard shortcuts

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