Documentation ¶
Index ¶
- type Config
- type Delegate
- type Gossip
- func (g *Gossip) GetPool(id int32) *Pool
- func (g *Gossip) ListPools() []int32
- func (g *Gossip) Listen(id uint16) (net.Listener, error)
- func (g *Gossip) ListenTCP() net.Listener
- func (g *Gossip) NodeName() string
- func (g *Gossip) RegisterPool(conf *PoolConfig) *Pool
- func (g *Gossip) Start() (err error)
- func (g *Gossip) UDPPackets() <-chan *memberlist.Packet
- type Pool
- type PoolConfig
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
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 (*Gossip) GetPool ¶
GetPool returns a gossip pool by the given id. It returns nil if the pool id does not exist
func (*Gossip) Listen ¶
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 ¶
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(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 ¶
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
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