Browse Source

Call peer.stop() if we're not going to start() it

pull/110/head
Jae Kwon 9 years ago
parent
commit
5107988fb5
2 changed files with 5 additions and 0 deletions
  1. +1
    -0
      common/repeat_timer.go
  2. +4
    -0
      p2p/switch.go

+ 1
- 0
common/repeat_timer.go View File

@ -6,6 +6,7 @@ import "sync"
/*
RepeatTimer repeatedly sends a struct{}{} to .Ch after each "dur" period.
It's good for keeping connections alive.
A RepeatTimer must be Stop()'d or it will keep a goroutine alive.
*/
type RepeatTimer struct {
Ch chan time.Time


+ 4
- 0
p2p/switch.go View File

@ -156,13 +156,16 @@ func (sw *Switch) Stop() {
}
// NOTE: This performs a blocking handshake before the peer is added.
// CONTRACT: Iff error is returned, peer is nil, and conn is immediately closed.
func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool) (*Peer, error) {
// First, perform handshake
peerNodeInfo, err := peerHandshake(conn, sw.nodeInfo)
if err != nil {
conn.Close()
return nil, err
}
if err := sw.nodeInfo.CompatibleWith(peerNodeInfo); err != nil {
conn.Close()
return nil, err
}
@ -183,6 +186,7 @@ func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool) (*Peer, er
log.Info("Added peer", "peer", peer)
} else {
log.Info("Ignoring duplicate peer", "peer", peer)
peer.stop() // will also close conn
return nil, ErrSwitchDuplicatePeer
}


Loading…
Cancel
Save