hub

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: GPL-3.0, Apache-2.0 Imports: 2 Imported by: 0

README

hub

topic relay for messages sent over channels; intended for use with timdrysdale/vw and timdrysdale/crossbar

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MpsFromNs

func MpsFromNs(ns float64) float64

MpsFromNs returns frequency of event occurring every ns nanoseconds

Types

type Client

type Client struct {
	Hub         *Hub
	Name        string       //for filtering who to send messages to
	Send        chan Message // for outbound messages to client
	Topic       string       // message broadcast scope is restricted to a single topic
	Done        chan struct{}
	ConnectedAt time.Time
}

Client is a middleperson between the hub and whatever is sending/receiving messages on it

type ClientReport

type ClientReport struct {
	Topic       string `json:"topic"`
	ConnectedAt string `json:"connected"`
}

ClientReport represents statistics that we report externally

type Hub

type Hub struct {
	// Registered clients.
	Clients map[string]map[*Client]bool

	// Inbound messages from the clients.
	Broadcast chan Message

	// Register requests from the clients.
	Register chan *Client

	// Unregister requests from clients.
	Unregister chan *Client
}

Hub maintains the set of active clients and broadcasts messages to the clients. From gorilla/websocket chat

func New

func New() *Hub

New returns a pointer to an initiatialised Hub

func (*Hub) Run

func (h *Hub) Run(closed chan struct{})

Run starts the hub

type Message

type Message struct {
	Data   []byte //text data are converted to/from bytes as needed
	Sender Client
	Sent   time.Time //when sent
	Type   int
}

Message represents a message that is wrapped and ready for multiplexing unwrapped messages cannot be multiplexed

Jump to

Keyboard shortcuts

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