From: Matt Joiner Date: Sat, 14 Jul 2018 01:28:54 +0000 (+1000) Subject: Send extended message before fast/bitfield X-Git-Tag: v1.0.0~81 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=d4d8f78906cfa2f46f7812300b72d4e1de5dfaa1;p=btrtrc.git Send extended message before fast/bitfield This is how Transmission does it. --- 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,