Version: v2.0.437+incompatible Latest Latest

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

Go to latest
Published: May 5, 2018 License: AGPL-3.0 Imports: 14 Imported by: 4




This section is empty.


This section is empty.


This section is empty.


type Peer

type Peer struct {
	// contains filtered or unexported fields

Peer represents a remote peer.

func (*Peer) Close

func (p *Peer) Close()

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 SubscriptionEvent

type SubscriptionEvent struct {
	Ssid message.Ssid  // The SSID for the subscription.
	Peer mesh.PeerName // The name of the peer.
	Conn security.ID   // The connection identifier.

SubscriptionEvent represents a subscription event.

func (*SubscriptionEvent) Encode

func (e *SubscriptionEvent) Encode() string

Encode encodes the event to string representation.

type Swarm

type Swarm struct {

	OnSubscribe   func(message.Ssid, message.Subscriber) bool // Delegate to invoke when the subscription event is received.
	OnUnsubscribe func(message.Ssid, message.Subscriber) bool // Delegate to invoke when the subscription event is received.
	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, closing chan bool) *Swarm

NewSwarm creates a new swarm messaging layer.

func (*Swarm) Close

func (s *Swarm) Close() error

Close terminates the connection.

func (*Swarm) FindPeer

func (s *Swarm) FindPeer(name mesh.PeerName) *Peer

FindPeer retrieves a peer.

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()

Listen creates the listener and serves the cluster.

func (*Swarm) NotifySubscribe

func (s *Swarm) NotifySubscribe(conn security.ID, ssid message.Ssid)

NotifySubscribe notifies the swarm when a subscription occurs.

func (*Swarm) NotifyUnsubscribe

func (s *Swarm) NotifyUnsubscribe(conn security.ID, ssid message.Ssid)

NotifyUnsubscribe notifies the swarm when an unsubscription occurs.

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.

Jump to

Keyboard shortcuts

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