Browse Source

Merge pull request #22 from tendermint/persistent

fix closing conn
pull/456/head
Ethan Buchman 8 years ago
committed by GitHub
parent
commit
c39e001a95
2 changed files with 10 additions and 6 deletions
  1. +6
    -1
      peer.go
  2. +4
    -5
      switch.go

+ 6
- 1
peer.go View File

@ -41,7 +41,12 @@ func newPeer(addr *NetAddress, reactorsByCh map[byte]Reactor, chDescs []*Channel
}
// outbound = true
return newPeerFromExistingConn(conn, true, reactorsByCh, chDescs, onPeerError, config, privKey)
peer, err := newPeerFromExistingConn(conn, true, reactorsByCh, chDescs, onPeerError, config, privKey)
if err != nil {
conn.Close()
return nil, err
}
return peer, nil
}
func newPeerFromExistingConn(conn net.Conn, outbound bool, reactorsByCh map[byte]Reactor, chDescs []*ChannelDescriptor, onPeerError func(*Peer, interface{}), config cfg.Config, privKey crypto.PrivKeyEd25519) (*Peer, error) {


+ 4
- 5
switch.go View File

@ -318,14 +318,13 @@ func (sw *Switch) DialPeerWithAddress(addr *NetAddress, persistent bool) (*Peer,
defer sw.dialing.Delete(addr.IP.String())
peer, err := newPeer(addr, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError, sw.config, sw.nodePrivKey)
if persistent {
peer.makePersistent()
}
if err != nil {
log.Info("Failed dialing peer", "address", addr, "error", err)
peer.CloseConn()
return nil, err
}
if persistent {
peer.makePersistent()
}
err = sw.AddPeer(peer)
if err != nil {
log.Info("Failed adding peer", "address", addr, "error", err)
@ -549,7 +548,7 @@ func makeSwitch(i int, network, version string, initSwitch func(int, *Switch) *S
func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool) error {
peer, err := newPeerFromExistingConn(conn, outbound, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError, sw.config, sw.nodePrivKey)
if err != nil {
peer.CloseConn()
conn.Close()
return err
}


Loading…
Cancel
Save