bmmc

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GossipRoute is the route for gossip messages.
	GossipRoute = "/gossip"
	// SolicitationRoute is the route for solicitation messages.
	SolicitationRoute = "/solicitation"
	// SynchronizationRoute is the route for synchronization messages.
	SynchronizationRoute = "/synchronization"
)
View Source
const (
	// NOCALLBACK is callback type for messages without callback.
	NOCALLBACK = callback.NOCALLBACK
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BMMC added in v0.3.0

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

BMMC is the bimodal multicast protocol.

func New

func New(cfg *Config) (*BMMC, error)

New creates a new instance for the protocol.

func (*BMMC) AddMessage added in v0.3.0

func (b *BMMC) AddMessage(msg any, callbackType string) error

AddMessage adds new message in messages buffer.

func (*BMMC) AddPeer added in v0.3.0

func (b *BMMC) AddPeer(p string) error

AddPeer adds new peer in peers buffer.

func (*BMMC) GetMessages added in v0.3.0

func (b *BMMC) GetMessages() []any

GetMessages returns a slice with all user messages from messages buffer.

func (*BMMC) GetPeers added in v0.3.0

func (b *BMMC) GetPeers() []string

GetPeers returns an array with all peers from peers buffer.

func (*BMMC) GossipHandler added in v0.7.0

func (b *BMMC) GossipHandler(body []byte)

GossipHandler handles a gossip message.

func (*BMMC) RemovePeer added in v0.3.0

func (b *BMMC) RemovePeer(p string) error

RemovePeer removes given peer from peers buffer.

func (*BMMC) SolicitationHandler added in v0.7.0

func (b *BMMC) SolicitationHandler(body []byte)

SolicitationHandler handles a solicitation message.

func (*BMMC) Start added in v0.3.0

func (b *BMMC) Start() error

Start starts the gossip server and the http server.

func (*BMMC) Stop added in v0.3.0

func (b *BMMC) Stop()

Stop stops the gossip server and the http server.

func (*BMMC) SynchronizationHandler added in v0.7.0

func (b *BMMC) SynchronizationHandler(body []byte)

SynchronizationHandler handles a synchronization message.

type Config

type Config struct {
	// Host is the host peer.
	// Required.
	Host peer.Peer
	// Beta is the expected fanout for gossip rounds.
	// Optional
	Beta float64
	// Logger.
	// Optional
	Logger *slog.Logger
	// Callbacks functions.
	// Optional
	Callbacks map[string]func(any, *slog.Logger) error
	// Gossip round duration.
	// Optional
	RoundDuration time.Duration
	// Buffer size.
	// When the buffer is full, the oldest message will be removed.
	// Required
	BufferSize int
}

Config is the config for the protocol.

type Gossip added in v0.7.0

type Gossip struct {
	Host        string       `json:"host"`
	RoundNumber *GossipRound `json:"roundNumber"`
	Digest      []string     `json:"digest"`
}

Gossip is gossip message for http server.

type GossipRound added in v0.3.0

type GossipRound struct {
	Number int64         `json:"number"`
	Mux    *sync.RWMutex `json:"mux"`
}

GossipRound is the number of gossiper rounds.

func NewGossipRound added in v0.3.0

func NewGossipRound() *GossipRound

NewGossipRound creates new GossipRound.

func (*GossipRound) GetNumber added in v0.3.0

func (r *GossipRound) GetNumber() int64

GetNumber returns the gossip round numbers.

func (*GossipRound) Increment added in v0.3.0

func (r *GossipRound) Increment()

Increment increments the gossip round numbers.

type Solicitation added in v0.7.0

type Solicitation struct {
	Host        string       `json:"host"`
	RoundNumber *GossipRound `json:"roundNumber"`
	Digest      []string     `json:"digest"`
}

Solicitation is solicitation message for server.

type Synchronization added in v0.7.0

type Synchronization struct {
	Host     string           `json:"host"`
	Elements []buffer.Element `json:"elements"`
}

Synchronization is synchronization message for server.

Jump to

Keyboard shortcuts

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