Stop announcing on DHT if a torrent is removed

This commit is contained in:
Matt Joiner 2014-08-25 06:01:05 +10:00
parent 78ed2c74d0
commit 6aa459dc0d
2 changed files with 15 additions and 2 deletions

View File

@ -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()

View File

@ -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