Misc good fixes

This commit is contained in:
Matt Joiner 2014-12-01 03:32:17 -06:00
parent d430cf9ec9
commit 76f83e60b2
1 changed files with 10 additions and 1 deletions

View File

@ -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