-
Notifications
You must be signed in to change notification settings - Fork 0
/
quic_impl.go
73 lines (63 loc) · 1.79 KB
/
quic_impl.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
68
69
70
71
72
73
package chained
import (
"context"
gtls "crypto/tls"
"net"
"time"
"github.com/getlantern/common/config"
"github.com/getlantern/errors"
"github.com/getlantern/flashlight/v7/ops"
"github.com/getlantern/keyman"
"github.com/getlantern/quicwrapper"
)
type quicImpl struct {
reportDialCore reportDialCoreFn
addr string
dialer *quicwrapper.Client
}
func newQUICImpl(name, addr string, pc *config.ProxyConfig, reportDialCore reportDialCoreFn) (proxyImpl, error) {
tlsConf := >ls.Config{
ServerName: pc.TLSServerNameIndicator,
InsecureSkipVerify: true,
KeyLogWriter: getTLSKeyLogWriter(),
}
disablePathMTUDiscovery := true
if ptSettingBool(pc, "path_mtu_discovery") == true {
disablePathMTUDiscovery = false
}
quicConf := &quicwrapper.Config{
MaxIncomingStreams: -1,
MaxIdleTimeout: IdleTimeout,
KeepAlivePeriod: 15 * time.Second,
DisablePathMTUDiscovery: disablePathMTUDiscovery,
}
cert, err := keyman.LoadCertificateFromPEMBytes([]byte(pc.Cert))
if err != nil {
return nil, log.Error(errors.Wrap(err).With("addr", addr))
}
pinnedCert := cert.X509()
dialFn := quicwrapper.DialWithNetx
dialer := quicwrapper.NewClientWithPinnedCert(
addr,
tlsConf,
quicConf,
dialFn,
pinnedCert,
)
return &quicImpl{reportDialCore, addr, dialer}, nil
}
func (impl *quicImpl) close() {
log.Debug("Closing quic session: Proxy closed.")
impl.dialer.Close()
}
func (impl *quicImpl) dialServer(op *ops.Op, ctx context.Context) (net.Conn, error) {
return impl.reportDialCore(op, func() (net.Conn, error) {
conn, err := impl.dialer.DialContext(ctx)
if err != nil {
log.Debugf("Failed to establish multiplexed connection: %s", err)
} else {
log.Debug("established new multiplexed quic connection.")
}
return conn, err
})
}