forked from p4gefau1t/trojan-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
43 lines (38 loc) · 876 Bytes
/
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
package main
import (
"flag"
"io/ioutil"
"os"
"os/signal"
"github.com/p4gefau1t/trojan-go/conf"
"github.com/p4gefau1t/trojan-go/log"
"github.com/p4gefau1t/trojan-go/proxy"
)
var logger = log.New(os.Stdout)
func main() {
logger.Info("Trojan-Go initializing...")
configFile := flag.String("config", "config.json", "Config file name")
flag.Parse()
data, err := ioutil.ReadFile(*configFile)
if err != nil {
logger.Fatal("Failed to read config file", err)
}
config, err := conf.ParseJSON(data)
if err != nil {
logger.Fatal("Failed to parse config file", err)
}
proxy := proxy.NewProxy(config)
errChan := make(chan error)
go func() {
errChan <- proxy.Run()
}()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt)
select {
case <-sigs:
proxy.Close()
case err := <-errChan:
logger.Fatal(err)
}
logger.Info("Trojan-Go exited")
}