mirror of https://github.com/BTCPrivate/lnd.git
brontide: modify the Dial function to take a *lnwire.NetAddress
This commit is contained in:
parent
99ed3b8616
commit
9850e8667e
|
@ -6,6 +6,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,17 +31,16 @@ var _ net.Conn = (*Conn)(nil)
|
||||||
// remote peer located at address which has remotePub as its long-term static
|
// remote peer located at address which has remotePub as its long-term static
|
||||||
// public key. In the case of a handshake failure, the connection is closed and
|
// public key. In the case of a handshake failure, the connection is closed and
|
||||||
// a non-nil error is returned.
|
// a non-nil error is returned.
|
||||||
func Dial(localPriv *btcec.PrivateKey, remotePub *btcec.PublicKey,
|
func Dial(localPriv *btcec.PrivateKey, netAddr *lnwire.NetAddress) (*Conn, error) {
|
||||||
address string) (*Conn, error) {
|
ipAddr := netAddr.Address.String()
|
||||||
|
conn, err := net.Dial("tcp", ipAddr)
|
||||||
conn, err := net.Dial("tcp", address)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b := &Conn{
|
b := &Conn{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
noise: NewBrontideMachine(true, localPriv, remotePub),
|
noise: NewBrontideMachine(true, localPriv, netAddr.IdentityKey),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initiate the handshake by sending the first act to the receiver.
|
// Initiate the handshake by sending the first act to the receiver.
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,14 +32,17 @@ func TestConnectionCorrectness(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
|
|
||||||
listenAddr := listener.Addr().String()
|
netAddr := &lnwire.NetAddress{
|
||||||
|
IdentityKey: localPriv.PubKey(),
|
||||||
|
Address: listener.Addr().(*net.TCPAddr),
|
||||||
|
}
|
||||||
|
|
||||||
// Initiate a connection with a separate goroutine, and listen with our
|
// Initiate a connection with a separate goroutine, and listen with our
|
||||||
// main one. If both errors are nil, then encryption+auth was succesful.
|
// main one. If both errors are nil, then encryption+auth was succesful.
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
connChan := make(chan net.Conn)
|
connChan := make(chan net.Conn)
|
||||||
go func() {
|
go func() {
|
||||||
conn, err := Dial(remotePriv, localPriv.PubKey(), listenAddr)
|
conn, err := Dial(remotePriv, netAddr)
|
||||||
errChan <- err
|
errChan <- err
|
||||||
connChan <- conn
|
connChan <- conn
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue