forked from bolt-observer/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
70 lines (60 loc) · 1.48 KB
/
settings.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package nodedata
import (
"sync"
"time"
entities "github.com/bolt-observer/agent/entities"
api "github.com/bolt-observer/agent/lightning"
)
// PerNodeSettings struct
type PerNodeSettings struct {
mutex sync.RWMutex
data map[string]Settings
}
// NewPerNodeSettings creates PerNodeSettings
func NewPerNodeSettings() *PerNodeSettings {
return &PerNodeSettings{
mutex: sync.RWMutex{},
data: make(map[string]Settings),
}
}
// GetKeys - get all keys
func (s *PerNodeSettings) GetKeys() []string {
s.mutex.RLock()
defer s.mutex.RUnlock()
keys := make([]string, 0, len(s.data))
for k := range s.data {
keys = append(keys, k)
}
return keys
}
// Get - get settings for one key
func (s *PerNodeSettings) Get(key string) Settings {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.data[key]
}
// Set - set settings for one key
func (s *PerNodeSettings) Set(key string, value Settings) {
s.mutex.Lock()
defer s.mutex.Unlock()
s.data[key] = value
}
// Delete - delete settings for one key
func (s *PerNodeSettings) Delete(key string) {
s.mutex.Lock()
defer s.mutex.Unlock()
delete(s.data, key)
}
// Settings struct
type Settings struct {
nodeDataCallback entities.NodeDataReportCallback
getAPI api.NewAPICall
hash uint64
identifier entities.NodeIdentifier
lastGraphCheck time.Time
lastReport time.Time
lastNodeReport time.Time
lastCheck time.Time
lastSyncedToChain time.Time
settings entities.ReportingSettings
}