github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/inspector/internal/cache/record.go (about)

     1  package cache
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/onflow/flow-go/model/flow"
     7  )
     8  
     9  // ClusterPrefixedMessagesReceivedRecord cache record that keeps track of the amount of cluster prefixed control messages received from a peer.
    10  // This struct implements the flow.Entity interface and uses  node ID of the sender for deduplication.
    11  type ClusterPrefixedMessagesReceivedRecord struct {
    12  	// NodeID the node ID of the sender.
    13  	NodeID flow.Identifier
    14  	// Gauge represents the approximate amount of cluster prefixed messages received by a peer, this
    15  	// value is decayed back to 0 after some time.
    16  	Gauge       float64
    17  	lastUpdated time.Time
    18  }
    19  
    20  func NewClusterPrefixedMessagesReceivedRecord(nodeID flow.Identifier) ClusterPrefixedMessagesReceivedRecord {
    21  	return ClusterPrefixedMessagesReceivedRecord{
    22  		NodeID:      nodeID,
    23  		Gauge:       0.0,
    24  		lastUpdated: time.Now(),
    25  	}
    26  }
    27  
    28  var _ flow.Entity = (*ClusterPrefixedMessagesReceivedRecord)(nil)
    29  
    30  // ID returns the node ID of the sender, which is used as the unique identifier of the entity for maintenance and
    31  // deduplication purposes in the cache.
    32  func (c ClusterPrefixedMessagesReceivedRecord) ID() flow.Identifier {
    33  	return c.NodeID
    34  }
    35  
    36  // Checksum returns the node ID of the sender, it does not have any purpose in the cache.
    37  // It is implemented to satisfy the flow.Entity interface.
    38  func (c ClusterPrefixedMessagesReceivedRecord) Checksum() flow.Identifier {
    39  	return c.NodeID
    40  }