transport

package module
v0.0.0-...-c4133e1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 8 Imported by: ? 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.

README

crucible/transport

A gRPC network transport for the Crucible cluster runtime: it carries actor deliver, spawn, and read-only time-travel operations between nodes over real gRPC (HTTP/2).

Status: experimental, pre-1.0. The transport is exercised over an in-process gRPC connection (bufconn) and the API may still change before v1.

Import path: github.com/stablekernel/crucible/transport

Requires Go 1.27.4.

What it is

cluster spreads a state machine and its child-machine actors across nodes over a pluggable Transport; its InMemoryTransport connects node-scoped systems in one process. This module is the over-the-network implementation: a Transport satisfies cluster.Transport on the client side and a server serves a node's cluster.WireEndpoint, so a parent on one host can spawn and drive an actor running on another.

It lives in its own module so the gRPC dependency stays out of the cluster core, which remains stdlib-only: a deployment that uses only the in-memory transport never compiles gRPC in.

How it works

Payloads (events and spawn inputs) cross the wire as the JSON the WireEndpoint seam already produces and consumes, through a JSON gRPC codec. There is no protobuf schema or codegen: the service descriptor is hand-written and both sides force the JSON codec explicitly (grpc.ForceCodec on the client, ForceServerCodec on the server), so the codec is never resolved through the global gRPC encoding registry and the import has no process-wide side effect.

Client

tr := transport.New()
tr.AddNode("node-b", conn) // conn is a *grpc.ClientConn the caller dials and owns

nodeA := cluster.NewSystem("node-a", actorSysA, cluster.WithTransport(tr))
ref, err := nodeA.Spawn(ctx, "node-b", "worker", "w-1", nil) // spawn on node-b over gRPC
delivered, err := nodeA.Deliver(ctx, ref, "finish")          // route to its owning node

A Transport holds one client connection per reachable node, registered with AddNode; the caller dials each node (grpc.NewClient) and owns the connection's lifecycle. An operation addressed to a node that was never registered reports cluster.ErrNodeUnreachable.

Server

gs := transport.NewServer(nodeBWireEndpoint) // gRPC server with the JSON codec + service registered
go gs.Serve(lis)

NewServer builds a gRPC server preconfigured with the JSON codec and the node's transport service registered; the caller serves it on a listener and owns its lifecycle. Pass extra grpc.ServerOptions (interceptors, credentials, keepalives) as needed, or register the service onto an existing server with RegisterServer.

Time travel

For durable instances, NewDurableTimeTravel adapts a durable.Store and machine into a TimeTravelEndpoint; NewTimeTravelServer / RegisterTimeTravel serve it, and the client Transport.StateAt reconstructs an instance's past state as of a recorded step over the wire. It is read-only: it runs no service, re-instantiates no actor, and dispatches no effect.

Documentation

Overview

Package transport is a gRPC network transport for the Crucible cluster runtime. It carries actor deliver and spawn operations between nodes over real gRPC (HTTP/2), implementing cluster.Transport on the client side and serving a node's cluster.WireEndpoint on the server side.

It lives in its own module so the gRPC dependency stays out of the cluster core, which remains stdlib-only: a deployment that uses only the in-memory transport never compiles gRPC in. Payloads (events and spawn inputs) cross the wire as the JSON the WireEndpoint seam already produces and consumes, via a JSON gRPC codec — no protobuf schema or codegen is involved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(ep cluster.WireEndpoint, opts ...grpc.ServerOption) *grpc.Server

NewServer builds a gRPC server preconfigured with the JSON codec and the node's transport service registered. The caller serves it on a listener and owns its lifecycle. Pass extra ServerOptions (interceptors, credentials, keepalives) as needed.

func NewTimeTravelServer

func NewTimeTravelServer(ep TimeTravelEndpoint, opts ...grpc.ServerOption) *grpc.Server

NewTimeTravelServer builds a gRPC server preconfigured with the JSON codec and the time-travel service registered. The caller serves it and owns its lifecycle.

func RegisterServer

func RegisterServer(gs grpc.ServiceRegistrar, ep cluster.WireEndpoint)

RegisterServer registers a node's cluster.WireEndpoint as the transport service on an existing gRPC server, so deliveries and spawns arriving over the wire are decoded into the node's concrete types and applied to its local actor system.

func RegisterTimeTravel

func RegisterTimeTravel(gs grpc.ServiceRegistrar, ep TimeTravelEndpoint)

RegisterTimeTravel registers a node's TimeTravelEndpoint as the time-travel service on an existing gRPC server, so remote nodes can reconstruct the past state of instances this node hosts.

Types

type DeliverRequest

type DeliverRequest struct {
	Ref   state.ActorRef `json:"ref"`
	Event []byte         `json:"event,omitempty"`
}

DeliverRequest carries a delivery to the actor named by Ref. Event is the JSON-encoded event the owning node decodes into its event type.

type DeliverResponse

type DeliverResponse struct {
	Delivered bool `json:"delivered"`
}

DeliverResponse reports whether the addressed actor accepted the event.

type DurableTimeTravel

type DurableTimeTravel[S comparable, E comparable, C any] struct {
	// contains filtered or unexported fields
}

DurableTimeTravel adapts a durable Store and machine into a TimeTravelEndpoint by running durable.StateAt and marshaling the reconstructed snapshot. It is read-only: it runs no service, re-instantiates no actor, and dispatches no effect.

func NewDurableTimeTravel

func NewDurableTimeTravel[S comparable, E comparable, C any](m *state.Machine[S, E, C], store durable.Store) *DurableTimeTravel[S, E, C]

NewDurableTimeTravel binds a machine and the durable Store its instances were recorded into. The Store should retain full history (a durable.HistoryStore) to reach arbitrary steps; otherwise reconstruction is limited to the latest checkpoint and tail.

func (*DurableTimeTravel[S, E, C]) StateAt

func (d *DurableTimeTravel[S, E, C]) StateAt(ctx context.Context, id string, step int) ([]byte, error)

StateAt reconstructs the instance's state as of step and marshals it.

type SpawnRequest

type SpawnRequest struct {
	Src   string `json:"src"`
	ID    string `json:"id"`
	Input []byte `json:"input,omitempty"`
}

SpawnRequest asks the owning node to start an actor with ID from Src, with the JSON-encoded Input.

type SpawnResponse

type SpawnResponse struct {
	Ref state.ActorRef `json:"ref"`
}

SpawnResponse returns a ref to the spawned actor.

type StateAtRequest

type StateAtRequest struct {
	ID   string `json:"id"`
	Step int    `json:"step"`
}

StateAtRequest asks for an instance's reconstructed state as of a recorded step.

type StateAtResponse

type StateAtResponse struct {
	Snapshot []byte `json:"snapshot"`
}

StateAtResponse carries the reconstructed snapshot as marshaled JSON; the caller decodes it with state.UnmarshalSnapshot for its own (S, E, C).

type TimeTravelEndpoint

type TimeTravelEndpoint interface {
	// StateAt reconstructs the instance's state as of step and returns it as a
	// marshaled kernel snapshot.
	StateAt(ctx context.Context, id string, step int) (snapshot []byte, err error)
}

TimeTravelEndpoint serves read-only historical state reconstruction for durable instances a node hosts. DurableTimeTravel adapts a durable Store + machine into one; a node registers it with RegisterTimeTravel so other nodes can query an instance's past state over the wire.

type Transport

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

Transport is the client side: it routes cluster operations to the gRPC server of the node that owns the target actor. It satisfies cluster.Transport. Register each reachable node's client connection with AddNode. It is safe for concurrent use.

func New

func New() *Transport

New returns a Transport with no nodes; register reachable nodes with AddNode.

func (*Transport) AddNode

func (t *Transport) AddNode(node string, conn grpc.ClientConnInterface)

AddNode registers the client connection used to reach node. The caller dials the node (grpc.NewClient) and owns the connection's lifecycle. Registering a node again replaces its connection.

func (*Transport) Deliver

func (t *Transport) Deliver(ctx context.Context, ref state.ActorRef, event any) (bool, error)

Deliver routes event to the actor named by ref on its owning node over gRPC. The event is JSON-encoded here and decoded into the owning node's event type there.

func (*Transport) Spawn

func (t *Transport) Spawn(ctx context.Context, node, src, id string, input map[string]any) (state.ActorRef, error)

Spawn asks node to start an actor with id from src, passing input, over gRPC, and returns a ref to it.

func (*Transport) StateAt

func (t *Transport) StateAt(ctx context.Context, node, id string, step int) ([]byte, error)

StateAt asks node to reconstruct an instance's state as of step and returns the marshaled snapshot, which the caller decodes with state.UnmarshalSnapshot for its own (S, E, C). It reuses the transport's registered connections.

Jump to

Keyboard shortcuts

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