]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add DisallowDataDownload/Upload to TorrentSpec and small log cleanup
authorMaxb <bittmanmax@gmail.com>
Wed, 3 Jun 2020 19:17:47 +0000 (12:17 -0700)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 4 Jun 2020 00:36:56 +0000 (10:36 +1000)
client.go
spec.go
torrent.go

index dd1c77d1ba80d40d83933562db6ba2352f1bf1fe..a3f0a78a8a1e650c8299de0d3c5a412b3896e534 100644 (file)
--- a/client.go
+++ b/client.go
@@ -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.
+// 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.
 func (t *Torrent) MergeSpec(spec *TorrentSpec) error {
        if spec.DisplayName != "" {
@@ -1172,6 +1173,8 @@ func (t *Torrent) MergeSpec(spec *TorrentSpec) error {
        }
        t.addTrackers(spec.Trackers)
        t.maybeNewConns()
+       t.dataDownloadDisallowed = spec.DisallowDataDownload
+       t.dataUploadDisallowed = spec.DisallowDataUpload
        return nil
 }
 
diff --git a/spec.go b/spec.go
index e0c0bc24232bfdc6837379c7d3aa7cb3565b4bc2..b5007c2612cc8619c9d47d0257ddd8d74793d66d 100644 (file)
--- a/spec.go
+++ b/spec.go
@@ -22,6 +22,10 @@ type TorrentSpec struct {
        // The chunk size to use for outbound requests. Defaults to 16KiB if not set.
        ChunkSize int
        Storage   storage.ClientImpl
+
+       // Whether to allow data download or upload
+       DisallowDataUpload   bool
+       DisallowDataDownload bool
 }
 
 func TorrentSpecFromMagnetURI(uri string) (spec *TorrentSpec, err error) {
index c2f936e2e2a41a08f4e9d357844d675ea9b3a2a2..7ceb91eec8d95294a212d782922cc3261297efda 100644 (file)
@@ -1975,7 +1975,6 @@ func (t *Torrent) DisallowDataDownload() {
 }
 
 func (t *Torrent) disallowDataDownloadLocked() {
-       log.Printf("disallowing data download")
        t.dataDownloadDisallowed = true
        t.iterPeers(func(c *peer) {
                c.updateRequests()
@@ -1985,7 +1984,6 @@ func (t *Torrent) disallowDataDownloadLocked() {
 func (t *Torrent) AllowDataDownload() {
        t.cl.lock()
        defer t.cl.unlock()
-       log.Printf("AllowDataDownload")
        t.dataDownloadDisallowed = false
        t.iterPeers(func(c *peer) {
                c.updateRequests()
@@ -1995,7 +1993,6 @@ func (t *Torrent) AllowDataDownload() {
 func (t *Torrent) AllowDataUpload() {
        t.cl.lock()
        defer t.cl.unlock()
-       log.Printf("AllowDataUpload")
        t.dataUploadDisallowed = false
        for c := range t.conns {
                c.updateRequests()
@@ -2005,7 +2002,6 @@ func (t *Torrent) AllowDataUpload() {
 func (t *Torrent) DisallowDataUpload() {
        t.cl.lock()
        defer t.cl.unlock()
-       log.Printf("DisallowDataUpload")
        t.dataUploadDisallowed = true
        for c := range t.conns {
                c.updateRequests()