broadcast

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultAddr defines the default Websocket server address.
	DefaultAddr = "127.0.0.1:8080"
)

Functions

This section is empty.

Types

type Connections

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

Connections keeps track of active Websocket connections.

func NewConnections

func NewConnections() *Connections

NewConnections create a new Websocket connections registry.

func (*Connections) Add

func (c *Connections) Add(ws *websocket.Conn)

Add adds a new Websocket connection to the registry.

func (*Connections) Close

func (c *Connections) Close()

Close closes all connections.

func (*Connections) Delete

func (c *Connections) Delete(ws *websocket.Conn) error

Delete removes a Websocket connection from the registry. Connections are closed after being removed.

func (*Connections) Iter

func (c *Connections) Iter(fn func(*websocket.Conn) bool)

Iter allows iterating the current connections. Iteration stops when when false is returned.

type Option

type Option func(*Server)

Option configures transaction broadcast servers.

func Address

func Address(addr string) Option

Address sets the server address.

func Origin

func Origin(origin string) Option

Origin sets the allowed origin for incoming requests.

func Secure

func Secure(certFile, keyFile string) Option

Secure enables secure Websockets (WSS).

type Server

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

Server handles Websocket connections and broadcasts new transactions. It watches the transactions head file and when new transactions are indexed it pushes the new entries to the connected clients.

func NewServer

func NewServer(options ...Option) *Server

NewServer creates a new transactions broadcast server.

func (*Server) HandleWS

func (s *Server) HandleWS(w http.ResponseWriter, r *http.Request)

HandleWS is an HTTP handler that upgrades incoming connections to WS or WSS.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts a new HTTP server to listen for incoming WS or WSS connections.

func (*Server) Watch

func (s *Server) Watch(ctx context.Context, name string) error

Watch starts watching a transaction head file and broadcasts the newly indexed transactions to all connected peers.

Jump to

Keyboard shortcuts

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