]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add extra pedantic checks to requesting to try and flush out @deranjer's panics
authorMatt Joiner <anacrolix@gmail.com>
Thu, 15 Feb 2018 04:21:51 +0000 (15:21 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 15 Feb 2018 04:21:51 +0000 (15:21 +1100)
connection.go

index 235d043005e3a421af8bc50d32e4d3780174fb78..f70e08481bdb3fc4a9236eaff095eaa7cc54dbe9 100644 (file)
@@ -420,10 +420,12 @@ func (cn *connection) request(r request, mw messageWriter) bool {
        if !cn.PeerHasPiece(r.Index.Int()) {
                panic("requesting piece peer doesn't have")
        }
-       cn.requests[r] = struct{}{}
        if _, ok := cn.t.conns[cn]; !ok {
                panic("requesting but not in active conns")
        }
+       if cn.closed.IsSet() {
+               panic("requesting when connection is closed")
+       }
        if cn.PeerChoked {
                if cn.peerAllowedFast.Get(int(r.Index)) {
                        torrent.Add("allowed fast requests sent", 1)
@@ -431,6 +433,7 @@ func (cn *connection) request(r request, mw messageWriter) bool {
                        panic("requesting while choked and not allowed fast")
                }
        }
+       cn.requests[r] = struct{}{}
        cn.t.pendingRequests[r]++
        return mw(pp.Message{
                Type:   pp.Request,
@@ -1384,6 +1387,9 @@ func (c *connection) deleteAllRequests() {
        for r := range c.requests {
                c.deleteRequest(r)
        }
+       if len(c.requests) != 0 {
+               panic(len(c.requests))
+       }
        // for c := range c.t.conns {
        //      c.tickleWriter()
        // }