mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00

* added a bit of logging * added update messages to mqtt (every second with a timestamp) * added isConnectionOpen to the interface and analysis this during execution * added connection loss handler and status check * put some global objects into an objects to avoid inter service testing issues * TestingLocker Mutex to RWMutex (increase performance) * termintationMutex became a sync.RWMutex * added logging to the mqtt mock client * made monitor Mutex a RWMutex * added Mutex protection to the numberOfElements varialbe * added another Waiting block to the machine attestation methods (CI tests) * had to adjust the test cases to the impact of that change. Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package monitor
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/planetmint/planetmint-go/config"
|
|
"github.com/syndtr/goleveldb/leveldb"
|
|
)
|
|
|
|
type MQTTMonitorClientI interface {
|
|
AddParticipant(address string, lastSeenTS int64) (err error)
|
|
SelectPoPParticipantsOutOfActiveActors() (challenger string, challengee string, err error)
|
|
Start() (err error)
|
|
}
|
|
|
|
var monitorMutex sync.RWMutex
|
|
var mqttMonitorInstance MQTTMonitorClientI
|
|
|
|
func SetMqttMonitorInstance(monitorInstance MQTTMonitorClientI) {
|
|
monitorMutex.Lock()
|
|
mqttMonitorInstance = monitorInstance
|
|
monitorMutex.Unlock()
|
|
}
|
|
|
|
func LazyMqttMonitorLoader(homeDir string) {
|
|
monitorMutex.RLock()
|
|
tmpInstance := mqttMonitorInstance
|
|
monitorMutex.RUnlock()
|
|
if tmpInstance != nil {
|
|
return
|
|
}
|
|
if homeDir == "" {
|
|
homeDir = "./"
|
|
}
|
|
aciveActorsDB, err := leveldb.OpenFile(homeDir+"activeActors.db", nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
SetMqttMonitorInstance(NewMqttMonitorService(aciveActorsDB, *config.GetConfig()))
|
|
err = mqttMonitorInstance.Start()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func SelectPoPParticipantsOutOfActiveActors() (challenger string, challengee string, err error) {
|
|
monitorMutex.RLock()
|
|
challenger, challengee, err = mqttMonitorInstance.SelectPoPParticipantsOutOfActiveActors()
|
|
monitorMutex.RUnlock()
|
|
return
|
|
}
|
|
|
|
func Start() (err error) {
|
|
err = mqttMonitorInstance.Start()
|
|
return
|
|
}
|
|
|
|
func AddParticipant(address string, lastSeenTS int64) (err error) {
|
|
monitorMutex.RLock()
|
|
err = mqttMonitorInstance.AddParticipant(address, lastSeenTS)
|
|
monitorMutex.RUnlock()
|
|
return
|
|
}
|