Only announce to DHT if we have dialers or listeners
This commit is contained in:
parent
eec337d4bc
commit
730cebf5aa
27
torrent.go
27
torrent.go
@ -91,6 +91,7 @@ type Torrent struct {
|
||||
// them. That encourages us to reconnect to peers that are well known in
|
||||
// the swarm.
|
||||
peers prioritizedPeers
|
||||
// Whether we want to know to know more peers.
|
||||
wantPeersEvent missinggo.Event
|
||||
// An announcer for each tracker URL.
|
||||
trackerAnnouncers map[string]torrentTrackerAnnouncer
|
||||
@ -1440,19 +1441,33 @@ func (t *Torrent) announceToDht(impliedPort bool, s DhtServer) error {
|
||||
|
||||
func (t *Torrent) dhtAnnouncer(s DhtServer) {
|
||||
cl := t.cl
|
||||
for {
|
||||
select {
|
||||
case <-t.closed.LockedChan(cl.locker()):
|
||||
return
|
||||
case <-t.wantPeersEvent.LockedChan(cl.locker()):
|
||||
}
|
||||
cl.lock()
|
||||
defer cl.unlock()
|
||||
for {
|
||||
for {
|
||||
if t.closed.IsSet() {
|
||||
return
|
||||
}
|
||||
if !t.wantPeers() {
|
||||
goto wait
|
||||
}
|
||||
// TODO: Determine if there's a listener on the port we're announcing.
|
||||
if len(cl.dialers) == 0 && len(cl.listeners) == 0 {
|
||||
goto wait
|
||||
}
|
||||
break
|
||||
wait:
|
||||
cl.event.Wait()
|
||||
}
|
||||
func() {
|
||||
t.numDHTAnnounces++
|
||||
cl.unlock()
|
||||
defer cl.lock()
|
||||
err := t.announceToDht(true, s)
|
||||
if err != nil {
|
||||
t.logger.WithValues(log.Warning).Printf("error announcing %q to DHT: %s", t, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user