Add DisallowDataDownload/Upload to TorrentSpec and small log cleanup

This commit is contained in:
Maxb 2020-06-03 12:17:47 -07:00 committed by Matt Joiner
parent 8606385985
commit a7689f52bd
3 changed files with 7 additions and 4 deletions

View File

@ -1148,6 +1148,7 @@ func (cl *Client) AddTorrentSpec(spec *TorrentSpec) (t *Torrent, new bool, err e
} }
// The trackers will be merged with the existing ones. If the Info isn't yet known, it will be set. // The trackers will be merged with the existing ones. If the Info isn't yet known, it will be set.
// spec.DisallowDataDownload/Upload will be read and applied
// The display name is replaced if the new spec provides one. Note that any `Storage` is ignored. // The display name is replaced if the new spec provides one. Note that any `Storage` is ignored.
func (t *Torrent) MergeSpec(spec *TorrentSpec) error { func (t *Torrent) MergeSpec(spec *TorrentSpec) error {
if spec.DisplayName != "" { if spec.DisplayName != "" {
@ -1172,6 +1173,8 @@ func (t *Torrent) MergeSpec(spec *TorrentSpec) error {
} }
t.addTrackers(spec.Trackers) t.addTrackers(spec.Trackers)
t.maybeNewConns() t.maybeNewConns()
t.dataDownloadDisallowed = spec.DisallowDataDownload
t.dataUploadDisallowed = spec.DisallowDataUpload
return nil return nil
} }

View File

@ -22,6 +22,10 @@ type TorrentSpec struct {
// The chunk size to use for outbound requests. Defaults to 16KiB if not set. // The chunk size to use for outbound requests. Defaults to 16KiB if not set.
ChunkSize int ChunkSize int
Storage storage.ClientImpl Storage storage.ClientImpl
// Whether to allow data download or upload
DisallowDataUpload bool
DisallowDataDownload bool
} }
func TorrentSpecFromMagnetURI(uri string) (spec *TorrentSpec, err error) { func TorrentSpecFromMagnetURI(uri string) (spec *TorrentSpec, err error) {

View File

@ -1975,7 +1975,6 @@ func (t *Torrent) DisallowDataDownload() {
} }
func (t *Torrent) disallowDataDownloadLocked() { func (t *Torrent) disallowDataDownloadLocked() {
log.Printf("disallowing data download")
t.dataDownloadDisallowed = true t.dataDownloadDisallowed = true
t.iterPeers(func(c *peer) { t.iterPeers(func(c *peer) {
c.updateRequests() c.updateRequests()
@ -1985,7 +1984,6 @@ func (t *Torrent) disallowDataDownloadLocked() {
func (t *Torrent) AllowDataDownload() { func (t *Torrent) AllowDataDownload() {
t.cl.lock() t.cl.lock()
defer t.cl.unlock() defer t.cl.unlock()
log.Printf("AllowDataDownload")
t.dataDownloadDisallowed = false t.dataDownloadDisallowed = false
t.iterPeers(func(c *peer) { t.iterPeers(func(c *peer) {
c.updateRequests() c.updateRequests()
@ -1995,7 +1993,6 @@ func (t *Torrent) AllowDataDownload() {
func (t *Torrent) AllowDataUpload() { func (t *Torrent) AllowDataUpload() {
t.cl.lock() t.cl.lock()
defer t.cl.unlock() defer t.cl.unlock()
log.Printf("AllowDataUpload")
t.dataUploadDisallowed = false t.dataUploadDisallowed = false
for c := range t.conns { for c := range t.conns {
c.updateRequests() c.updateRequests()
@ -2005,7 +2002,6 @@ func (t *Torrent) AllowDataUpload() {
func (t *Torrent) DisallowDataUpload() { func (t *Torrent) DisallowDataUpload() {
t.cl.lock() t.cl.lock()
defer t.cl.unlock() defer t.cl.unlock()
log.Printf("DisallowDataUpload")
t.dataUploadDisallowed = true t.dataUploadDisallowed = true
for c := range t.conns { for c := range t.conns {
c.updateRequests() c.updateRequests()