From d4d8f78906cfa2f46f7812300b72d4e1de5dfaa1 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 14 Jul 2018 11:28:54 +1000 Subject: [PATCH] Send extended message before fast/bitfield This is how Transmission does it. --- client.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/client.go b/client.go index ecd73b7b..1091070e 100644 --- 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, -- 2.48.1