gossip

package
v1.10.10-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: BSD-3-Clause Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

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

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 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 {
	Frequency time.Duration
	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[T any, U GossipableAny[T]] struct {
	// contains filtered or unexported fields
}

func NewGossiper

func NewGossiper[T any, U GossipableAny[T]](
	config Config,
	log logging.Logger,
	set Set[U],
	client *p2p.Client,
) *Gossiper[T, U]

func (*Gossiper[_, _]) Gossip

func (g *Gossiper[_, _]) Gossip(ctx context.Context)

type Handler

type Handler[T Gossipable] struct {
	p2p.Handler
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler[T Gossipable](set Set[T], maxResponseSize int) *Handler[T]

func (Handler[T]) AppRequest

func (h Handler[T]) AppRequest(_ context.Context, _ ids.NodeID, _ time.Time, requestBytes []byte) ([]byte, 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

Jump to

Keyboard shortcuts

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