forked from takyo101/lantern-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fronted.go
61 lines (50 loc) · 1.37 KB
/
fronted.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
package client
import (
"fmt"
"log"
"github.com/getlantern/balancer"
"github.com/getlantern/fronted"
)
type frontedServer struct {
Host string
Port int
MasqueradeSet string
InsecureSkipVerify bool
DialTimeoutMillis int
RedialAttempts int
QOS int
Weight int
}
// Wraps a fronted.Dialer with a balancer.Dialer.
func (s *frontedServer) dialer() *balancer.Dialer {
certPool, err := clientConfig.getTrustedCertPool()
if err != nil {
log.Fatalf("Could not get a pool of trusted CAs.")
}
fd := fronted.NewDialer(fronted.Config{
Host: s.Host,
Port: s.Port,
Masquerades: clientConfig.Client.MasqueradeSets[s.MasqueradeSet],
InsecureSkipVerify: s.InsecureSkipVerify,
BufferRequests: defaultBufferRequest,
DialTimeoutMillis: s.DialTimeoutMillis,
RedialAttempts: s.RedialAttempts,
RootCAs: certPool,
})
masqueradeQualifier := ""
if s.MasqueradeSet != "" {
masqueradeQualifier = fmt.Sprintf(" using masquerade set %s", s.MasqueradeSet)
}
return &balancer.Dialer{
Label: fmt.Sprintf("fronted proxy at %s:%d%s", s.Host, s.Port, masqueradeQualifier),
Weight: s.Weight,
QOS: s.QOS,
Dial: fd.Dial,
OnClose: func() {
err := fd.Close()
if err != nil {
log.Printf("Unable to close fronted dialer: %s", err)
}
},
}
}