memberlist

package
v0.0.0-...-5a6e01e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Overview

Package memberlist provides node discovery and failed nodes detection by hashicorp/memberlist.

Basically mitum memberlist uses the two features of hashicorp/memberlist:

  • join
  • leave

mitum memberlist implements Transport layer of hashicorp/memberlist, which depends on UDP/TCP connections by default. Transport layer of mitum memberlist uses quic network package of mitum, so there is no additional ports for discovery.

The publish url of node is translated to virtual IPv6 address, it will be used to identify node.

mitum memberlist maintains the joined nodes.

mitim memberlist allows multiple connections from same node up to `discovery.maxNodeConns` by virtual IPv6 address.

To get the joined nodes, mitum memberlist supports, `Discovery.Nodes()`. it returns `[]NodeConnInfo`. List of `NodeConnInfo` in same node are listed by added order, but it's order does not mean the joined order.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDiscoveryPath = "/_join"

	DefaultMaxNodeConns uint = 2
)
View Source
var (
	JoinDeclinedError    = util.NewError("joining declined")
	JoiningCanceledError = util.NewError("joining canceled")
)

Functions

func SuffrageHandlerFilter

func SuffrageHandlerFilter(suffrage base.Suffrage, nodepool *network.Nodepool) func(NodeMessage) error

Types

type ConnInfo

type ConnInfo struct {
	network.HTTPConnInfo
	Address       string
	LastActivated time.Time
}

func NewConnInfo

func NewConnInfo(addr string, publish *url.URL, insecure bool) ConnInfo

func NewConnInfoWithConnInfo

func NewConnInfoWithConnInfo(addr string, connInfo network.HTTPConnInfo) ConnInfo

func (ConnInfo) Bytes

func (ci ConnInfo) Bytes() []byte

func (ConnInfo) Equal

func (ci ConnInfo) Equal(b network.ConnInfo) bool

func (ConnInfo) IsValid

func (ci ConnInfo) IsValid([]byte) error

func (ConnInfo) MarshalJSON

func (ci ConnInfo) MarshalJSON() ([]byte, error)

func (*ConnInfo) UnmarshalJSON

func (ci *ConnInfo) UnmarshalJSON(b []byte) error

type ConnInfoMap

type ConnInfoMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewConnInfoMap

func NewConnInfoMap() *ConnInfoMap

type ConnInfoPackerJSON

type ConnInfoPackerJSON struct {
	A string `json:"address"`
}

type Discovery

type Discovery struct {
	*logging.Logging
	*util.ContextDaemon
	// contains filtered or unexported fields
}

func NewDiscovery

func NewDiscovery(
	local node.Local,
	connInfo network.ConnInfo,
	networkID base.NetworkID,
	enc encoder.Encoder,
) *Discovery

func (*Discovery) Broadcast

func (dis *Discovery) Broadcast(b []byte) error

Broadcast send bytese message to joined nodes, except local node.

func (*Discovery) Events

func (dis *Discovery) Events() *Events

func (*Discovery) GracefuleStop

func (dis *Discovery) GracefuleStop(timeout time.Duration) error

func (*Discovery) Handler

func (dis *Discovery) Handler(callback func(NodeMessage) error) http.HandlerFunc

func (*Discovery) Initialize

func (dis *Discovery) Initialize() error

func (*Discovery) Join

func (dis *Discovery) Join(nodes []ConnInfo, maxretry int) error

func (*Discovery) Leave

func (dis *Discovery) Leave(timeout time.Duration) error

func (*Discovery) LenNodes

func (dis *Discovery) LenNodes() int

func (*Discovery) NodeMeta

func (dis *Discovery) NodeMeta() NodeMeta

func (*Discovery) Nodes

func (dis *Discovery) Nodes() []discovery.NodeConnInfo

func (*Discovery) SetCheckMessage

func (dis *Discovery) SetCheckMessage(callback func(NodeMessage) error) *Discovery

func (*Discovery) SetLogging

func (dis *Discovery) SetLogging(l *logging.Logging) *logging.Logging

func (*Discovery) SetMaxNodeConns

func (dis *Discovery) SetMaxNodeConns(i uint) *Discovery

func (*Discovery) SetNotifyJoin

func (dis *Discovery) SetNotifyJoin(callback func(discovery.NodeConnInfo)) discovery.Discovery

func (*Discovery) SetNotifyLeave

func (dis *Discovery) SetNotifyLeave(
	callback func(discovery.NodeConnInfo, []discovery.NodeConnInfo),
) discovery.Discovery

func (*Discovery) SetNotifyUpdate

func (dis *Discovery) SetNotifyUpdate(callback func(discovery.NodeConnInfo)) discovery.Discovery

func (*Discovery) SetRequest

func (dis *Discovery) SetRequest(f QuicRequest) *Discovery

func (*Discovery) SetTimeout

func (dis *Discovery) SetTimeout(tcpTimeout, probeInterval, probeTimeout time.Duration) *Discovery

func (*Discovery) Start

func (dis *Discovery) Start() error

type Events

type Events struct {
	sync.RWMutex
	*logging.Logging
	// contains filtered or unexported fields
}

func NewEvents

func NewEvents(connInfo ConnInfo, meta NodeMeta, ma *ConnInfoMap) *Events

func (*Events) GetBroadcasts

func (dg *Events) GetBroadcasts(_, _ int) [][]byte

func (*Events) LocalState

func (dg *Events) LocalState(join bool) []byte

func (*Events) MergeRemoteState

func (dg *Events) MergeRemoteState(buf []byte, join bool)

func (*Events) NodeMeta

func (dg *Events) NodeMeta(int) []byte

func (*Events) NotifyAlive

func (dg *Events) NotifyAlive(peer *ml.Node) error

NotifyAlive does not do anything to filter node; if error occurs, alive mesage will be ignored.

func (*Events) NotifyJoin

func (dg *Events) NotifyJoin(peer *ml.Node)

func (*Events) NotifyLeave

func (dg *Events) NotifyLeave(peer *ml.Node)

func (*Events) NotifyMerge

func (dg *Events) NotifyMerge(peers []*ml.Node) error

func (*Events) NotifyMsg

func (dg *Events) NotifyMsg(b []byte)

func (*Events) NotifyUpdate

func (dg *Events) NotifyUpdate(peer *ml.Node)

func (*Events) SetLocalState

func (dg *Events) SetLocalState(callback func(bool) []byte) *Events

func (*Events) SetMergeRemoteState

func (dg *Events) SetMergeRemoteState(callback func([]byte, bool)) *Events

func (*Events) SetNodeMeta

func (dg *Events) SetNodeMeta(callback func(NodeMeta) []byte) *Events

func (*Events) SetNotifyAlive

func (dg *Events) SetNotifyAlive(callback func(peer *ml.Node, meta NodeMeta) error) *Events

func (*Events) SetNotifyJoin

func (dg *Events) SetNotifyJoin(callback func(peer *ml.Node, meta NodeMeta)) *Events

func (*Events) SetNotifyLeave

func (dg *Events) SetNotifyLeave(callback func(peer *ml.Node, meta NodeMeta)) *Events

func (*Events) SetNotifyMerge

func (dg *Events) SetNotifyMerge(callback func(peers []*ml.Node, metas map[string]NodeMeta) error) *Events

func (*Events) SetNotifyMsg

func (dg *Events) SetNotifyMsg(callback func([]byte)) *Events

func (*Events) SetNotifyUpdate

func (dg *Events) SetNotifyUpdate(callback func(peer *ml.Node, meta NodeMeta)) *Events

type NodeConnInfo

type NodeConnInfo struct {
	ConnInfo
	// contains filtered or unexported fields
}

func NewNodeConnInfo

func NewNodeConnInfo(connInfo ConnInfo, n base.Address) NodeConnInfo

func (NodeConnInfo) Node

func (conn NodeConnInfo) Node() base.Address

type NodeMessage

type NodeMessage struct {
	ConnInfo
	// contains filtered or unexported fields
}

func NewNodeMessage

func NewNodeMessage(
	n base.Address,
	connInfo ConnInfo,
	body []byte,
	connid string,
) NodeMessage

func (NodeMessage) IsValid

func (ms NodeMessage) IsValid(networkID []byte) error

func (NodeMessage) MarshalJSON

func (ms NodeMessage) MarshalJSON() ([]byte, error)

func (NodeMessage) Node

func (ms NodeMessage) Node() base.Address

func (NodeMessage) SignedAt

func (ms NodeMessage) SignedAt() time.Time

func (NodeMessage) Signer

func (ms NodeMessage) Signer() key.Publickey

func (*NodeMessage) Unpack

func (ms *NodeMessage) Unpack(b []byte, enc encoder.Encoder) error

type NodeMessagePackerJSON

type NodeMessagePackerJSON struct {
	Node      base.Address  `json:"node"`
	Address   string        `json:"address"`
	Publish   string        `json:"publish"`
	Insecure  bool          `json:"insecure"`
	Body      []byte        `json:"body"`
	ConID     string        `json:"connection_id,omitempty"`
	Signer    key.Publickey `json:"signer"`
	Signature key.Signature `json:"signature"`
	SignedAt  time.Time     `json:"signed_at"`
}

type NodeMessageUnpackerJSON

type NodeMessageUnpackerJSON struct {
	Node      base.AddressDecoder  `json:"node"`
	Address   string               `json:"address"`
	Publish   string               `json:"publish"`
	Insecure  bool                 `json:"insecure"`
	Body      []byte               `json:"body"`
	ConID     string               `json:"connection_id,omitempty"`
	Signer    key.PublickeyDecoder `json:"signer"`
	Signature key.Signature        `json:"signature"`
	SignedAt  localtime.Time       `json:"signed_at"`
}

type NodeMeta

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

func NewNodeMeta

func NewNodeMeta(publish string, insecure bool) (NodeMeta, error)

func NewNodeMetaFromBytes

func NewNodeMetaFromBytes(b []byte) (NodeMeta, error)

func (NodeMeta) AddMeta

func (meta NodeMeta) AddMeta(k string, v interface{}) (NodeMeta, error)

func (NodeMeta) Bytes

func (meta NodeMeta) Bytes() []byte

func (NodeMeta) GetMeta

func (meta NodeMeta) GetMeta(k string) (interface{}, bool)

func (NodeMeta) Insecure

func (meta NodeMeta) Insecure() bool

func (NodeMeta) IsValid

func (meta NodeMeta) IsValid([]byte) error

func (NodeMeta) MarshalJSON

func (meta NodeMeta) MarshalJSON() ([]byte, error)

func (NodeMeta) MarshalZerologObject

func (meta NodeMeta) MarshalZerologObject(e *zerolog.Event)

func (NodeMeta) Publish

func (meta NodeMeta) Publish() *url.URL

func (NodeMeta) SetPublish

func (meta NodeMeta) SetPublish(u *url.URL) NodeMeta

func (*NodeMeta) UnmarshalJSON

func (meta *NodeMeta) UnmarshalJSON(b []byte) error

type QuicConn

type QuicConn struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*QuicConn) Close

func (conn *QuicConn) Close() error

func (*QuicConn) LocalAddr

func (*QuicConn) LocalAddr() net.Addr

func (*QuicConn) Read

func (conn *QuicConn) Read(b []byte) (int, error)

func (*QuicConn) RemoteAddr

func (conn *QuicConn) RemoteAddr() net.Addr

func (*QuicConn) SetDeadline

func (*QuicConn) SetDeadline(time.Time) error

func (*QuicConn) SetReadDeadline

func (*QuicConn) SetReadDeadline(time.Time) error

func (*QuicConn) SetWriteDeadline

func (*QuicConn) SetWriteDeadline(time.Time) error

func (*QuicConn) Write

func (conn *QuicConn) Write(b []byte) (int, error)

type QuicRequest

type QuicRequest func(
	ctx context.Context,
	insecure bool,
	timeout time.Duration,
	u,
	method string,
	body []byte,
	header http.Header,
) (*http.Response, func() error, error)

func DefaultRequest

func DefaultRequest(p string) QuicRequest

type QuicTransport

type QuicTransport struct {
	*logging.Logging
	// contains filtered or unexported fields
}

func NewQuicTransport

func NewQuicTransport(
	request QuicRequest,
	newNodeMessage func([]byte, string) ([]byte, error),
	loadNodeMessage func([]byte) (NodeMessage, error),
	ma *ConnInfoMap,
	timeout time.Duration,
) *QuicTransport

func (*QuicTransport) DialAddressTimeout

func (tp *QuicTransport) DialAddressTimeout(a ml.Address, timeout time.Duration) (net.Conn, error)

func (*QuicTransport) DialTimeout

func (tp *QuicTransport) DialTimeout(addr string, timeout time.Duration) (net.Conn, error)

func (*QuicTransport) FinalAdvertiseAddr

func (*QuicTransport) FinalAdvertiseAddr(ip string, port int) (net.IP, int, error)

func (*QuicTransport) PacketCh

func (tp *QuicTransport) PacketCh() <-chan *ml.Packet

func (*QuicTransport) Shutdown

func (*QuicTransport) Shutdown() error

func (*QuicTransport) StreamCh

func (tp *QuicTransport) StreamCh() <-chan net.Conn

func (*QuicTransport) WriteTo

func (tp *QuicTransport) WriteTo(b []byte, addr string) (time.Time, error)

func (*QuicTransport) WriteToAddress

func (tp *QuicTransport) WriteToAddress(b []byte, a ml.Address) (time.Time, error)

Jump to

Keyboard shortcuts

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