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
@ -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
} }