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 ¶
- Variables
- func SuffrageHandlerFilter(suffrage base.Suffrage, nodepool *network.Nodepool) func(NodeMessage) error
- type ConnInfo
- type ConnInfoMap
- type ConnInfoPackerJSON
- type Discovery
- func (dis *Discovery) Broadcast(b []byte) error
- func (dis *Discovery) Events() *Events
- func (dis *Discovery) GracefuleStop(timeout time.Duration) error
- func (dis *Discovery) Handler(callback func(NodeMessage) error) http.HandlerFunc
- func (dis *Discovery) Initialize() error
- func (dis *Discovery) Join(nodes []ConnInfo, maxretry int) error
- func (dis *Discovery) Leave(timeout time.Duration) error
- func (dis *Discovery) LenNodes() int
- func (dis *Discovery) NodeMeta() NodeMeta
- func (dis *Discovery) Nodes() []discovery.NodeConnInfo
- func (dis *Discovery) SetCheckMessage(callback func(NodeMessage) error) *Discovery
- func (dis *Discovery) SetLogging(l *logging.Logging) *logging.Logging
- func (dis *Discovery) SetMaxNodeConns(i uint) *Discovery
- func (dis *Discovery) SetNotifyJoin(callback func(discovery.NodeConnInfo)) discovery.Discovery
- func (dis *Discovery) SetNotifyLeave(callback func(discovery.NodeConnInfo, []discovery.NodeConnInfo)) discovery.Discovery
- func (dis *Discovery) SetNotifyUpdate(callback func(discovery.NodeConnInfo)) discovery.Discovery
- func (dis *Discovery) SetRequest(f QuicRequest) *Discovery
- func (dis *Discovery) SetTimeout(tcpTimeout, probeInterval, probeTimeout time.Duration) *Discovery
- func (dis *Discovery) Start() error
- type Events
- func (dg *Events) GetBroadcasts(_, _ int) [][]byte
- func (dg *Events) LocalState(join bool) []byte
- func (dg *Events) MergeRemoteState(buf []byte, join bool)
- func (dg *Events) NodeMeta(int) []byte
- func (dg *Events) NotifyAlive(peer *ml.Node) error
- func (dg *Events) NotifyJoin(peer *ml.Node)
- func (dg *Events) NotifyLeave(peer *ml.Node)
- func (dg *Events) NotifyMerge(peers []*ml.Node) error
- func (dg *Events) NotifyMsg(b []byte)
- func (dg *Events) NotifyUpdate(peer *ml.Node)
- func (dg *Events) SetLocalState(callback func(bool) []byte) *Events
- func (dg *Events) SetMergeRemoteState(callback func([]byte, bool)) *Events
- func (dg *Events) SetNodeMeta(callback func(NodeMeta) []byte) *Events
- func (dg *Events) SetNotifyAlive(callback func(peer *ml.Node, meta NodeMeta) error) *Events
- func (dg *Events) SetNotifyJoin(callback func(peer *ml.Node, meta NodeMeta)) *Events
- func (dg *Events) SetNotifyLeave(callback func(peer *ml.Node, meta NodeMeta)) *Events
- func (dg *Events) SetNotifyMerge(callback func(peers []*ml.Node, metas map[string]NodeMeta) error) *Events
- func (dg *Events) SetNotifyMsg(callback func([]byte)) *Events
- func (dg *Events) SetNotifyUpdate(callback func(peer *ml.Node, meta NodeMeta)) *Events
- type NodeConnInfo
- type NodeMessage
- func (ms NodeMessage) IsValid(networkID []byte) error
- func (ms NodeMessage) MarshalJSON() ([]byte, error)
- func (ms NodeMessage) Node() base.Address
- func (ms NodeMessage) SignedAt() time.Time
- func (ms NodeMessage) Signer() key.Publickey
- func (ms *NodeMessage) Unpack(b []byte, enc encoder.Encoder) error
- type NodeMessagePackerJSON
- type NodeMessageUnpackerJSON
- type NodeMeta
- func (meta NodeMeta) AddMeta(k string, v interface{}) (NodeMeta, error)
- func (meta NodeMeta) Bytes() []byte
- func (meta NodeMeta) GetMeta(k string) (interface{}, bool)
- func (meta NodeMeta) Insecure() bool
- func (meta NodeMeta) IsValid([]byte) error
- func (meta NodeMeta) MarshalJSON() ([]byte, error)
- func (meta NodeMeta) MarshalZerologObject(e *zerolog.Event)
- func (meta NodeMeta) Publish() *url.URL
- func (meta NodeMeta) SetPublish(u *url.URL) NodeMeta
- func (meta *NodeMeta) UnmarshalJSON(b []byte) error
- type QuicConn
- func (conn *QuicConn) Close() error
- func (*QuicConn) LocalAddr() net.Addr
- func (conn *QuicConn) Read(b []byte) (int, error)
- func (conn *QuicConn) RemoteAddr() net.Addr
- func (*QuicConn) SetDeadline(time.Time) error
- func (*QuicConn) SetReadDeadline(time.Time) error
- func (*QuicConn) SetWriteDeadline(time.Time) error
- func (conn *QuicConn) Write(b []byte) (int, error)
- type QuicRequest
- type QuicTransport
- func (tp *QuicTransport) DialAddressTimeout(a ml.Address, timeout time.Duration) (net.Conn, error)
- func (tp *QuicTransport) DialTimeout(addr string, timeout time.Duration) (net.Conn, error)
- func (*QuicTransport) FinalAdvertiseAddr(ip string, port int) (net.IP, int, error)
- func (tp *QuicTransport) PacketCh() <-chan *ml.Packet
- func (*QuicTransport) Shutdown() error
- func (tp *QuicTransport) StreamCh() <-chan net.Conn
- func (tp *QuicTransport) WriteTo(b []byte, addr string) (time.Time, error)
- func (tp *QuicTransport) WriteToAddress(b []byte, a ml.Address) (time.Time, error)
Constants ¶
This section is empty.
Variables ¶
var ( DefaultDiscoveryPath = "/_join" DefaultMaxNodeConns uint = 2 )
var ( JoinDeclinedError = util.NewError("joining declined") JoiningCanceledError = util.NewError("joining canceled") )
Functions ¶
func SuffrageHandlerFilter ¶
Types ¶
type ConnInfo ¶
type ConnInfo struct { network.HTTPConnInfo Address string LastActivated time.Time }
func NewConnInfoWithConnInfo ¶
func NewConnInfoWithConnInfo(addr string, connInfo network.HTTPConnInfo) ConnInfo
func (ConnInfo) MarshalJSON ¶
func (*ConnInfo) UnmarshalJSON ¶
type ConnInfoMap ¶
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 (*Discovery) Handler ¶
func (dis *Discovery) Handler(callback func(NodeMessage) error) http.HandlerFunc
func (*Discovery) Initialize ¶
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 (*Discovery) SetMaxNodeConns ¶
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 ¶
type Events ¶
func (*Events) GetBroadcasts ¶
func (*Events) LocalState ¶
func (*Events) MergeRemoteState ¶
func (*Events) NotifyAlive ¶
NotifyAlive does not do anything to filter node; if error occurs, alive mesage will be ignored.
func (*Events) NotifyJoin ¶
func (*Events) NotifyLeave ¶
func (*Events) NotifyUpdate ¶
func (*Events) SetMergeRemoteState ¶
func (*Events) SetNotifyAlive ¶
func (*Events) SetNotifyJoin ¶
func (*Events) SetNotifyLeave ¶
func (*Events) SetNotifyMerge ¶
func (*Events) SetNotifyMsg ¶
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 (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
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 NewNodeMetaFromBytes ¶
func (NodeMeta) MarshalJSON ¶
func (NodeMeta) MarshalZerologObject ¶
func (*NodeMeta) UnmarshalJSON ¶
type QuicConn ¶
func (*QuicConn) RemoteAddr ¶
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 ¶
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 (*QuicTransport) DialTimeout ¶
func (*QuicTransport) FinalAdvertiseAddr ¶
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