Skip to content

Commit

Permalink
connmgr: Use same Dial func signature as net.Dial
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick authored and davecgh committed Mar 5, 2018
1 parent 03f7799 commit eb9f01f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,11 +1126,11 @@ func loadConfig() (*config, []string, error) {
// example, .onion addresses will be dialed using the onion specific proxy if
// one was specified, but will otherwise use the normal dial function (which
// could itself use a proxy or not).
func dcrdDial(addr net.Addr) (net.Conn, error) {
if strings.Contains(addr.String(), ".onion:") {
return cfg.oniondial(addr.Network(), addr.String())
func dcrdDial(network, addr string) (net.Conn, error) {
if strings.Contains(addr, ".onion:") {
return cfg.oniondial(network, addr)
}
return cfg.dial(addr.Network(), addr.String())
return cfg.dial(network, addr)
}

// dcrdLookup returns the correct DNS lookup function to use depending on the
Expand Down
6 changes: 3 additions & 3 deletions connmgr/connmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
const maxFailedAttempts = 25

var (
//ErrDialNil is used to indicate that Dial cannot be nil in the configuration.
// ErrDialNil is used to indicate that Dial cannot be nil in the configuration.
ErrDialNil = errors.New("config: dial cannot be nil")

// maxRetryDuration is the max duration of time retrying of a persistent
Expand Down Expand Up @@ -134,7 +134,7 @@ type Config struct {
GetNewAddress func() (net.Addr, error)

// Dial connects to the address on the named network. It cannot be nil.
Dial func(net.Addr) (net.Conn, error)
Dial func(network, addr string) (net.Conn, error)
}

// handleConnected is used to queue a successful connection.
Expand Down Expand Up @@ -300,7 +300,7 @@ func (cm *ConnManager) Connect(c *ConnReq) {
atomic.StoreUint64(&c.id, atomic.AddUint64(&cm.connReqCount, 1))
}
log.Debugf("Attempting to connect to %v", c)
conn, err := cm.cfg.Dial(c.Addr)
conn, err := cm.cfg.Dial(c.Addr.Network(), c.Addr.String())
if err != nil {
cm.requests <- handleFailed{c, err}
} else {
Expand Down
12 changes: 6 additions & 6 deletions connmgr/connmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func (c mockConn) SetWriteDeadline(t time.Time) error { return nil }

// mockDialer mocks the net.Dial interface by returning a mock connection to
// the given address.
func mockDialer(addr net.Addr) (net.Conn, error) {
func mockDialer(network, addr string) (net.Conn, error) {
r, w := io.Pipe()
c := &mockConn{rAddr: addr}
c := &mockConn{rAddr: &mockAddr{network, addr}}
c.Reader = r
c.Writer = w
return c, nil
Expand Down Expand Up @@ -307,10 +307,10 @@ func TestMaxRetryDuration(t *testing.T) {
time.AfterFunc(5*time.Millisecond, func() {
close(networkUp)
})
timedDialer := func(addr net.Addr) (net.Conn, error) {
timedDialer := func(network, addr string) (net.Conn, error) {
select {
case <-networkUp:
return mockDialer(addr)
return mockDialer(network, addr)
default:
return nil, errors.New("network down")
}
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestMaxRetryDuration(t *testing.T) {
// failure gracefully.
func TestNetworkFailure(t *testing.T) {
var dials uint32
errDialer := func(net net.Addr) (net.Conn, error) {
errDialer := func(network, addr string) (net.Conn, error) {
atomic.AddUint32(&dials, 1)
return nil, errors.New("network down")
}
Expand Down Expand Up @@ -391,7 +391,7 @@ func TestNetworkFailure(t *testing.T) {
// the failure.
func TestStopFailed(t *testing.T) {
done := make(chan struct{}, 1)
waitDialer := func(addr net.Addr) (net.Conn, error) {
waitDialer := func(network, addr string) (net.Conn, error) {
done <- struct{}{}
time.Sleep(time.Millisecond)
return nil, errors.New("network down")
Expand Down

0 comments on commit eb9f01f

Please sign in to comment.