hub

package module
v0.0.0-...-ac51456 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2019 License: Apache-2.0 Imports: 2 Imported by: 3

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

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
}

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"`
}

Stats that we report externally

type ClientRxTx

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

type ClientStats

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

Stats that we keep internally

func NewClientStats

func NewClientStats() *ClientStats

type Frames

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

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 HubStats
}

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

func New

func New() *Hub

func (*Hub) Run

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

func (*Hub) RunWithStats

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

type HubReport

type HubReport 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"`
}

Stats that we report externally

type HubStats

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

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
}

messages will be wrapped in this struct for muxing

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"`
}

Jump to

Keyboard shortcuts

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