tunnel

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tunnel implements the node side of flock.tunnel.v1.TunnelService: the persistent, node-initiated session over which the coordinator pushes dispatches, challenges and model assignments (SPEC §3: nodes dial out, never listen).

Index

Constants

View Source
const (
	// PingInterval is how long the connection may sit quiet before we ping.
	PingInterval = 20 * time.Second
	// PingTimeout is how long we wait for a ping ack before concluding the
	// connection is dead and reconnecting.
	PingTimeout = 10 * time.Second
)

Keepalive for the coordinator connection.

The daemon holds one long-lived stream open across whatever network the operator happens to be on, where a connection can die with neither end told. The heartbeat we send every few seconds proves this node is alive; it does not prove the path still works. On a half-open connection the heartbeats vanish, the coordinator closes the session and stops routing to us, and we notice only when the OS finally gives up on a write — minutes later, during which the dashboard cheerfully reports "serving". Pings turn that into seconds.

PingInterval is a CROSS-REPO CONTRACT: the coordinator rejects clients that ping more often than coordinator.PingMinTime by answering GOAWAY "too_many_pings" and closing the connection. Pinging faster than the server permits does not just fail to help, it actively disconnects every node. Keep this >= the coordinator's PingMinTime, and never lower it without deploying the server first.

Variables

View Source
var ErrBadSignature = errors.New("tunnel: dispatch signature verification failed")

ErrBadSignature means a DispatchRequest failed verification against the pinned coordinator key. Such dispatches are never executed (SPEC §6).

Functions

func SignDispatch

func SignDispatch(priv ed25519.PrivateKey, d *tunnelv1.DispatchRequest) error

SignDispatch sets d.Signature (coordinator side; used by fakecoord and control-plane tests).

func VerifyDispatch

func VerifyDispatch(pub ed25519.PublicKey, d *tunnelv1.DispatchRequest) error

VerifyDispatch checks d.Signature against the pinned coordinator key.

Types

type Admitter

type Admitter interface {
	Admit(ctx context.Context, id string) (context.Context, func(), error)
}

Admitter gates work through the governor. *governor.Governor satisfies it.

type Client

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

Client maintains the session and handles pushed work.

func NewClient

func NewClient(o Options) (*Client, error)

NewClient validates options and builds a client.

func (*Client) EffectiveMaxConcurrent added in v0.3.0

func (c *Client) EffectiveMaxConcurrent() int

EffectiveMaxConcurrent is min(operator cap, coordinator cap), 0 = none.

func (*Client) Run

func (c *Client) Run(ctx context.Context)

Run keeps the session alive until ctx is cancelled, reconnecting with jittered exponential backoff.

func (*Client) SendModelState added in v0.3.0

func (c *Client) SendModelState(m *typesv1.ModelState) error

SendModelState pushes a ModelStateUpdate on the live session (model assignment progress). Errors when no session is up.

func (*Client) Sessions

func (c *Client) Sessions() int

Sessions returns the number of successful handshakes (reconnect tests).

type Dialer

type Dialer interface {
	Dial(ctx context.Context, addr string) (*grpc.ClientConn, error)
}

Dialer abstracts the transport so it can swap without touching the session logic. Production transport is QUIC via quic-go (SPEC §6); gRPC-over-HTTP/2 with mTLS is the current implementation and remains the documented fallback. TODO(quic): add a quic-go Dialer implementing this interface once the coordinator terminates QUIC.

type Engine

type Engine interface {
	Complete(ctx context.Context, req rt.CompletionRequest) (rt.TokenStream, error)
}

Engine runs inference for dispatches and challenges. Satisfied by the daemon's engine wrapper around runtime.Instance.

type InsecureDialer

type InsecureDialer struct{}

InsecureDialer is for local development only.

func (InsecureDialer) Dial

type Options

type Options struct {
	Dialer Dialer
	Addr   string
	NodeID string
	// CoordinatorPubKey is the Ed25519 dispatch-signing key pinned at
	// enrollment. Required: dispatches with bad signatures are dropped.
	CoordinatorPubKey ed25519.PublicKey

	Engine Engine
	Admit  Admitter
	// Heartbeat returns a fresh heartbeat message (telemetry assembly).
	Heartbeat func() *tunnelv1.Heartbeat
	// Hello returns the session-open message (capability, models, budget).
	Hello func() *tunnelv1.Hello
	// OnModelAssignment is invoked for coordinator model placement pushes.
	OnModelAssignment func(ctx context.Context, ma *tunnelv1.ModelAssignment)
	// OnConfigUpdate observes coordinator ConfigUpdates after the client
	// has applied what it owns (heartbeat cadence, concurrency cap).
	OnConfigUpdate func(cu *tunnelv1.ConfigUpdate)
	// MaxConcurrent is the operator's dispatch concurrency ceiling
	// (budget.max_concurrent). The coordinator may lower the effective cap
	// with ConfigUpdate.max_concurrent_requests, never raise it. 0 = no cap.
	MaxConcurrent int

	HeartbeatInterval time.Duration
	ReconnectMin      time.Duration
	ReconnectMax      time.Duration
	Log               *slog.Logger
}

Options configures the Client.

type TLSDialer

type TLSDialer struct {
	// TLS may carry RootCAs (pinned coordinator CA) and Certificates
	// (client cert from enrollment).
	TLS *tls.Config
}

TLSDialer dials gRPC over TLS/H2, optionally with a client certificate (mTLS after enrollment).

func (*TLSDialer) Dial

func (d *TLSDialer) Dial(_ context.Context, addr string) (*grpc.ClientConn, error)

Directories

Path Synopsis
Package fakecoord is an in-process fake coordinator implementing flock.tunnel.v1.TunnelService over bufconn (SPEC §A2.2 key seam).
Package fakecoord is an in-process fake coordinator implementing flock.tunnel.v1.TunnelService over bufconn (SPEC §A2.2 key seam).

Jump to

Keyboard shortcuts

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