brontide/conn: handle read timeout errors

This commit is contained in:
Conner Fromknecht 2019-02-15 18:13:52 -08:00
parent 04febab85c
commit 41940c6c9e
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -61,7 +61,11 @@ func Dial(localPriv *btcec.PrivateKey, netAddr *lnwire.NetAddress,
// We'll ensure that we get ActTwo from the remote peer in a timely // We'll ensure that we get ActTwo from the remote peer in a timely
// manner. If they don't respond within 1s, then we'll kill the // manner. If they don't respond within 1s, then we'll kill the
// connection. // connection.
conn.SetReadDeadline(time.Now().Add(handshakeReadTimeout)) err = conn.SetReadDeadline(time.Now().Add(handshakeReadTimeout))
if err != nil {
b.conn.Close()
return nil, err
}
// If the first act was successful (we know that address is actually // If the first act was successful (we know that address is actually
// remotePub), then read the second act after which we'll be able to // remotePub), then read the second act after which we'll be able to
@ -91,7 +95,11 @@ func Dial(localPriv *btcec.PrivateKey, netAddr *lnwire.NetAddress,
// We'll reset the deadline as it's no longer critical beyond the // We'll reset the deadline as it's no longer critical beyond the
// initial handshake. // initial handshake.
conn.SetReadDeadline(time.Time{}) err = conn.SetReadDeadline(time.Time{})
if err != nil {
b.conn.Close()
return nil, err
}
return b, nil return b, nil
} }