node

package
v0.0.0-...-fe73bcc Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2018 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package node implements link.Node and link.Peer interfaces.

Index

Constants

This section is empty.

Variables

View Source
var WithDefault = func(n *Node) {
	l, e := net.Listen("tcp", "127.0.0.1:0")
	if e != nil {
		log.Fatalf("net.Listen tcp :0: %v", e)
	}
	n.listener = l
	n.addr = l.Addr()
}

WithDefault can be used to instantiate a new node with default options.

Functions

func WithAddr

func WithAddr(addr net.Addr) func(*Node)

WithAddr sets the address when instantiating a new node (e.g. New(WithAddr(...), ...)).

func WithID

func WithID(id string) func(*Node)

WithID sets the ID when instantiating a new node (e.g. New(WithID("identifier"), ...)).

func WithListener

func WithListener(l net.Listener) func(*Node)

WithListener sets the listener when instantiate a new node.

func WithPeer

func WithPeer(p link.Peer) func(*Node)

WithPeer adds a peer when instantiating a new node (e.g. New(WithPeer(...), ...)).

Types

type Node

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

Node represents a node in the cluster with its peers.

func New

func New(configs ...func(*Node)) *Node

New instantiates a new node.

func (*Node) AddPeer

func (n *Node) AddPeer(p link.Peer)

AddPeer adds a new peer to the peers list.

func (*Node) Listener

func (n *Node) Listener() net.Listener

Listener returns the network listener.

func (*Node) Members

func (n *Node) Members() []link.Peer

Members returns all the members including the current node.

func (*Node) N

func (n *Node) N() int

N returns total number of nodes in the cluster.

func (*Node) Peers

func (n *Node) Peers() []link.Peer

Peers returns the list of peers of the node.

type Peer

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

Peer represents a peer in the cluster.

func NewPeer

func NewPeer(id string, addr net.Addr) *Peer

NewPeer instantiates a peer.

func (*Peer) Addr

func (p *Peer) Addr() net.Addr

Addr returns the network addres of the node.

func (*Peer) ID

func (p *Peer) ID() string

ID returns the id of the node.

Jump to

Keyboard shortcuts

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