if len(newPriorities) == 0 {
return nil
}
- if t.Priorities == nil {
- t.Priorities = list.New()
- }
t.Priorities.PushFront(newPriorities[0])
for _, req := range newPriorities[1:] {
t.Priorities.PushBack(req)
if !me.DisableTrackers {
go me.announceTorrent(torrent)
}
- for i := range torrent.Pieces {
- me.queuePieceCheck(torrent, peer_protocol.Integer(i))
+ torrent.Priorities = list.New()
+
+ // Queue all pieces for hashing. This is done sequentially to avoid
+ // spamming goroutines.
+ for _, p := range torrent.Pieces {
+ p.QueuedForHash = true
}
+ go func() {
+ for i := range torrent.Pieces {
+ me.verifyPiece(torrent, peer_protocol.Integer(i))
+ }
+ }()
+
return nil
}
return conn.Request(req)
}
// First request prioritized chunks.
- if torrent.Priorities != nil {
- for e := torrent.Priorities.Front(); e != nil; e = e.Next() {
- if !addRequest(e.Value.(request)) {
- return
- }
+ for e := torrent.Priorities.Front(); e != nil; e = e.Next() {
+ if !addRequest(e.Value.(request)) {
+ return
}
}
// Then finish off incomplete pieces in order of bytes remaining.
p.PendingChunkSpecs = nil
log.Printf("%s: got piece %d, (%d/%d)", t, piece, t.NumPiecesCompleted(), t.NumPieces())
var next *list.Element
- if t.Priorities != nil {
- for e := t.Priorities.Front(); e != nil; e = next {
- next = e.Next()
- if e.Value.(request).Index == piece {
- t.Priorities.Remove(e)
- }
+ for e := t.Priorities.Front(); e != nil; e = next {
+ next = e.Next()
+ if e.Value.(request).Index == piece {
+ t.Priorities.Remove(e)
}
}
me.dataReady(dataSpec{