gossip

package
v1.10.18-rc.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2024 License: BSD-3-Clause Imports: 17 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Every

func Every(ctx context.Context, log logging.Logger, gossiper Gossiper, frequency time.Duration)

Every calls [Gossip] every [frequency] amount of time.

func ResetBloomFilterIfNeeded

func ResetBloomFilterIfNeeded(
	bloomFilter *BloomFilter,
	targetElements int,
) (bool, error)

ResetBloomFilterIfNeeded resets a bloom filter if it breaches [targetFalsePositiveProbability].

If [targetElements] exceeds [minTargetElements], the size of the bloom filter will grow to maintain the same [targetFalsePositiveProbability].

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 {
	// contains filtered or unexported fields
}

func NewBloomFilter

func NewBloomFilter(
	minTargetElements int,
	targetFalsePositiveProbability,
	resetFalsePositiveProbability float64,
) (*BloomFilter, error)

NewBloomFilter returns a new instance of a bloom filter with at least [minTargetElements] elements anticipated at any moment, and a false positive probability of [targetFalsePositiveProbability]. If the false positive probability exceeds [resetFalsePositiveProbability], the bloom filter will be reset.

Invariant: The returned bloom filter is not safe to reset concurrently with other operations. However, it is otherwise safe to access concurrently.

func (*BloomFilter) Add

func (b *BloomFilter) Add(gossipable Gossipable)

func (*BloomFilter) Has

func (b *BloomFilter) Has(gossipable Gossipable) bool

func (*BloomFilter) Marshal added in v1.10.18

func (b *BloomFilter) Marshal() ([]byte, []byte)

type Gossipable

type Gossipable interface {
	GossipID() ids.ID
}

Gossipable is an item that can be gossiped across the network

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 Gossipable] struct {
	p2p.Handler
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler[T Gossipable](
	log logging.Logger,
	marshaller Marshaller[T],
	accumulator Accumulator[T],
	set Set[T],
	metrics Metrics,
	targetResponseSize int,
) *Handler[T]

func (Handler[_]) AppGossip added in v1.10.18

func (h Handler[_]) AppGossip(ctx context.Context, nodeID ids.NodeID, gossipBytes []byte)

func (Handler[T]) AppRequest

func (h Handler[T]) AppRequest(_ context.Context, _ ids.NodeID, _ time.Time, requestBytes []byte) ([]byte, error)

type Marshaller added in v1.10.18

type Marshaller[T Gossipable] interface {
	MarshalGossip(T) ([]byte, error)
	UnmarshalGossip([]byte) (T, error)
}

Marshaller handles parsing logic for a concrete Gossipable type

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)

func (NoOpAccumulator[_]) Gossip added in v1.10.18

func (NoOpAccumulator[_]) Gossip(context.Context) error

type NoOpGossiper added in v1.10.18

type NoOpGossiper struct{}

func (NoOpGossiper) Gossip added in v1.10.18

type PullGossiper

type PullGossiper[T Gossipable] struct {
	// contains filtered or unexported fields
}

func NewPullGossiper

func NewPullGossiper[T Gossipable](
	log logging.Logger,
	marshaller Marshaller[T],
	set Set[T],
	client *p2p.Client,
	metrics Metrics,
	pollSize int,
) *PullGossiper[T]

func (*PullGossiper[_]) Gossip

func (p *PullGossiper[_]) Gossip(ctx context.Context) error

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](marshaller Marshaller[T], 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)

func (*PushGossiper[T]) Gossip added in v1.10.18

func (p *PushGossiper[T]) Gossip(ctx context.Context) error

Gossip flushes any queued gossipables

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)
}

Set holds a set of known Gossipable items

type TestAccumulator added in v1.10.18

type TestAccumulator[T Gossipable] struct {
	GossipF func(ctx context.Context) error
	AddF    func(...T)
}

func (TestAccumulator[T]) Add added in v1.10.18

func (t TestAccumulator[T]) Add(gossipables ...T)

func (TestAccumulator[T]) Gossip added in v1.10.18

func (t TestAccumulator[T]) Gossip(ctx context.Context) error

type TestGossiper added in v1.10.18

type TestGossiper struct {
	GossipF func(ctx context.Context) error
}

func (*TestGossiper) Gossip added in v1.10.18

func (t *TestGossiper) Gossip(ctx context.Context) error

type ValidatorGossiper

type ValidatorGossiper struct {
	Gossiper

	NodeID     ids.NodeID
	Validators p2p.ValidatorSet
}

ValidatorGossiper only calls [Gossip] if the given node is a validator

func (ValidatorGossiper) Gossip

func (v ValidatorGossiper) Gossip(ctx context.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL