gossip

package
v1.10.16-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: BSD-3-Clause Imports: 16 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidID = errors.New("invalid id")
)

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,
	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 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 Config

type Config struct {
	Namespace string
	PollSize  int
}

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

func NewHandler

func NewHandler[T Gossipable](
	set Set[T],
	config HandlerConfig,
	metrics prometheus.Registerer,
) (*Handler[T], error)

func (Handler[T]) AppRequest

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

type HandlerConfig

type HandlerConfig struct {
	Namespace          string
	TargetResponseSize int
}

type PullGossiper

type PullGossiper[T any, U GossipableAny[T]] struct {
	// contains filtered or unexported fields
}

func NewPullGossiper

func NewPullGossiper[T any, U GossipableAny[T]](
	config Config,
	log logging.Logger,
	set Set[U],
	client *p2p.Client,
	metrics prometheus.Registerer,
) (*PullGossiper[T, U], error)

func (*PullGossiper[_, _]) Gossip

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

type Set

type Set[T Gossipable] interface {
	// Add adds a Gossipable to the set
	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

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