]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Misc good fixes
authorMatt Joiner <anacrolix@gmail.com>
Mon, 1 Dec 2014 09:32:17 +0000 (03:32 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 1 Dec 2014 09:32:17 +0000 (03:32 -0600)
client.go

index 5d82833d16f96c3a99d9d8a4fc1910bb8214dd59..f5e0ad5dac2721943f6ac93933e50f8a10d11031 100644 (file)
--- a/client.go
+++ b/client.go
@@ -849,7 +849,7 @@ func (me *Client) peerGotPiece(t *torrent, c *connection, piece int) {
                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 @@ func (cl *Client) gotMetadataExtensionMsg(payload []byte, t *torrent, c *connect
                        break
                }
                t.SaveMetadataPiece(piece, payload[begin:])
+               c.UsefulChunksReceived++
+               c.lastUsefulChunkReceived = time.Now()
                if !t.HaveAllMetadataPieces() {
                        break
                }
@@ -1326,6 +1328,8 @@ func (cl *Client) setMetaData(t *torrent, md metainfo.Info, bytes []byte) (err e
        }
 
        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{
@@ -1365,6 +1369,11 @@ func newTorrent(ih InfoHash, announceList [][]string, halfOpenLimit int) (t *tor
        return
 }
 
+func init() {
+       // For shuffling the tracker tiers.
+       mathRand.Seed(time.Now().Unix())
+}
+
 // The trackers within each tier must be shuffled before use.
 // http://stackoverflow.com/a/12267471/149482
 // http://www.bittorrent.org/beps/bep_0012.html#order-of-processing