provider

package
v0.49.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: AGPL-3.0 Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// DefaultRequestProviderWorkers is the default number of workers used to process entity requests.
	DefaultRequestProviderWorkers = uint(5)

	// DefaultEntityRequestCacheSize is the default max message queue size for the provider engine.
	// This equates to ~5GB of memory usage with a full queue (10M*500)
	DefaultEntityRequestCacheSize = 500

	// DefaultMaxEntityIDs is the default maximum number of entity IDs that can be requested in a single
	// EntityRequest. This limit prevents amplification attacks where a small request triggers excessive
	// retrieval and serialization work. Note: the default requester engine (engine/common/requester) only
	// requests up to 32 entity IDs per batch (see BatchThreshold), so this limit provides ample headroom
	// for legitimate requests.
	DefaultMaxEntityIDs = 100

	// DefaultMaxResponseByteSize is the default maximum cumulative byte size of encoded entities in a response.
	// This is set conservatively below the network's DefaultMaxUnicastMsgSize (10MB) to account for
	// message overhead (headers, encoding wrappers, etc.). The provider will stop adding entities to the
	// response once this budget is exceeded, preventing unbounded serialization work.
	DefaultMaxResponseByteSize = 8 * 1024 * 1024 // 8MB
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	component.Component
	// contains filtered or unexported fields
}

Engine is a generic provider engine, handling the fulfillment of entity requests on the flow network. It is the `reply` part of the request-reply pattern provided by the pair of generic exchange engines.

func New

func New(
	log zerolog.Logger,
	metrics module.EngineMetrics,
	net network.EngineRegistry,
	me module.Local,
	state protocol.State,
	requestQueue engine.MessageStore,
	requestWorkers uint,
	channel channels.Channel,
	selector flow.IdentityFilter[flow.Identity],
	retrieve RetrieveFunc,
	opts ...Option) (*Engine, error)

New creates a new provider engine, operating on the provided network channel, and accepting requests for entities from a node within the set obtained by applying the provided selector filter. It uses the injected retrieve function to manage the fullfilment of these requests.

func (*Engine) Process

func (e *Engine) Process(channel channels.Channel, originID flow.Identifier, event any) error

Process processes the given message from the node with the given origin ID in a blocking manner. It returns the potential processing error when done.

type Option added in v0.49.0

type Option func(*Engine)

Option is a functional option for configuring the provider Engine.

func WithMaxEntityIDs added in v0.49.0

func WithMaxEntityIDs(max int) Option

WithMaxEntityIDs sets the maximum number of entity IDs that can be requested in a single request. Requests with more IDs will be truncated to this limit.

func WithMaxResponseByteSize added in v0.49.0

func WithMaxResponseByteSize(max int) Option

WithMaxResponseByteSize sets the maximum cumulative byte size of encoded entities in a response. The provider will stop adding entities once this budget is exceeded.

type RetrieveFunc

type RetrieveFunc func(flow.Identifier) (flow.Entity, error)

RetrieveFunc is a function provided to the provider engine upon construction. It is used by the engine when receiving requests in order to retrieve the related entities. It is important that the retrieve function return a `storage.ErrNotFound` error if the entity does not exist locally; otherwise, the logic will error and not send responses when failing to retrieve entities.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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