notifications

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalBlockMsg

func MarshalBlockMsg(blk block.Block) (string, error)

MarshalBlockMsg builds the JSON from a subset of block fields.

Types

type BlockMsg

type BlockMsg struct {
	Height    uint64
	Hash      string
	Timestamp int64
	Txs       []string

	// BlocksGeneratedCount is number of blocks generated last 24 hours.
	BlocksGeneratedCount uint
}

BlockMsg represents the data need by Explorer UI on each new block accepted.

type Broker

type Broker struct {

	// ConnectionChan is a shared queue to buffer incoming websocket connections
	// closing connChan will terminate the broker.
	ConnectionChan chan wsConn
	// contains filtered or unexported fields
}

Broker is a pub/sub broker that keeps updated all subscribers (websocket connections) with latest block accepted published by node layer.

IMPL Notes: Broker is implemented in a non-blocking manner. That means it should not be blocked on mutex-lock, chan push or any I/O operation. It should not expose anything than a channel.

func NewBroker

func NewBroker(id uint, eventBus eventbus.Broker, maxClientsCount uint, connChan chan wsConn) *Broker

NewBroker creates a new Broker instance.

func (*Broker) Run

func (b *Broker) Run()

Run represents the main loop of the Broker, where block data get piped to incoming connections. Connections are put in Idle state after 30 seconds of inactivity.

type BrokerPool

type BrokerPool struct {
	QuitChan chan bool

	ConnectionsChan chan wsConn
	// contains filtered or unexported fields
}

BrokerPool is a set of broker workers to provide a simple load balancing. Running multiple broker workers also could provide failover.

func NewPool

func NewPool(eventBus *eventbus.EventBus, brokersNum, clientsPerBroker uint) *BrokerPool

NewPool intantiates the specified amount of brokers and run them in separate goroutines. Thus it returns a new BrokerPool instance populated with said brokers.

func (*BrokerPool) Close

func (bp *BrokerPool) Close()

Close the BrokerPool by closing the underlying connection channel.

func (*BrokerPool) PushConn

func (bp *BrokerPool) PushConn(conn *websocket.Conn)

PushConn pushes a websocket connection to the broker pool.

Jump to

Keyboard shortcuts

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