gossip

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2018 License: MPL-2.0 Imports: 14 Imported by: 0

README

gossip

gossip extends the hashicorp/memberlist library to provide additional features

Extensions
  • Allows running multiple gossip pools on a single port.
  • Exposes underlying TCP/UDP transport to run apps on a single port.
  • Network tomography via vivaldi coordinates.

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
	PublicKey     []byte // Public key for the node
	Coordinate    *vivaldi.Config
	Logger        *log.Logger
	Debug         bool // Turn on debug
}

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 {
	NotifyMsg(msg []byte)
	MergeRemoteState(remote *net.TCPAddr, buf []byte, join bool)
	LocalState(join bool) []byte
}

Delegate is the overwritten memberlist delegate

type EventsDelegate

type EventsDelegate interface {
	NotifyJoin(*peerspb.Peer)
	NotifyUpdate(*peerspb.Peer)
	NotifyLeave(*peerspb.Peer)
}

EventsDelegate implements in interface called on member events

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

func (g *Gossip) RegisterPool(pconf *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(data []byte) error

Broadcast queues data to be broadcasted to the network via memberlist

func (*Pool) Peers

func (p *Pool) Peers() peers.Library

Peers returns a peers library containing all peers in the pool

func (*Pool) Start

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

Start creates the underlying memberlist object

type PoolConfig

type PoolConfig struct {
	ID         int32
	Peers      peers.Library
	Vivaldi    *vivaldi.Client
	Memberlist *memberlist.Config
	Delegate   Delegate
	Events     EventsDelegate
	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
peerspb
Package peerspb is a generated protocol buffer package.
Package peerspb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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