Merge pull request #211 from fjl/fix-server-disc

p2p: fix call to Server.removePeer
This commit is contained in:
Jeffrey Wilcke 2014-12-15 22:50:05 +01:00
commit bb17591959
1 changed files with 2 additions and 7 deletions

View File

@ -246,12 +246,7 @@ func (srv *Server) Stop() {
func (srv *Server) discLoop() { func (srv *Server) discLoop() {
for peer := range srv.peerDisconnect { for peer := range srv.peerDisconnect {
// peer has just disconnected. free up its slot. srv.removePeer(peer)
srvlog.Infof("%v is gone", peer)
srv.peerSlots <- peer.slot
srv.lock.Lock()
srv.peers[peer.slot] = nil
srv.lock.Unlock()
} }
} }
@ -384,7 +379,7 @@ func (srv *Server) addPeer(conn net.Conn, desc *peerAddr, slot int) *Peer {
func (srv *Server) removePeer(peer *Peer) { func (srv *Server) removePeer(peer *Peer) {
srv.lock.Lock() srv.lock.Lock()
defer srv.lock.Unlock() defer srv.lock.Unlock()
srvlog.Debugf("Removing peer %v %v (slot %v)\n", peer, peer.slot) srvlog.Debugf("Removing %v (slot %v)\n", peer, peer.slot)
if srv.peers[peer.slot] != peer { if srv.peers[peer.slot] != peer {
srvlog.Warnln("Invalid peer to remove:", peer) srvlog.Warnln("Invalid peer to remove:", peer)
return return