Versions in this module Expand all Collapse all v0 v0.1.0 Aug 17, 2026 Changes in this version + const CanonicalStateSchema + const RouterStateSchema + const TraceSchemaVersion + var ErrDuplicateNode = errors.New("sim: node is already registered") + var ErrEmptyNode = errors.New("sim: node identifier must not be empty") + var ErrEventIDExhausted = errors.New("sim: event identifier space exhausted") + var ErrInvalidEventTag = errors.New("sim: invalid event tag") + var ErrInvalidLink = errors.New("sim: invalid network link configuration") + var ErrInvalidMatrix = errors.New("sim: invalid partition matrix") + var ErrInvalidNetworkDecision = errors.New("sim: invalid network decision") + var ErrNegativeTime = errors.New("sim: virtual time and delays must not be negative") + var ErrNilHandler = errors.New("sim: node handler must not be nil") + var ErrNilRand = errors.New("sim: router requires a random source") + var ErrNilSimulator = errors.New("sim: router requires a simulator") + var ErrPacketExhausted = errors.New("sim: packet identifier space exhausted") + var ErrPast = errors.New("sim: cannot schedule or advance into the past") + var ErrTimeOverflow = errors.New("sim: virtual time overflow") + var ErrUncacheableRouter = errors.New("sim: router state is not canonically inspectable") + var ErrUncacheableState = errors.New("sim: state is not canonically inspectable") + var ErrUnknownSource = errors.New("sim: packet source is not registered") + var ErrUnknownTarget = errors.New("sim: packet target is not registered") + func CloneBytes(message []byte) []byte + type Action func(*Simulator) + type CanonicalLinkState struct + From NodeID + LossProbabilityBits uint64 + MaxLatencyNS int64 + MinLatencyNS int64 + To NodeID + type CanonicalRouteState struct + From NodeID + To NodeID + type Clock struct + func (c *Clock) Now() time.Duration + type CloneFunc func(M) M + type DropReason uint8 + const DropLoss + const DropPartition + const DropTargetUnavailable + const NotDropped + type EventID uint64 + type EventKind string + const EventElectionTimer + const EventExternalAction + const EventHeartbeatTimer + const EventNetworkDelivery + const EventPersistenceAck + const EventScheduledCrash + const EventScheduledRestart + const EventStorageCompletion + type EventTag struct + Data json.RawMessage + Kind EventKind + func JSONPacketEventTagger[M any](packet Packet[M]) (EventTag, error) + type Handler func(Packet[M]) + type JSONLRecorder struct + func NewJSONLRecorder(writer io.Writer) *JSONLRecorder + func (r *JSONLRecorder) Err() error + func (r *JSONLRecorder) RecordTrace(event TraceEvent) + type LinkConfig struct + LossProbability float64 + MaxLatency time.Duration + MinLatency time.Duration + func (c LinkConfig) Validate() error + type NetworkDecisionSource interface + Drop func(Packet[M], LinkConfig) (bool, error) + Latency func(Packet[M], LinkConfig) (time.Duration, error) + type NetworkEvent struct + At time.Duration + DeliveryAt time.Duration + Kind NetworkEventKind + Packet Packet[M] + Reason DropReason + WasInFlight bool + type NetworkEventKind uint8 + const PacketDelivered + const PacketDropped + const PacketScheduled + type NodeID string + type Observer func(NetworkEvent[M]) + type Packet struct + From NodeID + ID uint64 + Message M + SentAt time.Duration + To NodeID + type PacketEventTagger func(Packet[M]) (EventTag, error) + type PartitionMatrix struct + func NewPartitionMatrix(nodes []NodeID, allowed [][]bool) (*PartitionMatrix, error) + func NewPartitions(groups ...[]NodeID) (*PartitionMatrix, error) + func (m *PartitionMatrix) Allows(source, target NodeID) bool + func (m *PartitionMatrix) Nodes() []NodeID + type PendingEventState struct + AtNS int64 + ID EventID + Order uint64 + Tag EventTag + type Rand struct + func NewRand(seed uint64) *Rand + func (r *Rand) Chance(p float64) bool + func (r *Rand) Duration(min, max time.Duration) time.Duration + func (r *Rand) Float64() float64 + func (r *Rand) IntN(n int) int + func (r *Rand) SetTraceSink(sink TraceSink, stream string) + func (r *Rand) Split() *Rand + func (r *Rand) State() RandState + func (r *Rand) Uint64() uint64 + func (r *Rand) Uint64N(n uint64) uint64 + type RandState struct + SplitCount uint64 + State uint64 + type Router struct + func NewRouter[M any](simulator *Simulator, random *Rand, defaultLink LinkConfig, clone CloneFunc[M]) (*Router[M], error) + func (r *Router[M]) CanonicalState() (RouterState, error) + func (r *Router[M]) Register(node NodeID, handler Handler[M]) error + func (r *Router[M]) ResetLink(from, to NodeID) + func (r *Router[M]) Send(from, to NodeID, message M) (SendResult, error) + func (r *Router[M]) SetDecisionSource(source NetworkDecisionSource[M]) + func (r *Router[M]) SetLink(from, to NodeID, config LinkConfig) error + func (r *Router[M]) SetObserver(observer Observer[M]) + func (r *Router[M]) SetPacketEventTagger(tagger PacketEventTagger[M]) + func (r *Router[M]) SetPartition(matrix *PartitionMatrix) + func (r *Router[M]) SetTraceSink(sink TraceSink) + func (r *Router[M]) Unregister(node NodeID) bool + type RouterState struct + Allowed []CanonicalRouteState + DefaultLink CanonicalLinkState + Endpoints []NodeID + Exhausted bool + Links []CanonicalLinkState + NextPacket uint64 + PartitionActive bool + PartitionNodes []NodeID + Random RandState + Schema string + type SendResult struct + DeliveryAt time.Duration + DropReason DropReason + PacketID uint64 + Scheduled bool + type Simulator struct + func New() *Simulator + func (s *Simulator) Cancel(id EventID) bool + func (s *Simulator) CanonicalState() (SimulatorState, error) + func (s *Simulator) Clock() *Clock + func (s *Simulator) Len() int + func (s *Simulator) NextEventTime() (time.Duration, bool) + func (s *Simulator) Now() time.Duration + func (s *Simulator) Run() int + func (s *Simulator) RunSteps(limit int) int + func (s *Simulator) RunUntil(end time.Duration) (int, error) + func (s *Simulator) Schedule(delay time.Duration, action Action) (EventID, error) + func (s *Simulator) ScheduleAt(when time.Duration, action Action) (EventID, error) + func (s *Simulator) ScheduleAtTagged(when time.Duration, tag EventTag, action Action) (EventID, error) + func (s *Simulator) ScheduleTagged(delay time.Duration, tag EventTag, action Action) (EventID, error) + func (s *Simulator) SetTraceSink(sink TraceSink) + func (s *Simulator) Step() bool + type SimulatorState struct + Events []PendingEventState + Exhausted bool + NextID EventID + NowNS int64 + Schema string + type TraceEvent struct + Action string + AtNS *int64 + Component string + DeliveryAtNS *int64 + Details any + DropReason string + EventID EventID + From NodeID + Kind TraceEventKind + Link *TraceLinkConfig + Message any + Node NodeID + PacketID uint64 + PartitionActive *bool + PartitionAllowed []TraceRoute + PartitionNodes []NodeID + RandomArguments map[string]string + RandomOperation string + RandomResult string + RandomStream string + ScheduledForNS *int64 + To NodeID + type TraceEventKind string + const TraceClockAdvanced + const TraceEventCanceled + const TraceEventExecuted + const TraceEventScheduled + const TraceLinkReset + const TraceLinkSet + const TraceNodeRegistered + const TraceNodeUnregistered + const TracePacketDelivered + const TracePacketDropped + const TracePacketScheduled + const TracePartitionChanged + const TracePersistence + const TraceProcessLifecycle + const TraceProtocolDrop + const TraceProtocolInput + const TraceProtocolState + const TraceRandomDraw + type TraceFunc func(TraceEvent) + func (f TraceFunc) RecordTrace(event TraceEvent) + type TraceLinkConfig struct + LossProbability float64 + MaxLatencyNS int64 + MinLatencyNS int64 + type TraceRecord struct + Schema string + Sequence uint64 + type TraceRoute struct + From NodeID + To NodeID + type TraceSink interface + RecordTrace func(TraceEvent)