forked from trey-jones/xmrwasp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
100 lines (84 loc) · 2.2 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"flag"
"fmt"
"log"
"os"
ews "github.com/eyesore/ws"
"github.com/trey-jones/xmrwasp/config"
"github.com/trey-jones/xmrwasp/logger"
"github.com/trey-jones/xmrwasp/tcp"
"github.com/trey-jones/xmrwasp/ws"
)
var (
version = "1.0.0"
// cmd line options
configFile *string
)
func printWelcomeMessage() {
logger.Get().Println("************************************************************************")
logger.Get().Printf("* XMR Web and Stratum Proxy \t\t\t\t v%s \n", version)
if !config.Get().DisableWebsocket {
port := config.Get().WebsocketPort
logger.Get().Printf("* Accepting Websocket Connections on port: \t\t %v\n", port)
}
if !config.Get().DisableTCP {
port := config.Get().StratumPort
logger.Get().Printf("* Accepting TCP Connections on port: \t\t\t\t %v\n", port)
}
statInterval := config.Get().StatInterval
logger.Get().Printf("* Printing stats every: \t\t\t\t %v seconds\n", statInterval)
logger.Get().Println("************************************************************************")
}
func usage() {
fmt.Printf("Usage: %s [-c CONFIG_PATH] \n", os.Args[0])
flag.PrintDefaults()
}
func setOptions() {
configFile = flag.String("c", "", "JSON file from which to read configuration values")
flag.Parse()
config.File = *configFile
}
func setupLogger() {
lc := &logger.Config{W: nil}
c := config.Get()
if c.Debug {
lc.Level = logger.Debug
}
if c.LogFile != "" {
f, err := os.Create(c.LogFile)
if err != nil {
log.Fatal("could not open log file for writing: ", err)
}
lc.W = f
}
if c.DiscardLog {
lc.Discard = true
}
logger.Configure(lc)
logger.Get().Debugln("logger is configured")
}
func main() {
setOptions()
setupLogger()
flag.Usage = usage
flag.Parse()
if args := flag.Args(); len(args) > 1 && (args[1] == "help" || args[1] == "-h") {
flag.Usage()
return
}
config.File = *configFile
ews.SetDebug(false)
holdOpen := make(chan bool, 1)
if config.Get().DisableWebsocket && config.Get().DisableTCP {
logger.Get().Fatal("No servers configured for listening. Bye!")
}
if !config.Get().DisableWebsocket {
go ws.StartServer()
}
if !config.Get().DisableTCP {
go tcp.StartServer()
}
printWelcomeMessage()
<-holdOpen
}