diff --git a/peerconn.go b/peerconn.go index df395006..779e9a73 100644 --- a/peerconn.go +++ b/peerconn.go @@ -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 } diff --git a/torrent.go b/torrent.go index 52c6124d..d231a8e5 100644 --- a/torrent.go +++ b/torrent.go @@ -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()