client.go | 11 ++++++----- diff --git a/client.go b/client.go index 95dc790acd04735b9837221663409cba330b7183..03b029984244d16639e7b76abd5241cbd955c835 100644 --- a/client.go +++ b/client.go @@ -77,7 +77,7 @@ IP net.IP Port int } -func (t torrent) PieceSize(piece int) (size int64) { +func (t *torrent) PieceSize(piece int) (size int64) { if piece == len(t.Pieces)-1 { size = t.Data.Size() % t.MetaInfo.PieceLength } @@ -313,14 +313,15 @@ if _, ok := me.torrents[torrent.InfoHash]; ok { break } me.torrents[torrent.InfoHash] = torrent - for i := range torrent.Pieces { - go func(piece int) { + go func() { + for _piece := range torrent.Pieces { + piece := _piece sum := torrent.HashPiece(piece) me.withContext(func() { me.pieceHashed(torrent.InfoHash, piece, sum == torrent.Pieces[piece].Hash) }) - }(i) - } + } + }() case infoHash := <-me.torrentFinished: delete(me.torrents, infoHash) case task := <-me.actorTask: