controller

package
v0.0.0-...-c387957 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Time allowed to write a message to the peer.
	WriteWait = 10 * time.Second

	// Time allowed to read the next pong message from the peer.
	PongWait = 60 * time.Second

	// Send pings to peer with this period. Must be less than pongWait.
	PingPeriod = (PongWait * 9) / 10

	// Maximum message size allowed from peer.
	MaxMessageSize = 512
)
View Source
const WORK_TIMEOUT_S = time.Second * 30

Timeout waiting for work response from client

Variables

View Source
var ActiveChannels = models.NewSyncArray()

Channels for reach specific work request

View Source
var Upgrader = websocket.Upgrader{}

Functions

func BroadcastWorkRequestAndWait

func BroadcastWorkRequestAndWait(workRequest serializableModels.ClientMessage) (*serializableModels.ClientWorkResponse, error)

Method to handle a work request response 1) Broadcast to every client 2) Create a channel for the response 3) Wait for response on the channel until timeout

func WorkerChl

func WorkerChl(hub *Hub, w http.ResponseWriter, r *http.Request)

serveWs handles websocket requests from the peer.

func WriteChannelSafe

func WriteChannelSafe(out chan []byte, msg []byte) (err error)

Recover from panic if the channel is closed

Types

type Client

type Client struct {
	Hub *Hub

	// The websocket connection.
	Conn *websocket.Conn

	// Buffered channel of outbound messages.
	Send chan []byte

	// IP Address
	IPAddress string

	Email string
}

Client is a middleman between the websocket connection and the hub.

type ClientWSMessage

type ClientWSMessage struct {
	ClientEmail string `json:"email"`
	// contains filtered or unexported fields
}

type Hub

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

	// Outbound messages to the client
	Broadcast chan []byte

	// Inbound messages from client
	Response chan ClientWSMessage

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

	// Unregister requests from clients.
	Unregister chan *Client

	// Channel to broadcast stats to
	StatsChan *chan repository.WorkMessage
	// contains filtered or unexported fields
}

Hub maintains the set of active clients and broadcasts messages to the clients.

var ActiveHub *Hub

func NewHub

func NewHub(statsChan *chan repository.WorkMessage) *Hub

func (*Hub) AlreadyConnected

func (h *Hub) AlreadyConnected(ip string) bool

func (*Hub) BlockAwardedWorker

func (h *Hub) BlockAwardedWorker(blockAwardedChan <-chan serializableModels.ClientMessage)

func (*Hub) Run

func (h *Hub) Run()

Jump to

Keyboard shortcuts

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