+func (t *Torrent) Metainfo() metainfo.MetaInfo {
+ t.cl.rLock()
+ defer t.cl.rUnlock()
+ return t.newMetaInfo()
+}
+
+func (t *Torrent) addReader(r *reader) {
+ t.cl.lock()
+ defer t.cl.unlock()
+ if t.readers == nil {
+ t.readers = make(map[*reader]struct{})
+ }
+ t.readers[r] = struct{}{}
+ r.posChanged()
+}
+
+func (t *Torrent) deleteReader(r *reader) {
+ delete(t.readers, r)
+ t.readersChanged()
+}
+
+// Raise the priorities of pieces in the range [begin, end) to at least Normal
+// priority. Piece indexes are not the same as bytes. Requires that the info
+// has been obtained, see Torrent.Info and Torrent.GotInfo.
+func (t *Torrent) DownloadPieces(begin, end pieceIndex) {
+ t.cl.lock()
+ t.downloadPiecesLocked(begin, end)
+ t.cl.unlock()
+}
+
+func (t *Torrent) downloadPiecesLocked(begin, end pieceIndex) {
+ for i := begin; i < end; i++ {
+ if t.pieces[i].priority.Raise(PiecePriorityNormal) {
+ t.updatePiecePriority(i, "Torrent.DownloadPieces")
+ }
+ }
+}
+
+func (t *Torrent) CancelPieces(begin, end pieceIndex) {
+ t.cl.lock()
+ t.cancelPiecesLocked(begin, end, "Torrent.CancelPieces")
+ t.cl.unlock()
+}
+
+func (t *Torrent) cancelPiecesLocked(begin, end pieceIndex, reason string) {
+ for i := begin; i < end; i++ {
+ p := &t.pieces[i]
+ if p.priority == PiecePriorityNone {
+ continue
+ }
+ p.priority = PiecePriorityNone
+ t.updatePiecePriority(i, reason)
+ }