github.com/MetalBlockchain/metalgo@v1.11.9/network/throttling/common.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package throttling 5 6 import ( 7 "sync" 8 9 "github.com/MetalBlockchain/metalgo/ids" 10 "github.com/MetalBlockchain/metalgo/snow/validators" 11 "github.com/MetalBlockchain/metalgo/utils/logging" 12 ) 13 14 // Used by the sybil-safe inbound and outbound message throttlers 15 type MsgByteThrottlerConfig struct { 16 VdrAllocSize uint64 `json:"vdrAllocSize"` 17 AtLargeAllocSize uint64 `json:"atLargeAllocSize"` 18 NodeMaxAtLargeBytes uint64 `json:"nodeMaxAtLargeBytes"` 19 } 20 21 // Used by the sybil-safe inbound and outbound message throttlers 22 type commonMsgThrottler struct { 23 log logging.Logger 24 lock sync.Mutex 25 vdrs validators.Manager 26 // Max number of bytes that can be taken from the 27 // at-large byte allocation by a given node. 28 nodeMaxAtLargeBytes uint64 29 // Number of bytes left in the validator byte allocation. 30 // Initialized to [maxVdrBytes]. 31 remainingVdrBytes uint64 32 // Number of bytes left in the at-large byte allocation 33 remainingAtLargeBytes uint64 34 // Node ID --> Bytes they've taken from the validator allocation 35 nodeToVdrBytesUsed map[ids.NodeID]uint64 36 // Node ID --> Bytes they've taken from the at-large allocation 37 nodeToAtLargeBytesUsed map[ids.NodeID]uint64 38 // Max number of unprocessed bytes from validators 39 maxVdrBytes uint64 40 }