eventstream

package module
v0.2.5-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: AGPL-3.0 Imports: 19 Imported by: 2 modules, 3 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

eventstream

ci codecov

Pub/sub event delivery plugin for the Pilot Protocol daemon. Binds service port 1002 and ships events between Pilot peers over the daemon's reliable stream transport.

Install

import "github.com/pilot-protocol/eventstream"

Usage

// Register as a plugin on the daemon runtime:
rt.Register(eventstream.NewService())

// Or use the client directly:
c, err := eventstream.Dial(ctx, peerAddr)
if err != nil {
    return err
}
defer c.Close()
if err := c.Subscribe("ticker.btcusd"); err != nil {
    return err
}
for {
    ev, err := c.Read()
    if err != nil {
        return err
    }
    handle(ev)
}

From pilotctl:

pilotctl subscribe <peer-address> ticker.btcusd
pilotctl publish   <peer-address> ticker.btcusd --data '...'

Layout

File What it does
eventstream.go Wire format: Event{Topic, Payload}, subscription policy interface, and length-prefixed framing. WriteEvent / ReadEvent.
client.go Subscriber side: Client.Dial, .Subscribe(topic), .Read, .Close.
governed.go Signed publication envelope, broker-side verifier, and enforceable topic/payload constraints.
server.go Publisher side: Server accepts inbound stream connections and broadcasts.
service.go *Service — coreapi.Service adapter, binds port 1002. Build tag !no_eventstream.
service_disabled.go Stub when -tags no_eventstream is set.
examples/main.go Minimal publisher + subscriber example.

Build tags

Tag Effect
no_eventstream Compiles a no-op stub service.

Governed publication

An enterprise broker can call SetGovernedPublication before Start with a DecisionEventVerifier (or an equivalent local verifier). Its GovernedTopic transport envelope binds a publication topic and exact bytes to a signed decision.Intent and decision.Decision. The broker verifies the tenant authority state, local deterministic ceiling, exact broker resource, and understood constraints before it forwards the original event. Subscribers receive the original topic and payload, never the envelope.

After all publishers have been upgraded, set require to true; unsigned legacy publications are then dropped at the broker. This is intentionally a publication control: subscription access remains governed by the existing TopicPolicy. A workflow-approved publication uses the same short-lived execution Decision as an ordinary allowed publication, rather than a reusable workflow token.

For a typed-disclosure profile, use PublishGovernedWithDisclosure and bind the canonical decision.DisclosureBinding hash into the signed Intent. A DecisionEventVerifier with RequireDisclosure rejects otherwise-valid governed publications that do not carry matching content metadata. With a receipt recorder configured, typed publications require V2 disclosure-evidence support before broker fanout; the signed receipt contains only the disclosure hash, not event plaintext.

For auditable enterprise publishing, also call SetGovernedReceiptRecorder before Start and require it. The broker appends evidence for the exact signed Intent and Decision before fanout; a recorder failure denies the publication, so subscribers never receive an unreceipted governed event.

Local content inspection

Call SetGovernedContentInspector before Start to inspect verified governed event bytes locally before broker fan-out. RequireGovernedContentInspection makes a missing hook a startup failure, while a detector error rejects only the publication. decision.PresidioInspector provides a bounded text/structured- text adapter for a tenant-local OSS Presidio service; unsupported binary types are rejected rather than bypassing inspection. This hook is not invoked by the central decision authority.

Typed disclosure binding V2 can carry a signed retention_class, which a policy may restrict before fan-out. This binds metadata for downstream retention operations; it is not a substitute for a retention executor.

Per-agent publication quotas

SetGovernedTransferQuota applies a bounded local byte/action budget to each verified publisher Intent.AgentID. The budget is charged after signature and local-policy verification, never from a network address or caller-supplied identity, and covers admitted attempts that later fail local inspection or receipt recording.

License

AGPL-3.0-or-later. See LICENSE.

Documentation

Index

Constants

View Source
const GovernedTopic = "\x00pilot.governed.v1"

GovernedTopic is reserved for a signed publication envelope. The broker unwraps it only after local verification and forwards the original topic and payload to subscribers; subscribers never receive this transport topic.

Variables

This section is empty.

Functions

func GovernedEventPayloadHash added in v0.2.4

func GovernedEventPayloadHash(topic string, payload []byte) string

GovernedEventPayloadHash returns the exact payload binding required by a GovernedTopic Intent. It includes topic and bytes, so callers must use it when creating the Intent before PublishGoverned.

func WriteEvent

func WriteEvent(w io.Writer, e *Event) error

WriteEvent writes an event to a writer.

Types

type Client

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

Client connects to a remote event stream broker on port 1002.

func Subscribe

func Subscribe(d *driver.Driver, addr protocol.Addr, topic string) (*Client, error)

Subscribe connects to the event stream and subscribes to a topic. Use "*" to subscribe to all events.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) Publish

func (c *Client) Publish(topic string, payload []byte) error

Publish sends an event to the broker for distribution.

func (*Client) PublishGoverned added in v0.2.4

func (c *Client) PublishGoverned(event *Event, intent decision.Intent, result decision.Decision) error

PublishGoverned publishes an event with its exact signed intent and authority decision. A broker configured to require governed publications verifies the envelope before forwarding the inner event to subscribers.

func (*Client) PublishGovernedWithDisclosure added in v0.2.4

func (c *Client) PublishGovernedWithDisclosure(event *Event, intent decision.Intent, result decision.Decision, disclosure decision.DisclosureBinding) error

PublishGovernedWithDisclosure publishes a signed event whose Intent binds typed disclosure metadata. The broker can require this form per topic.

func (*Client) Recv

func (c *Client) Recv() (*Event, error)

Recv waits for the next event from the broker.

type DecisionEventVerifier added in v0.2.4

type DecisionEventVerifier struct {
	Enforcer          *decision.Enforcer
	Resource          func(coreapi.Addr, *Event) string
	RequireDisclosure bool
}

DecisionEventVerifier is the reference broker-side verifier. Resource must return the exact local resource for the incoming publication (for example, "eventstream:alerts"). It prevents a valid decision for one topic from being replayed to another topic at the same broker.

func (DecisionEventVerifier) VerifyGovernedEvent added in v0.2.4

func (verifier DecisionEventVerifier) VerifyGovernedEvent(ctx context.Context, remote coreapi.Addr, governed GovernedEvent) error

type Event

type Event struct {
	Topic   string
	Payload []byte
}

Event is a typed message published to the event stream. Wire format: [2-byte topic length][topic][4-byte payload length][payload]

func EncodeGovernedEvent added in v0.2.4

func EncodeGovernedEvent(event GovernedEvent) (*Event, error)

func ReadEvent

func ReadEvent(r io.Reader) (*Event, error)

ReadEvent reads an event from a reader.

type GovernedDisclosureReceiptRecorder added in v0.2.4

type GovernedDisclosureReceiptRecorder interface {
	RecordGovernedDisclosureReceipt(context.Context, decision.Intent, decision.Decision, decision.DisclosureBinding) error
}

GovernedDisclosureReceiptRecorder records V2 evidence for typed governed publications. Brokers fail closed instead of recording a V1 receipt that omits disclosure proof.

type GovernedEvent added in v0.2.4

type GovernedEvent struct {
	Version    uint16                      `json:"version"`
	Topic      string                      `json:"topic"`
	Payload    []byte                      `json:"payload"`
	Disclosure *decision.DisclosureBinding `json:"disclosure,omitempty"`
	Intent     decision.Intent             `json:"intent"`
	Decision   decision.Decision           `json:"decision"`
}

GovernedEvent transports one published Event with its exact signed intent and authority decision. Its payload binding includes both topic and bytes, so neither can be changed after authorization.

func DecodeGovernedEvent added in v0.2.4

func DecodeGovernedEvent(event *Event) (GovernedEvent, error)

func NewGovernedEvent added in v0.2.4

func NewGovernedEvent(event *Event, intent decision.Intent, result decision.Decision) (GovernedEvent, error)

func NewGovernedEventWithDisclosure added in v0.2.4

func NewGovernedEventWithDisclosure(event *Event, intent decision.Intent, result decision.Decision, disclosure decision.DisclosureBinding) (GovernedEvent, error)

NewGovernedEventWithDisclosure creates a governed event whose Intent binds canonical disclosure metadata. The caller is responsible for requesting a Decision for that exact disclosure-bound Intent before publication.

func (GovernedEvent) Event added in v0.2.4

func (event GovernedEvent) Event() *Event

func (GovernedEvent) Validate added in v0.2.4

func (event GovernedEvent) Validate() error

type GovernedEventVerifier added in v0.2.4

type GovernedEventVerifier interface {
	VerifyGovernedEvent(context.Context, coreapi.Addr, GovernedEvent) error
}

GovernedEventVerifier verifies a governed publication against the local broker's authority state before it is distributed to subscribers.

type GovernedReceiptRecorder added in v0.2.4

type GovernedReceiptRecorder interface {
	RecordGovernedReceipt(context.Context, decision.Intent, decision.Decision) error
}

GovernedReceiptRecorder durably records a broker-side enforcement receipt for a verified governed publication before it is fanned out to subscribers. Required enterprise deployments treat a recorder failure as a publication denial, so an event is never delivered without its evidence.

type Server

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

Server is a pub/sub event broker on port 1002. Clients connect, subscribe to topics, and publish events. The first event from a client is treated as a subscription: - Topic "*" subscribes to all events - Any other topic subscribes to that specific topic Subsequent events are published to all matching subscribers.

func NewServer

func NewServer(d *driver.Driver) *Server

NewServer creates an event stream server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe binds port 1002 and starts the broker.

type Service

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

Service is the L11 plugin adapter. cmd/daemon/main.go (L12) and cmd/pilotctl _daemon-run construct it via NewService and register via daemon.RegisterPlugin.

func NewService

func NewService() *Service

NewService returns a Service ready for daemon.RegisterPlugin.

func (*Service) Name

func (s *Service) Name() string

func (*Service) Order

func (s *Service) Order() int

Order: 120 — after the trust subsystem (50) and other application services that may want to publish before the broker is up.

func (*Service) RequireGovernedContentInspection added in v0.2.4

func (s *Service) RequireGovernedContentInspection(require bool)

RequireGovernedContentInspection makes startup fail closed when a local DLP hook is absent. Call this from the enterprise attachment after an operator has supplied the tenant-local inspector.

func (*Service) SetGovernedContentInspector added in v0.2.4

func (s *Service) SetGovernedContentInspector(inspector decision.DisclosureContentInspector)

SetGovernedContentInspector installs a receiver-local DLP hook. It runs after a signed governed envelope has passed its local policy ceiling and before the event reaches subscribers. The hook receives a reader over the event bytes; it never runs in the central decision authority.

func (*Service) SetGovernedPublication added in v0.2.4

func (s *Service) SetGovernedPublication(verifier GovernedEventVerifier, require bool)

SetGovernedPublication configures the broker-side authorization gate for published events. When require is true every publication must be a signed governed envelope. Call before Start; a required gate without a verifier makes Start fail closed.

func (*Service) SetGovernedReceiptRecorder added in v0.2.4

func (s *Service) SetGovernedReceiptRecorder(recorder GovernedReceiptRecorder, require bool)

SetGovernedReceiptRecorder attaches a durable evidence recorder to governed publications. When require is true the broker refuses to start without both a required governed gate and this recorder.

func (*Service) SetGovernedTransferQuota added in v0.2.4

func (s *Service) SetGovernedTransferQuota(limiter *decision.TransferQuotaLimiter)

SetGovernedTransferQuota installs a receiver-local per-agent admission quota. It is charged only after a signed governed event verifies, using the signed Intent.AgentID rather than a transport address.

func (*Service) SetTopicPolicy added in v0.2.3

func (s *Service) SetTopicPolicy(p TopicPolicy)

SetTopicPolicy installs a TopicPolicy for subscription authorization. Must be called before Start. A nil value is ignored (policy stays at the previous setting, which defaults to allow-all).

func (*Service) Start

func (s *Service) Start(ctx context.Context, deps coreapi.Deps) error

func (*Service) Stop

func (s *Service) Stop(ctx context.Context) error

type TopicPolicy added in v0.2.3

type TopicPolicy interface {
	AllowSubscribe(remoteAddr coreapi.Addr, topic string) bool
}

TopicPolicy is the authorization gate for topic subscription. Implementations check whether a peer may subscribe to a named topic. The enabled service uses an allow-all policy unless its caller installs a stricter implementation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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