Stop announcing on DHT if a torrent is removed
This commit is contained in:
parent
78ed2c74d0
commit
6aa459dc0d
|
@ -961,6 +961,8 @@ func newTorrent(ih InfoHash, announceList [][]string) (t *torrent, err error) {
|
|||
t = &torrent{
|
||||
InfoHash: ih,
|
||||
Peers: make(map[peersKey]Peer, 2000),
|
||||
|
||||
closing: make(chan struct{}),
|
||||
}
|
||||
t.Trackers = make([][]tracker.Client, len(announceList))
|
||||
for tierIndex := range announceList {
|
||||
|
@ -1115,6 +1117,9 @@ func (cl *Client) announceTorrentDHT(t *torrent) {
|
|||
log.Printf("error adding peers from dht for torrent %q: %s", t, err)
|
||||
break getPeers
|
||||
}
|
||||
case <-t.closing:
|
||||
ps.Close()
|
||||
return
|
||||
}
|
||||
}
|
||||
ps.Close()
|
||||
|
|
12
torrent.go
12
torrent.go
|
@ -334,11 +334,19 @@ func (t *torrent) Length() int64 {
|
|||
}
|
||||
|
||||
func (t *torrent) isClosed() bool {
|
||||
return t.closed
|
||||
select {
|
||||
case <-t.closing:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (t *torrent) Close() (err error) {
|
||||
t.closed = true
|
||||
if t.isClosed() {
|
||||
return
|
||||
}
|
||||
close(t.closing)
|
||||
t.dataLock.Lock()
|
||||
t.Data.Close()
|
||||
t.Data = nil
|
||||
|
|
Loading…
Reference in New Issue