-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdial.go
50 lines (41 loc) · 1.33 KB
/
dial.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
package ptc
import "golang.org/x/net/proxy"
// PTDialMethodConfig creates proxy dails for using PT client/severs
type PTDialMethodConfig struct {
Args Args `json:"args"`
ClientAddr string
ServerAddr string
}
func (p *PTDialMethodConfig) auth() *proxy.Auth {
optsstr := encodeClientArgs(p.Args)
var username, password string
username = optsstr[0:1]
password = optsstr[1:]
auth := &proxy.Auth{
User: username,
Password: password,
}
return auth
}
// ClientDailer returns an socks5 proxy dialer for the pluggable transport client connection
func (p PTDialMethodConfig) ClientDialer() (proxy.Dialer, error) {
// tcp is hardcoded for the time being.
network := "tcp4"
auth := p.auth()
clidial, err := proxy.SOCKS5(network, p.ClientAddr, auth, proxy.Direct)
if err != nil {
return nil, err
}
return clidial, err
}
// ClientDailer returns an socks5 proxy dialer relevant if the other end of the pluggable transport server is also an socks5 proxy, in that case this proxy dialer can be used to access the internet.
func (p PTDialMethodConfig) ServerSocksDialer() (proxy.Dialer, error) {
// tcp is hardcoded for the time being.
network := "tcp4"
clientDialer, err := p.ClientDialer()
if err != nil {
return nil, err
}
socksDailer, err := proxy.SOCKS5(network, p.ServerAddr, nil, clientDialer)
return socksDailer, err
}