github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/node/internal/cacheEntity.go (about) 1 package internal 2 3 import ( 4 "github.com/libp2p/go-libp2p/core/peer" 5 6 "github.com/onflow/flow-go/model/flow" 7 "github.com/onflow/flow-go/network" 8 ) 9 10 // disallowListCacheEntity is the model data type for the disallow list cache. 11 // It represents a single peer that is disallow-listed and the reasons for it. 12 // The key for storing this entity is the id field which is the hash of the peerID. 13 // This means that the entities are deduplicated by their peerID. 14 type disallowListCacheEntity struct { 15 peerID peer.ID 16 causes map[network.DisallowListedCause]struct{} 17 // id is the hash of the peerID which is used as the key for storing the entity in the cache. 18 // we cache it internally to avoid hashing the peerID multiple times. 19 entityId flow.Identifier 20 } 21 22 var _ flow.Entity = (*disallowListCacheEntity)(nil) 23 24 // ID returns the hash of the peerID which is used as the key for storing the entity in the cache. 25 // Returns: 26 // - the hash of the peerID as a flow.Identifier. 27 func (d *disallowListCacheEntity) ID() flow.Identifier { 28 return d.entityId 29 } 30 31 // Checksum returns the hash of the peerID, there is no use for this method in the cache. It is implemented to satisfy 32 // the flow.Entity interface. 33 // Returns: 34 // - the hash of the peerID as a flow.Identifier. 35 func (d *disallowListCacheEntity) Checksum() flow.Identifier { 36 return d.entityId 37 } 38 39 // makeId is a helper function for creating the id field of the disallowListCacheEntity by hashing the peerID. 40 // Returns: 41 // - the hash of the peerID as a flow.Identifier. 42 func makeId(peerID peer.ID) flow.Identifier { 43 return flow.MakeID([]byte(peerID)) 44 }