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
- Variables
- func DialOptions() []grpc.DialOption
- func SignDispatch(priv ed25519.PrivateKey, d *tunnelv1.DispatchRequest) error
- func VerifyDispatch(pub ed25519.PublicKey, d *tunnelv1.DispatchRequest) error
- type Admitter
- type Client
- func (c *Client) Earnings() (EarningsState, bool)
- func (c *Client) EffectiveMaxConcurrent() int
- func (c *Client) Run(ctx context.Context)
- func (c *Client) SendBudget() error
- func (c *Client) SendModelState(m *typesv1.ModelState) error
- func (c *Client) Sessions() int
- func (c *Client) SetMaxConcurrent(n int)
- type Dialer
- type EarningsState
- type Engine
- type ImageTaker
- type InsecureDialer
- type Options
- type ReleaseSink
- type TLSDialer
Constants ¶
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.
const MaxMessageBytes = 64 << 20
MaxMessageBytes is the largest message the node accepts on the tunnel. gRPC's default for a received message is 4 MiB; a dispatch may carry images by value (4 x 10 MiB at the gateway's default limits), so the limit matches the coordinator's (control-plane coordinator. MaxMessageBytes; proto design note 2026-11-29). Only what the coordinator signed is ever this large.
const RejectModelNotReady = "model-not-ready"
RejectModelNotReady is the DispatchAck reason for a model this node cannot serve the request on right now; the coordinator treats it as routing information (control-plane coordinator/inflight.go).
Variables ¶
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 DialOptions ¶ added in v0.9.7
func DialOptions() []grpc.DialOption
DialOptions are the options every tunnel connection is dialled with, whatever its transport: keepalive pings and the message size limit. The in-memory test coordinator (fakecoord) uses them too, so its tests run under the limit production runs under.
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 Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client maintains the session and handles pushed work.
func (*Client) Earnings ¶ added in v0.6.1
func (c *Client) Earnings() (EarningsState, bool)
Earnings returns the last ledger snapshot; ok is false before the first one arrives (a fresh enrollment, or a coordinator that predates it).
func (*Client) EffectiveMaxConcurrent ¶ added in v0.3.0
EffectiveMaxConcurrent is min(operator cap, coordinator cap), 0 = none.
func (*Client) Run ¶
Run keeps the session alive until ctx is cancelled, reconnecting with jittered exponential backoff.
func (*Client) SendBudget ¶ added in v0.9.0
SendBudget pushes a BudgetUpdate carrying Options.Budget() on the live session, so the coordinator's capacity view follows a settings change (max_disk_mb, max_ram_mb, the serve policy) without a reconnect (proto design note 2026-11-01). Nothing is sent when the budget equals the one the coordinator already has for this session, or between sessions (the next Hello carries the live values anyway). Coordinators that predate the message drop it.
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) SetMaxConcurrent ¶ added in v0.7.4
SetMaxConcurrent changes the operator's dispatch concurrency ceiling on a running client (budget.max_concurrent edited through the limits API). It applies to the next dispatch; the coordinator learns the new ceiling from the next session's Hello, or from SendBudget.
type Dialer ¶
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 EarningsState ¶ added in v0.6.1
type EarningsState struct {
Snapshot *tunnelv1.EarningsSnapshot
ReceivedAt time.Time
}
EarningsState is the last EarningsSnapshot pushed by the coordinator (the operator account's ledger position, docs#24) and the local time it arrived, which is what its freshness is judged from: the snapshot's own as_of is the coordinator's clock.
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 ImageTaker ¶ added in v0.9.7
ImageTaker is implemented by an Engine that knows whether a loaded model takes image input. One that does not implement it is sent whatever arrives.
type InsecureDialer ¶
type InsecureDialer struct{}
InsecureDialer is for local development only.
func (InsecureDialer) Dial ¶
func (InsecureDialer) Dial(_ context.Context, addr string) (*grpc.ClientConn, error)
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
// Budget returns the operator's ResourceBudget as it stands now, for
// SendBudget (a live settings change). May be nil: then SendBudget is
// a no-op. The Hello's budget is expected to come from the same
// source.
Budget func() *typesv1.ResourceBudget
// 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)
// OnEarnings observes each EarningsSnapshot after the client has
// cached it (Earnings). May be nil.
OnEarnings func(es *tunnelv1.EarningsSnapshot)
// Releases receives the coordinator's release channel
// (ConfigUpdate.latest_version / minimum_version / release_url) as the
// authoritative version source. *update.Checker satisfies it. May be
// nil.
Releases ReleaseSink
// 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 ReleaseSink ¶ added in v0.5.0
type ReleaseSink interface {
ApplyMesh(latest, minimum, url string)
}
ReleaseSink is fed the coordinator's release channel. Empty strings mean "unknown" and must not clear a previously known value.