cluster

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MsgBind represents a bind cluster message.
	MsgBind = iota

	// MsgBatchBind represents a batch bind cluster message.
	MsgBatchBind

	// MsgUnbind represents a unbind cluster message.
	MsgUnbind

	// MsgUpdatePresence represents an update presence cluster message.
	MsgUpdatePresence

	// MsgUpdateContext represents a context update cluster message.
	MsgUpdateContext

	// MsgRouteStanza represents a route stanza cluster message.
	MsgRouteStanza
)

Variables

This section is empty.

Functions

This section is empty.

Types

type C2S

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

C2S represents a cluster c2s stream.

func (*C2S) Context

func (s *C2S) Context() map[string]interface{}

Context returns a copy of the stream associated context.

func (*C2S) Disconnect

func (s *C2S) Disconnect(_ context.Context, _ error)

Disconnect disconnects remote peer by closing the underlying TCP socket connection.

func (*C2S) Domain

func (s *C2S) Domain() string

Domain returns current stream domain.

func (*C2S) GetBool

func (s *C2S) GetBool(key string) bool

GetBool returns the context value associated with the key as a boolean.

func (*C2S) GetFloat

func (s *C2S) GetFloat(key string) float64

GetFloat returns the context value associated with the key as a float64.

func (*C2S) GetInt

func (s *C2S) GetInt(key string) int

GetInt returns the context value associated with the key as an integer.

func (*C2S) GetString

func (s *C2S) GetString(key string) string

GetString returns the context value associated with the key as a string.

func (*C2S) ID

func (s *C2S) ID() string

ID returns stream identifier.

func (*C2S) IsAuthenticated

func (s *C2S) IsAuthenticated() bool

IsAuthenticated returns whether or not the XMPP stream has successfully authenticated.

func (*C2S) IsSecured

func (s *C2S) IsSecured() bool

IsSecured returns whether or not the XMPP stream has been secured using SSL/TLS.

func (*C2S) JID

func (s *C2S) JID() *jid.JID

JID returns current user JID.

func (*C2S) Presence

func (s *C2S) Presence() *xmpp.Presence

Presence returns last sent presence element.

func (*C2S) Resource

func (s *C2S) Resource() string

Resource returns current stream resource.

func (*C2S) SendElement

func (s *C2S) SendElement(ctx context.Context, elem xmpp.XElement)

SendElement writes an XMPP element to the stream.

func (*C2S) SetBool

func (s *C2S) SetBool(_ context.Context, _ string, _ bool)

SetBool associates a boolean context value to a key.

func (*C2S) SetFloat

func (s *C2S) SetFloat(_ context.Context, _ string, _ float64)

SetFloat associates a float context value to a key.

func (*C2S) SetInt

func (s *C2S) SetInt(_ context.Context, _ string, _ int)

SetInt associates an integer context value to a key.

func (*C2S) SetPresence

func (s *C2S) SetPresence(presence *xmpp.Presence)

SetPresence updates the C2S stream presence.

func (*C2S) SetString

func (s *C2S) SetString(_ context.Context, _ string, _ string)

SetString associates a string context value to a key.

func (*C2S) UpdateContext

func (s *C2S) UpdateContext(m map[string]interface{})

UpdateContext updates stream context by copying all 'm' values

func (*C2S) Username

func (s *C2S) Username() string

Username returns current stream username.

type Cluster

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

Cluster represents a c2s sub system.

func New

func New(config *Config, delegate Delegate) (*Cluster, error)

New returns an initialized c2s instance

func (*Cluster) BroadcastMessage

func (c *Cluster) BroadcastMessage(ctx context.Context, msg *Message)

BroadcastMessage broadcasts a cluster message to all nodes.

func (*Cluster) C2SStream

func (c *Cluster) C2SStream(jid *jid.JID, presence *xmpp.Presence, context map[string]interface{}, node string) *C2S

C2SStream returns a cluster C2S stream.

func (*Cluster) Join

func (c *Cluster) Join() error

Join tries to join the c2s by contacting all the given hosts.

func (*Cluster) LocalNode

func (c *Cluster) LocalNode() string

LocalNode returns the local node identifier.

func (*Cluster) SendMessageTo

func (c *Cluster) SendMessageTo(ctx context.Context, node string, msg *Message)

SendMessageTo sends a cluster message to a concrete node.

func (*Cluster) Shutdown

func (c *Cluster) Shutdown() error

Shutdown shuts down cluster sub system.

type Config

type Config struct {
	Name      string
	BindPort  int
	Hosts     []string
	InTimeout time.Duration
}

Config represents an cluster configuration.

func (*Config) UnmarshalYAML added in v0.8.0

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML satisfies Unmarshaler interface.

type Delegate

type Delegate interface {
	NodeJoined(ctx context.Context, node *Node)
	NodeUpdated(ctx context.Context, node *Node)
	NodeLeft(ctx context.Context, node *Node)

	NotifyMessage(ctx context.Context, msg *Message)
}

Delegate is the interface that will receive all c2s related events.

type Message

type Message struct {
	Type     int
	Node     string
	Payloads []MessagePayload
}

Message is the c2s message type. A message can contain one or more payloads.

func (*Message) FromBytes added in v0.7.0

func (m *Message) FromBytes(buf *bytes.Buffer) error

FromBytes reads Message fields from its binary representation.

func (*Message) ToBytes added in v0.7.0

func (m *Message) ToBytes(buf *bytes.Buffer) error

ToBytes converts a Message instance to its binary representation.

type MessagePayload

type MessagePayload struct {
	JID     *jid.JID
	Context map[string]interface{}
	Stanza  xmpp.Stanza
}

MessagePayload represents a message payload type.

func (*MessagePayload) FromBytes added in v0.7.0

func (p *MessagePayload) FromBytes(buf *bytes.Buffer) error

FromBytes reads MessagePayload fields from its binary representation.

func (*MessagePayload) ToBytes added in v0.7.0

func (p *MessagePayload) ToBytes(buf *bytes.Buffer) error

ToBytes converts a MessagePayload instance to its binary representation.

type Metadata

type Metadata struct {
	Version   string
	GoVersion string
}

Metadata type represents all metadata information associated to a node.

type Node

type Node struct {
	Name     string
	Metadata Metadata
}

Node represents a concrete c2s node and metadata information.

Jump to

Keyboard shortcuts

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