-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
60 lines (57 loc) · 1.25 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
package main
import (
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
"github.com/wwqgtxx/wstunnel/client"
"github.com/wwqgtxx/wstunnel/client/mtproxy/tools"
"github.com/wwqgtxx/wstunnel/config"
"github.com/wwqgtxx/wstunnel/server"
"github.com/wwqgtxx/wstunnel/udp"
)
func main() {
if len(os.Args) > 2 && os.Args[1] == "generate-secret" {
tools.Generate(os.Args[2])
return
}
log.SetFlags(log.Lshortfile | log.LstdFlags)
configFile := "config.yaml"
if len(os.Args) == 2 {
configFile = os.Args[1]
}
if !filepath.IsAbs(configFile) {
currentDir, _ := os.Getwd()
configFile = filepath.Join(currentDir, configFile)
}
buf, err := config.ReadConfig(configFile)
if err != nil {
panic(err)
}
cfg, err := config.ParseConfig(buf)
if err != nil {
panic(err)
}
for _, clientConfig := range cfg.ClientConfigs {
client.BuildClient(clientConfig)
}
for _, serverConfig := range cfg.ServerConfigs {
server.BuildServer(serverConfig)
}
for _, udpConfig := range cfg.UdpConfigs {
udp.BuildUdp(udpConfig)
}
if !cfg.DisableClient {
client.StartClients()
}
if !cfg.DisableServer {
server.StartServers()
}
if !cfg.DisableUdp {
udp.StartUdps()
}
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh
}