X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t.go;h=45856cc7acbeaa5988074f74435d078a49111a57;hb=HEAD;hp=2bce0d7c05f6cdb5cbdeb89e380645d6eaea965e;hpb=32d89830ede8d8e50c22389175a686760c385762;p=btrtrc.git diff --git a/t.go b/t.go index 2bce0d7c..45856cc7 100644 --- a/t.go +++ b/t.go @@ -32,7 +32,7 @@ func (t *Torrent) Info() (info *metainfo.Info) { // Returns a Reader bound to the torrent's data. All read calls block until the data requested is // actually available. Note that you probably want to ensure the Torrent Info is available first. func (t *Torrent) NewReader() Reader { - return t.newReader(0, *t.length) + return t.newReader(0, t.length()) } func (t *Torrent) newReader(offset, length int64) Reader { @@ -86,8 +86,8 @@ func (t *Torrent) NumPieces() pieceIndex { // Get missing bytes count for specific piece. func (t *Torrent) PieceBytesMissing(piece int) int64 { - t.cl.lock() - defer t.cl.unlock() + t.cl.rLock() + defer t.cl.rUnlock() return int64(t.pieces[piece].bytesLeft()) } @@ -100,7 +100,10 @@ func (t *Torrent) Drop() { defer wg.Wait() t.cl.lock() defer t.cl.unlock() - t.cl.dropTorrent(t.infoHash, &wg) + err := t.cl.dropTorrent(t.infoHash, &wg) + if err != nil { + panic(err) + } } // Number of bytes of the entire torrent we have completed. This is the sum of @@ -122,9 +125,9 @@ func (t *Torrent) SubscribePieceStateChanges() *pubsub.Subscription[PieceStateCh // Returns true if the torrent is currently being seeded. This occurs when the // client is willing to upload without wanting anything in return. func (t *Torrent) Seeding() (ret bool) { - t.cl.lock() + t.cl.rLock() ret = t.seeding() - t.cl.unlock() + t.cl.rUnlock() return } @@ -147,14 +150,14 @@ func (t *Torrent) Name() string { // The completed length of all the torrent data, in all its files. This is // derived from the torrent info, when it is available. func (t *Torrent) Length() int64 { - return *t.length + return t._length.Value } // Returns a run-time generated metainfo for the torrent that includes the // info bytes and announce-list as currently known to the client. func (t *Torrent) Metainfo() metainfo.MetaInfo { - t.cl.lock() - defer t.cl.unlock() + t.cl.rLock() + defer t.cl.rUnlock() return t.newMetaInfo() } @@ -211,23 +214,13 @@ func (t *Torrent) initFiles() { var offset int64 t.files = new([]*File) for _, fi := range t.info.UpvertedFiles() { - var path []string - if len(fi.PathUTF8) != 0 { - path = fi.PathUTF8 - } else { - path = fi.Path - } - dp := t.info.Name - if len(fi.Path) != 0 { - dp = strings.Join(fi.Path, "/") - } *t.files = append(*t.files, &File{ t, - strings.Join(append([]string{t.info.Name}, path...), "/"), + strings.Join(append([]string{t.info.BestName()}, fi.BestPath()...), "/"), offset, fi.Length, fi, - dp, + fi.DisplayPath(t.info), PiecePriorityNone, }) offset += fi.Length @@ -242,8 +235,8 @@ func (t *Torrent) Files() []*File { func (t *Torrent) AddPeers(pp []PeerInfo) (n int) { t.cl.lock() + defer t.cl.unlock() n = t.addPeers(pp) - t.cl.unlock() return }