routing

package
v0.36.21 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Unlicense Imports: 3 Imported by: 0

Documentation

Overview

Package routing provides event routing services for the ORLY relay. It dispatches events to specialized handlers based on event kind.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDeleteKind

func IsDeleteKind(k uint16) bool

IsDeleteKind returns true if the kind is a delete event (kind 5).

func IsEphemeral

func IsEphemeral(k uint16) bool

IsEphemeral checks if a kind is ephemeral (20000-29999).

Types

type Action

type Action int

Action indicates what to do after routing.

const (
	// Continue means continue to normal processing.
	Continue Action = iota
	// Handled means event was fully handled, return success.
	Handled
	// Error means an error occurred.
	Error
)

type DefaultRouter

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

DefaultRouter implements Router with a handler registry.

func New

func New() *DefaultRouter

New creates a new DefaultRouter.

func (*DefaultRouter) HasHandler

func (r *DefaultRouter) HasHandler(kind uint16) bool

HasHandler returns true if a handler is registered for the given kind.

func (*DefaultRouter) Register

func (r *DefaultRouter) Register(kind uint16, handler Handler)

Register adds a handler for a specific kind.

func (*DefaultRouter) RegisterKindCheck

func (r *DefaultRouter) RegisterKindCheck(name string, check func(uint16) bool, handler Handler)

RegisterKindCheck adds a handler for a kind category.

func (*DefaultRouter) Route

func (r *DefaultRouter) Route(ev *event.E, authedPubkey []byte) Result

Route checks if event should be handled specially.

type DeleteProcessor

type DeleteProcessor interface {
	// SaveDeleteEvent saves the delete event itself.
	SaveDeleteEvent(ctx context.Context, ev *event.E) error
	// ProcessDeletion removes the target events.
	ProcessDeletion(ctx context.Context, ev *event.E) error
	// DeliverEvent sends the delete event to subscribers.
	DeliverEvent(ev *event.E)
}

DeleteProcessor handles event deletion operations.

type Handler

type Handler func(ev *event.E, authedPubkey []byte) Result

Handler processes a specific event kind. authedPubkey is the authenticated pubkey of the connection (may be nil).

func MakeDeleteHandler

func MakeDeleteHandler(processor DeleteProcessor) Handler

MakeDeleteHandler creates a handler for delete events (kind 5). Delete events: - Save the delete event itself first - Process target event deletions - Deliver the delete event to subscribers

func MakeEphemeralHandler

func MakeEphemeralHandler(publisher Publisher) Handler

MakeEphemeralHandler creates a handler for ephemeral events. Ephemeral events (kinds 20000-29999): - Are NOT persisted to the database - Are immediately delivered to subscribers

type KindCheck

type KindCheck struct {
	Name    string
	Check   func(kind uint16) bool
	Handler Handler
}

KindCheck tests whether an event kind matches a category (e.g., ephemeral).

type Publisher

type Publisher interface {
	// Deliver sends an event to all matching subscribers.
	Deliver(ev *event.E)
}

Publisher abstracts event delivery to subscribers.

type Result

type Result struct {
	Action  Action
	Message string // Success or error message
	Error   error  // Error if Action == Error
}

Result contains the routing decision.

func ContinueResult

func ContinueResult() Result

ContinueResult returns a result indicating normal processing should continue.

func ErrorResult

func ErrorResult(err error) Result

ErrorResult returns a result indicating an error occurred.

func HandledResult

func HandledResult(msg string) Result

HandledResult returns a result indicating the event was fully handled.

type Router

type Router interface {
	// Route checks if event should be handled specially.
	Route(ev *event.E, authedPubkey []byte) Result

	// Register adds a handler for a specific kind.
	Register(kind uint16, handler Handler)

	// RegisterKindCheck adds a handler for a kind category.
	RegisterKindCheck(name string, check func(uint16) bool, handler Handler)
}

Router dispatches events to specialized handlers.

Source Files

  • delete.go
  • ephemeral.go
  • routing.go

Jump to

Keyboard shortcuts

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