Documentation
¶
Index ¶
Constants ¶
const (
// MaxRetryJitter is the maximum number of milliseconds to wait between attempts for a 1-1 direct connection
MaxRetryJitter = 5
)
Variables ¶
This section is empty.
Functions ¶
func IsErrMaxRetries ¶ added in v0.30.0
IsErrMaxRetries returns whether an error is ErrMaxRetries.
Types ¶
type Config ¶ added in v0.33.1
type Config struct { StreamCreationRetryAttemptBudget uint64 // number of times we have to try to open a stream to the peer before we give up. ConsecutiveSuccessfulStream uint64 // consecutive number of successful streams to the peer since the last time stream creation failed. }
Config is a struct that represents the dial config for a peer.
type ConfigCache ¶ added in v0.33.1
type ConfigCache interface { // GetOrInit returns the dial config for the given peer id. If the config does not exist, it creates a new config // using the factory function and stores it in the cache. // Args: // - peerID: the peer id of the dial config. // Returns: // - *Config, the dial config for the given peer id. // - error if the factory function returns an error. Any error should be treated as an irrecoverable error and indicates a bug. GetOrInit(peerID peer.ID) (*Config, error) // Adjust adjusts the dial config for the given peer id using the given adjustFunc. // It returns an error if the adjustFunc returns an error. // Args: // - peerID: the peer id of the dial config. // - adjustFunc: the function that adjusts the dial config. // Returns: // - error if the adjustFunc returns an error. Any error should be treated as an irrecoverable error and indicates a bug. Adjust(peerID peer.ID, adjustFunc UnicastConfigAdjustFunc) (*Config, error) // Size returns the number of dial configs in the cache. Size() uint }
ConfigCache is a thread-safe cache for dial configs. It is used by the unicast service to store the dial configs for peers.
type DialConfigCacheFactory ¶ added in v0.32.2
type DialConfigCacheFactory func(configFactory func() Config) ConfigCache
type ErrMaxRetries ¶ added in v0.30.0
type ErrMaxRetries struct {
// contains filtered or unexported fields
}
ErrMaxRetries indicates retries completed with max retries without a successful attempt.
func NewMaxRetriesErr ¶ added in v0.30.0
func NewMaxRetriesErr(attempts uint64, err error) ErrMaxRetries
NewMaxRetriesErr returns a new ErrMaxRetries.
func (ErrMaxRetries) Error ¶ added in v0.30.0
func (e ErrMaxRetries) Error() string
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages libp2p stream negotiation and creation, which is utilized for unicast dispatches.
func NewUnicastManager ¶
func NewUnicastManager(cfg *ManagerConfig) (*Manager, error)
NewUnicastManager creates a new unicast manager. Args:
- cfg: configuration for the unicast manager.
Returns:
- a new unicast manager.
- an error if the configuration is invalid, any error is irrecoverable.
func (*Manager) CreateStream ¶
CreateStream tries establishing a libp2p stream to the remote peer id. It tries creating streams in the descending order of preference until it either creates a successful stream or runs out of options. Args:
- ctx: context for the stream creation.
- peerID: peer ID of the remote peer.
Returns:
- a new libp2p stream.
- error if the stream creation fails; the error is benign and can be retried.
func (*Manager) Register ¶
func (m *Manager) Register(protocol protocols.ProtocolName) error
Register registers given protocol name as preferred unicast. Each invocation of register prioritizes the current protocol over previously registered ones.
func (*Manager) SetDefaultHandler ¶ added in v0.32.0
func (m *Manager) SetDefaultHandler(defaultHandler libp2pnet.StreamHandler)
SetDefaultHandler sets the default stream handler for this unicast manager. The default handler is utilized as the core handler for other unicast protocols, e.g., compressions.
type ManagerConfig ¶ added in v0.32.2
type ManagerConfig struct { Logger zerolog.Logger `validate:"required"` StreamFactory p2p.StreamFactory `validate:"required"` SporkId flow.Identifier `validate:"required"` Metrics module.UnicastManagerMetrics `validate:"required"` // CreateStreamBackoffDelay is the backoff delay between retrying stream creations to the same peer. CreateStreamBackoffDelay time.Duration `validate:"gt=0"` // StreamZeroRetryResetThreshold is the threshold that determines when to reset the stream creation retry budget to the default value. // // For example the default value of 100 means that if the stream creation retry budget is decreased to 0, then it will be reset to default value // when the number of consecutive successful streams reaches 100. // // This is to prevent the retry budget from being reset too frequently, as the retry budget is used to gauge the reliability of the stream creation. // When the stream creation retry budget is reset to the default value, it means that the stream creation is reliable enough to be trusted again. // This parameter mandates when the stream creation is reliable enough to be trusted again; i.e., when the number of consecutive successful streams reaches this threshold. // Note that the counter is reset to 0 when the stream creation fails, so the value of for example 100 means that the stream creation is reliable enough that the recent // 100 stream creations are all successful. StreamZeroRetryResetThreshold uint64 `validate:"gt=0"` // MaxStreamCreationRetryAttemptTimes is the maximum number of attempts to be made to create a stream to a remote node over a direct unicast (1:1) connection before we give up. MaxStreamCreationRetryAttemptTimes uint64 `validate:"gt=0"` // UnicastConfigCacheFactory is a factory function to create a new dial config cache. UnicastConfigCacheFactory DialConfigCacheFactory `validate:"required"` }
type UnicastConfigAdjustFunc ¶ added in v0.33.1
UnicastConfigAdjustFunc is a function that is used to adjust the fields of a DialConfigEntity. The function is called with the current config and should return the adjusted record. Returned error indicates that the adjustment is not applied, and the config should not be updated. In BFT setup, the returned error should be treated as a fatal error.