]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Improve announcer routines
authorMatt Joiner <anacrolix@gmail.com>
Sat, 21 Feb 2015 04:02:06 +0000 (15:02 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 21 Feb 2015 04:02:06 +0000 (15:02 +1100)
client.go

index ba689c91a8f3d0016e0f419a503c22d4ae92d44b..d6ab47270503d319956b39200f413aeeb14b1c2c 100644 (file)
--- 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