p2p

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotReady = errors.New("tx gossiper is not ready")

Functions

This section is empty.

Types

type GossipMessage

type GossipMessage struct {
	Data []byte
	From peer.ID
}

GossipMessage represents message gossiped via P2P network (e.g. transaction, Block etc).

type GossipValidator

type GossipValidator func(*GossipMessage) bool

GossipValidator is a callback function type.

type Gossiper

type Gossiper struct {
	// contains filtered or unexported fields
}

Gossiper is an abstraction of P2P publish subscribe mechanism.

func NewGossiper

func NewGossiper(host host.Host, ps *pubsub.PubSub, topicStr string, logger log.Logger, options ...GossiperOption) (*Gossiper, error)

NewGossiper creates new, ready to use instance of Gossiper.

Returned Gossiper object can be used for sending (Publishing) and receiving messages in topic identified by topicStr.

func (*Gossiper) Close

func (g *Gossiper) Close() error

Close is used to disconnect from topic and free resources used by Gossiper.

func (*Gossiper) ProcessMessages

func (g *Gossiper) ProcessMessages(ctx context.Context)

ProcessMessages waits for messages published in the topic and execute handler.

func (*Gossiper) Publish

func (g *Gossiper) Publish(ctx context.Context, data []byte) error

Publish publishes data to gossip topic.

type GossiperOption

type GossiperOption func(*Gossiper) error

GossiperOption sets optional parameters of Gossiper.

func WithValidator

func WithValidator(validator GossipValidator) GossiperOption

WithValidator options registers topic validator for Gossiper.

Jump to

Keyboard shortcuts

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