From 672e3c4136928f195b061d2e8e640d66f4d1069d Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 11 Dec 2015 03:04:04 +1100 Subject: [PATCH] Don't consider a peer to have touched a piece if a chunk isn't written successfully This prevents peers being banned when there are issues with the data service locally. --- client.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index b2c9813c..c12eeb7d 100644 --- 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()