]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Missing torrent functions
authorMatt Joiner <anacrolix@gmail.com>
Sat, 13 Sep 2014 18:06:17 +0000 (04:06 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 13 Sep 2014 18:06:17 +0000 (04:06 +1000)
torrent.go

index 19b5f053a7a34b8fcfa71c50bcf5d2243e4a9306..ce9d92730b0e5d52248f79b0dd80fd9eca51bea9 100644 (file)
@@ -561,3 +561,19 @@ func (t *torrent) wantPiece(index int) bool {
        p := t.Pieces[index]
        return p.EverHashed && len(p.PendingChunkSpecs) != 0
 }
+
+func (t *torrent) connHasWantedPieces(c *connection) bool {
+       for p := range t.Pieces {
+               if t.wantPiece(p) && c.PeerHasPiece(pp.Integer(p)) {
+                       return true
+               }
+       }
+       return false
+}
+
+func (t *torrent) extentPieces(off, _len int64) (pieces []int) {
+       for i := off / int64(t.UsualPieceSize()); i*int64(t.UsualPieceSize()) < off+_len; i++ {
+               pieces = append(pieces, int(i))
+       }
+       return
+}