plugin

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockHookData

type BlockHookData struct {
	HookData
	Block  interfaces.Block `json:"-"`
	Result any              `json:"result,omitempty"`
	Error  error            `json:"error,omitempty"`
}

BlockHookData is passed to block-related hooks

type DifficultyHookData

type DifficultyHookData struct {
	HookData
	OldDifficulty any                `json:"old_difficulty"`
	NewDifficulty any                `json:"new_difficulty"`
	Blocks        []interfaces.Block `json:"-"`
	Reason        string             `json:"reason"`
}

DifficultyHookData is passed to difficulty adjustment hooks

type Event

type Event struct {
	ID        string         `json:"id"`
	Type      EventType      `json:"type"`
	Source    string         `json:"source"`
	Timestamp time.Time      `json:"timestamp"`
	Data      any            `json:"data"`
	Metadata  map[string]any `json:"metadata,omitempty"`
}

Event represents a consensus event

func NewEvent

func NewEvent(eventType EventType, source string, data any) *Event

NewEvent creates a new event

type EventBus

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

EventBus manages event publishing and subscriptions

func NewEventBus

func NewEventBus() *EventBus

NewEventBus creates a new event bus

func (*EventBus) Close

func (eb *EventBus) Close()

Close shuts down the event bus

func (*EventBus) GetHistory

func (eb *EventBus) GetHistory(limit int) []*Event

GetHistory returns recent events

func (*EventBus) GetMetrics

func (eb *EventBus) GetMetrics() *EventMetrics

GetMetrics returns event bus metrics

func (*EventBus) Publish

func (eb *EventBus) Publish(event *Event) error

Publish sends an event to all subscribers

func (*EventBus) Subscribe

func (eb *EventBus) Subscribe(eventTypes []EventType, handler EventHandler) string

Subscribe registers a handler for specific event types

func (*EventBus) SubscribeAsync

func (eb *EventBus) SubscribeAsync(eventTypes []EventType, handler EventHandler) string

SubscribeAsync registers an async handler for specific event types

func (*EventBus) SubscribeWithFilter

func (eb *EventBus) SubscribeWithFilter(eventTypes []EventType, handler EventHandler, filter EventFilter, async bool) string

SubscribeWithFilter registers a handler with a filter

func (*EventBus) Unsubscribe

func (eb *EventBus) Unsubscribe(subscriptionID string) error

Unsubscribe removes a subscription

type EventFilter

type EventFilter func(event *Event) bool

EventFilter filters events before delivery

type EventHandler

type EventHandler func(ctx context.Context, event *Event) error

EventHandler handles events

type EventMetrics

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

EventMetrics tracks event bus statistics

func NewEventMetrics

func NewEventMetrics() *EventMetrics

NewEventMetrics creates new metrics tracker

func (*EventMetrics) EventDelivered

func (m *EventMetrics) EventDelivered(eventType EventType)

func (*EventMetrics) EventDeliveryFailed

func (m *EventMetrics) EventDeliveryFailed(eventType EventType)

func (*EventMetrics) EventPublished

func (m *EventMetrics) EventPublished(eventType EventType)

func (*EventMetrics) GetStats

func (m *EventMetrics) GetStats() map[string]any

GetStats returns current metrics

func (*EventMetrics) SubscriptionCreated

func (m *EventMetrics) SubscriptionCreated()

func (*EventMetrics) SubscriptionRemoved

func (m *EventMetrics) SubscriptionRemoved()

type EventType

type EventType string

EventType represents the type of event

const (
	// State change events
	EventStateChanged       EventType = "state_changed"
	EventConfigUpdated      EventType = "config_updated"
	EventPluginRegistered   EventType = "plugin_registered"
	EventPluginUnregistered EventType = "plugin_unregistered"

	// Consensus events
	EventConsensusStarted EventType = "consensus_started"
	EventConsensusStopped EventType = "consensus_stopped"
	EventConsensusError   EventType = "consensus_error"

	// Block events
	EventBlockProposed  EventType = "block_proposed"
	EventBlockValidated EventType = "block_validated"
	EventBlockAccepted  EventType = "block_accepted"
	EventBlockRejected  EventType = "block_rejected"
	EventBlockFinalized EventType = "block_finalized"

	// Worker events (consensus work processing)
	EventWorkStarted      EventType = "work_started"
	EventWorkStopped      EventType = "work_stopped"
	EventWorkCompleted    EventType = "work_completed"
	EventSolutionFound    EventType = "solution_found"
	EventThroughputUpdate EventType = "throughput_update"

	// Difficulty events
	EventDifficultyAdjusted EventType = "difficulty_adjusted"
	EventTargetUpdated      EventType = "target_updated"

	// Network events
	EventPeerConnected    EventType = "peer_connected"
	EventPeerDisconnected EventType = "peer_disconnected"
	EventSyncStarted      EventType = "sync_started"
	EventSyncCompleted    EventType = "sync_completed"

	// Performance events
	EventHighLatency       EventType = "high_latency"
	EventResourceWarning   EventType = "resource_warning"
	EventPerformanceMetric EventType = "performance_metric"
)

type ExtensionChain

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

ExtensionChain chains multiple extensions together

func NewExtensionChain

func NewExtensionChain(extensions ...interfaces.Extension) *ExtensionChain

NewExtensionChain creates a new extension chain

func (*ExtensionChain) Execute

Execute runs all extensions in the chain

type ExtensionFactory

type ExtensionFactory func(config map[string]any) (interfaces.Extension, error)

ExtensionFactory creates extensions of a specific type

type ExtensionRegistry

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

ExtensionRegistry manages extensions

func NewExtensionRegistry

func NewExtensionRegistry() *ExtensionRegistry

NewExtensionRegistry creates a new extension registry

func (*ExtensionRegistry) CreateExtension

func (r *ExtensionRegistry) CreateExtension(extType interfaces.ExtensionType, config map[string]any) (interfaces.Extension, error)

CreateExtension creates an extension using a registered factory

func (*ExtensionRegistry) ExecuteExtensions

func (r *ExtensionRegistry) ExecuteExtensions(ctx context.Context, pointName string, input interfaces.ExtensionInput) ([]interfaces.ExtensionOutput, error)

ExecuteExtensions runs all extensions at a specific point

func (*ExtensionRegistry) GetExtensions

func (r *ExtensionRegistry) GetExtensions(pointName string) ([]interfaces.Extension, error)

GetExtensions returns all extensions for a specific point

func (*ExtensionRegistry) RegisterExtension

func (r *ExtensionRegistry) RegisterExtension(pointName string, ext interfaces.Extension) error

RegisterExtension adds an extension to a specific point

func (*ExtensionRegistry) RegisterExtensionPoint

func (r *ExtensionRegistry) RegisterExtensionPoint(point *interfaces.ExtensionPoint) error

RegisterExtensionPoint registers a new extension point

func (*ExtensionRegistry) RegisterFactory

func (r *ExtensionRegistry) RegisterFactory(extType interfaces.ExtensionType, factory ExtensionFactory)

RegisterFactory registers a factory for creating extensions

type HasherExtension

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

HasherExtension adds custom hash algorithms

func NewHasherExtension

func NewHasherExtension(name string, hasher interfaces.Hasher) *HasherExtension

NewHasherExtension creates a new hasher extension

func (*HasherExtension) Execute

func (*HasherExtension) GetMetadata

func (e *HasherExtension) GetMetadata() interfaces.ExtensionMetadata

func (*HasherExtension) GetName

func (e *HasherExtension) GetName() string

func (*HasherExtension) GetType

func (*HasherExtension) Validate

func (e *HasherExtension) Validate(input interfaces.ExtensionInput) error

type HookData

type HookData struct {
	Type      HookPoint      `json:"type"`
	Timestamp int64          `json:"timestamp"`
	Data      map[string]any `json:"data"`
}

HookData contains data passed to hooks at various points

type HookFunc

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

HookFunc is a simple function-based hook implementation

func NewHookFunc

func NewHookFunc(name string, priority int, fn func(context.Context, any) error) *HookFunc

NewHookFunc creates a new function-based hook

func (*HookFunc) ContinueOnError

func (h *HookFunc) ContinueOnError() bool

func (*HookFunc) Execute

func (h *HookFunc) Execute(ctx context.Context, data any) error

func (*HookFunc) GetName

func (h *HookFunc) GetName() string

func (*HookFunc) GetPriority

func (h *HookFunc) GetPriority() int

func (*HookFunc) IsEnabled

func (h *HookFunc) IsEnabled() bool

func (*HookFunc) SetEnabled

func (h *HookFunc) SetEnabled(enabled bool)

type HookManager

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

HookManager manages hook execution with proper ordering and error handling

func NewHookManager

func NewHookManager() *HookManager

NewHookManager creates a new hook manager

func (*HookManager) Clear

func (m *HookManager) Clear(point HookPoint)

Clear removes all hooks from a specific point

func (*HookManager) ClearAll

func (m *HookManager) ClearAll()

ClearAll removes all hooks

func (*HookManager) Clone

func (m *HookManager) Clone() *HookManager

Clone creates a deep copy of the HookManager

func (*HookManager) Execute

func (m *HookManager) Execute(ctx context.Context, point HookPoint, data any) error

Execute runs all hooks for a specific point

func (*HookManager) GetHooks

func (m *HookManager) GetHooks(point HookPoint) []interfaces.Hook

GetHooks returns all hooks for a specific point

func (*HookManager) Register

func (m *HookManager) Register(point HookPoint, hook interfaces.Hook)

Register adds a hook to a specific point

func (*HookManager) Unregister

func (m *HookManager) Unregister(point HookPoint, name string) error

Unregister removes a hook by name from a specific point

type HookPoint

type HookPoint string

HookPoint defines where hooks can be attached in the consensus flow

const (
	// Consensus lifecycle hooks
	HookBeforeConsensusStart HookPoint = "before_consensus_start"
	HookAfterConsensusStart  HookPoint = "after_consensus_start"
	HookBeforeConsensusStop  HookPoint = "before_consensus_stop"
	HookAfterConsensusStop   HookPoint = "after_consensus_stop"

	// Block processing hooks
	HookBeforeBlockPropose  HookPoint = "before_block_propose"
	HookAfterBlockPropose   HookPoint = "after_block_propose"
	HookBeforeBlockValidate HookPoint = "before_block_validate"
	HookAfterBlockValidate  HookPoint = "after_block_validate"
	HookBeforeBlockAccept   HookPoint = "before_block_accept"
	HookAfterBlockAccept    HookPoint = "after_block_accept"
	HookBeforeBlockReject   HookPoint = "before_block_reject"
	HookAfterBlockReject    HookPoint = "after_block_reject"

	// Worker hooks (consensus work processing)
	HookBeforeWorkStart HookPoint = "before_work_start"
	HookAfterWorkStart  HookPoint = "after_work_start"
	HookBeforeWorkStop  HookPoint = "before_work_stop"
	HookAfterWorkStop   HookPoint = "after_work_stop"
	HookOnSolutionFound HookPoint = "on_solution_found"
	HookOnWorkProgress  HookPoint = "on_work_progress"

	// Difficulty adjustment hooks
	HookBeforeDifficultyAdjust HookPoint = "before_difficulty_adjust"
	HookAfterDifficultyAdjust  HookPoint = "after_difficulty_adjust"

	// Validation hooks
	HookBeforeValidation    HookPoint = "before_validation"
	HookAfterValidation     HookPoint = "after_validation"
	HookOnValidationFailure HookPoint = "on_validation_failure"

	// Network hooks
	HookOnPeerConnect    HookPoint = "on_peer_connect"
	HookOnPeerDisconnect HookPoint = "on_peer_disconnect"
	HookOnBlockReceived  HookPoint = "on_block_received"
	HookOnBlockBroadcast HookPoint = "on_block_broadcast"
)

type MiddlewareExtension

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

MiddlewareExtension adds processing middleware

func NewMiddlewareExtension

func NewMiddlewareExtension(name string, middleware func(context.Context, any) (any, error)) *MiddlewareExtension

NewMiddlewareExtension creates a new middleware extension

func (*MiddlewareExtension) Execute

func (*MiddlewareExtension) GetMetadata

func (*MiddlewareExtension) GetName

func (e *MiddlewareExtension) GetName() string

func (*MiddlewareExtension) GetType

func (*MiddlewareExtension) Validate

type Registry

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

Registry manages plugin registration and lifecycle

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new plugin registry

func (*Registry) Clone

func (r *Registry) Clone() *Registry

Clone creates a deep copy of the Registry Note: This clones the structure but plugins themselves are references (as they're interfaces) The cloned registry will have: - The same plugins registered (but not initialized/started) - A clone of the HookManager with all hooks - A new EventBus (subscriptions are not cloned)

func (*Registry) Close

func (r *Registry) Close() error

Close shuts down the registry and all plugins

func (*Registry) ExecuteHooks

func (r *Registry) ExecuteHooks(point HookPoint, data any) error

ExecuteHooks executes all hooks for a specific point in priority order

func (*Registry) Get

func (r *Registry) Get(name string) (interfaces.Plugin, error)

Get returns a plugin by name

func (*Registry) GetByCapability

func (r *Registry) GetByCapability(capability interfaces.Capability) []interfaces.Plugin

GetByCapability returns all plugins with a specific capability

func (*Registry) GetEventBus

func (r *Registry) GetEventBus() *EventBus

GetEventBus returns the event bus for publishing/subscribing to events

func (*Registry) GetHookManager

func (r *Registry) GetHookManager() *HookManager

GetHookManager returns the hook manager for direct access to hook operations

func (*Registry) InitializeAll

func (r *Registry) InitializeAll(ctx context.Context, configs map[string]map[string]any) error

InitializeAll initializes all plugins in dependency order

func (*Registry) List

func (r *Registry) List() []interfaces.Plugin

List returns all registered plugins

func (*Registry) Register

func (r *Registry) Register(plugin interfaces.Plugin) error

Register adds a plugin to the registry

func (*Registry) RegisterHook

func (r *Registry) RegisterHook(point HookPoint, hook interfaces.Hook)

RegisterHook registers a hook for a specific hook point with priority support

func (*Registry) StartAll

func (r *Registry) StartAll(ctx context.Context) error

StartAll starts all plugins

func (*Registry) StopAll

func (r *Registry) StopAll() error

StopAll stops all plugins in reverse order

func (*Registry) Unregister

func (r *Registry) Unregister(name string) error

Unregister removes a plugin from the registry

type StateChangeEvent

type StateChangeEvent struct {
	Component string `json:"component"`
	OldState  any    `json:"old_state"`
	NewState  any    `json:"new_state"`
	Reason    string `json:"reason,omitempty"`
}

StateChangeEvent represents a state change in the consensus

type Subscription

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

Subscription represents an event subscription

type ValidationHookData

type ValidationHookData struct {
	HookData
	Block     interfaces.Block            `json:"-"`
	Validator interfaces.Validator        `json:"-"`
	Result    interfaces.ValidationResult `json:"result"`
}

ValidationHookData is passed to validation hooks

type ValidatorExtension

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

ValidatorExtension adds custom validation logic

func NewValidatorExtension

func NewValidatorExtension(name string, validator interfaces.Validator) *ValidatorExtension

NewValidatorExtension creates a new validator extension

func (*ValidatorExtension) Execute

func (*ValidatorExtension) GetMetadata

func (*ValidatorExtension) GetName

func (e *ValidatorExtension) GetName() string

func (*ValidatorExtension) GetType

func (*ValidatorExtension) Validate

type WorkerHookData

type WorkerHookData struct {
	HookData
	JobID    string                 `json:"job_id"`
	Work     interfaces.WorkPackage `json:"-"`
	Result   interfaces.WorkResult  `json:"-"`
	Progress WorkerProgress         `json:"progress,omitempty"`
}

WorkerHookData is passed to worker-related hooks

type WorkerProgress

type WorkerProgress struct {
	Iterations uint64        `json:"iterations"`
	Throughput float64       `json:"throughput"`
	Elapsed    time.Duration `json:"elapsed"`
}

WorkerProgress contains work progress information

Jump to

Keyboard shortcuts

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