pubsub

package
v0.2.24-beta.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 11 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"

	// HareProtocol is the protocol id for hare messages.
	HareProtocol = "hr1"

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

	// 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"
)
View Source
const (
	// ValidationAccept should be returned if message is good and can be broadcasted.
	ValidationAccept = pubsub.ValidationAccept
	// ValidationIgnore should be returned if message might be good, but outdated
	// and shouldn't be broadcasted.
	ValidationIgnore = pubsub.ValidationIgnore
	// ValidationReject should be returned if message is malformed or malicious
	// and shouldn't be broadcasted. Peer might be potentially get banned when on this result.
	ValidationReject = pubsub.ValidationReject
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// TODO(dshulyak) change it to NoFlood
	Flood          bool
	IsBootnode     bool
	MaxMessageSize int
}

Config for PubSub.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig for PubSub.

type GossipHandler

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

GossipHandler is a function that is for receiving messages.

func ChainGossipHandler

func ChainGossipHandler(handlers ...GossipHandler) GossipHandler

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

type PubSub

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

PubSub is a spacemesh-specific wrapper around gossip protocol.

func New

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

New creates PubSub instance.

func (*PubSub) ProtocolPeers

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

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

func (*PubSub) Publish

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

Publish message to the topic.

func (*PubSub) Register

func (ps *PubSub) Register(topic string, handler GossipHandler)

Register handler for topic.

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)
}

Subscriber is an interface for subcribing to messages.

type ValidationResult

type ValidationResult = pubsub.ValidationResult

ValidationResult is a one of the validation result constants.

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