server

package
v0.0.0-...-028f6a4 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2017 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LEADER    = 0
	FOLLOWER  = 1
	CANDIDATE = 2
	OBSERVER  = 3
)
View Source
const (
	LOG_ENTRIES    = 0
	GROUP_PEERS    = 1
	GROUP_META     = 2
	NODES_LIST     = 3
	GROUP_LAST_IDX = 4
	CLIENT         = 5
	SERVER_CONF    = 100
)
View Source
const (
	NODE_LIST_GROUP   = 1
	CLIENT_LIST_GROUP = 2
	CONFIG_GROUP      = 0
)
View Source
const (
	UINT32_LEN = 4
	UINT64_LEN = 8
)
View Source
const MAX_TERM_BUMP = 10

Variables

This section is empty.

Functions

func AppendLogEntrySignData

func AppendLogEntrySignData(groupId uint64, term uint64, prevIndex uint64, prevTerm uint64) []byte

func ApproveAppendSignData

func ApproveAppendSignData(res *pb.ApproveAppendResponse) []byte

func BytesU64

func BytesU64(bs []byte, offset int) uint64

func CommandSignData

func CommandSignData(group uint64, sender uint64, reqId uint64, data []byte) []byte

func ComposeKeyPrefix

func ComposeKeyPrefix(group uint64, t uint32) []byte

func EB

func EB(b bool) byte

func ExpectedHonestPeers

func ExpectedHonestPeers(group_peers []*pb.Peer) int

func GenerateKey

func GenerateKey() ([]byte, []byte, error)

func GetConfig

func GetConfig(kv *badger.KV) (*pb.ServerConfig, error)

func GetGroupFromKV

func GetGroupFromKV(groupId uint64, KV *badger.KV) *pb.RaftGroup

func GetGroupPeersFromKV

func GetGroupPeersFromKV(group uint64, KV *badger.KV) map[uint64]*pb.Peer

func HashPublicKey

func HashPublicKey(key *rsa.PublicKey) uint64

func ItemValue

func ItemValue(item *badger.KVItem) *[]byte

func LogEntryKey

func LogEntryKey(groupId uint64, entryIndex uint64) []byte

func LogHash

func LogHash(prevHash []byte, index uint64, funcId uint64, args []byte) ([]byte, crypto.Hash)

func ParsePrivateKey

func ParsePrivateKey(data []byte) (*rsa.PrivateKey, error)

func ParsePublicKey

func ParsePublicKey(data []byte) (*rsa.PublicKey, error)

func PublicKeyFromPrivate

func PublicKeyFromPrivate(key *rsa.PrivateKey) *rsa.PublicKey

func RandomTimeout

func RandomTimeout(mult float32) int

func RefreshTimer

func RefreshTimer(meta *RTGroupMeta, mult float32)

func RequestVoteRequestSignData

func RequestVoteRequestSignData(req *pb.RequestVoteRequest) []byte

func RequestVoteResponseSignData

func RequestVoteResponseSignData(res *pb.RequestVoteResponse) []byte

func SHA1Hash

func SHA1Hash(data []byte) ([]byte, crypto.Hash)

func ScanHostedGroups

func ScanHostedGroups(kv *badger.KV, serverId uint64) map[uint64]*RTGroupMeta

func U32Bytes

func U32Bytes(t uint32) []byte

func U64Bytes

func U64Bytes(n uint64) []byte

func VerifySign

func VerifySign(publicKey *rsa.PublicKey, signature []byte, data []byte) error

Types

type BFTRaftServer

type BFTRaftServer struct {
	Id                  uint64
	Opts                Options
	DB                  *badger.KV
	FuncReg             map[uint64]map[uint64]func(arg []byte) []byte
	GroupsOnboard       map[uint64]*RTGroupMeta
	Peers               *cache.Cache
	Groups              *cache.Cache
	Nodes               *cache.Cache
	Clients             *cache.Cache
	GroupAppendedLogs   *cache.Cache
	GroupApprovedLogs   *cache.Cache
	GroupLeaderLiveness *cache.Cache
	NodePublicKeys      *cache.Cache
	ClientPublicKeys    *cache.Cache
	PrivateKey          *rsa.PrivateKey
	ClusterClients      ClusterClientStore
	ClientRPCs          ClientStore
	// contains filtered or unexported fields
}

func (*BFTRaftServer) AppendEntries

func (*BFTRaftServer) AppendEntryToLocal

func (s *BFTRaftServer) AppendEntryToLocal(group *pb.RaftGroup, entry *pb.LogEntry) error

func (*BFTRaftServer) ApproveAppend

func (*BFTRaftServer) BecomeCandidate

func (s *BFTRaftServer) BecomeCandidate(meta *RTGroupMeta)

func (*BFTRaftServer) BecomeFollower

func (s *BFTRaftServer) BecomeFollower(meta *RTGroupMeta, appendEntryReq *pb.AppendEntriesRequest) bool

func (*BFTRaftServer) BecomeLeader

func (s *BFTRaftServer) BecomeLeader(meta *RTGroupMeta)

func (*BFTRaftServer) CommitGroupLog

func (s *BFTRaftServer) CommitGroupLog(groupId uint64, cmd *pb.CommandRequest) *[]byte

func (*BFTRaftServer) ExecCommand

func (s *BFTRaftServer) ExecCommand(ctx context.Context, cmd *pb.CommandRequest) (*pb.CommandResponse, error)

func (*BFTRaftServer) GetClient

func (s *BFTRaftServer) GetClient(clientId uint64) *spb.Client

func (*BFTRaftServer) GetClientPublicKey

func (s *BFTRaftServer) GetClientPublicKey(clientId uint64) *rsa.PublicKey

func (*BFTRaftServer) GetGroup

func (s *BFTRaftServer) GetGroup(groupId uint64) *pb.RaftGroup

func (*BFTRaftServer) GetGroupLogLastIndex

func (s *BFTRaftServer) GetGroupLogLastIndex(groupId uint64) uint64

func (*BFTRaftServer) GetLogEntry

func (s *BFTRaftServer) GetLogEntry(groupId uint64, entryIndex uint64) *pb.LogEntry

func (*BFTRaftServer) GetNode

func (s *BFTRaftServer) GetNode(nodeId uint64) *pb.Node

func (*BFTRaftServer) GetNodePublicKey

func (s *BFTRaftServer) GetNodePublicKey(nodeId uint64) *rsa.PublicKey

func (*BFTRaftServer) GetPeer

func (s *BFTRaftServer) GetPeer(group uint64, peer_id uint64) *pb.Peer

func (*BFTRaftServer) GroupPeersSlice

func (s *BFTRaftServer) GroupPeersSlice(groupId uint64) []*pb.Peer

func (*BFTRaftServer) GroupServerPeer

func (s *BFTRaftServer) GroupServerPeer(groupId uint64) *pb.Peer

func (*BFTRaftServer) IncrGetGroupLogLastIndex

func (s *BFTRaftServer) IncrGetGroupLogLastIndex(groupId uint64) uint64

func (*BFTRaftServer) LastEntryHash

func (s *BFTRaftServer) LastEntryHash(group_id uint64) []byte

func (*BFTRaftServer) LastLogEntry

func (s *BFTRaftServer) LastLogEntry(group uint64) *pb.LogEntry

func (*BFTRaftServer) NodesIterator

func (s *BFTRaftServer) NodesIterator() NodeIterator

func (*BFTRaftServer) PeerApprovedAppend

func (s *BFTRaftServer) PeerApprovedAppend(groupId uint64, logIndex uint64, peer uint64, group_peers []*pb.Peer, isApproved bool)

func (*BFTRaftServer) PeerUncommittedLogEntries

func (s *BFTRaftServer) PeerUncommittedLogEntries(group *pb.RaftGroup, peer *pb.Peer) ([]*pb.LogEntry, *pb.LogEntry)

func (*BFTRaftServer) RegisterServerFunc

func (s *BFTRaftServer) RegisterServerFunc(group uint64, func_id uint64, fn func(arg []byte) []byte)

func (*BFTRaftServer) RequestVote

func (*BFTRaftServer) ReversedLogIterator

func (s *BFTRaftServer) ReversedLogIterator(group uint64) LogEntryIterator

func (*BFTRaftServer) SaveGroup

func (s *BFTRaftServer) SaveGroup(group *pb.RaftGroup)

func (*BFTRaftServer) SavePeer

func (s *BFTRaftServer) SavePeer(peer *pb.Peer)

func (*BFTRaftServer) SendFollowersHeartbeat

func (s *BFTRaftServer) SendFollowersHeartbeat(ctx context.Context, leader_peer_id uint64, group *pb.RaftGroup)

func (*BFTRaftServer) SendPeerUncommittedLogEntries

func (s *BFTRaftServer) SendPeerUncommittedLogEntries(ctx context.Context, group *pb.RaftGroup, peer *pb.Peer)

func (*BFTRaftServer) SetLogAppended

func (s *BFTRaftServer) SetLogAppended(groupId uint64, logIndex uint64, isApproved bool)

func (*BFTRaftServer) Sign

func (s *BFTRaftServer) Sign(data []byte) []byte

func (*BFTRaftServer) StartTimingWheel

func (s *BFTRaftServer) StartTimingWheel()

func (*BFTRaftServer) VerifyCommandSign

func (s *BFTRaftServer) VerifyCommandSign(cmd *spb.CommandRequest) bool

func (*BFTRaftServer) WaitLogApproved

func (s *BFTRaftServer) WaitLogApproved(groupId uint64, logIndex uint64) bool

type Client

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

type ClientStore

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

func NewClientStore

func NewClientStore() ClientStore

func (*ClientStore) Get

func (cs *ClientStore) Get(serverAddr string) (*Client, error)

type ClusterClient

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

type ClusterClientStore

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

func NewClusterClientStore

func NewClusterClientStore() ClusterClientStore

func (*ClusterClientStore) Get

func (cs *ClusterClientStore) Get(serverAddr string) (*ClusterClient, error)

type LogAppendError

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

func (*LogAppendError) Error

func (e *LogAppendError) Error() string

type LogEntryIterator

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

func (*LogEntryIterator) Close

func (liter *LogEntryIterator) Close()

func (*LogEntryIterator) Next

func (liter *LogEntryIterator) Next() *pb.LogEntry

type NodeIterator

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

func (*NodeIterator) Close

func (liter *NodeIterator) Close()

func (*NodeIterator) Next

func (liter *NodeIterator) Next() *pb.Node

type Options

type Options struct {
	MaxReplications  uint32
	DBPath           string
	Address          string
	PrivateKey       []byte
	ConsensusTimeout time.Duration
}

type RTGroupMeta

type RTGroupMeta struct {
	Peer       uint64
	Leader     uint64
	VotedPeer  uint64
	Lock       sync.RWMutex
	GroupPeers map[uint64]*pb.Peer
	Group      *pb.RaftGroup
	Timeout    time.Time
	Role       int
	Votes      []*pb.RequestVoteResponse
	IsNewTerm  bool
}

Jump to

Keyboard shortcuts

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