Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DialThrottler ¶
type DialThrottler interface {
// Block until the event associated with this Acquire can happen.
// If [ctx] is canceled, gives up and returns an error.
Acquire(ctx context.Context) error
}
func NewDialThrottler ¶
func NewDialThrottler(throttleLimit int) DialThrottler
func NewNoDialThrottler ¶
func NewNoDialThrottler() DialThrottler
type InboundConnUpgradeThrottler ¶ added in v1.6.0
type InboundConnUpgradeThrottler interface {
// Dispatch starts this InboundConnUpgradeThrottler.
// Must be called before [ShouldUpgrade].
// Blocks until [Stop] is called (i.e. should be called in a goroutine.)
Dispatch()
// Stop this InboundConnUpgradeThrottler and causes [Dispatch] to return.
// Should be called when we're done with this InboundConnUpgradeThrottler.
// This InboundConnUpgradeThrottler must not be used after [Stop] is called.
Stop()
// Returns whether we should upgrade an inbound connection from [ipStr].
// Must only be called after [Dispatch] has been called.
// Must not be called after [Stop] has been called.
ShouldUpgrade(ipStr string) bool
}
InboundConnUpgradeThrottler returns whether we should upgrade an inbound connection from IP [ipStr]. If ShouldUpgrade(ipStr) returns false, the connection to that IP should be closed. Note that InboundConnUpgradeThrottler rate-limits _upgrading_ of inbound connections, whereas throttledListener rate-limits _acceptance_ of inbound connections.
func NewInboundConnUpgradeThrottler ¶ added in v1.6.0
func NewInboundConnUpgradeThrottler(log logging.Logger, config InboundConnUpgradeThrottlerConfig) InboundConnUpgradeThrottler
Returns an InboundConnUpgradeThrottler that upgrades an inbound connection from a given IP at most every [UpgradeCooldown].
type InboundConnUpgradeThrottlerConfig ¶ added in v1.6.0
type InboundConnUpgradeThrottlerConfig struct {
// ShouldUpgrade(ipStr) returns true if it has been at least [UpgradeCooldown]
// since the last time ShouldUpgrade(ipStr) returned true or if
// ShouldUpgrade(ipStr) has never been called.
// If <= 0, inbound connections not rate-limited.
UpgradeCooldown time.Duration `json:"upgradeCooldown"`
// Maximum number of inbound connections upgraded within [UpgradeCooldown].
// (As implemented in inboundConnUpgradeThrottler, may actually upgrade
// [MaxRecentConnsUpgraded+1] due to a race condition but that's fine.)
// If <= 0, inbound connections not rate-limited.
MaxRecentConnsUpgraded int `json:"maxRecentConnsUpgraded"`
}
type InboundMsgThrottler ¶
type InboundMsgThrottler interface {
// Blocks until we can read a message of size [msgSize] from [nodeID].
// For every call to Acquire([msgSize], [nodeID]), we must (!) call
// Release([msgSize], [nodeID]) when done processing the message
// (or when we give up trying to read the message.)
Acquire(msgSize uint64, nodeID ids.ShortID)
// Mark that we're done processing a message of size [msgSize]
// from [nodeID].
Release(msgSize uint64, nodeID ids.ShortID)
}
InboundMsgThrottler rate-limits inbound messages from the network.
func NewInboundMsgThrottler ¶ added in v1.6.2
func NewInboundMsgThrottler( log logging.Logger, namespace string, registerer prometheus.Registerer, vdrs validators.Set, config InboundMsgThrottlerConfig, ) (InboundMsgThrottler, error)
Returns a new, sybil-safe inbound message throttler.
func NewNoInboundThrottler ¶
func NewNoInboundThrottler() InboundMsgThrottler
Returns an InboundMsgThrottler where Acquire() always returns immediately.
type InboundMsgThrottlerConfig ¶ added in v1.6.2
type InboundMsgThrottlerConfig struct {
MsgByteThrottlerConfig
MaxProcessingMsgsPerNode uint64 `json:"maxProcessingMsgsPerNode"`
}
type MsgByteThrottlerConfig ¶ added in v1.6.2
type MsgByteThrottlerConfig struct {
VdrAllocSize uint64 `json:"vdrAllocSize"`
AtLargeAllocSize uint64 `json:"atLargeAllocSize"`
NodeMaxAtLargeBytes uint64 `json:"nodeMaxAtLargeBytes"`
}
Used by the sybil-safe inbound and outbound message throttlers
type OutboundMsgThrottler ¶
type OutboundMsgThrottler interface {
// Returns true if we can queue a message of size [msgSize] to be sent to node [nodeID].
// Returns false if the message should be dropped (not sent to [nodeID]).
// If this method returns true, Release([msgSize], [nodeID]) must be called (!) when
// the message is sent (or when we give up trying to send the message, if applicable.)
// If this method returns false, do not make a corresponding call to Release.
Acquire(msgSize uint64, nodeID ids.ShortID) bool
// Mark that a message of size [msgSize] has been sent to [nodeID] or we have
// given up sending the message. Must correspond to a previous call to
// Acquire([msgSize], [nodeID]) that returned true.
Release(msgSize uint64, nodeID ids.ShortID)
}
Rate-limits outgoing messages
func NewNoOutboundThrottler ¶
func NewNoOutboundThrottler() OutboundMsgThrottler
func NewSybilOutboundMsgThrottler ¶
func NewSybilOutboundMsgThrottler( log logging.Logger, namespace string, registerer prometheus.Registerer, vdrs validators.Set, config MsgByteThrottlerConfig, ) (OutboundMsgThrottler, error)