Skip to content

Commit

Permalink
fix: Allow TLS to work over socks proxy. (#1666)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJCross committed May 5, 2020
1 parent f7b64cf commit c6eb1d4
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 300 deletions.
21 changes: 8 additions & 13 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,20 @@ func (b *Broker) Open(conf *Config) error {
go withRecover(func() {
defer b.lock.Unlock()

dialer := net.Dialer{
Timeout: conf.Net.DialTimeout,
KeepAlive: conf.Net.KeepAlive,
LocalAddr: conf.Net.LocalAddr,
}

if conf.Net.TLS.Enable {
b.conn, b.connErr = tls.DialWithDialer(&dialer, "tcp", b.addr, conf.Net.TLS.Config)
} else if conf.Net.Proxy.Enable {
b.conn, b.connErr = conf.Net.Proxy.Dialer.Dial("tcp", b.addr)
} else {
b.conn, b.connErr = dialer.Dial("tcp", b.addr)
}
dialer := conf.getDialer()
b.conn, b.connErr = dialer.Dial("tcp", b.addr)
if b.connErr != nil {
Logger.Printf("Failed to connect to broker %s: %s\n", b.addr, b.connErr)
b.conn = nil
atomic.StoreInt32(&b.opened, 0)
return
}

if conf.Net.TLS.Enable {
Logger.Printf("Using tls")
b.conn = tls.Client(b.conn, conf.Net.TLS.Config)
}

b.conn = newBufConn(b.conn)

b.conf = conf
Expand Down

0 comments on commit c6eb1d4

Please sign in to comment.