gossip

package
v0.12.5-rc.3-20231201 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: GPL-3.0, LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const HashLength = 8

Variables

This section is empty.

Functions

func ResetBloomFilterIfNeeded

func ResetBloomFilterIfNeeded(
	bloomFilter *BloomFilter,
	maxFilledRatio float64,
) bool

ResetBloomFilterIfNeeded resets a bloom filter if it breaches a ratio of filled elements. 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
	Salt []byte
}

func NewBloomFilter

func NewBloomFilter(m uint64, p float64) (*BloomFilter, error)

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 {
	// GetHash represents the unique hash of this item
	GetHash() Hash
	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

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,
	set Set[U],
	client *p2p.Client,
	codec codec.Manager,
	codecVersion uint16,
) *Gossiper[T, U]

func (*Gossiper[T, U]) Gossip

func (g *Gossiper[T, U]) Gossip(shutdownChan chan struct{}, shutdownWg *sync.WaitGroup)

type Handler

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

func NewHandler

func NewHandler[T Gossipable](set Set[T], codec codec.Manager, codecVersion uint16) *Handler[T]

func (Handler[T]) AppGossip

func (h Handler[T]) AppGossip(context.Context, ids.NodeID, []byte) error

func (Handler[T]) AppRequest

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

func (Handler[T]) CrossChainAppRequest

func (h Handler[T]) CrossChainAppRequest(context.Context, ids.ID, time.Time, []byte) ([]byte, error)

type Hash

type Hash [HashLength]byte

func HashFromBytes

func HashFromBytes(b []byte) Hash

type PullGossipRequest

type PullGossipRequest struct {
	FilterBytes []byte `serialize:"true"`
	SaltBytes   []byte `serialize:"true"`
}

type PullGossipResponse

type PullGossipResponse struct {
	GossipBytes [][]byte `serialize:"true"`
}

type Set

type Set[T Gossipable] interface {
	// Add adds a Gossipable to the set
	Add(gossipable T) error
	// Get returns elements that match the provided filter function
	Get(filter func(gossipable T) bool) []T
	// GetFilter returns a bloom filter containing the elements in Set
	GetFilter() *BloomFilter
}

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