Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateKey(keyPath string, SecLv int) (heimdall.PriKey, heimdall.PubKey)
- func GenerateNewKey(keyPath string, SecLv int) (heimdall.PriKey, heimdall.PubKey)
- func GetNodeID(keyPath string) string
- func LoadKeyPair(keyPath string) (heimdall.PriKey, heimdall.PubKey)
- func NewPacketListener(ip net.IP, port int) (*net.UDPConn, error)
- func ParseHostPort(address string) (net.IP, uint16, error)
- type AliveMessage
- type Awareness
- type Config
- type DefaultMessageEndpoint
- type IndProbeResponse
- type Item
- type MbrStatsMsgStore
- type Member
- type MemberID
- type MemberMap
- func (m *MemberMap) Alive(aliveMessage AliveMessage) (bool, error)
- func (m *MemberMap) GetMembers() []Member
- func (memberMap *MemberMap) Merge(membership *pb.Message_Membership)
- func (m *MemberMap) Reset()
- func (m *MemberMap) SelectKRandomMemberID(k int) []Member
- func (m *MemberMap) Suspect(msg SuspectMessage) (bool, error)
- type MemberMessage
- type MessageEndpoint
- type MessageEndpointConfig
- type MessageHandler
- type Packet
- type PacketTransport
- type PacketTransportConfig
- type PriorityMbrStatsMsgStore
- type PriorityQueue
- type ProbeResponse
- type SWIM
- type Status
- type SuspectMessage
- type Suspicion
- type SuspicionConfig
- type Task
- type TaskResponse
- type TaskRunner
- type UDPTransport
Constants ¶
const ( AVAILABLE status = iota DIE )
const (
InitialPriority = 0
)
Variables ¶
var ErrCallbackCollectIntervalNotSpecified = errors.New("Error callback collect interval should be specified")
var ErrCreatingSuspicion = errors.New("error occurred while creating suspicion")
var ErrEmptyMemberID = errors.New("MemberID is empty")
var ErrIndProbeFailed = errors.New("error when indirect-probe failed")
var ErrInvalidMbrStatsMsgType = errors.New("error invalid mbrStatsMsg type")
var ErrInvalidMessage = errors.New("Error invalid message")
var ErrInvalidPayloadType = errors.New("invalid indirect-ping response payload type")
var ErrMemberUnknownState = errors.New("error member is in unknown state")
var ErrPingFailed = errors.New("error ping failed")
var ErrPopInvalidType = errors.New("pop invalid typed item")
var ErrSendTimeout = errors.New("Error send timeout")
var ErrStoreEmpty = errors.New("empty store")
var ErrUnreachable = errors.New("Error this shouldn't reach")
Functions ¶
func GenerateKey ¶
if the key already exists, create a new one, or load the existing key.
func GenerateNewKey ¶
Types ¶
type AliveMessage ¶
type AliveMessage struct {
MemberMessage
}
type Awareness ¶
Awareness manages health of the local node. This related to Lifeguard L1 "self-awareness" concept. Expect to receive replies to probe messages we sent Start timeouts low, increase in response to absence of replies
func NewAwareness ¶
func (*Awareness) ApplyDelta ¶
ApplyDelta with given delta applies it to the score in thread-safe manner score must be bound from 0 to max value
func (*Awareness) GetHealthScore ¶
type Config ¶
type Config struct { // The maximum number of times the same piggyback data can be queried MaxlocalCount int // The maximum number of node-self-awareness counter MaxNsaCounter int // T is the the period of the probe T int // Timeout of ack after ping to a member AckTimeOut int // K is the number of members to send indirect ping K int // my address and port BindAddress string BindPort int }
type DefaultMessageEndpoint ¶
type DefaultMessageEndpoint struct {
// contains filtered or unexported fields
}
MessageEndpoint basically do receiving packet and determine which logic executed based on the packet.
func (*DefaultMessageEndpoint) Listen ¶
func (m *DefaultMessageEndpoint) Listen()
Listen is a log running goroutine that pulls packet from the transport and pass it for processing
func (*DefaultMessageEndpoint) Send ¶
func (m *DefaultMessageEndpoint) Send(addr string, msg pb.Message) error
Send asynchronously send message to member of addr, don't wait until response come back, after response came back, callback function executed, Send can be used in the case of gossip message to other members
func (*DefaultMessageEndpoint) Shutdown ¶
func (m *DefaultMessageEndpoint) Shutdown()
func (*DefaultMessageEndpoint) SyncSend ¶
SyncSend synchronously send message to member of addr, waits until response come back, whether it is timeout or send failed, SyncSend can be used in the case of pinging to other members. if @timeout is provided then set send timeout to given parameters, if not then calculate timeout based on the its awareness
type IndProbeResponse ¶
type IndProbeResponse struct {
// contains filtered or unexported fields
}
func (IndProbeResponse) Ok ¶
func (r IndProbeResponse) Ok() bool
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
An Item is something we manage in a priority queue.
type MbrStatsMsgStore ¶
type MbrStatsMsgStore interface { Len() int Push(pbk pb.MbrStatsMsg) Get() (pb.MbrStatsMsg, error) IsEmpty() bool }
type Member ¶
type Member struct { // Id of member ID MemberID // Ip address Addr net.IP // Port Port uint16 // Current member status from my point of view Status Status // Time last status change happened LastStatusChange time.Time // Incarnation helps to keep the most fresh information about member status in the system // which tells that suspect member confirming that it is alive, and only when suspect // got suspicion message, that member can increments incarnation Incarnation uint32 // Suspicion manages the suspect timer and helps to accelerate the timeout // as member self got more independent confirmations that a target member is suspect. Suspicion *Suspicion }
Struct of Member
func (*Member) GetIDString ¶
type MemberMap ¶
type MemberMap struct {
// contains filtered or unexported fields
}
func NewMemberMap ¶
func NewMemberMap(config *SuspicionConfig) *MemberMap
func (*MemberMap) Alive ¶
func (m *MemberMap) Alive(aliveMessage AliveMessage) (bool, error)
Process Alive message
Return 2 parameter bool, error bool means Changed in MemberList ¶
1. If aliveMessage Id is empty return false and ErrEmptyMemberID 2. if aliveMessage Id is not in MemberList then Create Member and Add MemberList 3. if aliveMessage Id is in MemberList and existingMember's Incarnation is bigger than AliveMessage's Incarnation Than return false, ErrIncarnation 4. if aliveMessage Id is in MemberList and AliveMessage's Incarnation is bigger than existingMember's Incarnation Than Update Member and Return true, nil
func (*MemberMap) GetMembers ¶
func (*MemberMap) Merge ¶
func (memberMap *MemberMap) Merge(membership *pb.Message_Membership)
func (*MemberMap) SelectKRandomMemberID ¶
Select K random member (length of returning member can be lower than k).
type MemberMessage ¶
type MessageEndpoint ¶
type MessageEndpoint interface { Listen() SyncSend(addr string, msg pb.Message) (pb.Message, error) Send(addr string, msg pb.Message) error Shutdown() }
func NewMessageEndpoint ¶
func NewMessageEndpoint(config MessageEndpointConfig, transport UDPTransport, messageHandler MessageHandler) (MessageEndpoint, error)
type MessageEndpointConfig ¶
type MessageHandler ¶
type MessageHandler interface {
// contains filtered or unexported methods
}
handler interface to handle received message
type Packet ¶
type Packet struct { // Buffer is the contents of the packet. Buf []byte // From has the address of the peer. This is an actual net.Addr so we // can expose some concrete details about incoming packets. Addr net.Addr // Timestamp is the time when the packet was received. Timestamp time.Time }
Packet is used to provide some metadata about incoming packets from peers over a packet connection
type PacketTransport ¶
type PacketTransport struct {
// contains filtered or unexported fields
}
PacketTransport implements Transport interface, which is used ONLY for connectionless UDP packet operations
func NewPacketTransport ¶
func NewPacketTransport(config *PacketTransportConfig) (*PacketTransport, error)
func (*PacketTransport) PacketCh ¶
func (t *PacketTransport) PacketCh() <-chan *Packet
func (*PacketTransport) Shutdown ¶
func (t *PacketTransport) Shutdown() error
type PacketTransportConfig ¶
type PacketTransportConfig struct { // BindAddrs is representing an address to use for UDP communication BindAddress string // BindPort is the port to listen on, for the address specified above BindPort int }
PacketTransportConfig is used to configure a udp transport
type PriorityMbrStatsMsgStore ¶
type PriorityMbrStatsMsgStore struct {
// contains filtered or unexported fields
}
PiggyBackStore stores piggyback data in the priority queue and returns data with smallest local count.
func NewPriorityMbrStatsMsgStore ¶
func NewPriorityMbrStatsMsgStore(maxLocalCount int) *PriorityMbrStatsMsgStore
macLocalCount is the max priority value
func (*PriorityMbrStatsMsgStore) Get ¶
func (p *PriorityMbrStatsMsgStore) Get() (pb.MbrStatsMsg, error)
Return the mbrStatsMsg with the smallest local count in the list, increment the local count and sort it again, not delete the data.
func (*PriorityMbrStatsMsgStore) IsEmpty ¶
func (p *PriorityMbrStatsMsgStore) IsEmpty() bool
func (*PriorityMbrStatsMsgStore) Len ¶
func (p *PriorityMbrStatsMsgStore) Len() int
Return current size of data
func (*PriorityMbrStatsMsgStore) Push ¶
func (p *PriorityMbrStatsMsgStore) Push(msg pb.MbrStatsMsg)
Initially, set the local count to zero. If the queue size is max, delete the data with the highest localcount and insert it.
type PriorityQueue ¶
type PriorityQueue []*Item
A PriorityQueue implements heap.Interface and holds Items.
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
We want Pop to give us the lowest, not highest, priority so we use lower than here.
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(x interface{})
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
We want Pop to give us the lowest, not highest, priority so we use lower than here.
type ProbeResponse ¶
type ProbeResponse struct {
// contains filtered or unexported fields
}
func (ProbeResponse) Ok ¶
func (r ProbeResponse) Ok() bool
type SWIM ¶
type SWIM struct {
// contains filtered or unexported fields
}
func New ¶
func New(config *Config, suspicionConfig *SuspicionConfig, messageEndpointConfig MessageEndpointConfig, member *Member) *SWIM
type SuspectMessage ¶
type SuspectMessage struct { MemberMessage ConfirmerID string }
Suspect message struct
type Suspicion ¶
type Suspicion struct {
// contains filtered or unexported fields
}
Suspicion manages the suspect timer and helps to accelerate the timeout as member self got more independent confirmations that a target member is suspect.
func NewSuspicion ¶
func NewSuspicion(confirmer MemberID, k int, min time.Duration, max time.Duration, timeoutHandler func()) (*Suspicion, error)
NewSuspicion returns a timer started with the max value, and according to Lifeguard L2 (Dynamic Suspicion timeout) each unique confirmation will drive the timer to min value
type SuspicionConfig ¶
type SuspicionConfig struct {
// contains filtered or unexported fields
}
type TaskResponse ¶
type TaskResponse struct {
// contains filtered or unexported fields
}
type TaskRunner ¶
type TaskRunner struct {
// contains filtered or unexported fields
}
func NewTaskRunner ¶
func NewTaskRunner(task Task, ctx context.Context) *TaskRunner
func (*TaskRunner) Start ¶
func (t *TaskRunner) Start() TaskResponse
type UDPTransport ¶
type UDPTransport interface { // WriteTo is a packet-oriented interface that fires off the given // payload to the given address in a connectionless fashion. This should // return a time stamp that's as close as possible to when the packet // was transmitted to help make accurate RTT measurements during probes. // // We also treat the address here as a // string, similar to Dial, so it's network neutral, so this usually is // in the form of "host:port". WriteTo(b []byte, addr string) (time.Time, error) // PacketCh returns a channel that can be read to receive incoming // packets from other peers. PacketCh() <-chan *Packet // Shutdown all running go-routine inside UDPTransport Shutdown() error }
UDP Transport is used to udp abstract over communicating with other peers.