client.go | 11 ++++++++++- diff --git a/client.go b/client.go index 5d82833d16f96c3a99d9d8a4fc1910bb8214dd59..f5e0ad5dac2721943f6ac93933e50f8a10d11031 100644 --- a/client.go +++ b/client.go @@ -849,7 +849,7 @@ for piece >= len(c.PeerPieces) { c.PeerPieces = append(c.PeerPieces, false) } c.PeerPieces[piece] = true - if !t.havePiece(piece) { + if t.wantPiece(piece) { me.replenishConnRequests(t, c) } } @@ -956,6 +956,8 @@ log.Printf("got bad metadata piece") break } t.SaveMetadataPiece(piece, payload[begin:]) + c.UsefulChunksReceived++ + c.lastUsefulChunkReceived = time.Now() if !t.HaveAllMetadataPieces() { break } @@ -1326,6 +1328,8 @@ }() } cl.downloadStrategy.TorrentStarted(t) + // TODO(anacrolix): I think this should be made available as a method, the + // channel only acts as a signal that the metadata has become available. select { case t.gotMetainfo <- &metainfo.MetaInfo{ Info: metainfo.InfoEx{ @@ -1363,6 +1367,11 @@ t.wantPeers.L = &t.stateMu t.GotMetainfo = t.gotMetainfo t.addTrackers(announceList) return +} + +func init() { + // For shuffling the tracker tiers. + mathRand.Seed(time.Now().Unix()) } // The trackers within each tier must be shuffled before use.