hub

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: AGPL-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 ChannelStats

type ChannelStats struct {
	Last  string  `json:"last"` //how many seconds ago...
	Bytes float64 `json:"bytes"`
	Dt    float64 `json:"dt"` //Messages per second
}

ChannelStats represents statistics on a particular channel's communications

type Client

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

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

type ClientReport

type ClientReport struct {
	Topic     string     `json:"topic"`
	Connected string     `json:"connected"`
	Stats     ClientRxTx `json:"stats"`
}

ClientReport represents statistics that we report externally

type ClientRxTx

type ClientRxTx struct {
	Tx ChannelStats `json:"tx"`
	Rx ChannelStats `json:"rx"`
}

ClientRxTx represents statistics on a particular client's communications

type ClientStats

type ClientStats struct {
	ConnectedAt time.Time
	Rx          *Frames
	Tx          *Frames
}

ClientStats represents statistics that we keep internally

func NewClientStats

func NewClientStats() *ClientStats

NewClientStats returns a pointer to a new initialised ClientStats

type Frames

type Frames struct {
	Last time.Time
	Size *welford.Stats
	Dt   *welford.Stats
}

Frames represents statistics on (video) frames

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

	Stats Stats
}

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

func (*Hub) RunWithStats

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

RunWithStats starts the hub, and records statistics

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

type Report

type Report struct {
	Started  string       `json:"started"`
	Last     string       `json:"last"`
	Audience WelfordStats `json:"audience"`
	Bytes    WelfordStats `json:"bytes"`
	Latency  WelfordStats `json:"latency"`
	Dt       WelfordStats `json:"dt"`
}

Report represents statistics that we report externally

type Stats

type Stats struct {
	Started  time.Time
	Last     time.Time
	Audience *welford.Stats
	Bytes    *welford.Stats
	Latency  *welford.Stats
	Dt       *welford.Stats
}

Stats represents overall statistics for the hub

type WelfordStats

type WelfordStats struct {
	Count    uint64  `json:"count"`
	Min      float64 `json:"min"`
	Max      float64 `json:"max"`
	Mean     float64 `json:"mean"`
	Stddev   float64 `json:"stddev"`
	Variance float64 `json:"variance"`
}

WelfordStats represents the statistical values we record

Jump to

Keyboard shortcuts

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