-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
44 lines (37 loc) · 823 Bytes
/
node.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
38
39
40
41
42
43
44
package discovery
import (
"fmt"
"github.com/iain17/logger"
"github.com/iain17/discovery/pb"
"sync"
)
type Node struct {
id string //Unique random string identifier
info map[string]string
logger *logger.Logger
infoMutex sync.Mutex
}
func (n *Node) String() string {
return fmt.Sprintf("bare node with info: %#v", n.info)
}
func (n *Node) SetInfo(key string, value string) {
n.infoMutex.Lock()
n.info[key] = value
n.infoMutex.Unlock()
}
func (n *Node) SetMapInfo(info map[string]string) {
n.infoMutex.Lock()
n.info = info
n.infoMutex.Unlock()
}
func (n *Node) GetInfo(key string) string {
n.infoMutex.Lock()
defer n.infoMutex.Unlock()
return n.info[key]
}
func (n *Node) Initialize(info *pb.DPeerInfo) {
n.infoMutex.Lock()
n.id = info.Id
n.info = info.Info
n.infoMutex.Unlock()
}