From: Matt Joiner Date: Sat, 13 Sep 2014 18:06:17 +0000 (+1000) Subject: Missing torrent functions X-Git-Tag: v1.0.0~1556 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e30f2777fc8883d8b13102b528aaa9b3458d8ad3;p=btrtrc.git Missing torrent functions --- diff --git a/torrent.go b/torrent.go index 19b5f053..ce9d9273 100644 --- a/torrent.go +++ b/torrent.go @@ -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 +}