-
Notifications
You must be signed in to change notification settings - Fork 2
/
net.go
45 lines (32 loc) · 800 Bytes
/
net.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
package main
import (
"net"
"time"
"code.google.com/p/go.net/proxy"
)
type ConnHandler struct {
ProxyType string
ProxyAddress string
ProxyUsername string
ProxyPassword string
ProxyTimeout int
}
func (handler *ConnHandler) HandleConnection(network, addr string) (conn net.Conn, err error) {
forwardDialer := &net.Dialer{
Timeout: time.Duration(handler.ProxyTimeout) * time.Minute,
DualStack: true,
}
if len(handler.ProxyAddress) > 1 {
auth := &proxy.Auth{
User: handler.ProxyUsername,
Password: handler.ProxyPassword,
}
// setup the socks proxy
dialer, err := proxy.SOCKS5("tcp", handler.ProxyAddress, auth, forwardDialer)
if err != nil {
return nil, err
}
return dialer.Dial(network, addr)
}
return forwardDialer.Dial(network, addr)
}