Documentation ¶
Index ¶
- func Every(ctx context.Context, log logging.Logger, gossiper Gossiper, ...)
- func ResetBloomFilterIfNeeded(bloomFilter *BloomFilter, falsePositiveProbability float64) (bool, error)
- type Accumulator
- type BloomFilter
- type Gossipable
- type GossipableAny
- type Gossiper
- type Handler
- type Metrics
- type NoOpAccumulator
- type NoOpGossiper
- type PullGossiper
- type PushGossiper
- type Set
- type ValidatorGossiper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResetBloomFilterIfNeeded ¶
func ResetBloomFilterIfNeeded( bloomFilter *BloomFilter, falsePositiveProbability float64, ) (bool, error)
ResetBloomFilterIfNeeded resets a bloom filter if it breaches a target false positive probability. Returns true if the bloom filter was reset.
Types ¶
type Accumulator ¶ added in v1.10.18
type Accumulator[T Gossipable] interface { Gossiper // Add queues gossipables to be gossiped Add(gossipables ...T) }
Accumulator allows a caller to accumulate gossipables to be gossiped
type BloomFilter ¶
type BloomFilter struct { Bloom *bloomfilter.Filter // Salt is provided to eventually unblock collisions in Bloom. It's possible // that conflicting Gossipable items collide in the bloom filter, so a salt // is generated to eventually resolve collisions. Salt ids.ID }
func NewBloomFilter ¶
func NewBloomFilter( maxExpectedElements uint64, falsePositiveProbability float64, ) (*BloomFilter, error)
NewBloomFilter returns a new instance of a bloom filter with at most [maxExpectedElements] elements anticipated at any moment, and a false positive probability of [falsePositiveProbability].
func (*BloomFilter) Add ¶
func (b *BloomFilter) Add(gossipable Gossipable)
func (*BloomFilter) Has ¶
func (b *BloomFilter) Has(gossipable Gossipable) bool
type Gossipable ¶
type Gossipable interface { GetID() ids.ID Marshal() ([]byte, error) Unmarshal(bytes []byte) error }
Gossipable is an item that can be gossiped across the network
type GossipableAny ¶
type GossipableAny[T any] interface { *T Gossipable }
GossipableAny exists to help create non-nil pointers to a concrete Gossipable ref: https://stackoverflow.com/questions/69573113/how-can-i-instantiate-a-non-nil-pointer-of-type-argument-with-generic-go
type Gossiper ¶
type Gossiper interface { // Gossip runs a cycle of gossip. Returns an error if we failed to gossip. Gossip(ctx context.Context) error }
Gossiper gossips Gossipables to other nodes
type Handler ¶
type Handler[T any, U GossipableAny[T]] struct { p2p.Handler // contains filtered or unexported fields }
func NewHandler ¶
func NewHandler[T any, U GossipableAny[T]]( log logging.Logger, accumulator Accumulator[U], set Set[U], metrics Metrics, targetResponseSize int, ) *Handler[T, U]
type Metrics ¶ added in v1.10.18
type Metrics struct {
// contains filtered or unexported fields
}
Metrics that are tracked across a gossip protocol. A given protocol should only use a single instance of Metrics.
func NewMetrics ¶ added in v1.10.18
func NewMetrics( metrics prometheus.Registerer, namespace string, ) (Metrics, error)
NewMetrics returns a common set of metrics
type NoOpAccumulator ¶ added in v1.10.18
type NoOpAccumulator[T Gossipable] struct{}
func (NoOpAccumulator[T]) Add ¶ added in v1.10.18
func (NoOpAccumulator[T]) Add(...T)
type NoOpGossiper ¶ added in v1.10.18
type NoOpGossiper struct{}
type PullGossiper ¶
type PullGossiper[T any, U GossipableAny[T]] struct { // contains filtered or unexported fields }
func NewPullGossiper ¶
func NewPullGossiper[T any, U GossipableAny[T]]( log logging.Logger, set Set[U], client *p2p.Client, metrics Metrics, pollSize int, ) *PullGossiper[T, U]
type PushGossiper ¶ added in v1.10.18
type PushGossiper[T Gossipable] struct { // contains filtered or unexported fields }
PushGossiper broadcasts gossip to peers randomly in the network
func NewPushGossiper ¶ added in v1.10.18
func NewPushGossiper[T Gossipable](client *p2p.Client, metrics Metrics, targetGossipSize int) *PushGossiper[T]
NewPushGossiper returns an instance of PushGossiper
func (*PushGossiper[T]) Add ¶ added in v1.10.18
func (p *PushGossiper[T]) Add(gossipables ...T)
type Set ¶
type Set[T Gossipable] interface { // Add adds a Gossipable to the set. Returns an error if gossipable was not // added. Add(gossipable T) error // Iterate iterates over elements until [f] returns false Iterate(f func(gossipable T) bool) // GetFilter returns the byte representation of bloom filter and its // corresponding salt. GetFilter() (bloom []byte, salt []byte, err error) }
Set holds a set of known Gossipable items
type ValidatorGossiper ¶
type ValidatorGossiper struct { Gossiper NodeID ids.NodeID Validators p2p.ValidatorSet }
ValidatorGossiper only calls [Gossip] if the given node is a validator