forked from quickfixgo/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdialer.go
56 lines (48 loc) · 1.3 KB
/
dialer.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
package quickfix
import (
"fmt"
"net"
"github.com/quickfixgo/quickfix/config"
"golang.org/x/net/proxy"
)
func loadDialerConfig(settings *SessionSettings) (dialer proxy.Dialer, err error) {
stdDialer := &net.Dialer{}
if settings.HasSetting(config.SocketTimeout) {
if stdDialer.Timeout, err = settings.DurationSetting(config.SocketTimeout); err != nil {
return
}
}
dialer = stdDialer
if !settings.HasSetting(config.ProxyType) {
return
}
var proxyType string
if proxyType, err = settings.Setting(config.ProxyType); err != nil {
return
}
switch proxyType {
case "socks":
var proxyHost string
var proxyPort int
if proxyHost, err = settings.Setting(config.ProxyHost); err != nil {
return
} else if proxyPort, err = settings.IntSetting(config.ProxyPort); err != nil {
return
}
proxyAuth := new(proxy.Auth)
if settings.HasSetting(config.ProxyUser) {
if proxyAuth.User, err = settings.Setting(config.ProxyUser); err != nil {
return
}
}
if settings.HasSetting(config.ProxyPassword) {
if proxyAuth.Password, err = settings.Setting(config.ProxyPassword); err != nil {
return
}
}
dialer, err = proxy.SOCKS5("tcp", fmt.Sprintf("%s:%d", proxyHost, proxyPort), proxyAuth, dialer)
default:
err = fmt.Errorf("unsupported proxy type %s", proxyType)
}
return
}