-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmemList.go
37 lines (32 loc) · 845 Bytes
/
memList.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"time"
)
type MemListEntry struct {
Tag Tag
Addr string
Heartbeat int
Timestamp int64
Active bool
}
// delete node in membership list
func (m MemListEntry) deactiveNode() {
m.Active = false
}
// delete node from membership list
func (n *Node) delNode(id int) {
delete(n.mem_list, id)
}
// update local membership list by membership list in incoming message
func (n *Node) checkPeers(memlist map[int]MemListEntry) {
for id, entry := range memlist{
if _, isIn := n.mem_list[id]; !isIn {
entry.Timestamp = time.Now().UnixNano()
n.mem_list[id] = entry
} else if (n.mem_list[id].Heartbeat <= entry.Heartbeat) {
entry.Timestamp = time.Now().UnixNano()
n.mem_list[id] = entry
}
}
return
}