coordinator

package
v0.0.0-...-8567bd0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2019 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package coordinator contains the coordinator definition

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized")

ErrUnauthorized indicates that a peer is not authorized for the role

Functions

func ConnectClient

func ConnectClient(state *State, conn ws.IWebsocket)

ConnectClient establish a ws connection to a client

func ConnectCommServer

func ConnectCommServer(state *State, conn ws.IWebsocket, role protocol.Role)

ConnectCommServer establish a ws connection to a communication server

func Register

func Register(state *State, mux *http.ServeMux)

Register coordinator endpoints for server discovery and client connect

func Start

func Start(state *State)

Start starts the coordinator

func UpgradeRequest

func UpgradeRequest(state *State, role protocol.Role, w http.ResponseWriter, r *http.Request) (ws.IWebsocket, error)

UpgradeRequest upgrades a HTTP request to ws protocol and authenticates for the role

Types

type ByAlias

type ByAlias []uint64

ByAlias is a utility to sort peers by alias

func (ByAlias) Len

func (a ByAlias) Len() int

func (ByAlias) Less

func (a ByAlias) Less(i, j int) bool

func (ByAlias) Swap

func (a ByAlias) Swap(i, j int)

type Config

type Config struct {
	Log            *logging.Logger
	ServerSelector IServerSelector
	Auth           authentication.CoordinatorAuthenticator
	Reporter       func(stats Stats)
	ReportPeriod   time.Duration
}

Config is the coordinator config

type DefaultServerSelector

type DefaultServerSelector struct {
	ServerAliases map[uint64]bool
}

DefaultServerSelector is the default server selector

func (*DefaultServerSelector) GetServerAliasList

func (r *DefaultServerSelector) GetServerAliasList(role protocol.Role) []uint64

GetServerAliasList returns a list of tracked server aliases

func (*DefaultServerSelector) GetServerCount

func (r *DefaultServerSelector) GetServerCount() int

GetServerCount return amount of servers registered

func (*DefaultServerSelector) ServerRegistered

func (r *DefaultServerSelector) ServerRegistered(role protocol.Role, alias uint64)

ServerRegistered register a new server

func (*DefaultServerSelector) ServerUnregistered

func (r *DefaultServerSelector) ServerUnregistered(alias uint64)

ServerUnregistered removes an unregistered server from the list

type IServerSelector

type IServerSelector interface {
	ServerRegistered(role protocol.Role, alias uint64)
	ServerUnregistered(alias uint64)
	GetServerAliasList(forRole protocol.Role) []uint64
	GetServerCount() int
}

IServerSelector is in charge of tracking and processing the server list

type Peer

type Peer struct {
	Alias uint64
	// contains filtered or unexported fields
}

Peer represents any peer, both server and clients

type State

type State struct {
	LastPeerAlias uint64

	Peers map[uint64]*Peer
	// contains filtered or unexported fields
}

State represent the state of the coordinator

func MakeState

func MakeState(config *Config) *State

MakeState creates a new CoordinatorState

type Stats

type Stats struct {
	ServerCount int
	ClientCount int
}

Stats expose coordinator stats for reporting purposes

Jump to

Keyboard shortcuts

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