github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/unicast/cache/unicastConfigEntity.go (about) 1 package unicastcache 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/p2p/unicast" 8 ) 9 10 // UnicastConfigEntity is a struct that represents a unicast config entry for storing in the unicast config cache. 11 // It implements the flow.Entity interface. 12 type UnicastConfigEntity struct { 13 unicast.Config 14 PeerId peer.ID // remote peer id; used as the "key" in the unicast config cache. 15 EntityId flow.Identifier // cache the id for fast lookup (HeroCache). 16 } 17 18 var _ flow.Entity = (*UnicastConfigEntity)(nil) 19 20 // ID returns the ID of the unicast config entity; it is hash value of the peer id. 21 func (d UnicastConfigEntity) ID() flow.Identifier { 22 return d.EntityId 23 } 24 25 // Checksum acts the same as ID. 26 func (d UnicastConfigEntity) Checksum() flow.Identifier { 27 return d.ID() 28 } 29 30 // entityIdOf converts a peer ID to a flow ID by taking the hash of the peer ID. 31 // This is used to convert the peer ID in a notion that is compatible with HeroCache. 32 // This is not a protocol-level conversion, and is only used internally by the cache, MUST NOT be exposed outside the cache. 33 // Args: 34 // - peerId: the peer ID of the peer in the GossipSub protocol. 35 // Returns: 36 // - flow.Identifier: the flow ID of the peer. 37 func entityIdOf(pid peer.ID) flow.Identifier { 38 return flow.MakeID(pid) 39 }