github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/disallowListCache.go (about) 1 package p2p 2 3 import ( 4 "github.com/libp2p/go-libp2p/core/peer" 5 6 "github.com/onflow/flow-go/module" 7 "github.com/onflow/flow-go/network" 8 ) 9 10 // DisallowListCache is an interface for a cache that keeps the list of disallow-listed peers. 11 // It is designed to present a centralized interface for keeping track of disallow-listed peers for different reasons. 12 type DisallowListCache interface { 13 // IsDisallowListed determines whether the given peer is disallow-listed for any reason. 14 // Args: 15 // - peerID: the peer to check. 16 // Returns: 17 // - []network.DisallowListedCause: the list of causes for which the given peer is disallow-listed. If the peer is not disallow-listed for any reason, 18 // a nil slice is returned. 19 // - bool: true if the peer is disallow-listed for any reason, false otherwise. 20 IsDisallowListed(peerID peer.ID) ([]network.DisallowListedCause, bool) 21 22 // DisallowFor disallow-lists a peer for a cause. 23 // Args: 24 // - peerID: the peerID of the peer to be disallow-listed. 25 // - cause: the cause for disallow-listing the peer. 26 // Returns: 27 // - the list of causes for which the peer is disallow-listed. 28 // - error if the operation fails, error is irrecoverable. 29 DisallowFor(peerID peer.ID, cause network.DisallowListedCause) ([]network.DisallowListedCause, error) 30 31 // AllowFor removes a cause from the disallow list cache entity for the peerID. 32 // Args: 33 // - peerID: the peerID of the peer to be allow-listed. 34 // - cause: the cause for allow-listing the peer. 35 // Returns: 36 // - the list of causes for which the peer is disallow-listed. If the peer is not disallow-listed for any reason, 37 // an empty list is returned. 38 AllowFor(peerID peer.ID, cause network.DisallowListedCause) []network.DisallowListedCause 39 } 40 41 // DisallowListCacheConfig is the configuration for the disallow-list cache. 42 // The disallow-list cache is used to temporarily disallow-list peers. 43 type DisallowListCacheConfig struct { 44 // MaxSize is the maximum number of peers that can be disallow-listed at any given time. 45 // When the cache is full, no further new peers can be disallow-listed. 46 // Recommended size is 100 * number of staked nodes. 47 MaxSize uint32 48 49 // Metrics is the HeroCache metrics collector to be used for the disallow-list cache. 50 Metrics module.HeroCacheMetrics 51 }