From: Matt Joiner Date: Sat, 16 Jun 2018 07:00:50 +0000 (+1000) Subject: Rework Torrent pending requests assertions X-Git-Tag: v1.0.0~127^2~16 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=174120e1e8edcd64c12f4560a0536999abe47112;p=btrtrc.git Rework Torrent pending requests assertions Should provide more info, and sooner for #249. --- diff --git a/connection.go b/connection.go index 2f9b5494..41359787 100644 --- a/connection.go +++ b/connection.go @@ -1369,7 +1369,15 @@ func (c *connection) deleteRequest(r request) bool { return false } delete(c.requests, r) - c.t.pendingRequests[r]-- + pr := c.t.pendingRequests + pr[r]-- + n := pr[r] + if n == 0 { + delete(pr, r) + } + if n < 0 { + panic(n) + } c.updateRequests() return true } diff --git a/torrent.go b/torrent.go index 3259dcc4..2a002d41 100644 --- a/torrent.go +++ b/torrent.go @@ -1231,10 +1231,8 @@ func (t *Torrent) deleteConnection(c *connection) (ret bool) { } func (t *Torrent) assertNoPendingRequests() { - for _, num := range t.pendingRequests { - if num != 0 { - panic(num) - } + if len(t.pendingRequests) != 0 { + panic(t.pendingRequests) } }