gossip

package module
Version: v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2019 License: MPL-2.0 Imports: 8 Imported by: 0

README

gossip

gossip extends the hashicorp/memberlist library to provide additional features particularly the transport layer.

Extensions

  • Allows running multiple gossip pools on a single port.
  • Exposes underlying TCP/UDP transport to run apps on the same port.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name          string
	AdvertiseAddr string
	AdvertisePort int
	BindAddr      string
	BindPort      int
	Logger        *log.Logger
	Debug         bool
}

Config holds the config instantiate a Gossip instance

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default config to instantiate a Gossip instance

func (*Config) Validate

func (conf *Config) Validate()

Validate validates thte config

type Delegate

type Delegate interface {
	// NodeMeta is used to retrieve meta-data about the current node
	// when broadcasting an alive message. It's length is limited to
	// the given byte size. This metadata is available in the Node structure.
	NodeMeta(limit int) []byte

	// NotifyMsg is called when a user-data message is received.
	// Care should be taken that this method does not block, since doing
	// so would block the entire UDP packet receive loop. Additionally, the byte
	// slice may be modified after the call returns, so it should be copied if needed
	NotifyMsg([]byte)

	// LocalState is used for a TCP Push/Pull. This is sent to
	// the remote side in addition to the membership information. Any
	// data can be sent here. See MergeRemoteState as well. The `join`
	// boolean indicates this is for a join instead of a push/pull.
	LocalState(join bool) []byte

	// MergeRemoteState is invoked after a TCP Push/Pull. This is the
	// state received from the remote side and is the result of the
	// remote side's LocalState call. The 'join'
	// boolean indicates this is for a join instead of a push/pull.
	MergeRemoteState(buf []byte, join bool)
}

Delegate is the interface that clients must implement if they want to hook into the gossip layer of Memberlist. All the methods must be thread-safe, as they can and generally will be called concurrently.

This removes the memberlist.Delegate.GetBroadcast to provide a broadcast interface.

type Gossip

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

Gossip is the top-level gossip struct to manage multiple pools

func New

func New(conf *Config) (*Gossip, error)

New returns a new Gossip instance based on the given config

func (*Gossip) GetPool

func (g *Gossip) GetPool(id int32) *Pool

GetPool returns a gossip pool by the given id. It returns nil if the pool id does not exist

func (*Gossip) ListPools

func (g *Gossip) ListPools() []int32

ListPools returns a slice of int32 pool ids

func (*Gossip) Listen

func (g *Gossip) Listen(id uint16) (net.Listener, error)

Listen returns a new muxed listener by the given id. The dialer must send the same id at the time of connection. It returns an error if the id is taken. All listeners must be registered before gossip is actually started as the addition of listeners is not thread-safe

func (*Gossip) ListenTCP

func (g *Gossip) ListenTCP() net.Listener

ListenTCP returns a TCP Listener interface for native non-muxed protocols. This does not actually start listening but rather returns a Listener interface backed by a channel of incoming connections

func (*Gossip) NodeName added in v0.6.0

func (g *Gossip) NodeName() string

NodeName returns the name of this node

func (*Gossip) RegisterPool

func (g *Gossip) RegisterPool(conf *PoolConfig) *Pool

RegisterPool creates a new gossip pool with the given config. All pools must be registered before gossip is started as the addition of pools is not thread-safe

func (*Gossip) Start

func (g *Gossip) Start() (err error)

Start starts the underlying transport and all registered gossip pools This should be called only after all pools have been registered

func (*Gossip) UDPPackets

func (g *Gossip) UDPPackets() <-chan *memberlist.Packet

UDPPackets returns a read-only channel incoming non-gossip udp packets. This is useful for custom application transport allowing network communication on a single port

type Pool

type Pool struct {

	// memberlist for pool
	*memberlist.Memberlist
	// contains filtered or unexported fields
}

Pool is a single gossip pool

func NewPool

func NewPool(conf *PoolConfig) *Pool

NewPool returns a new gossip pool using the given config

func (*Pool) Broadcast

func (p *Pool) Broadcast(b []byte)

Broadcast broadcasts the given bytes to the pool

func (*Pool) Start

func (p *Pool) Start() (err error)

Start creates the underlying memberlist object

type PoolConfig

type PoolConfig struct {
	ID                int32
	BroadcastBuffSize int
	Delegate          Delegate
	Memberlist        *memberlist.Config
	Logger            *log.Logger
	Debug             bool
}

PoolConfig is the config for a single gossip pool

func DefaultLANPoolConfig

func DefaultLANPoolConfig(id int32) *PoolConfig

DefaultLANPoolConfig returns a sane config suitable for LAN based pool

func DefaultLocalPoolConfig

func DefaultLocalPoolConfig(id int32) *PoolConfig

DefaultLocalPoolConfig returns a sane config suitable for local pool

func DefaultPoolConfig

func DefaultPoolConfig(id int32) *PoolConfig

DefaultPoolConfig returns a base config to init a new gossip pool

func DefaultWANPoolConfig

func DefaultWANPoolConfig(id int32) *PoolConfig

DefaultWANPoolConfig returns a sane config suitable for WAN based pool

func (*PoolConfig) Validate

func (conf *PoolConfig) Validate()

Validate validates the pool config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL