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 IsErrDialInProgress ¶ added in v0.30.0
IsErrDialInProgress returns whether an error is ErrDialInProgress
func IsErrMaxRetries ¶ added in v0.30.0
IsErrMaxRetries returns whether an error is ErrMaxRetries.
Types ¶
type DialConfig ¶ added in v0.32.2
type DialConfig struct { DialRetryAttemptBudget uint64 // number of times we have to try to dial the peer before we give up. StreamCreationRetryAttemptBudget uint64 // number of times we have to try to open a stream to the peer before we give up. LastSuccessfulDial time.Time // timestamp of the last successful dial to the peer. ConsecutiveSuccessfulStream uint64 // consecutive number of successful streams to the peer since the last time stream creation failed. }
DialConfig is a struct that represents the dial config for a peer.
type DialConfigAdjustFunc ¶ added in v0.32.2
type DialConfigAdjustFunc func(DialConfig) (DialConfig, error)
DialConfigAdjustFunc 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.
type DialConfigCache ¶ added in v0.32.2
type DialConfigCache 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: // - *DialConfig, 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) (*DialConfig, 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 DialConfigAdjustFunc) (*DialConfig, error) // Size returns the number of dial configs in the cache. Size() uint }
DialConfigCache 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() DialConfig) DialConfigCache
type ErrDialInProgress ¶ added in v0.30.0
type ErrDialInProgress struct {
// contains filtered or unexported fields
}
ErrDialInProgress indicates that the libp2p node is currently dialing the peer.
func NewDialInProgressErr ¶ added in v0.30.0
func NewDialInProgressErr(pid peer.ID) ErrDialInProgress
NewDialInProgressErr returns a new ErrDialInProgress.
func (ErrDialInProgress) Error ¶ added in v0.30.0
func (e ErrDialInProgress) Error() string
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"` ConnStatus p2p.PeerConnections `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"` // DialInProgressBackoffDelay is the backoff delay for parallel attempts on dialing to the same peer. // When the unicast manager is invoked to create stream to the same peer concurrently while there is // already an ongoing dialing attempt to the same peer, the unicast manager will wait for this backoff delay // and retry creating the stream after the backoff delay has elapsed. This is to prevent the unicast manager // from creating too many parallel dialing attempts to the same peer. DialInProgressBackoffDelay time.Duration `validate:"gt=0"` // DialBackoffDelay is the backoff delay between retrying connection to the same peer. DialBackoffDelay 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"` // DialZeroRetryResetThreshold is the threshold that determines when to reset the dial retry budget to the default value. // For example the threshold of 1 hour means that if the dial retry budget is decreased to 0, then it will be reset to default value // when it has been 1 hour since the last successful dial. // // This is to prevent the retry budget from being reset too frequently, as the retry budget is used to gauge the reliability of the dialing a remote peer. // When the dial retry budget is reset to the default value, it means that the dialing is reliable enough to be trusted again. // This parameter mandates when the dialing is reliable enough to be trusted again; i.e., when it has been 1 hour since the last successful dial. // Note that the last dial attempt timestamp is reset to zero when the dial fails, so the value of for example 1 hour means that the dialing to the remote peer is reliable enough that the last // successful dial attempt was 1 hour ago. DialZeroRetryResetThreshold time.Duration `validate:"gt=0"` // MaxDialRetryAttemptTimes is the maximum number of attempts to be made to connect to a remote node to establish a unicast (1:1) connection before we give up. MaxDialRetryAttemptTimes 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"` // DialConfigCacheFactory is a factory function to create a new dial config cache. DialConfigCacheFactory DialConfigCacheFactory `validate:"required"` }