]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Send bitfield messages before other initial messages
authorMatt Joiner <anacrolix@gmail.com>
Mon, 5 Feb 2018 06:41:53 +0000 (17:41 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 5 Feb 2018 06:41:53 +0000 (17:41 +1100)
client.go

index 81a7936b3b48dda103450140f0dde68b378390af..5ae32af67d99042af1451d42f31587be511414e3 100644 (file)
--- a/client.go
+++ b/client.go
@@ -851,6 +851,20 @@ func (cl *Client) runHandshookConn(c *connection, t *Torrent, outgoing bool) {
 }
 
 func (cl *Client) sendInitialMessages(conn *connection, torrent *Torrent) {
+       func() {
+               if conn.fastEnabled() {
+                       if torrent.haveAllPieces() {
+                               conn.Post(pp.Message{Type: pp.HaveAll})
+                               conn.sentHaves.AddRange(0, conn.t.NumPieces())
+                               return
+                       } else if !torrent.haveAnyPieces() {
+                               conn.Post(pp.Message{Type: pp.HaveNone})
+                               conn.sentHaves.Clear()
+                               return
+                       }
+               }
+               conn.PostBitfield()
+       }()
        if conn.PeerExtensionBytes.SupportsExtended() && cl.extensionBytes.SupportsExtended() {
                conn.Post(pp.Message{
                        Type:       pp.Extended,
@@ -893,20 +907,6 @@ func (cl *Client) sendInitialMessages(conn *connection, torrent *Torrent) {
                        }(),
                })
        }
-       func() {
-               if conn.fastEnabled() {
-                       if torrent.haveAllPieces() {
-                               conn.Post(pp.Message{Type: pp.HaveAll})
-                               conn.sentHaves.AddRange(0, conn.t.NumPieces())
-                               return
-                       } else if !torrent.haveAnyPieces() {
-                               conn.Post(pp.Message{Type: pp.HaveNone})
-                               conn.sentHaves.Clear()
-                               return
-                       }
-               }
-               conn.PostBitfield()
-       }()
        if conn.PeerExtensionBytes.SupportsDHT() && cl.extensionBytes.SupportsDHT() && cl.dHT != nil {
                conn.Post(pp.Message{
                        Type: pp.Port,