Removed the config.Proxy variable and renamed config.ProxyServer to config.Proxy. Client now connects over the specified proxy if config.Proxy isn't an empty string.

This commit is contained in:
Brenton Morris 2015-09-20 19:37:26 +12:00
parent 866e8dac8a
commit f90b498ac4
1 changed files with 16 additions and 19 deletions

View File

@ -4,15 +4,16 @@ import (
"bufio" "bufio"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"github.com/fluffle/goirc/logging"
"github.com/fluffle/goirc/state"
"io" "io"
"net" "net"
"net/url"
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/fluffle/goirc/logging"
"github.com/fluffle/goirc/state"
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
"net/url"
) )
// Conn encapsulates a connection to a single IRC server. Create // Conn encapsulates a connection to a single IRC server. Create
@ -34,13 +35,13 @@ type Conn struct {
stRemovers []Remover stRemovers []Remover
// I/O stuff to server // I/O stuff to server
dialer *net.Dialer dialer *net.Dialer
proxyDialer proxy.Dialer proxyDialer proxy.Dialer
sock net.Conn sock net.Conn
io *bufio.ReadWriter io *bufio.ReadWriter
in chan *Line in chan *Line
out chan string out chan string
connected bool connected bool
// Control channel and WaitGroup for goroutines // Control channel and WaitGroup for goroutines
die chan struct{} die chan struct{}
@ -73,12 +74,10 @@ type Config struct {
SSL bool SSL bool
SSLConfig *tls.Config SSLConfig *tls.Config
// Are we connecting via proxy? Set this to true to connect via // To connect via proxy set the proxy url here.
// the proxy server provided.
// Changing these after connection will have no effect until the // Changing these after connection will have no effect until the
// client reconnects. // client reconnects.
Proxy bool Proxy string
ProxyServer string
// Local address to bind to when connecting to the server. // Local address to bind to when connecting to the server.
LocalAddr string LocalAddr string
@ -111,7 +110,6 @@ type Config struct {
// Split PRIVMSGs, NOTICEs and CTCPs longer than SplitLen characters // Split PRIVMSGs, NOTICEs and CTCPs longer than SplitLen characters
// over multiple lines. Default to 450 if not set. // over multiple lines. Default to 450 if not set.
SplitLen int SplitLen int
} }
// NewConfig creates a Config struct containing sensible defaults. // NewConfig creates a Config struct containing sensible defaults.
@ -289,9 +287,8 @@ func (conn *Conn) ConnectTo(host string, pass ...string) error {
// To enable explicit SSL on the connection to the IRC server, set Config.SSL // To enable explicit SSL on the connection to the IRC server, set Config.SSL
// to true before calling Connect(). The port will default to 6697 if SSL is // to true before calling Connect(). The port will default to 6697 if SSL is
// enabled, and 6667 otherwise. // enabled, and 6667 otherwise.
// To enable connecting via a proxy server, set Config.Proxy to true and // To enable connecting via a proxy server, set Config.Proxy to the proxy URL
// Config.ProxyServer to the proxy URL (example socks5://localhost:9000) before // (example socks5://localhost:9000) before calling Connect().
// before calling Connect().
// //
// Upon successful connection, Connected will return true and a REGISTER event // Upon successful connection, Connected will return true and a REGISTER event
// will be fired. This is mostly for internal use; it is suggested that a // will be fired. This is mostly for internal use; it is suggested that a
@ -317,8 +314,8 @@ func (conn *Conn) Connect() error {
} }
} }
if conn.cfg.Proxy { if conn.cfg.Proxy != "" {
proxyURL, err := url.Parse(conn.cfg.ProxyServer) proxyURL, err := url.Parse(conn.cfg.Proxy)
if err != nil { if err != nil {
return err return err
} }