From: Matt Joiner Date: Sat, 21 Feb 2015 04:02:06 +0000 (+1100) Subject: Improve announcer routines X-Git-Tag: v1.0.0~1327 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=2025daa77c39666f253b64f305b6c4a95ef68bed;p=btrtrc.git Improve announcer routines --- diff --git a/client.go b/client.go index ba689c91..d6ab4727 100644 --- a/client.go +++ b/client.go @@ -1807,12 +1807,14 @@ func (cl *Client) AddMagnet(uri string) (T Torrent, err error) { // for replacements. func (cl *Client) connectionPruner(t *torrent) { for { - time.Sleep(15 * time.Second) - cl.mu.Lock() select { case <-t.ceasingNetworking: - default: + return + case <-t.closing: + return + case <-time.After(15 * time.Second): } + cl.mu.Lock() license := len(t.Conns) - (socketsPerTorrent+1)/2 for _, c := range t.Conns { if license <= 0 { @@ -1923,7 +1925,7 @@ func (cl *Client) waitWantPeers(t *torrent) bool { return false default: } - if len(t.Peers) < torrentPeersLowWater { + if len(t.Peers) < torrentPeersLowWater && t.needData() { return true } cl.mu.Unlock() @@ -2042,6 +2044,9 @@ func (cl *Client) announceTorrentTrackers(t *torrent) { PeerId: cl.peerID, InfoHash: t.InfoHash, } + if !cl.waitWantPeers(t) { + return + } cl.mu.RLock() req.Left = t.BytesLeft() trackers := t.Trackers