Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 InboundConnThrottler ¶ added in v1.4.11
type InboundConnThrottler interface { // Dispatch starts this InboundConnThrottler. // Must be called before [Allow]. // Blocks until [Stop] is called (i.e. should be called in a goroutine.) Dispatch() // Stop this InboundConnThrottler and causes [Dispatch] to return. // Should be called when we're done with this InboundConnThrottler. // This InboundConnThrottler must not be used after [Stop] is called. Stop() // Returns whether we should allow an inbound connection from [ipStr]. // Must only be called after [Dispatch] has been called. // Must not be called after [Stop] has been called. Allow(ipStr string) bool }
InboundConnThrottler decides whether to allow an inbound connection from IP [ipStr]. If Allow(ipStr) returns false, the connection to that IP should be closed.
func NewInboundConnThrottler ¶ added in v1.4.11
func NewInboundConnThrottler(log logging.Logger, config InboundConnThrottlerConfig) InboundConnThrottler
Returns an InboundConnThrottler that allows an inbound connection from a given IP every [AllowCooldown].
type InboundConnThrottlerConfig ¶ added in v1.4.11
type InboundConnThrottlerConfig struct { // Allow(ipStr) returns true if it has been at least [AllowCooldown] // since the last time Allow(ipStr) returned true or if // Allow(ipStr) has never been called. // If <= 0, inbound connections not rate-limited. AllowCooldown time.Duration // Maximum number of inbound connections allowed within [AllowCooldown]. // (As implemented in inboundConnThrottler, may actually allow // [MaxRecentConns+1] due to a race condition but that's fine.) // If <= 0, inbound connections not rate-limited. MaxRecentConns int }
type InboundMsgThrottler ¶
type InboundMsgThrottler interface { // Blocks until node [nodeID] can put a message of // size [msgSize] onto the incoming message buffer. Acquire(msgSize uint64, nodeID ids.ShortID) // Mark that a message from [nodeID] of size [msgSize] // has been removed from the incoming message buffer. Release(msgSize uint64, nodeID ids.ShortID) }
InboundMsgThrottler rate-limits incoming messages from the network.
func NewNoInboundThrottler ¶
func NewNoInboundThrottler() InboundMsgThrottler
func NewSybilInboundMsgThrottler ¶
func NewSybilInboundMsgThrottler( log logging.Logger, namespace string, registerer prometheus.Registerer, vdrs validators.Set, config MsgThrottlerConfig, ) (InboundMsgThrottler, error)
Returns a new MsgThrottler. If this function returns an error, the returned MsgThrottler may still be used. However, some of its metrics may not be registered.
type MsgThrottlerConfig ¶
type MsgThrottlerConfig struct { VdrAllocSize uint64 AtLargeAllocSize uint64 NodeMaxAtLargeBytes uint64 }
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 MsgThrottlerConfig, ) (OutboundMsgThrottler, error)
Click to show internal directories.
Click to hide internal directories.