Browse Source

fixed a bug

pull/9/head
Jae Kwon 11 years ago
parent
commit
04eb07c26f
1 changed files with 5 additions and 4 deletions
  1. +5
    -4
      p2p/peer_set.go

+ 5
- 4
p2p/peer_set.go View File

@ -50,14 +50,15 @@ func (ps *PeerSet) Remove(peer *Peer) {
return return
} }
index := item.index index := item.index
// Copy the list but without the last element.
// (we must copy because we're mutating the list)
newList := make([]*Peer, len(ps.list)-1)
copy(newList, ps.list)
// If it's the last peer, that's an easy special case. // If it's the last peer, that's an easy special case.
if index == len(ps.list)-1 { if index == len(ps.list)-1 {
ps.list = ps.list[:len(ps.list)-1]
ps.list = newList
return return
} }
// Copy the list but without the last element.
newList := make([]*Peer, len(ps.list)-1)
copy(newList, ps.list)
// Move the last item from ps.list to "index" in list. // Move the last item from ps.list to "index" in list.
lastPeer := ps.list[len(ps.list)-1] lastPeer := ps.list[len(ps.list)-1]
lastPeerAddr := lastPeer.RemoteAddress().String() lastPeerAddr := lastPeer.RemoteAddress().String()


Loading…
Cancel
Save