relayx

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Channel = "ploykit:relay:v1"
View Source
const MaxHops = 4

MaxHops bounds the relay chain: the origin-drop check protects against hearing your own broadcast, but a consumer misusing Broadcast as a point-to-point deliver (orkome field report) loops the frame between ≥2 replicas exponentially — the hop cap turns that into a bounded fan with a WARN naming the frame instead of silent CPU burn. 4 comfortably exceeds any sane fan-out topology.

Variables

This section is empty.

Functions

This section is empty.

Types

type Envelope

type Envelope struct {
	Origin string       `json:"origin"`
	Scope  string       `json:"scope"`
	Frame  wswire.Frame `json:"frame"`

	// Hops counts how many instances have relayed this envelope. Every hop
	// that forwards (rather than terminating) the frame must increment it
	// before re-publishing; Run drops frames whose Hops reached MaxHops.
	Hops int `json:"hops,omitempty"`
}

type MemoryTransport

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

func NewMemoryTransport

func NewMemoryTransport() *MemoryTransport

func (*MemoryTransport) Publish

func (m *MemoryTransport) Publish(_ context.Context, payload []byte) error

func (*MemoryTransport) Subscribe

func (m *MemoryTransport) Subscribe(ctx context.Context, fn func(payload []byte)) error

type RedisTransport

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

func (*RedisTransport) Publish

func (t *RedisTransport) Publish(ctx context.Context, payload []byte) error

func (*RedisTransport) Subscribe

func (t *RedisTransport) Subscribe(ctx context.Context, fn func(payload []byte)) error

type Relay

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

func NewRelay

func NewRelay(self string, tp Transport, log *slog.Logger) *Relay

func (*Relay) Forward added in v0.5.0

func (r *Relay) Forward(ctx context.Context, env Envelope) bool

Forward re-publishes a received envelope to the other instances (the hop that keeps the chain going). Run's deliver callback handles the local delivery; Forward is the only sanctioned way to keep it traveling, and it refuses frames at the hop cap.

func (*Relay) PublishOut

func (r *Relay) PublishOut(ctx context.Context, scope string, frame wswire.Frame)

func (*Relay) Run

func (r *Relay) Run(ctx context.Context, deliver func(env Envelope)) error

type Transport

type Transport interface {
	Publish(ctx context.Context, payload []byte) error

	Subscribe(ctx context.Context, fn func(payload []byte)) error
}

func NewRedisTransport

func NewRedisTransport(client redis.UniversalClient) Transport

Jump to

Keyboard shortcuts

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