From e30f2777fc8883d8b13102b528aaa9b3458d8ad3 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 14 Sep 2014 04:06:17 +1000 Subject: [PATCH] Missing torrent functions --- torrent.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 +} -- 2.48.1