brontide+tor:add timeout value for network connections
This commit is contained in:
4 files changed
+68
-25
No files matched your search
+3
-2
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/tor"
|
||||
)
|
||||
|
||||
// Conn is an implementation of net.Conn which enforces an authenticated key
|
||||
@@ -34,12 +35,12 @@ var _ net.Conn = (*Conn)(nil)
|
||||
// public key. In the case of a handshake failure, the connection is closed and
|
||||
// a non-nil error is returned.
|
||||
func Dial(local keychain.SingleKeyECDH, netAddr *lnwire.NetAddress,
|
||||
dialer func(string, string) (net.Conn, error)) (*Conn, error) {
|
||||
timeout time.Duration, dialer tor.DialFunc) (*Conn, error) {
|
||||
|
||||
ipAddr := netAddr.Address.String()
|
||||
var conn net.Conn
|
||||
var err error
|
||||
conn, err = dialer("tcp", ipAddr)
|
||||
conn, err = dialer("tcp", ipAddr, timeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/tor"
|
||||
)
|
||||
|
||||
type maybeNetConn struct {
|
||||
@@ -66,7 +67,10 @@ func establishTestConnection() (net.Conn, net.Conn, func(), error) {
|
||||
// successful.
|
||||
remoteConnChan := make(chan maybeNetConn, 1)
|
||||
go func() {
|
||||
remoteConn, err := Dial(remoteKeyECDH, netAddr, net.Dial)
|
||||
remoteConn, err := Dial(
|
||||
remoteKeyECDH, netAddr,
|
||||
tor.DefaultConnTimeout, net.DialTimeout,
|
||||
)
|
||||
remoteConnChan <- maybeNetConn{remoteConn, err}
|
||||
}()
|
||||
|
||||
@@ -196,7 +200,10 @@ func TestConcurrentHandshakes(t *testing.T) {
|
||||
remoteKeyECDH := &keychain.PrivKeyECDH{PrivKey: remotePriv}
|
||||
|
||||
go func() {
|
||||
remoteConn, err := Dial(remoteKeyECDH, netAddr, net.Dial)
|
||||
remoteConn, err := Dial(
|
||||
remoteKeyECDH, netAddr,
|
||||
tor.DefaultConnTimeout, net.DialTimeout,
|
||||
)
|
||||
connChan <- maybeNetConn{remoteConn, err}
|
||||
}()
|
||||
|
||||
|
||||
Reference in new issue
Block a user