-
Notifications
You must be signed in to change notification settings - Fork 0
/
densor.go
72 lines (60 loc) · 1.8 KB
/
densor.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
71
72
package main
import (
"crypto/x509"
"fmt"
"log"
"os"
"time"
)
var logger *log.Logger
var local LocalInstance
func main() {
// Read local and start logging
homeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
defaultDataDir := homeDir + "/.densor/"
if err := os.Mkdir(defaultDataDir, 0755); err != nil && !os.IsExist(err) {
panic(fmt.Errorf("Could not create default data directory: %s", err))
}
logfile, err := os.OpenFile(defaultDataDir+"/densor.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
panic(err)
}
defer logfile.Close()
logger = log.New(logfile, "", log.LstdFlags)
logger.Println("Starting densor...")
readConfig()
loadTLSCerts()
localCert, err := x509.ParseCertificate(local.keyPair.Certificate[0])
if err != nil {
logger.Fatal("Error parsing local certificate. Exiting.")
}
logger.Println("---------------------------------------------------------------------------------------------")
logger.Println("Number of remote instances: ", len(local.RemoteInstances))
logger.Println("Number of local sensors: ", len(local.SensorsUUIDs))
logger.Println("Data Directory: ", local.DataDir)
logger.Println("Instance UUID: ", local.UUID)
logger.Println("Instance DisplayName: ", local.DisplayName)
logger.Println("Instance TLS Certificate: ", SHA256FromTLSCert(localCert))
logger.Println("---------------------------------------------------------------------------------------------")
go StartWebInterface()
go startSyncServer()
go connectToRemoteInstances()
go startSensors()
go debug()
// if --dashboard show dashboard
for {
//showDashboard()
time.Sleep(1 * time.Second)
}
// else block!
// select {}
}
func debug() {
for {
// logger.Println(local.RemoteInstances, "\n\n\n")
time.Sleep(2 * time.Second)
}
}