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 ¶
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 ¶
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 Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client maintains the session and handles pushed work.
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) 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.
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 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 ¶
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
// 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)
// 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.