Add per-torrent ability to disable uploading

This commit is contained in:
Maxb 2020-05-30 12:42:51 -07:00 committed by Matt Joiner
parent c7ea314de0
commit d7627143bc
2 changed files with 27 additions and 0 deletions

View File

@ -1325,6 +1325,9 @@ func (c *PeerConn) uploadAllowed() bool {
if c.t.cl.config.NoUpload {
return false
}
if c.t.dataUploadDisallowed {
return false
}
if c.t.seeding() {
return true
}

View File

@ -45,6 +45,7 @@ type Torrent struct {
networkingEnabled bool
dataDownloadDisallowed bool
dataUploadDisallowed bool
userOnWriteChunkErr func(error)
// Determines what chunks to request from peers.
@ -1273,6 +1274,9 @@ func (t *Torrent) seeding() bool {
if t.closed.IsSet() {
return false
}
if t.dataUploadDisallowed {
return false
}
if cl.config.NoUpload {
return false
}
@ -1969,6 +1973,26 @@ 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()
}
}
func (t *Torrent) DisallowDataUpload() {
t.cl.lock()
defer t.cl.unlock()
log.Printf("DisallowDataUpload")
t.dataUploadDisallowed = true
for c := range t.conns {
c.updateRequests()
}
}
func (t *Torrent) SetOnWriteChunkError(f func(error)) {
t.cl.lock()
defer t.cl.unlock()