2020-05-07 12:26:55 +02:00
|
|
|
package cluster
|
|
|
|
|
|
|
|
import (
|
2020-05-09 16:34:12 +02:00
|
|
|
"github.com/costela/wesher/common"
|
2020-05-07 12:26:55 +02:00
|
|
|
"github.com/hashicorp/memberlist"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2020-05-09 16:34:12 +02:00
|
|
|
// DelegateNode implements the memberlist delegation interface
|
|
|
|
type delegateNode struct {
|
|
|
|
*common.Node
|
|
|
|
}
|
|
|
|
|
2020-05-10 16:38:28 +02:00
|
|
|
// NotifyConflict implements the memberlist.Delegate interface
|
2020-05-09 16:34:12 +02:00
|
|
|
func (n *delegateNode) NotifyConflict(node, other *memberlist.Node) {
|
2020-05-07 12:26:55 +02:00
|
|
|
logrus.Errorf("node name conflict detected: %s", other.Name)
|
|
|
|
}
|
|
|
|
|
2020-05-10 16:38:28 +02:00
|
|
|
// NodeMeta implements the memberlist.Delegate interface
|
2020-05-07 14:33:29 +02:00
|
|
|
// Metadata is provided by the local node settings, encoding is handled
|
|
|
|
// by the node implementation directly
|
2020-05-09 16:34:12 +02:00
|
|
|
func (n *delegateNode) NodeMeta(limit int) []byte {
|
|
|
|
encoded, err := n.Encode(limit)
|
2020-05-07 12:26:55 +02:00
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("failed to encode local node: %s", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return encoded
|
|
|
|
}
|
|
|
|
|
2020-05-10 16:38:28 +02:00
|
|
|
// NotifyMsg implements the memberlist.Delegate interface
|
2020-05-09 16:34:12 +02:00
|
|
|
func (n *delegateNode) NotifyMsg([]byte) {}
|
2020-05-07 14:33:29 +02:00
|
|
|
|
2020-05-10 16:38:28 +02:00
|
|
|
// GetBroadcasts implements the memberlist.Delegate interface
|
2020-05-09 16:34:12 +02:00
|
|
|
func (n *delegateNode) GetBroadcasts(overhead, limit int) [][]byte { return nil }
|
2020-05-07 14:33:29 +02:00
|
|
|
|
2020-05-10 16:38:28 +02:00
|
|
|
// LocalState implements the memberlist.Delegate interface
|
2020-05-09 16:34:12 +02:00
|
|
|
func (n *delegateNode) LocalState(join bool) []byte { return nil }
|
2020-05-07 14:33:29 +02:00
|
|
|
|
2020-05-10 16:38:28 +02:00
|
|
|
// MergeRemoteState implements the memberlist.Delegate interface
|
2020-05-09 16:34:12 +02:00
|
|
|
func (n *delegateNode) MergeRemoteState(buf []byte, join bool) {}
|