From f57437201e5e825081074a6f58a4f804fcf8e768 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 5 Feb 2018 17:41:53 +1100 Subject: [PATCH] Send bitfield messages before other initial messages --- client.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/client.go b/client.go index 81a7936b..5ae32af6 100644 --- 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, -- 2.48.1