-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (55 loc) · 1.28 KB
/
main.go
File metadata and controls
73 lines (55 loc) · 1.28 KB
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
73
package main
import (
"bufio"
"log"
"os"
"os/signal"
"strings"
"sync"
_ "github.com/mattn/go-sqlite3"
"github.com/tofa-project/client-daemon/appdata"
"github.com/tofa-project/client-daemon/db"
"github.com/tofa-project/client-daemon/glob"
oserv "github.com/tofa-project/client-daemon/onion-serv"
tserv "github.com/tofa-project/client-daemon/tor-serv"
ws_rpc "github.com/tofa-project/client-daemon/ws-rpc/http"
)
func main() {
wg := sync.WaitGroup{}
wg.Add(1)
// gracefully shutdown
go func() {
sc := make(chan os.Signal, 1)
signal.Notify(sc, os.Interrupt)
<-sc
log.Println("daemon quitting...")
db.Instance.Close()
tserv.Instance.Close()
wg.Done()
}()
glob.Init()
reader := bufio.NewReader(os.Stdin)
// read db key from stdin
log.Print("Input db key: ")
dbKey, err := reader.ReadString('\n')
if err != nil {
panic(err)
}
glob.V_DB_KEY = strings.Trim(dbKey, "\n")
// read ws key from stdin
log.Print("Input wsrpc key: ")
wsKey, err := reader.ReadString('\n')
if err != nil {
panic(err)
}
glob.V_WS_RPC_HEADER_SECRET = strings.Trim(wsKey, "\n")
appdata.Init()
db.Init()
// attempt to retrieve data from database
// this will crash the daemon if password is incorrect
db.GetApps()
ws_rpc.Init()
tserv.Init()
oserv.Init()
wg.Wait()
}