From: Matt Joiner Date: Mon, 1 Dec 2014 09:32:17 +0000 (-0600) Subject: Misc good fixes X-Git-Tag: v1.0.0~1460 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=76f83e60b26e531c84b88e734c3be9242b417a1b;p=btrtrc.git Misc good fixes --- diff --git a/client.go b/client.go index 5d82833d..f5e0ad5d 100644 --- 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