Documentation
¶
Index ¶
- func RandomTimeout(minVal time.Duration) <-chan time.Time
- type HTTP2Transport
- func (h *HTTP2Transport) Consumer() <-chan RPC
- func (h *HTTP2Transport) ListenAndServe() error
- func (h *HTTP2Transport) SendHeartbeat(ctx context.Context, peer string, msg *HeartBeatMsg, resp *HeartbeatResponse) error
- func (h *HTTP2Transport) SendVoteRequest(ctx context.Context, peer string, msg *VoteRequest, resp *VoteResponse) error
- func (h *HTTP2Transport) Shutdown(ctx context.Context) error
- type HeartBeatMsg
- type HeartbeatRequest
- type HeartbeatResponse
- type Node
- type RPC
- type RPCResponse
- type State
- type Transport
- type VoteRequest
- type VoteResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HTTP2Transport ¶
type HTTP2Transport struct {
// contains filtered or unexported fields
}
HTTP2Transport implements Transport with http2.
func NewHTTP2Transport ¶
func NewHTTP2Transport(addr string) *HTTP2Transport
NewHTTP2Transport returns a new HTTP2Transport instance.
func (*HTTP2Transport) Consumer ¶
func (h *HTTP2Transport) Consumer() <-chan RPC
func (*HTTP2Transport) ListenAndServe ¶
func (h *HTTP2Transport) ListenAndServe() error
func (*HTTP2Transport) SendHeartbeat ¶
func (h *HTTP2Transport) SendHeartbeat(ctx context.Context, peer string, msg *HeartBeatMsg, resp *HeartbeatResponse) error
func (*HTTP2Transport) SendVoteRequest ¶
func (h *HTTP2Transport) SendVoteRequest(ctx context.Context, peer string, msg *VoteRequest, resp *VoteResponse) error
type HeartBeatMsg ¶
type HeartBeatMsg struct {
Lead uint64 // Current leader announcing itself.
Term uint64 // Current term.
}
HeartBeatMsg is the message sent by the leader to the followers.
type HeartbeatRequest ¶
type HeartbeatResponse ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func NewNode ¶
func NewNode(id uint64, heartbeatTimeout time.Duration, peers map[uint64]string, transport Transport) *Node
NewNode returns new Node.
func (*Node) RemovePeer ¶
type RPC ¶
type RPC struct {
Command any
RespChan chan RPCResponse
}
type RPCResponse ¶
type Transport ¶
type Transport interface {
// SendVoteRequest sends a vote request message to the given peer.
SendVoteRequest(ctx context.Context, peer string, msg *VoteRequest, resp *VoteResponse) error
// SendHeartbeat sends a heartbeat message to the given peer.
SendHeartbeat(ctx context.Context, peer string, msg *HeartBeatMsg, resp *HeartbeatResponse) error
// Consumer returns a channel that can be used to
// consume and respond to RPC requests.
Consumer() <-chan RPC
}
Transport provides an interface for network transports to allow node to communicate with other nodes.
type VoteRequest ¶
type VoteRequest struct {
Candidate uint64 // Candidate requesting vote.
Term uint64 // Candidate's term.
}
VoteRequest is the message sent by the candidate to the followers.
Click to show internal directories.
Click to hide internal directories.