From 1f6a7eb8108abbbcd615e059a7faeb95b5bb001d Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 21 Sep 2017 19:32:03 +1000 Subject: [PATCH] It looks like Torrent.worstBadConn was returning an arbitrary bad connection, it wasn't the worst heap.Init got lost somewhere along the way? Need a unit test for this. --- torrent.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/torrent.go b/torrent.go index 641f8fc0..cb838ef4 100644 --- a/torrent.go +++ b/torrent.go @@ -204,7 +204,7 @@ func (t *Torrent) addrActive(addr string) bool { 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 @@ func (t *Torrent) wantPieceIndex(index int) bool { // 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 {