]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Stop announcing on DHT if a torrent is removed
authorMatt Joiner <anacrolix@gmail.com>
Sun, 24 Aug 2014 20:01:05 +0000 (06:01 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 24 Aug 2014 20:01:05 +0000 (06:01 +1000)
client.go
torrent.go

index e4e9cecbd1b07f112478274bd086478422a8afcb..ecbbcc4ce55ceb5d0b8415a68e4cf9b87ca2fb6a 100644 (file)
--- a/client.go
+++ b/client.go
@@ -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()
index 07a18c4878883a11f387496555f28ec051d88972..82256f1e4284dbaa8c197de3bb38cdc5db343ff2 100644 (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