-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.go
65 lines (53 loc) · 1.23 KB
/
config.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
package main
import (
"log"
"net/url"
"strings"
utls "github.com/refraction-networking/utls"
)
type CLIFlags struct {
addr string
port string
cert string
key string
upstreamProxy string
client string
verbose bool
}
var (
Flags CLIFlags
DefaultClientHelloID utls.ClientHelloID
DefaultUpstreamProxy *url.URL
)
func getClientHelloID(client string) (utls.ClientHelloID, bool) {
clientArr := strings.Split(client, "-")
if len(clientArr) != 2 {
return utls.ClientHelloID{}, false
}
return utls.ClientHelloID{
Client: clientArr[0],
Version: clientArr[1],
Seed: nil,
Weights: nil,
}, true
}
func setDefaultClientHelloID(client string) {
clientHelloId, ok := getClientHelloID(client)
if !ok {
log.Fatalf("Invalid client format: %s", client)
}
DefaultClientHelloID = clientHelloId
}
func setDefaultUpstreamProxy(upstreamProxy string) {
proxyUrl, err := url.Parse(upstreamProxy)
if err != nil {
log.Fatalf("Invalid upstream proxy: %s", upstreamProxy)
}
DefaultUpstreamProxy = proxyUrl
}
func loadDefaultProxyConfig() {
setDefaultClientHelloID(Flags.client)
if len(Flags.upstreamProxy) > 0 {
setDefaultUpstreamProxy(Flags.upstreamProxy)
}
}