torrent.go | 5 +++-- diff --git a/torrent.go b/torrent.go index 641f8fc078a1c44e5f0b9c4c2460acffa6334744..cb838ef4e1ae3c8c451b5a906f499e3363e6cc18 100644 --- a/torrent.go +++ b/torrent.go @@ -204,7 +204,7 @@ } return false } -func (t *Torrent) worstUnclosedConns() (ret []*connection) { +func (t *Torrent) unclosedConnsAsSlice() (ret []*connection) { ret = make([]*connection, 0, len(t.conns)) for c := range t.conns { if !c.closed.IsSet() { @@ -758,7 +758,8 @@ // for the longest. A bad connection is one that usually sends us unwanted // pieces, or has been in worser half of the established connections for more // than a minute. func (t *Torrent) worstBadConn() *connection { - wcs := worseConnSlice{t.worstUnclosedConns()} + wcs := worseConnSlice{t.unclosedConnsAsSlice()} + heap.Init(&wcs) for wcs.Len() != 0 { c := heap.Pop(&wcs).(*connection) if c.UnwantedChunksReceived >= 6 && c.UnwantedChunksReceived > c.UsefulChunksReceived {