// Returns the priority per File.SetPriority.
func (f *File) Priority() (prio piecePriority) {
- f.t.cl.lock()
+ f.t.cl.rLock()
prio = f.prio
- f.t.cl.unlock()
+ f.t.cl.rUnlock()
return
}
logger: pc.logger,
w: pc.w,
keepAlive: func() bool {
- pc.locker().Lock()
- defer pc.locker().Unlock()
+ pc.locker().RLock()
+ defer pc.locker().RUnlock()
return pc.useful()
},
writeBuffer: new(bytes.Buffer),
"bytes"
"errors"
"fmt"
- "golang.org/x/time/rate"
"io"
"math/rand"
"net"
pp "github.com/anacrolix/torrent/peer_protocol"
request_strategy "github.com/anacrolix/torrent/request-strategy"
"github.com/anacrolix/torrent/typed-roaring"
+ "golang.org/x/time/rate"
)
type PeerSource string
}
func (cn *Peer) DownloadRate() float64 {
- cn.locker().Lock()
- defer cn.locker().Unlock()
+ cn.locker().RLock()
+ defer cn.locker().RUnlock()
return cn.downloadRate()
}
// 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())
}
// 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
}
// 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()
}