pubsub

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// GossipScoreThreshold when a peer's score drops below this threshold, no gossip is emitted towards that peer
	// and gossip from that peer is ignored.
	GossipScoreThreshold = -500
	// PublishScoreThreshold when a peer's score drops below this threshold, self published messages are not propagated
	// towards this peer when (flood) publishing.
	PublishScoreThreshold = -1000
	// GraylistScoreThreshold when a peer's score drops below this threshold, the peer is graylisted and its RPCs
	// are ignored.
	GraylistScoreThreshold = -2500
	// AcceptPXScoreThreshold when a peer sends us PX information with a prune, we only accept it and connect to the
	// supplied peers if the originating peer's score exceeds this threshold.
	AcceptPXScoreThreshold = 1000
	// OpportunisticGraftScoreThreshold when the median peer score in the mesh drops below this value, the router
	// may select more peers with score above the median to opportunistically graft on the mesh.
	OpportunisticGraftScoreThreshold = 3.5

	// AtxProtocol is the protocol id for ATXs.
	AtxProtocol = "ax1"
	// ProposalProtocol is the protocol id for block proposals.
	ProposalProtocol = "pp1"
	// TxProtocol iis the protocol id for transactions.
	TxProtocol = "tx1"

	// BlockCertify is the protocol id for block certification.
	BlockCertify = "bc1"

	// BeaconProtocol is used currently only for recording metrics, but
	// potentially will become used as an actual protocol if we decide to merge
	// the beacon protocols.
	// https://github.com/spacemeshos/go-spacemesh/issues/4207
	BeaconProtocol = "b1"
	// BeaconWeakCoinProtocol is the protocol id for beacon weak coin.
	BeaconWeakCoinProtocol = "bw1"
	// BeaconProposalProtocol is the protocol id for beacon proposals.
	BeaconProposalProtocol = "bp1"
	// BeaconFirstVotesProtocol is the protocol id for beacon first vote.
	BeaconFirstVotesProtocol = "bf1"
	// BeaconFollowingVotesProtocol is the protocol id for beacon following votes.
	BeaconFollowingVotesProtocol = "bo1"

	MalfeasanceProof = "mp1"
)

Variables

View Source
var (
	WithValidatorInline      = pubsub.WithValidatorInline
	WithValidatorConcurrency = pubsub.WithValidatorConcurrency
)
View Source
var ErrValidationReject = errors.New("validation reject")

ErrValidationReject is returned by a GossipHandler to indicate that the pubsub validation result is ValidationReject. ValidationAccept is indicated by a nil error and ValidationIgnore is indicated by any error that is not a ErrValidationReject.

Functions

This section is empty.

Types

type Config

type Config struct {
	Flood      bool
	IsBootnode bool
	Bootnodes  []peer.AddrInfo
	// Direct peers should be configured on both ends.
	Direct                []peer.AddrInfo
	MaxMessageSize        int
	PeerOutboundQueueSize int
	QueueSize             int
	Throttle              int
}

Config for PubSub.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig for PubSub.

type GossipHandler

type GossipHandler = func(context.Context, peer.ID, []byte) error

GossipHandler is a function that is for receiving p2p messages.

func ChainGossipHandler

func ChainGossipHandler(handlers ...GossipHandler) GossipHandler

ChainGossipHandler helper to chain multiple GossipHandler together. Called synchronously and in the order.

func DropPeerOnValidationReject

func DropPeerOnValidationReject(handler GossipHandler, h host.Host, logger log.Log) GossipHandler

DropPeerOnValidationReject wraps a gossip handler to provide a handler that drops a peer if the wrapped handler returns ErrValidationReject.

type GossipPubSub added in v1.4.2

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

GossipPubSub is a spacemesh-specific wrapper around gossip protocol.

func New

func New(ctx context.Context, logger log.Log, h host.Host, cfg Config) (*GossipPubSub, error)

New creates PubSub instance.

func (*GossipPubSub) ProtocolPeers added in v1.4.2

func (ps *GossipPubSub) ProtocolPeers(protocol string) []peer.ID

ProtocolPeers returns list of peers that are communicating in a given protocol.

func (*GossipPubSub) Publish added in v1.4.2

func (ps *GossipPubSub) Publish(ctx context.Context, topic string, msg []byte) error

Publish message to the topic.

func (*GossipPubSub) Register added in v1.4.2

func (ps *GossipPubSub) Register(topic string, handler GossipHandler, opts ...ValidatorOpt)

Register handler for topic.

type NullPubSub added in v1.4.2

type NullPubSub struct{}

func (*NullPubSub) ProtocolPeers added in v1.4.2

func (*NullPubSub) ProtocolPeers(protocol string) []peer.ID

ProtocolPeers implements PubSub.

func (*NullPubSub) Publish added in v1.4.2

func (*NullPubSub) Publish(ctx context.Context, topic string, msg []byte) error

Publish implements PubSub.

func (*NullPubSub) Register added in v1.4.2

func (*NullPubSub) Register(
	topic string,
	handler func(context.Context, peer.ID, []byte) error,
	opts ...pubsub.ValidatorOpt,
)

Register implements PubSub.

type PubSub

type PubSub interface {
	Register(topic string, handler GossipHandler, opts ...ValidatorOpt)
	Publish(ctx context.Context, topic string, msg []byte) error
	ProtocolPeers(protocol string) []peer.ID
}

type PublishSubsciber

type PublishSubsciber interface {
	Publisher
	Subscriber
}

PublishSubsciber common interface for publisher and subscribing.

type Publisher

type Publisher interface {
	Publish(context.Context, string, []byte) error
}

Publisher interface for publishing messages.

type Subscriber

type Subscriber interface {
	Register(string, GossipHandler, ...ValidatorOpt)
}

Subscriber is an interface for subcribing to messages.

type SyncHandler added in v1.1.0

type SyncHandler = func(context.Context, types.Hash32, peer.ID, []byte) error

SyncHandler is a function that is for receiving synced data.

func DropPeerOnSyncValidationReject added in v1.1.0

func DropPeerOnSyncValidationReject(handler SyncHandler, h host.Host, logger log.Log) SyncHandler

type ValidatorOpt added in v1.1.4

type ValidatorOpt = pubsub.ValidatorOpt

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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