]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Don't consider a peer to have touched a piece if a chunk isn't written successfully
authorMatt Joiner <anacrolix@gmail.com>
Thu, 10 Dec 2015 16:04:04 +0000 (03:04 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 10 Dec 2015 16:04:04 +0000 (03:04 +1100)
This prevents peers being banned when there are issues with the data service locally.

client.go

index b2c9813c8b63c9d221609e85c99344d4f6e14a8e..c12eeb7d53cca85fcbb8685af3fadf811154cbf5 100644 (file)
--- a/client.go
+++ b/client.go
@@ -2584,12 +2584,13 @@ func (me *Client) downloadedChunk(t *torrent, c *connection, msg *pp.Message) er
                        return
                }
                tr.Stop("write chunk")
+               me.mu.Lock()
+               if c.peerTouchedPieces == nil {
+                       c.peerTouchedPieces = make(map[int]struct{})
+               }
+               c.peerTouchedPieces[int(req.Index)] = struct{}{}
+               me.mu.Unlock()
        }()
-       // This could be made dependent on whether any actual data was written.
-       if c.peerTouchedPieces == nil {
-               c.peerTouchedPieces = make(map[int]struct{})
-       }
-       c.peerTouchedPieces[int(req.Index)] = struct{}{}
 
        // log.Println("got chunk", req)
        me.event.Broadcast()