torrent.go | 17 +++++++---------- diff --git a/torrent.go b/torrent.go index 9edfdc8f1e66e48573359fb4f9540cc01585ac7a..133918b261687106a5e907d15c6d61f29415fff9 100644 --- a/torrent.go +++ b/torrent.go @@ -1355,20 +1355,17 @@ func (t *Torrent) dhtAnnouncer(s *dht.Server) { cl := t.cl for { select { - case <-t.wantPeersEvent.LockedChan(cl.locker()): case <-t.closed.LockedChan(cl.locker()): return + case <-t.wantPeersEvent.LockedChan(cl.locker()): } + cl.lock() + t.numDHTAnnounces++ + cl.unlock() err := t.announceToDht(true, s) - func() { - cl.lock() - defer cl.unlock() - if err == nil { - t.numDHTAnnounces++ - } else { - t.logger.Printf("error announcing %q to DHT: %s", t, err) - } - }() + if err != nil { + t.logger.Printf("error announcing %q to DHT: %s", t, err) + } } }