forked from zhuhaow/TcpRoute2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (48 loc) · 1.33 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
// TcpRoute2 project main.go
package main
import (
"github.com/koding/multiconfig"
"time"
"flag"
"fmt"
)
const version = "0.1.2"
type ServerConfig struct {
Addr string `default:":5050"`
UpStreams []ServerConfigUpStream
}
type ServerConfigUpStream struct {
Name string`default:""`
ProxyUrl string`default:"direct://0.0.0.0:0000"`
DnsResolve bool `default:"false"`
Credit int `default:"0"`
Sleep int `default:"0"`
CorrectDelay int `default:"0"`
}
func main() {
printVer := flag.Bool("version", false, "print version")
config_path := flag.String("config", "config.toml", "配置文件路径")
flag.Parse()
if *printVer {
fmt.Println("TcpRoute2 version", version)
return
}
m := multiconfig.NewWithPath(*config_path)
serverConfig := new(ServerConfig)
m.MustLoad(serverConfig)
// 创建 tcpping 上层代理
upStream := NewTcppingUpStream()
for _, up := range serverConfig.UpStreams {
if up.Name == "" {
up.Name = up.ProxyUrl
}
if err := upStream.AddUpStream(up.Name, up.ProxyUrl, up.DnsResolve, up.Credit, time.Duration(up.Sleep) * time.Millisecond, time.Duration(up.CorrectDelay) * time.Millisecond); err != nil {
panic(err)
}
}
// 服务器监听
srv := NewServer(serverConfig.Addr, upStream)
// DNS 配置
// 各端口需要的安全级别
srv.ListAndServe()
}