]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Send extended message before fast/bitfield
authorMatt Joiner <anacrolix@gmail.com>
Sat, 14 Jul 2018 01:28:54 +0000 (11:28 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 14 Jul 2018 01:28:54 +0000 (11:28 +1000)
This is how Transmission does it.

client.go

index ecd73b7b54b0b85b1248ea960202acacc8113bef..1091070e81781f45dd818654cc5209a336d08335 100644 (file)
--- a/client.go
+++ b/client.go
@@ -810,21 +810,8 @@ func (cl *Client) runHandshookConn(c *connection, t *Torrent) {
        }
 }
 
+// See the order given in Transmission's tr_peerMsgsNew.
 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, bitmap.BitIndex(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,
@@ -852,6 +839,20 @@ 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, bitmap.BitIndex(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.haveDhtServer() {
                conn.Post(pp.Message{
                        Type: pp.Port,