underlay

package
v0.37.0-crescendo-RC4 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: AGPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxUnicastMsgSize defines maximum message size in unicast mode for most messages
	DefaultMaxUnicastMsgSize = 10 * mb // 10 mb

	// LargeMsgMaxUnicastMsgSize defines maximum message size in unicast mode for large messages
	LargeMsgMaxUnicastMsgSize = gb // 1 gb

	// DefaultUnicastTimeout is the default maximum time to wait for a default unicast request to complete
	// assuming at least a 1mb/sec connection
	DefaultUnicastTimeout = 5 * time.Second

	// LargeMsgUnicastTimeout is the maximum time to wait for a unicast request to complete for large message size
	LargeMsgUnicastTimeout = 1000 * time.Second
)

Variables

View Source
var ErrNetworkShutdown = errors.New("network has already shutdown")
View Source
var (
	// ErrUnicastMsgWithoutSub error is provided to the slashing violations consumer in the case where
	// the network receives a message via unicast but does not have a corresponding subscription for
	// the channel in that message.
	ErrUnicastMsgWithoutSub = errors.New("networking layer does not have subscription for the channel ID indicated in the unicast message received")
)

Functions

func DefaultValidators

func DefaultValidators(log zerolog.Logger, flowID flow.Identifier) []network.MessageValidator

func UnicastMaxMsgSizeByCode

func UnicastMaxMsgSizeByCode(payload []byte) (int, error)

UnicastMaxMsgSizeByCode returns the max permissible size for a unicast message code

Types

type Network

type Network struct {
	*component.ComponentManager
	// contains filtered or unexported fields
}

Network serves as the comprehensive networking layer that integrates three interfaces within Flow; Underlay, EngineRegistry, and ConduitAdapter. It is responsible for creating conduits through which engines can send and receive messages to and from other engines on the network, as well as registering other services such as BlobService and PingService. It also provides a set of APIs that can be used to send messages to other nodes on the network. Network is also responsible for managing the topology of the network, i.e., the set of nodes that are connected to each other. It is also responsible for managing the set of nodes that are connected to each other.

func NewNetwork

func NewNetwork(param *NetworkConfig, opts ...NetworkOption) (*Network, error)

NewNetwork creates a new network with the given configuration. Args: param: network configuration opts: network options Returns: Network: a new network

func (*Network) Identities

func (n *Network) Identities() flow.IdentityList

func (*Network) Identity

func (n *Network) Identity(pid peer.ID) (*flow.Identity, bool)

func (*Network) MulticastOnChannel

func (n *Network) MulticastOnChannel(channel channels.Channel, message interface{}, num uint, targetIDs ...flow.Identifier) error

MulticastOnChannel unreliably sends the specified event over the channel to randomly selected 'num' number of recipients selected from the specified targetIDs.

func (*Network) OnAllowListNotification

func (n *Network) OnAllowListNotification(notification *network.AllowListingUpdate)

func (*Network) OnDisallowListNotification

func (n *Network) OnDisallowListNotification(notification *network.DisallowListingUpdate)

func (*Network) PublishOnChannel

func (n *Network) PublishOnChannel(channel channels.Channel, message interface{}, targetIDs ...flow.Identifier) error

PublishOnChannel sends the message in an unreliable way to the given recipients. In this context, unreliable means that the message is published over a libp2p pub-sub channel and can be read by any node subscribed to that channel. The selector could be used to optimize or restrict delivery.

func (*Network) Receive

func (n *Network) Receive(msg network.IncomingMessageScope) error

func (*Network) Register

func (n *Network) Register(channel channels.Channel, messageProcessor network.MessageProcessor) (network.Conduit, error)

Register will register the given engine with the given unique engine engineID, returning a conduit to directly submit messages to the message bus of the engine.

func (*Network) RegisterBlobService

func (n *Network) RegisterBlobService(channel channels.Channel, ds datastore.Batching, opts ...network.BlobServiceOption) (network.BlobService, error)

RegisterBlobService registers a BlobService on the given channel. The returned BlobService can be used to request blobs from the network.

func (*Network) RegisterPingService

func (n *Network) RegisterPingService(pingProtocol protocol.ID, provider network.PingInfoProvider) (network.PingService, error)

func (*Network) ReportMisbehaviorOnChannel

func (n *Network) ReportMisbehaviorOnChannel(channel channels.Channel, report network.MisbehaviorReport)

ReportMisbehaviorOnChannel reports the misbehavior of a node on sending a message to the current node that appears valid based on the networking layer but is considered invalid by the current node based on the Flow protocol. The misbehavior report is sent to the current node's networking layer on the given channel to be processed. Args: - channel: The channel on which the misbehavior report is sent. - report: The misbehavior report to be sent. Returns: none

func (*Network) Subscribe

func (n *Network) Subscribe(channel channels.Channel) error

Subscribe subscribes the network to a channel. No errors are expected during normal operation.

func (*Network) Topology

func (n *Network) Topology() flow.IdentityList

func (*Network) UnRegisterChannel

func (n *Network) UnRegisterChannel(channel channels.Channel) error

UnRegisterChannel unregisters the engine for the specified channel. The engine will no longer be able to send or receive messages from that channel.

func (*Network) UnicastOnChannel

func (n *Network) UnicastOnChannel(channel channels.Channel, payload interface{}, targetID flow.Identifier) error

UnicastOnChannel sends the message in a reliable way to the given recipient. It uses 1-1 direct messaging over the underlying network to deliver the message. It returns an error if unicasting fails.

func (*Network) Unsubscribe

func (n *Network) Unsubscribe(channel channels.Channel) error

Unsubscribe unsubscribes the network from a channel. The following benign errors are expected during normal operations from libP2P: - the libP2P node fails to unsubscribe to the topic created from the provided channel.

All errors returned from this function can be considered benign.

func (*Network) UpdateNodeAddresses

func (n *Network) UpdateNodeAddresses()

type NetworkConfig

type NetworkConfig struct {
	Logger                           zerolog.Logger
	Codec                            network.Codec
	Me                               module.Local
	Topology                         network.Topology
	Metrics                          module.NetworkCoreMetrics
	IdentityProvider                 module.IdentityProvider
	IdentityTranslator               p2p.IDTranslator
	ReceiveCache                     *netcache.ReceiveCache
	ConduitFactory                   network.ConduitFactory
	AlspCfg                          *alspmgr.MisbehaviorReportManagerConfig
	SporkId                          flow.Identifier
	UnicastMessageTimeout            time.Duration
	Libp2pNode                       p2p.LibP2PNode
	BitSwapMetrics                   module.BitswapMetrics
	SlashingViolationConsumerFactory func(network.ConduitAdapter) network.ViolationsConsumer
}

NetworkConfig is a configuration struct for the network. It contains all the necessary components to create a new network.

func (*NetworkConfig) Validate

func (cfg *NetworkConfig) Validate()

Validate validates the configuration, and sets default values for any missing fields.

type NetworkConfigOption

type NetworkConfigOption func(*NetworkConfig)

NetworkConfigOption is a function that can be used to override network config parmeters.

func WithAlspConfig

WithAlspConfig overrides the default misbehavior report manager config. It is mostly used for testing purposes. Note: do not override the default misbehavior report manager config in production unless you know what you are doing. Args: cfg: misbehavior report manager config Returns: NetworkConfigOption: network param option

func WithCodec

func WithCodec(codec network.Codec) NetworkConfigOption

WithCodec overrides the default codec (i.e., encoder and decoder). It is mostly used for testing purposes. Note: do not override the default codec in production unless you know what you are doing.

func WithSlashingViolationConsumerFactory

func WithSlashingViolationConsumerFactory(factory func(adapter network.ConduitAdapter) network.ViolationsConsumer) NetworkConfigOption

type NetworkOption

type NetworkOption func(*Network)

NetworkOption is a function that can be used to override network attributes. It is mostly used for testing purposes. Note: do not override network attributes in production unless you know what you are doing.

func WithAlspManager

func WithAlspManager(mgr network.MisbehaviorReportManager) NetworkOption

WithAlspManager sets the misbehavior report manager for the network. It overrides the default misbehavior report manager that is created from the config. Note that this option is mostly used for testing purposes, do not use it in production unless you know what you are doing.

Args:

mgr: misbehavior report manager

Returns:

NetworkOption: network option

func WithMessageValidators

func WithMessageValidators(validators ...network.MessageValidator) NetworkOption

WithMessageValidators sets the message validators for the network. It overrides the default message validators.

func WithPeerManagerFilters

func WithPeerManagerFilters(filters ...p2p.PeerFilter) NetworkOption

WithPeerManagerFilters sets the peer manager filters for the network. It overrides the default peer manager filters that are created from the config.

func WithPreferredUnicastProtocols

func WithPreferredUnicastProtocols(protocols ...protocols.ProtocolName) NetworkOption

WithPreferredUnicastProtocols sets the preferred unicast protocols for the network. It overrides the default preferred unicast.

func WithUnicastRateLimiters

func WithUnicastRateLimiters(limiters *ratelimit.RateLimiters) NetworkOption

WithUnicastRateLimiters sets the unicast rate limiters for the network. It overrides the default unicast rate limiters that are created from the config.

type NoopConduit added in v0.33.12

type NoopConduit struct{}

func (*NoopConduit) Close added in v0.33.12

func (n *NoopConduit) Close() error

func (*NoopConduit) Multicast added in v0.33.12

func (n *NoopConduit) Multicast(event interface{}, num uint, targetIDs ...flow.Identifier) error

func (*NoopConduit) Publish added in v0.33.12

func (n *NoopConduit) Publish(event interface{}, targetIDs ...flow.Identifier) error

func (*NoopConduit) ReportMisbehavior added in v0.33.12

func (n *NoopConduit) ReportMisbehavior(network.MisbehaviorReport)

func (*NoopConduit) Unicast added in v0.33.12

func (n *NoopConduit) Unicast(event interface{}, targetID flow.Identifier) error

type NoopEngineRegister added in v0.33.12

type NoopEngineRegister struct {
	module.NoopComponent
}

func (NoopEngineRegister) Register added in v0.33.12

func (n NoopEngineRegister) Register(channel channels.Channel, messageProcessor network.MessageProcessor) (network.Conduit, error)

func (NoopEngineRegister) RegisterBlobService added in v0.33.12

func (n NoopEngineRegister) RegisterBlobService(channel channels.Channel, store datastore.Batching, opts ...network.BlobServiceOption) (network.BlobService, error)

func (NoopEngineRegister) RegisterPingService added in v0.33.12

func (n NoopEngineRegister) RegisterPingService(pingProtocolID protocol.ID, pingInfoProvider network.PingInfoProvider) (network.PingService, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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