grpc

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package grpc implements the config-sync gRPC transport: the control-plane server, the data-plane client, the connection hub, and the auth interceptors and credentials that secure the channel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScopeFromContext

func ScopeFromContext(ctx context.Context) string

func WithScope

func WithScope(ctx context.Context, scope string) context.Context

Types

type AuthInterceptor

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

func NewAuthInterceptor

func NewAuthInterceptor(cfg *config.Config, logger *slog.Logger) (*AuthInterceptor, error)

func (*AuthInterceptor) StreamServerInterceptor

func (a *AuthInterceptor) StreamServerInterceptor() grpc.StreamServerInterceptor

func (*AuthInterceptor) UnaryServerInterceptor

func (a *AuthInterceptor) UnaryServerInterceptor() grpc.UnaryServerInterceptor

type Client

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

Client is the data-plane end of the config-sync transport. It implements configsync.ConfigFetcher (Fetch via GetSnapshot) and configsync.StreamTransport (Watch/Ack via the long-lived Sync stream), reconnecting the Sync stream on break.

func NewClient

func NewClient(cfg config.ConfigSyncConfig, logger *slog.Logger) (*Client, error)

NewClient dials the control plane with TLS (or dev-insecure), per-RPC bearer credentials, and keepalive tuning.

func (*Client) Ack

func (c *Client) Ack(_ context.Context, appliedVersion string) error

Ack reports the applied version to the control plane over the Sync stream.

func (*Client) Close

func (c *Client) Close() error

Close cancels the Sync stream context and tears down the underlying connection, unblocking any in-flight stream receive.

func (*Client) Endpoint

func (c *Client) Endpoint() string

Endpoint returns the control-plane gRPC address the client dials.

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, etag string) ([]byte, string, bool, error)

Fetch pulls the current snapshot via GetSnapshot, short-circuiting on not_modified and verifying the reassembled body length against the header.

func (*Client) Watch

func (c *Client) Watch(_ context.Context) (string, error)

Watch blocks for the next VersionNotice on the Sync stream, reopening the stream (and re-sending Hello) when it is not yet established or has broken.

type ConnectionStore

type ConnectionStore interface {
	MarkConnected(ctx context.Context, scope, instanceID string) error
	MarkAck(ctx context.Context, scope, instanceID, appliedVersion string) error
	MarkDisconnected(ctx context.Context, scope, instanceID string) error
}

ConnectionStore persists the observed lifecycle of data-plane Sync streams so the control plane can answer "is this data plane online?". The Hub calls it best-effort: a nil store or a returned error must never fail a stream or the fail-closed verification path. scope is opaque to the store.

type Hub

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

Hub is the registry of connected data-plane Sync streams. Broadcast fans a new version out to every connection through a latest-only, size-1 drop-oldest channel so a slow consumer never blocks the dispatcher and only the newest version is ever delivered. When a ConnectionStore is present the Hub also records each stream's lifecycle best-effort for the admin read API.

func NewHub

func NewHub(logger *slog.Logger, store ConnectionStore) *Hub

NewHub builds an empty Hub. store may be nil, in which case connection lifecycle is not persisted (in-memory-only self-host).

func (*Hub) Broadcast

func (h *Hub) Broadcast(version string)

Broadcast delivers version to every connected data plane, coalescing to the newest version per connection. It never blocks.

func (*Hub) ConnectionCount

func (h *Hub) ConnectionCount() int

ConnectionCount reports the number of registered data-plane streams.

type Server

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

Server wraps a *grpc.Server and its listener, implementing the shared server.Server Run/Shutdown lifecycle contract so the control-plane gRPC listener slots into the shared serve loop.

func NewServer

NewServer builds the control-plane ConfigSync gRPC listener with TLS (when configured), the auth interceptors, and keepalive enforcement.

func (*Server) Run

func (s *Server) Run() error

Run serves until Shutdown is called, mapping the graceful-stop signal to a clean nil return.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown gracefully drains in-flight RPCs and stops the listener.

type Service

type Service struct {
	snapshotpb.UnimplementedConfigSyncServer
	// contains filtered or unexported fields
}

Service implements the ConfigSync gRPC server: the bidi Sync control channel and the server-streaming GetSnapshot bulk transfer.

func NewService

func NewService(hub *Hub, source SnapshotSource, logger *slog.Logger) *Service

NewService builds the ConfigSync server implementation.

func (*Service) GetSnapshot

GetSnapshot answers not_modified when the DP's applied_version matches current, otherwise streams a SnapshotHeader followed by fixed-size data chunks.

func (*Service) Sync

Sync registers the data plane's stream, pushes an immediate notice when the DP's last-applied version is stale, then forwards broadcasts as VersionNotice messages while draining the DP's Acks.

type SnapshotSource

type SnapshotSource interface {
	SnapshotFor(scope string) (raw []byte, version string, ok bool)
}

Jump to

Keyboard shortcuts

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