grpcserver

package
v0.2.2 Latest Latest
Warning

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

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

Documentation

Overview

Package grpcserver implements the candacenet.warden.v1 WardenService: the three unary cluster RPCs (Vote/Heartbeat/Identify) delegating to the existing warden.IRPCHandler through the wireconv boundary, and the server-streaming WatchCluster that pushes full ClusterView snapshots from a warden.IViewSource.

The server holds no mutable state of its own: the unary handlers are pure delegations and every WatchCluster invocation is an independent consumer goroutine (see watch.go). Error codes follow the single table in errors.go, which is the package's contract with clients: every code a caller can observe is named there, no handler invents one inline, and a code in that table is wire behaviour rather than an implementation detail. Embedding the generated Unimplemented base means a schema that grows a new RPC still compiles here, so additive schema growth never breaks a node mid-upgrade.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGRPCServer

func NewGRPCServer(s *Server) *grpc.Server

NewGRPCServer builds a *grpc.Server for h2c (cleartext HTTP/2) serving with the warden panic-recovery interceptors installed and s registered. The listener it is served on provides transport security (the tailnet), so no transport credentials are configured here — see the grpcmux package.

Types

type Server

type Server struct {
	wardenv1.UnimplementedWardenServiceServer
	// contains filtered or unexported fields
}

Server adapts a warden.IRPCHandler and a warden.IViewSource to the generated WardenService. Embedding the Unimplemented base keeps it forward-compatible with additive schema growth.

func New

func New(rpc warden.IRPCHandler, views warden.IViewSource, drain context.Context) *Server

New builds a Server. drain is the process shutdown signal for WatchCluster streams; pass a never-canceled context (or nil) when there is no drain coordinator (e.g. focused tests). The structured logger is captured from core.Logger at construction, matching the election manager.

func (*Server) Heartbeat

Heartbeat delegates a HeartbeatRequest to the RPCHandler. A heartbeat asserting no leader is rejected with InvalidArgument (leader_id is required).

func (*Server) Identify

Identify answers the cluster-identity handshake. The request is intentionally empty, so there is nothing to validate.

func (*Server) Vote

Vote delegates a VoteRequest to the RPCHandler. A vote naming no candidate is rejected with InvalidArgument (candidate_id is required); the handler itself never fails, so success is the only other outcome.

func (*Server) WatchCluster

WatchCluster streams full ClusterView snapshots to a client, one per observed cluster-state change, keyed by ClusterViewCursor for dedup and resume.

The handler is a self-contained consumer goroutine (the one gRPC runs it in). It owns exactly one ViewSource subscription and tears it down on return. It never blocks the election loop: the subscription channel is best-effort (the loop drops when the buffer is full), and on every wake the handler re-reads ViewSource.View() for the LATEST snapshot rather than trusting the channel payload — a slow client therefore skips straight to current state (drop-to-latest) instead of applying a backlog, and the loop is never back-pressured.

Dedup: two snapshots with an equal cursor denote the same observable state, so a repeat (e.g. the periodic publish tick re-emitting an unchanged follower view) is suppressed. The `since` cursor lets a resuming client suppress the redundant initial snapshot when its state already matches.

Teardown: the select watches the stream context (client disconnect or RPC deadline) AND the server drain signal, so the handler always returns promptly and unsubscribes — no goroutine or subscription leak. Removing the stream-ctx case would leak the handler goroutine on client disconnect; that is the goroutine-leak counterfactual the contract suite exercises.

Jump to

Keyboard shortcuts

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