server

package
v0.0.0-...-b3bd0e4 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader, v interface{}) error

func Encode

func Encode(v interface{}) (*bytes.Buffer, error)

func EncodeTo

func EncodeTo(w io.Writer, v interface{}) error

func Mux

func Mux(r *Raft) http.Handler

Types

type AppendEntriesRequest

type AppendEntriesRequest struct {
	Term         state.Term      `json:"term"`
	LeaderID     [16]byte        `json:"leader_id"`
	PrevLogIndex int             `json:"prev_log_index"`
	PrevLogTerm  state.Term      `json:"prev_log_term"`
	Entries      []state.Command `json:"entries"`
	LeaderCommit int             `json:"leader_commit"`
}

type AppendEntriesResponse

type AppendEntriesResponse struct {
	Term    state.Term `json:"term"`
	Success bool       `json:"success"`
}

type Raft

type Raft struct {
	Volatile   state.Volatile
	Persistent state.Persistent
	Leader     state.Leader
}

func (*Raft) AppendEntries

func (r *Raft) AppendEntries(appendEntries AppendEntriesRequest, appendResponse *AppendEntriesResponse)

func (*Raft) HasVoted

func (r *Raft) HasVoted() bool

func (*Raft) HasVotedFor

func (r *Raft) HasVotedFor(candidateID []byte) bool

func (*Raft) VoteRequest

func (r *Raft) VoteRequest(requestVote RequestVoteRequest, voteResponse *RequestVoteResponse)

type RequestVoteRequest

type RequestVoteRequest struct {
	// CandidateID is candidate requesting vote.
	CandidateID []byte `json:"candidate_id"`
	// LastLogIndex is index of candidate’s last log entry.
	LastLogIndex int `json:"last_log_index"`
	// LastLogTerm is term of candidate’s last log entry.
	LastLogTerm state.Term `json:"last_log_term"`
	// Term is candidate’s term.
	Term state.Term `json:"term"`
}

type RequestVoteResponse

type RequestVoteResponse struct {
	// Term is currentTerm, for candidate to update itself.
	Term state.Term `json:"term"`
	// VoteGranted if true means candidate received vote.
	VoteGranted bool `json:"vote_granted"`
}

Jump to

Keyboard shortcuts

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