libcentrifugo

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2016 License: MIT Imports: 37 Imported by: 0

Documentation

Overview

Package libcentrifugo is a real-time core for Centrifugo server.

Package libcentrifugo is a generated protocol buffer package.

It is generated from these files:
	message.proto

It has these top-level messages:
	ClientInfo
	Message
	JoinMessage
	LeaveMessage
	ControlMessage
	AdminMessage

Index

Constants

View Source
const (
	// AuthTokenKey is a key for admin authorization token.
	AuthTokenKey = "token"
	// AuthTokenValue is a value for secure admin authorization token.
	AuthTokenValue = "authorized"
)
View Source
const (
	// RedisSubscribeChannelSize is the size for the internal buffered channels RedisEngine
	// uses to synchronize subscribe/unsubscribe. It allows for effective batching during bulk re-subscriptions,
	// and allows large volume of incoming subscriptions to not block when PubSub connection is reconnecting.
	// Two channels of this size will be allocated, one for Subscribe and one for Unsubscribe
	RedisSubscribeChannelSize = 4096
	// Maximum number of channels to include in a single subscribe call. Redis documentation doesn't specify a
	// maximum allowed but we think it probably makes sense to keep a sane limit given how many subscriptions a single
	// Centrifugo instance might be handling
	RedisSubscribeBatchLimit = 2048
	// RedisPublishChannelSize is the size for the internal buffered channel RedisEngine
	// uses to collect publish requests.
	RedisPublishChannelSize = 1024
	// RedisPublishBatchLimit is a maximum limit of publish requests one batched publish
	// operation can contain.
	RedisPublishBatchLimit = 2048
)
View Source
const (
	RedisAPIKeySuffix         = ".api"
	RedisControlChannelSuffix = ".control"
	RedisAdminChannelSuffix   = ".admin"
	RedisMessageChannelPrefix = ".message."
	RedisJoinChannelPrefix    = ".join."
	RedisLeaveChannelPrefix   = ".leave."
)
View Source
const (
	AdminWebsocketReadBufferSize  = 1024
	AdminWebsocketWriteBufferSize = 1024
)
View Source
const (
	// CloseStatus is status code set when closing client connections.
	CloseStatus = 3000
)

Variables

View Source
var (
	// ErrInvalidMessage means that you sent invalid message to Centrifugo.
	ErrInvalidMessage = errors.New("invalid message")
	// ErrInvalidToken means that client sent invalid token.
	ErrInvalidToken = errors.New("invalid token")
	// ErrUnauthorized means unauthorized access.
	ErrUnauthorized = errors.New("unauthorized")
	// ErrMethodNotFound means that method sent in command does not exist.
	ErrMethodNotFound = errors.New("method not found")
	// ErrPermissionDenied means that access to resource not allowed.
	ErrPermissionDenied = errors.New("permission denied")
	// ErrNamespaceNotFound means that namespace in channel name does not exist.
	ErrNamespaceNotFound = errors.New("namespace not found")
	// ErrInternalServerError means server error, if returned this is a signal that
	// something went wrong with Centrifugo itself.
	ErrInternalServerError = errors.New("internal server error")
	// ErrAlreadySubscribed returned when client wants to subscribe on channel
	// it already subscribed to.
	ErrAlreadySubscribed = errors.New("already subscribed")
	// ErrLimitExceeded says that some sort of limit exceeded, server logs should give
	// more detailed information.
	ErrLimitExceeded = errors.New("limit exceeded")
	// ErrNotAvailable means that resource is not enabled.
	ErrNotAvailable = errors.New("not available")
	// ErrSendTimeout means that timeout occurred when sending message into connection.
	ErrSendTimeout = errors.New("send timeout")
	// ErrClientClosed means that client connection already closed.
	ErrClientClosed = errors.New("client is closed")
)
View Source
var (
	ErrInvalidLengthMessage = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowMessage   = fmt.Errorf("proto: integer overflow")
)
View Source
var DefaultConfig = &Config{
	Version:                     "-",
	Name:                        defaultName,
	Debug:                       false,
	AdminPassword:               "",
	AdminSecret:                 "",
	ChannelPrefix:               defaultChannelPrefix,
	MaxChannelLength:            255,
	PingInterval:                25 * time.Second,
	NodePingInterval:            defaultNodePingInterval * time.Second,
	NodeInfoCleanInterval:       defaultNodePingInterval * 3 * time.Second,
	NodeInfoMaxDelay:            defaultNodePingInterval*2*time.Second + 1*time.Second,
	NodeMetricsInterval:         60 * time.Second,
	PresencePingInterval:        25 * time.Second,
	PresenceExpireInterval:      60 * time.Second,
	MessageSendTimeout:          0,
	PrivateChannelPrefix:        "$",
	NamespaceChannelBoundary:    ":",
	ClientChannelBoundary:       "&",
	UserChannelBoundary:         "#",
	UserChannelSeparator:        ",",
	ExpiredConnectionCloseDelay: 25 * time.Second,
	StaleConnectionCloseDelay:   25 * time.Second,
	ClientRequestMaxSize:        65536,
	ClientQueueMaxSize:          10485760,
	ClientQueueInitialCapacity:  2,
	ClientChannelLimit:          100,
	Insecure:                    false,
}

DefaultConfig is Config initialized with default values for all fields.

View Source
var DefaultMuxOptions = MuxOptions{
	HandlerFlags:  HandlerRawWS | HandlerSockJS | HandlerAPI | HandlerAdmin,
	SockjsOptions: sockjs.DefaultOptions,
}

DefaultMuxOptions contain default SockJS options.

Functions

func DefaultMux added in v0.2.0

func DefaultMux(app *Application, muxOpts MuxOptions) *http.ServeMux

DefaultMux returns a mux including set of default handlers for Centrifugo server.

func NewSockJSHandler added in v0.2.0

func NewSockJSHandler(app *Application, sockjsPrefix string, sockjsOpts sockjs.Options) http.Handler

NewSockJSHandler returns SockJS handler bind to sockjsPrefix url prefix. SockJS handler has several handlers inside responsible for various tasks according to SockJS protocol.

Types

type AdminMessage added in v1.5.0

type AdminMessage struct {
	UID    string                                                   `protobuf:"bytes,1,opt,name=UID" json:"uid"`
	Method string                                                   `protobuf:"bytes,2,opt,name=Method" json:"method"`
	Params *github_com_centrifugal_centrifugo_libcentrifugo_raw.Raw `protobuf:"bytes,3,opt,name=Params,customtype=github.com/centrifugal/centrifugo/libcentrifugo/raw.Raw" json:"params"`
}

func NewPopulatedAdminMessage added in v1.5.0

func NewPopulatedAdminMessage(r randyMessage, easy bool) *AdminMessage

func (*AdminMessage) Descriptor added in v1.5.0

func (*AdminMessage) Descriptor() ([]byte, []int)

func (*AdminMessage) Equal added in v1.5.0

func (this *AdminMessage) Equal(that interface{}) bool

func (*AdminMessage) GetMethod added in v1.5.0

func (m *AdminMessage) GetMethod() string

func (*AdminMessage) GetUID added in v1.5.0

func (m *AdminMessage) GetUID() string

func (*AdminMessage) Marshal added in v1.5.0

func (m *AdminMessage) Marshal() (data []byte, err error)

func (*AdminMessage) MarshalTo added in v1.5.0

func (m *AdminMessage) MarshalTo(data []byte) (int, error)

func (*AdminMessage) ProtoMessage added in v1.5.0

func (*AdminMessage) ProtoMessage()

func (*AdminMessage) Reset added in v1.5.0

func (m *AdminMessage) Reset()

func (*AdminMessage) Size added in v1.5.0

func (m *AdminMessage) Size() (n int)

func (*AdminMessage) String added in v1.5.0

func (m *AdminMessage) String() string

func (*AdminMessage) Unmarshal added in v1.5.0

func (m *AdminMessage) Unmarshal(data []byte) error

type Application added in v0.2.0

type Application struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Application is a heart of Centrifugo – it internally manages client and admin hubs, maintains information about other Centrifugo nodes, keeps references to config, engine, metrics etc.

func NewApplication added in v0.2.0

func NewApplication(config *Config) (*Application, error)

NewApplication returns new Application instance, the only required argument is config, structure and engine must be set via corresponding methods.

func (*Application) APIHandler added in v0.2.3

func (app *Application) APIHandler(w http.ResponseWriter, r *http.Request)

APIHandler is responsible for receiving API commands over HTTP.

func (*Application) AdminWebsocketHandler added in v0.2.0

func (app *Application) AdminWebsocketHandler(w http.ResponseWriter, r *http.Request)

AdminWebsocketHandler handles admin websocket connections.

func (*Application) AuthHandler added in v0.2.0

func (app *Application) AuthHandler(w http.ResponseWriter, r *http.Request)

AuthHandler allows to get admin web interface token.

func (*Application) Disconnect added in v0.2.0

func (app *Application) Disconnect(user UserID) error

Disconnect allows to close all user connections to Centrifugo. Note that user still can try to reconnect to the server after being disconnected.

func (*Application) History added in v0.2.0

func (app *Application) History(ch Channel) ([]Message, error)

History returns a slice of last messages published into project channel.

func (*Application) Logged added in v0.2.0

func (app *Application) Logged(h http.Handler) http.Handler

Logged middleware logs request.

func (*Application) Presence added in v0.2.0

func (app *Application) Presence(ch Channel) (map[ConnID]ClientInfo, error)

Presence returns a map of active clients in project channel.

func (*Application) Publish added in v0.2.0

func (app *Application) Publish(ch Channel, data []byte, client ConnID, info *ClientInfo) error

Publish sends a message to all clients subscribed on channel with provided data, client and ClientInfo.

func (*Application) RawWebsocketHandler added in v0.2.0

func (app *Application) RawWebsocketHandler(w http.ResponseWriter, r *http.Request)

RawWebsocketHandler called when new client connection comes to raw Websocket endpoint.

func (*Application) Run added in v0.2.0

func (app *Application) Run() error

Run performs all startup actions. At moment must be called once on start after engine and structure set.

func (*Application) SetConfig added in v0.2.0

func (app *Application) SetConfig(c *Config)

SetConfig binds config to application.

func (*Application) SetEngine added in v0.2.0

func (app *Application) SetEngine(e Engine)

SetEngine binds engine to application.

func (*Application) SetMediator added in v0.2.0

func (app *Application) SetMediator(m Mediator)

SetMediator binds mediator to application.

func (*Application) Shutdown added in v0.2.0

func (app *Application) Shutdown()

Shutdown sets shutdown flag and does various connection clean ups (at moment only unsubscribes all clients from all channels and disconnects them).

func (*Application) Unsubscribe added in v0.2.0

func (app *Application) Unsubscribe(user UserID, ch Channel) error

Unsubscribe unsubscribes user from channel, if channel is equal to empty string then user will be unsubscribed from all channels.

func (*Application) WrapShutdown added in v0.2.0

func (app *Application) WrapShutdown(h http.Handler) http.Handler

WrapShutdown will return an http Handler. If Application in shutdown it will return http.StatusServiceUnavailable.

type Channel added in v0.1.1

type Channel string

Channel is a string channel name.

type ChannelID added in v0.1.1

type ChannelID string

ChannelID is unique channel identificator in Redis.

type ChannelOptions

type ChannelOptions struct {
	// Watch determines if message published into channel will be also sent into admin channel.
	// Note that this option must be used carefully in channels with high rate of new messages
	// as admin client can not process all of those messages. Use this option for testing or for
	// channels with reasonable message rate.
	Watch bool `json:"watch"`

	// Publish determines if client can publish messages into channel directly. This allows to use
	// Centrifugo without backend. All messages go through Centrifugo and delivered to clients. But
	// in this case you lose everything your backend code could give - validation, persistence etc.
	// This option most useful for demos, testing real-time ideas.
	Publish bool `json:"publish"`

	// Anonymous determines is anonymous access (with empty user ID) allowed or not. In most
	// situations your application works with authorized users so every user has its own unique
	// id. But if you provide real-time features for public access you may need anauthorized
	// access to channels. Turn on this option and use empty string as user ID.
	Anonymous bool `json:"anonymous"`

	// Presence turns on(off) presence information for channels. Presense is a structure with
	// clients currently subscribed on channel.
	Presence bool `json:"presence"`

	// JoinLeave turns on(off) join/leave messages for channels. When client subscribes on channel
	// join message sent to all clients in this channel. When client leaves channel (unsubscribes)
	// leave message sent.
	JoinLeave bool `mapstructure:"join_leave" json:"join_leave"`

	// HistorySize determines max amount of history messages for channel, 0 means no history for channel.
	// Centrifugo history has auxiliary role – it can not replace your backend persistent storage.
	HistorySize int `mapstructure:"history_size" json:"history_size"`

	// HistoryLifetime determines time in seconds until expiration for history messages. As Centrifugo
	// keeps history in memory (in process memory or in Redis process memory) it's important to remove
	// old messages to prevent infinite memory grows.
	HistoryLifetime int `mapstructure:"history_lifetime" json:"history_lifetime"`

	// Recover enables recover mechanism for channels. This means that Centrifugo will
	// try to recover missed messages for resubscribing client. This option uses messages
	// from history and must be used with reasonable HistorySize and HistoryLifetime
	// configuration.
	Recover bool `json:"recover"`

	// HistoryDropInactive enables an optimization where history is only saved for channels that have at
	// least one active subscriber. This can give a huge memory saving, with only minor edgecases that are
	// different from without it as noted on https://github.com/centrifugal/centrifugo/issues/50.
	HistoryDropInactive bool `mapstructure:"history_drop_inactive" json:"history_drop_inactive"`
}

ChannelOptions represent channel specific configuration for namespace or project in a whole

type ClientInfo added in v0.1.1

type ClientInfo struct {
	User        string                                                   `protobuf:"bytes,1,opt,name=User" json:"user"`
	Client      string                                                   `protobuf:"bytes,2,opt,name=Client" json:"client"`
	DefaultInfo *github_com_centrifugal_centrifugo_libcentrifugo_raw.Raw `` /* 136-byte string literal not displayed */
	ChannelInfo *github_com_centrifugal_centrifugo_libcentrifugo_raw.Raw `` /* 136-byte string literal not displayed */
}

func NewPopulatedClientInfo added in v1.5.0

func NewPopulatedClientInfo(r randyMessage, easy bool) *ClientInfo

func (*ClientInfo) Descriptor added in v1.5.0

func (*ClientInfo) Descriptor() ([]byte, []int)

func (*ClientInfo) Equal added in v1.5.0

func (this *ClientInfo) Equal(that interface{}) bool

func (*ClientInfo) GetClient added in v1.5.0

func (m *ClientInfo) GetClient() string

func (*ClientInfo) GetUser added in v1.5.0

func (m *ClientInfo) GetUser() string

func (*ClientInfo) Marshal added in v1.5.0

func (m *ClientInfo) Marshal() (data []byte, err error)

func (*ClientInfo) MarshalTo added in v1.5.0

func (m *ClientInfo) MarshalTo(data []byte) (int, error)

func (*ClientInfo) ProtoMessage added in v1.5.0

func (*ClientInfo) ProtoMessage()

func (*ClientInfo) Reset added in v1.5.0

func (m *ClientInfo) Reset()

func (*ClientInfo) Size added in v1.5.0

func (m *ClientInfo) Size() (n int)

func (*ClientInfo) String added in v1.5.0

func (m *ClientInfo) String() string

func (*ClientInfo) Unmarshal added in v1.5.0

func (m *ClientInfo) Unmarshal(data []byte) error

type Config added in v0.2.0

type Config struct {
	// Version is a version of node as string, in most cases this will
	// be Centrifugo server version.
	Version string `json:"version"`

	// Name of this node - must be unique, used as human readable and
	// meaningful node identificator.
	Name string `json:"name"`

	// Debug turns on application debug mode.
	Debug bool `json:"debug"`

	// Admin enables admin socket.
	Admin bool
	// AdminPassword is an admin password.
	AdminPassword string `json:"-"`
	// AdminSecret is a secret to generate auth token for admin socket connection.
	AdminSecret string `json:"-"`
	// Web enables admin web interface.
	Web bool `json:"web"`

	// ChannelPrefix is a string prefix before each channel.
	ChannelPrefix string `json:"channel_prefix"`
	// MaxChannelLength is a maximum length of channel name.
	MaxChannelLength int `json:"max_channel_length"`

	// PingInterval sets interval server will send ping messages to clients.
	PingInterval time.Duration `json:"ping_interval"`

	// NodePingInterval is an interval how often node must send ping
	// control message.
	NodePingInterval time.Duration `json:"node_ping_interval"`
	// NodeInfoCleanInterval is an interval in seconds, how often node must clean
	// information about other running nodes.
	NodeInfoCleanInterval time.Duration `json:"node_info_clean_interval"`
	// NodeInfoMaxDelay is an interval in seconds – how many seconds node info
	// considered actual.
	NodeInfoMaxDelay time.Duration `json:"node_info_max_delay"`
	// NodeMetricsInterval detects interval node will use to aggregate metrics.
	NodeMetricsInterval time.Duration `json:"node_metrics_interval"`

	// PresencePingInterval is an interval how often connected clients
	// must update presence info.
	PresencePingInterval time.Duration `json:"presence_ping_interval"`
	// PresenceExpireInterval is an interval how long to consider
	// presence info valid after receiving presence ping.
	PresenceExpireInterval time.Duration `json:"presence_expire_interval"`

	// ExpiredConnectionCloseDelay is an interval given to client to
	// refresh its connection in the end of connection lifetime.
	ExpiredConnectionCloseDelay time.Duration `json:"expired_connection_close_delay"`

	// StaleConnectionCloseDelay is an interval in seconds after which
	// connection will be closed if still not authenticated.
	StaleConnectionCloseDelay time.Duration `json:"stale_connection_close_delay"`

	// MessageSendTimeout is an interval how long time the node
	// may take to send a message to a client before disconnecting the client.
	MessageSendTimeout time.Duration `json:"message_send_timeout"`

	// ClientRequestMaxSize sets maximum size in bytes of allowed client request.
	ClientRequestMaxSize int `json:"client_request_max_size"`
	// ClientQueueMaxSize is a maximum size of client's message queue in bytes.
	// After this queue size exceeded Centrifugo closes client's connection.
	ClientQueueMaxSize int `json:"client_queue_max_size"`
	// ClientQueueInitialCapacity sets initial amount of slots in client message
	// queue. When these slots are full client queue is automatically resized to
	// a bigger size. This option can reduce amount of allocations when message
	// rate is very high and client queue resizes frequently. Note that memory
	// consumption per client connection grows with this option.
	ClientQueueInitialCapacity int `json:"client_queue_initial_capacity"`

	// ClientChannelLimit sets upper limit of channels each client can subscribe to.
	ClientChannelLimit int `json:"client_channel_limit"`

	// PrivateChannelPrefix is a prefix in channel name which indicates that
	// channel is private.
	PrivateChannelPrefix string `json:"private_channel_prefix"`
	// NamespaceChannelBoundary is a string separator which must be put after
	// namespace part in channel name.
	NamespaceChannelBoundary string `json:"namespace_channel_boundary"`
	// UserChannelBoundary is a string separator which must be set before allowed
	// users part in channel name.
	UserChannelBoundary string `json:"user_channel_boundary"`
	// UserChannelSeparator separates allowed users in user part of channel name.
	UserChannelSeparator string `json:"user_channel_separator"`
	// ClientChannelBoundary is a string separator which must be set before client
	// connection ID in channel name so only client with this ID can subscribe on
	// that channel.
	ClientChannelBoundary string `json:"client_channel_separator"`

	// Insecure turns on insecure mode - when it's turned on then no authentication
	// required at all when connecting to Centrifugo, anonymous access and publish
	// allowed for all channels, no connection check performed. This can be suitable
	// for demonstration or personal usage.
	Insecure bool `json:"insecure"`
	// InsecureAPI turns on insecure mode for HTTP API calls. This means that no
	// API sign required when sending commands. This can be useful if you don't want
	// to sign every request - for example if you closed API endpoint with firewall
	// or you want to play with API commands from command line using CURL.
	InsecureAPI bool `json:"insecure_api"`
	// InsecureAdmin turns on insecure mode for admin endpoints - no auth required to
	// connect to admin socket and web interface. Protect admin resources with firewall
	// rules in production when enabling this option.
	InsecureAdmin bool `json:"insecure_admin"`

	// Secret is a secret key, used to sign API requests and client connection tokens.
	Secret string `json:"secret"`

	// ConnLifetime determines time until connection expire, 0 means no connection expire at all.
	ConnLifetime int64 `json:"connection_lifetime"`

	// ChannelOptions embedded to config.
	ChannelOptions `json:"channel_options"`

	// Namespaces - list of namespaces for custom channel options.
	Namespaces []Namespace `json:"namespaces"`
}

Config contains Application configuration options.

func (*Config) Validate added in v1.0.0

func (c *Config) Validate() error

Validate validates config and returns error if problems found

type ConnID added in v0.1.1

type ConnID string

ConnID is a unique connection ID.

type ControlMessage added in v1.5.0

type ControlMessage struct {
	// UID in case of controlCommand is a unique node ID which originally published
	// this control command.
	UID    string                                                   `protobuf:"bytes,1,opt,name=UID" json:"uid"`
	Method string                                                   `protobuf:"bytes,2,opt,name=Method" json:"method"`
	Params *github_com_centrifugal_centrifugo_libcentrifugo_raw.Raw `protobuf:"bytes,3,opt,name=Params,customtype=github.com/centrifugal/centrifugo/libcentrifugo/raw.Raw" json:"params"`
}

func NewPopulatedControlMessage added in v1.5.0

func NewPopulatedControlMessage(r randyMessage, easy bool) *ControlMessage

func (*ControlMessage) Descriptor added in v1.5.0

func (*ControlMessage) Descriptor() ([]byte, []int)

func (*ControlMessage) Equal added in v1.5.0

func (this *ControlMessage) Equal(that interface{}) bool

func (*ControlMessage) GetMethod added in v1.5.0

func (m *ControlMessage) GetMethod() string

func (*ControlMessage) GetUID added in v1.5.0

func (m *ControlMessage) GetUID() string

func (*ControlMessage) Marshal added in v1.5.0

func (m *ControlMessage) Marshal() (data []byte, err error)

func (*ControlMessage) MarshalTo added in v1.5.0

func (m *ControlMessage) MarshalTo(data []byte) (int, error)

func (*ControlMessage) ProtoMessage added in v1.5.0

func (*ControlMessage) ProtoMessage()

func (*ControlMessage) Reset added in v1.5.0

func (m *ControlMessage) Reset()

func (*ControlMessage) Size added in v1.5.0

func (m *ControlMessage) Size() (n int)

func (*ControlMessage) String added in v1.5.0

func (m *ControlMessage) String() string

func (*ControlMessage) Unmarshal added in v1.5.0

func (m *ControlMessage) Unmarshal(data []byte) error

type Engine added in v0.2.0

type Engine interface {
	// contains filtered or unexported methods
}

Engine is an interface with all methods that can be used by client or application to publish message, handle subscriptions, save or retrieve presence and history data.

type HandlerFlag added in v1.3.0

type HandlerFlag int

HandlerFlag is a bit mask of handlers that must be enabled in mux.

const (
	// HandlerRawWS enables Raw Websocket handler.
	HandlerRawWS HandlerFlag = 1 << iota
	// HandlerSockJS enables SockJS handler.
	HandlerSockJS
	// HandlerAPI enables API handler.
	HandlerAPI
	// HandlerAdmin enables admin handlers - admin websocket, web interface endpoints.
	HandlerAdmin
	// HandlerDebug enables debug handlers.
	HandlerDebug
)

func (HandlerFlag) String added in v1.3.0

func (flags HandlerFlag) String() string

type JoinMessage added in v1.5.0

type JoinMessage struct {
	Channel string     `protobuf:"bytes,1,opt,name=Channel" json:"channel"`
	Data    ClientInfo `protobuf:"bytes,2,opt,name=Data" json:"data"`
}

func NewPopulatedJoinMessage added in v1.5.0

func NewPopulatedJoinMessage(r randyMessage, easy bool) *JoinMessage

func (*JoinMessage) Descriptor added in v1.5.0

func (*JoinMessage) Descriptor() ([]byte, []int)

func (*JoinMessage) Equal added in v1.5.0

func (this *JoinMessage) Equal(that interface{}) bool

func (*JoinMessage) GetChannel added in v1.5.0

func (m *JoinMessage) GetChannel() string

func (*JoinMessage) GetData added in v1.5.0

func (m *JoinMessage) GetData() ClientInfo

func (*JoinMessage) Marshal added in v1.5.0

func (m *JoinMessage) Marshal() (data []byte, err error)

func (*JoinMessage) MarshalTo added in v1.5.0

func (m *JoinMessage) MarshalTo(data []byte) (int, error)

func (*JoinMessage) ProtoMessage added in v1.5.0

func (*JoinMessage) ProtoMessage()

func (*JoinMessage) Reset added in v1.5.0

func (m *JoinMessage) Reset()

func (*JoinMessage) Size added in v1.5.0

func (m *JoinMessage) Size() (n int)

func (*JoinMessage) String added in v1.5.0

func (m *JoinMessage) String() string

func (*JoinMessage) Unmarshal added in v1.5.0

func (m *JoinMessage) Unmarshal(data []byte) error

type LeaveMessage added in v1.5.0

type LeaveMessage struct {
	Channel string     `protobuf:"bytes,1,opt,name=Channel" json:"channel"`
	Data    ClientInfo `protobuf:"bytes,2,opt,name=Data" json:"data"`
}

func NewPopulatedLeaveMessage added in v1.5.0

func NewPopulatedLeaveMessage(r randyMessage, easy bool) *LeaveMessage

func (*LeaveMessage) Descriptor added in v1.5.0

func (*LeaveMessage) Descriptor() ([]byte, []int)

func (*LeaveMessage) Equal added in v1.5.0

func (this *LeaveMessage) Equal(that interface{}) bool

func (*LeaveMessage) GetChannel added in v1.5.0

func (m *LeaveMessage) GetChannel() string

func (*LeaveMessage) GetData added in v1.5.0

func (m *LeaveMessage) GetData() ClientInfo

func (*LeaveMessage) Marshal added in v1.5.0

func (m *LeaveMessage) Marshal() (data []byte, err error)

func (*LeaveMessage) MarshalTo added in v1.5.0

func (m *LeaveMessage) MarshalTo(data []byte) (int, error)

func (*LeaveMessage) ProtoMessage added in v1.5.0

func (*LeaveMessage) ProtoMessage()

func (*LeaveMessage) Reset added in v1.5.0

func (m *LeaveMessage) Reset()

func (*LeaveMessage) Size added in v1.5.0

func (m *LeaveMessage) Size() (n int)

func (*LeaveMessage) String added in v1.5.0

func (m *LeaveMessage) String() string

func (*LeaveMessage) Unmarshal added in v1.5.0

func (m *LeaveMessage) Unmarshal(data []byte) error

type Mediator added in v0.2.0

type Mediator interface {
	Connect(client ConnID, user UserID)
	Subscribe(ch Channel, client ConnID, user UserID)
	Unsubscribe(ch Channel, client ConnID, user UserID)
	Disconnect(client ConnID, user UserID)
	Message(ch Channel, data []byte, client ConnID, info *ClientInfo) bool
}

Mediator is an interface to work with libcentrifugo events from Go code. Implemented Mediator must be set to Application via corresponding Application method SetMediator.

type MemoryEngine added in v0.2.0

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

MemoryEngine allows to run Centrifugo without using Redis at all. All data managed inside process memory. With this engine you can only run single Centrifugo node. If you need to scale you should use Redis engine instead.

func NewMemoryEngine added in v0.2.0

func NewMemoryEngine(app *Application) *MemoryEngine

NewMemoryEngine initializes Memory Engine.

type Message added in v0.1.1

type Message struct {
	UID       string                                                   `protobuf:"bytes,1,opt,name=UID" json:"uid"`
	Timestamp string                                                   `protobuf:"bytes,2,opt,name=Timestamp" json:"timestamp"`
	Channel   string                                                   `protobuf:"bytes,3,opt,name=Channel" json:"channel"`
	Data      *github_com_centrifugal_centrifugo_libcentrifugo_raw.Raw `protobuf:"bytes,4,opt,name=Data,customtype=github.com/centrifugal/centrifugo/libcentrifugo/raw.Raw" json:"data"`
	Client    string                                                   `protobuf:"bytes,5,opt,name=Client" json:"client,omitempty"`
	Info      *ClientInfo                                              `protobuf:"bytes,6,opt,name=Info" json:"info,omitempty"`
}

func NewPopulatedMessage added in v1.5.0

func NewPopulatedMessage(r randyMessage, easy bool) *Message

func (*Message) Descriptor added in v1.5.0

func (*Message) Descriptor() ([]byte, []int)

func (*Message) Equal added in v1.5.0

func (this *Message) Equal(that interface{}) bool

func (*Message) GetChannel added in v1.5.0

func (m *Message) GetChannel() string

func (*Message) GetClient added in v1.5.0

func (m *Message) GetClient() string

func (*Message) GetInfo added in v1.5.0

func (m *Message) GetInfo() *ClientInfo

func (*Message) GetTimestamp added in v1.5.0

func (m *Message) GetTimestamp() string

func (*Message) GetUID added in v1.5.0

func (m *Message) GetUID() string

func (*Message) Marshal added in v1.5.0

func (m *Message) Marshal() (data []byte, err error)

func (*Message) MarshalTo added in v1.5.0

func (m *Message) MarshalTo(data []byte) (int, error)

func (*Message) ProtoMessage added in v1.5.0

func (*Message) ProtoMessage()

func (*Message) Reset added in v1.5.0

func (m *Message) Reset()

func (*Message) Size added in v1.5.0

func (m *Message) Size() (n int)

func (*Message) String added in v1.5.0

func (m *Message) String() string

func (*Message) Unmarshal added in v1.5.0

func (m *Message) Unmarshal(data []byte) error

type MessageID added in v1.2.0

type MessageID string

MessageID is a unique message ID

type MuxOptions added in v0.3.0

type MuxOptions struct {
	Prefix        string
	Admin         bool
	Web           bool
	WebPath       string
	WebFS         http.FileSystem
	SockjsOptions sockjs.Options
	HandlerFlags  HandlerFlag
}

MuxOptions contain various options for DefaultMux.

type Namespace added in v0.2.0

type Namespace struct {
	// Name is a unique namespace name.
	Name NamespaceKey `json:"name"`

	// ChannelOptions for namespace determine channel options for channels belonging to this namespace.
	ChannelOptions `mapstructure:",squash"`
}

Namespace allows to create channels with different channel options within the Project

type NamespaceKey added in v0.1.1

type NamespaceKey string

NamespaceKey is a name of namespace unique for project.

type RedisEngine added in v0.2.0

type RedisEngine struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RedisEngine uses Redis datastructures and PUB/SUB to manage Centrifugo logic. This engine allows to scale Centrifugo - you can run several Centrifugo instances connected to the same Redis and load balance clients between instances.

func NewRedisEngine added in v0.2.0

func NewRedisEngine(app *Application, conf *RedisEngineConfig) *RedisEngine

NewRedisEngine initializes Redis Engine.

type RedisEngineConfig added in v1.3.0

type RedisEngineConfig struct {
	// Host is Redis server host.
	Host string
	// Port is Redis server port.
	Port string
	// Password is password to use when connecting to Redis database. If empty then password not used.
	Password string
	// DB is Redis database number as string. If empty then database 0 used.
	DB string
	// URL to redis server in format redis://:password@hostname:port/db_number
	URL string
	// PoolSize is a size of Redis connection pool.
	PoolSize int
	// API enables listening for API queues to publish API commands into Centrifugo via pushing
	// commands into Redis queue.
	API bool
	// NumAPIShards is a number of sharded API queues in Redis to increase volume of commands
	// (most probably publish) that Centrifugo instance can process.
	NumAPIShards int

	// MasterName is a name of Redis instance master Sentinel monitors.
	MasterName string
	// SentinelAddrs is a slice of Sentinel addresses.
	SentinelAddrs []string

	// Timeout on read operations. Note that at moment it should be greater than node
	// ping interval in order to prevent timing out Pubsub connection's Receive call.
	ReadTimeout time.Duration
	// Timeout on write operations
	WriteTimeout time.Duration
	// Timeout on connect operation
	ConnectTimeout time.Duration
}

RedisEngineConfig is struct with Redis Engine options.

type UserID added in v0.1.1

type UserID string

UserID is web application user ID as string.

Directories

Path Synopsis
Package auth provides functions to generate and check Centrifugo tokens and signs.
Package auth provides functions to generate and check Centrifugo tokens and signs.
Package bytequeue provides []byte queue for libcentrifugo package client messages.
Package bytequeue provides []byte queue for libcentrifugo package client messages.
Package priority provides priority queue for libcentrifugo package Memory Engine.
Package priority provides priority queue for libcentrifugo package Memory Engine.
package raw contains Raw type (alias to slice of bytes).
package raw contains Raw type (alias to slice of bytes).

Jump to

Keyboard shortcuts

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