gossip

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseCSVAddrs

func ParseCSVAddrs(csv string, port uint16) ([]string, error)

func UniqTCPAddr

func UniqTCPAddr(one string, all []string) (*net.TCPAddr, []*net.TCPAddr, error)

Types

type Delegate

type Delegate interface {
	// GossipStarted give the sender to delegate
	// announce gossip server started
	GossipStarted(*Sender)

	// Metadata get local node meta data
	Metadata(limit int) []byte
	// NotifyJoin notify node join or node online
	NotifyJoin(*Node)
	// NotifyJoin notify node leave or node offline
	NotifyLeave(*Node)
	// NotifyUpdate notify node's metadata updated
	NotifyUpdate(*Node)

	// PingPayload given the payload push to other node while pinging.
	// And payload will be compress by lzw default, then aes encrypt optionally,
	// the final size must less than udp packet max size limit
	PingPayload() []byte
	// NotifyPing notify that other node pushed it's payload to me while pinging
	NotifyPing(other *Node, payload []byte)

	// NotifyMessage notify received message
	NotifyMessage(msg []byte)
}

type Node

type Node struct {
	Name string
	Addr net.IP
	Port uint16
	Meta []byte
	RTT  time.Duration
	// contains filtered or unexported fields
}

func (*Node) Address

func (n *Node) Address() string

func (*Node) String

func (n *Node) String() string

type Sender

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

func (*Sender) Broadcast

func (s *Sender) Broadcast(msg []byte)

func (*Sender) Name

func (s *Sender) Name() string

func (*Sender) Peer

func (s *Sender) Peer(name string) *Node

func (*Sender) Peers

func (s *Sender) Peers() []*Node

func (*Sender) Ping

func (s *Sender) Ping(name string) (time.Duration, error)

func (*Sender) Self

func (s *Sender) Self() *Node

func (*Sender) SendBestEffort

func (s *Sender) SendBestEffort(name string, msg []byte)

func (*Sender) SendReliable

func (s *Sender) SendReliable(name string, msg []byte)

func (*Sender) UpdateMetadata

func (s *Sender) UpdateMetadata(timeout time.Duration) error

type Server

type Server struct {
	Config *memberlist.Config
	// contains filtered or unexported fields
}

func NewServer

func NewServer(name, key string) *Server

NewServer return a gossip server, enable lzw compression default

func (*Server) Peer

func (s *Server) Peer(name string) *Node

func (*Server) Peers

func (s *Server) Peers() []*Node

func (*Server) RegisterDelegate

func (s *Server) RegisterDelegate(d Delegate) error

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, bindstr string, bootstrapsstr ...string) error

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Jump to

Keyboard shortcuts

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