cluster

package
v0.0.0-...-996fa4a Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Peer

type Peer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Peer represents a remote peer.

func (*Peer) Close

func (p *Peer) Close() error

Close termintes the peer and stops everything associated with this peer.

func (*Peer) ID

func (p *Peer) ID() string

ID returns the unique identifier of the subsriber.

func (*Peer) IsActive

func (p *Peer) IsActive() bool

IsActive checks whether a peer is still active or not.

func (*Peer) Send

func (p *Peer) Send(m *message.Message) error

Send forwards the message to the remote server.

func (*Peer) Type

func (p *Peer) Type() message.SubscriberType

Type returns the type of the subscriber.

type Swarm

type Swarm struct {
	sync.Mutex

	OnSubscribe   func(message.Subscriber, *event.Subscription) bool // Delegate to invoke when the subscription event is received.
	OnUnsubscribe func(message.Subscriber, *event.Subscription) bool // Delegate to invoke when the unsubscription event is received.
	OnDisconnect  func(message.Subscriber, *event.Connection) bool   // Delegate to invoke when the client is disconnected.
	OnMessage     func(*message.Message)                             // Delegate to invoke when a new message is received.
	// contains filtered or unexported fields
}

Swarm represents a gossiper.

func NewSwarm

func NewSwarm(cfg *config.ClusterConfig) *Swarm

NewSwarm creates a new swarm messaging layer.

func (*Swarm) Close

func (s *Swarm) Close() error

Close terminates the connection.

func (*Swarm) Contains

func (s *Swarm) Contains(ev event.Event) bool

Contains checks whether an event is currently triggered within the cluster.

func (*Swarm) Gossip

func (s *Swarm) Gossip() (complete mesh.GossipData)

Gossip returns the state of everything we know; gets called periodically.

func (*Swarm) ID

func (s *Swarm) ID() uint64

ID returns the local node ID.

func (*Swarm) Join

func (s *Swarm) Join(peers ...string) (errs []error)

Join attempts to join a set of existing peers.

func (*Swarm) Listen

func (s *Swarm) Listen(ctx context.Context)

Listen creates the listener and serves the cluster.

func (*Swarm) Notify

func (s *Swarm) Notify(ev event.Event, enabled bool)

Notify notifies the swarm when an event is on/off.

func (*Swarm) NumPeers

func (s *Swarm) NumPeers() int

NumPeers returns the number of connected peers.

func (*Swarm) OnGossip

func (s *Swarm) OnGossip(buf []byte) (delta mesh.GossipData, err error)

OnGossip merges received data into state and returns "everything new I've just learnt", or nil if nothing in the received data was new.

func (*Swarm) OnGossipBroadcast

func (s *Swarm) OnGossipBroadcast(src mesh.PeerName, buf []byte) (delta mesh.GossipData, err error)

OnGossipBroadcast merges received data into state and returns a representation of the received data (typically a delta) for further propagation.

func (*Swarm) OnGossipUnicast

func (s *Swarm) OnGossipUnicast(src mesh.PeerName, buf []byte) (err error)

OnGossipUnicast occurs when the gossip unicast is received. In emitter this is used only to forward message frames around.

func (*Swarm) Printf

func (s *Swarm) Printf(format string, args ...interface{})

Printf logs the error

func (*Swarm) SendTo

func (s *Swarm) SendTo(name mesh.PeerName, msg *message.Message) error

SendTo sends a message to a peer.

Jump to

Keyboard shortcuts

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