node

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CloseNormalClosure indicates normal closure
	CloseNormalClosure = websocket.CloseNormalClosure

	// CloseInternalServerErr indicates closure because of internal error
	CloseInternalServerErr = websocket.CloseInternalServerErr

	// CloseAbnormalClosure indicates ubnormal close
	CloseAbnormalClosure = websocket.CloseAbnormalClosure

	// CloseGoingAway indicates ubnormal close
	CloseGoingAway = websocket.CloseGoingAway
)
View Source
const (
	// PING stores the "ping" message identifier
	PING = "ping"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandResult

type CommandResult struct {
	Streams        []string
	StopAllStreams bool
	Transmissions  []string
	Disconnect     bool
}

CommandResult is a result of performing controller action, which contains informations about streams to subscribe, messages to sent

type Controller

type Controller interface {
	Shutdown() error
	Authenticate(sid string, path string, headers *map[string]string) (string, []string, error)
	Subscribe(sid string, id string, channel string) (*CommandResult, error)
	Unsubscribe(sid string, id string, channel string) (*CommandResult, error)
	Perform(sid string, id string, channel string, data string) (*CommandResult, error)
	Disconnect(sid string, id string, subscriptions []string, path string, headers *map[string]string) error
}

Controller is an interface describing business-logic handler (e.g. RPC)

type DisconnectQueue

type DisconnectQueue struct {
	// contains filtered or unexported fields
}

DisconnectQueue is a rate-limited executor

func NewDisconnectQueue

func NewDisconnectQueue(node *Node, rate int) *DisconnectQueue

NewDisconnectQueue builds new queue with a specified rate (max calls per second)

func (*DisconnectQueue) Enqueue

func (d *DisconnectQueue) Enqueue(s *Session)

Enqueue adds session to the disconnect queue

func (*DisconnectQueue) Run

func (d *DisconnectQueue) Run()

Run starts queue

func (*DisconnectQueue) Shutdown

func (d *DisconnectQueue) Shutdown() error

Shutdown stops throttling and makes requests one by one

func (*DisconnectQueue) Size

func (d *DisconnectQueue) Size() int

Size returns the number of enqueued tasks

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub stores all the sessions and the corresponding subscriptions info

func NewHub

func NewHub() *Hub

NewHub builds new hub instance

func (*Hub) Run

func (h *Hub) Run()

Run makes hub active

func (*Hub) Shutdown

func (h *Hub) Shutdown()

Shutdown sends shutdown command to hub

func (*Hub) Size

func (h *Hub) Size() int

Size returns a number of active sessions

func (*Hub) StreamsSize

func (h *Hub) StreamsSize() int

StreamsSize returns a number of uniq streams

func (*Hub) UniqSize

func (h *Hub) UniqSize() int

UniqSize returns a number of uniq identifiers

type Message

type Message struct {
	Command    string `json:"command"`
	Identifier string `json:"identifier"`
	Data       string `json:"data"`
}

Message represents incoming client message

type Node

type Node struct {
	Config  *config.Config
	Metrics *metrics.Metrics
	// contains filtered or unexported fields
}

Node represents the whole application

func NewNode

func NewNode(config *config.Config, controller Controller, metrics *metrics.Metrics) *Node

NewNode builds new node struct

func (*Node) Authenticate

func (n *Node) Authenticate(s *Session, path string, headers *map[string]string) error

Authenticate calls controller to perform authentication. If authentication is successful, session is registered with a hub.

func (*Node) Broadcast

func (n *Node) Broadcast(msg *StreamMessage)

Broadcast message to stream

func (*Node) Disconnect

func (n *Node) Disconnect(s *Session)

Disconnect adds session to disconnector queue and unregister session from hub

func (*Node) DisconnectNow

func (n *Node) DisconnectNow(s *Session) error

DisconnectNow execute disconnect on controller

func (*Node) HandleCommand

func (n *Node) HandleCommand(s *Session, raw []byte)

HandleCommand parses incoming message from client and execute the command (if recognized)

func (*Node) HandlePubsub

func (n *Node) HandlePubsub(raw []byte)

HandlePubsub parses incoming pubsub message and broadcast it

func (*Node) Perform

func (n *Node) Perform(s *Session, msg *Message)

Perform executes client command

func (*Node) Shutdown

func (n *Node) Shutdown()

Shutdown stops all services (hub, controller)

func (*Node) Subscribe

func (n *Node) Subscribe(s *Session, msg *Message)

Subscribe subscribes session to a channel

func (*Node) Unsubscribe

func (n *Node) Unsubscribe(s *Session, msg *Message)

Unsubscribe unsubscribes session from a channel

type Reply

type Reply struct {
	Type       string      `json:"type,omitempty"`
	Identifier string      `json:"identifier"`
	Message    interface{} `json:"message"`
}

Reply represents outgoing client message

type Session

type Session struct {
	UID         string
	Identifiers string
	Log         *log.Entry
	// contains filtered or unexported fields
}

Session represents active client

func NewSession

func NewSession(node *Node, ws *websocket.Conn, request *http.Request) (*Session, error)

NewSession build a new Session struct from ws connetion and http request

func (*Session) Close

func (s *Session) Close(reason string, code int)

Close websocket connection with the specified reason

func (*Session) Disconnect

func (s *Session) Disconnect(reason string, code int)

Disconnect enqueues RPC disconnect request and closes the connection

func (*Session) ReadMessages

func (s *Session) ReadMessages()

ReadMessages reads messages from ws connection and send them to node

func (*Session) Send

func (s *Session) Send(msg []byte)

Send data to client connection

func (*Session) SendMessages

func (s *Session) SendMessages(ctx context.Context)

SendMessages waits for incoming messages and send them to the client connection

type StreamMessage

type StreamMessage struct {
	Stream string `json:"stream"`
	Data   string `json:"data"`
}

StreamMessage represents a message to be sent to stream

type SubscriptionInfo

type SubscriptionInfo struct {
	// contains filtered or unexported fields
}

SubscriptionInfo contains information about session-channel(-stream) subscription

Jump to

Keyboard shortcuts

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