Browse Source

Merge pull request #848 from tendermint/p2p-catch-conn.SetDeadline-errors

p2p: peer should respect errors from SetDeadline
pull/842/merge
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
49faa79bdc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions
  1. +9
    -3
      p2p/peer.go

+ 9
- 3
p2p/peer.go View File

@ -113,7 +113,9 @@ func newPeerFromConnAndConfig(rawConn net.Conn, outbound bool, reactorsByCh map[
// Encrypt connection
if config.AuthEnc {
conn.SetDeadline(time.Now().Add(config.HandshakeTimeout * time.Second))
if err := conn.SetDeadline(time.Now().Add(config.HandshakeTimeout * time.Second)); err != nil {
return nil, errors.Wrap(err, "Error setting deadline while encrypting connection")
}
var err error
conn, err = MakeSecretConnection(conn, ourNodePrivKey)
@ -165,7 +167,9 @@ func (p *peer) IsPersistent() bool {
// NOTE: blocking
func (p *peer) HandshakeTimeout(ourNodeInfo *NodeInfo, timeout time.Duration) error {
// Set deadline for handshake so we don't block forever on conn.ReadFull
p.conn.SetDeadline(time.Now().Add(timeout))
if err := p.conn.SetDeadline(time.Now().Add(timeout)); err != nil {
return errors.Wrap(err, "Error setting deadline")
}
var peerNodeInfo = new(NodeInfo)
var err1 error
@ -196,7 +200,9 @@ func (p *peer) HandshakeTimeout(ourNodeInfo *NodeInfo, timeout time.Duration) er
}
// Remove deadline
p.conn.SetDeadline(time.Time{})
if err := p.conn.SetDeadline(time.Time{}); err != nil {
return errors.Wrap(err, "Error removing deadline")
}
peerNodeInfo.RemoteAddr = p.Addr().String()


Loading…
Cancel
Save