mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-27 03:31:42 +00:00
SetDeadline for authEnc. Stop peer if Add fails
This commit is contained in:
6
peer.go
6
peer.go
@ -48,12 +48,18 @@ func newPeerFromExistingConn(conn net.Conn, outbound bool, reactorsByCh map[byte
|
|||||||
// Encrypt connection
|
// Encrypt connection
|
||||||
if config.GetBool(configKeyAuthEnc) {
|
if config.GetBool(configKeyAuthEnc) {
|
||||||
var err error
|
var err error
|
||||||
|
// Set deadline for handshake so we don't block forever on conn.ReadFull
|
||||||
|
timeout := time.Duration(config.GetInt(configKeyHandshakeTimeoutSeconds)) * time.Second
|
||||||
|
conn.SetDeadline(time.Now().Add(timeout))
|
||||||
conn, err = MakeSecretConnection(conn, privKey)
|
conn, err = MakeSecretConnection(conn, privKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// remove deadline
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Key and NodeInfo are set after Handshake
|
||||||
p := &Peer{
|
p := &Peer{
|
||||||
outbound: outbound,
|
outbound: outbound,
|
||||||
authEnc: config.GetBool(configKeyAuthEnc),
|
authEnc: config.GetBool(configKeyAuthEnc),
|
||||||
|
@ -226,6 +226,7 @@ func (sw *Switch) AddPeer(peer *Peer) error {
|
|||||||
// ignore if duplicate or if we already have too many for that IP range
|
// ignore if duplicate or if we already have too many for that IP range
|
||||||
if err := sw.peers.Add(peer); err != nil {
|
if err := sw.peers.Add(peer); err != nil {
|
||||||
log.Notice("Ignoring peer", "error", err, "peer", peer)
|
log.Notice("Ignoring peer", "error", err, "peer", peer)
|
||||||
|
peer.Stop()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,7 +545,7 @@ func makeSwitch(i int, network, version string, initSwitch func(int, *Switch) *S
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddPeerWithConnection is a helper function for testing.
|
// AddPeerWithConnection creates a newPeer from the connection, performs the handshake, and adds it to the switch.
|
||||||
func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool, reactorsByCh map[byte]Reactor, chDescs []*ChannelDescriptor, onPeerError func(*Peer, interface{}), config cfg.Config, privKey crypto.PrivKeyEd25519) error {
|
func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool, reactorsByCh map[byte]Reactor, chDescs []*ChannelDescriptor, onPeerError func(*Peer, interface{}), config cfg.Config, privKey crypto.PrivKeyEd25519) error {
|
||||||
peer, err := newPeerFromExistingConn(conn, outbound, reactorsByCh, chDescs, onPeerError, config, privKey)
|
peer, err := newPeerFromExistingConn(conn, outbound, reactorsByCh, chDescs, onPeerError, config, privKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -260,7 +260,7 @@ func TestSwitchStopsNonPersistentPeerOnError(t *testing.T) {
|
|||||||
assert.False(peer.IsRunning())
|
assert.False(peer.IsRunning())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSwitchReconnectsToPeerIfItIsPersistent(t *testing.T) {
|
func TestSwitchReconnectsToPersistentPeer(t *testing.T) {
|
||||||
assert, require := assert.New(t), require.New(t)
|
assert, require := assert.New(t), require.New(t)
|
||||||
|
|
||||||
sw := makeSwitch(1, "testing", "123.123.123", initSwitchFunc)
|
sw := makeSwitch(1, "testing", "123.123.123", initSwitchFunc)
|
||||||
|
Reference in New Issue
Block a user