-
Notifications
You must be signed in to change notification settings - Fork 0
/
obfs4_impl.go
59 lines (49 loc) · 1.48 KB
/
obfs4_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
package chained
import (
"context"
"fmt"
"net"
pt "git.torproject.org/pluggable-transports/goptlib.git"
"gitlab.com/yawning/obfs4.git/transports/base"
"gitlab.com/yawning/obfs4.git/transports/obfs4"
"github.com/getlantern/common/config"
"github.com/getlantern/flashlight/v7/ops"
)
type obfs4Impl struct {
nopCloser
dialCore coreDialer
addr string
cf base.ClientFactory
args interface{}
}
func newOBFS4Impl(name, addr string, pc *config.ProxyConfig, dialCore coreDialer) (proxyImpl, error) {
if pc.Cert == "" {
return nil, fmt.Errorf("No Cert configured for obfs4 server, can't connect")
}
cf, err := (&obfs4.Transport{}).ClientFactory("")
if err != nil {
return nil, log.Errorf("Unable to create obfs4 client factory: %v", err)
}
ptArgs := &pt.Args{}
ptArgs.Add("cert", pc.Cert)
ptArgs.Add("iat-mode", ptSetting(pc, "iat-mode"))
args, err := cf.ParseArgs(ptArgs)
if err != nil {
return nil, log.Errorf("Unable to parse client args: %v", err)
}
return &obfs4Impl{
dialCore: dialCore,
addr: addr,
cf: cf,
args: args,
}, nil
}
func (impl *obfs4Impl) dialServer(op *ops.Op, ctx context.Context) (net.Conn, error) {
dial := func(network, address string) (net.Conn, error) {
// We know for sure the network and address are the same as what
// the inner DailServer uses.
return impl.dialCore(op, ctx, impl.addr)
}
// The proxy it wrapped already has timeout applied.
return impl.cf.Dial("whatever", "whatever", dial, impl.args)
}