added raft over tls

This commit is contained in:
ston1th 2020-11-15 00:30:35 +01:00
commit 585baea183
16 changed files with 563 additions and 300 deletions

View file

@ -2,42 +2,24 @@ package cluster
import (
"context"
"errors"
"github.com/hashicorp/raft"
"git.giftfish.de/ston1th/vipman/pkg/config"
"github.com/go-logr/logr"
)
// Cluster - The Cluster object manages the state of the cluster for a particular node
type Cluster struct {
kv *KV
r *raft.Raft
type Cluster interface {
Start(logr.Logger, *config.Config) error
Stepdown()
Stop()
}
stop chan struct{}
done chan struct{}
Callbacks Callbacks
type KV interface {
Get(k string) []byte
Set(k string, v []byte) error
Delete(k string) error
}
type Callbacks struct {
Leader func(context.Context, *KV)
Follower func(context.Context, *KV)
}
// InitCluster - Will attempt to initialise all of the required settings for the cluster
func InitCluster(callbacks Callbacks) (*Cluster, error) {
if callbacks.Leader == nil {
return nil, errors.New("Leader is nil")
}
if callbacks.Follower == nil {
return nil, errors.New("Follower is nil")
}
c := &Cluster{
kv: &KV{
m: make(map[string][]byte),
},
stop: make(chan struct{}, 1),
done: make(chan struct{}, 1),
Callbacks: callbacks,
}
return c, nil
Leader func(context.Context, KV)
Follower func(context.Context, KV)
}