Add DisallowDataDownload/Upload to TorrentSpec and small log cleanup
This commit is contained in:
parent
8606385985
commit
a7689f52bd
|
@ -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
|
||||
}
|
||||
|
||||
|
|
4
spec.go
4
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) {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue