Send extended message before fast/bitfield

This is how Transmission does it.
This commit is contained in:
Matt Joiner 2018-07-14 11:28:54 +10:00
parent cc6441a791
commit d4d8f78906
1 changed files with 15 additions and 14 deletions

View File

@ -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,