Send extended message before fast/bitfield
This is how Transmission does it.
This commit is contained in:
parent
cc6441a791
commit
d4d8f78906
29
client.go
29
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,
|
||||
|
|
Loading…
Reference in New Issue