swim

package module
v0.0.0-...-3f013c7 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

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

A Node is a network node participating in the SWIM protocol.

func Start

func Start(address string) (*Node, error)

Start creates a new Node listening on the local UDP address.

If the address's host is empty or a literal unspecified IP address, the Node listens on all available IP addresses of the local system except multicast IP addresses. If the port is empty or "0", as in "127.0.0.1:" or "[::1]:0", a port number is automatically chosen.

func (*Node) ID

func (n *Node) ID() string

ID returns n's ID on the network.

func (*Node) Join

func (n *Node) Join(remote netip.AddrPort) error

Join connects n to a remote node. This is typically used to connect a new node to an existing network.

func (*Node) LocalAddr

func (n *Node) LocalAddr() netip.AddrPort

LocalAddr returns the local network address.

func (*Node) OnFail

func (n *Node) OnFail(f func(nodeID string))

OnFail uses f as n's failure handler, to be called when a peer leaves the network. For each peer, the call to f happens after all calls to the memo handler (if any) return.

func (*Node) OnJoin

func (n *Node) OnJoin(f func(nodeID string, addr netip.AddrPort))

OnJoin uses f as n's join handler, to be called when a peer joins the network.

func (*Node) OnMemo

func (n *Node) OnMemo(f func(nodeID string, addr netip.AddrPort, memo []byte))

OnMemo uses f as n's memo handler, to be called when n receives a memo. For each peer, calls to f happen after the join handler (if any) returns.

func (*Node) PostMemo

func (n *Node) PostMemo(b []byte) error

PostMemo disseminates a memo throughout the network. To ensure transmission within a single UDP packet, PostMemo enforces a length limit of 500 bytes; if len(b) exceeds this, PostMemo returns an error instead.

Directories

Path Synopsis
internal
roundrobinrandom
Package roundrobinrandom implements a randomized round-based ordering type.
Package roundrobinrandom implements a randomized round-based ordering type.
rpq
Package rpq implements a recurrent priority queue: a priority queue whose elements can be returned multiple times, up to a specified quota, prioritized according to how many times they have already been returned.
Package rpq implements a recurrent priority queue: a priority queue whose elements can be returned multiple times, up to a specified quota, prioritized according to how many times they have already been returned.

Jump to

Keyboard shortcuts

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