Unverified Commit a8af17a5 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #346 from ipfs/feat/prioritize-wants

feat: prioritize more important wants
parents 6728add5 c444535f
...@@ -551,19 +551,18 @@ func (mq *MessageQueue) extractOutgoingMessage(supportsHave bool) (bsmsg.BitSwap ...@@ -551,19 +551,18 @@ func (mq *MessageQueue) extractOutgoingMessage(supportsHave bool) (bsmsg.BitSwap
// Size of the message so far // Size of the message so far
msgSize := 0 msgSize := 0
// Add each broadcast want-have to the message // Always prioritize cancels, then targeted, then broadcast.
for i := 0; i < len(bcstEntries) && msgSize < mq.maxMessageSize; i++ {
// Broadcast wants are sent as want-have
wantType := pb.Message_Wantlist_Have
// If the remote peer doesn't support HAVE / DONT_HAVE messages, // Add each cancel to the message
// send a want-block instead cancels := mq.cancels.Keys()
if !supportsHave { for i := 0; i < len(cancels) && msgSize < mq.maxMessageSize; i++ {
wantType = pb.Message_Wantlist_Block c := cancels[i]
}
e := bcstEntries[i] msgSize += mq.msg.Cancel(c)
msgSize += mq.msg.AddEntry(e.Cid, e.Priority, wantType, false)
// Clear the cancel - we make a best effort to let peers know about
// cancels but won't save them to resend if there's a failure.
mq.cancels.Remove(c)
} }
// Add each regular want-have / want-block to the message // Add each regular want-have / want-block to the message
...@@ -578,16 +577,19 @@ func (mq *MessageQueue) extractOutgoingMessage(supportsHave bool) (bsmsg.BitSwap ...@@ -578,16 +577,19 @@ func (mq *MessageQueue) extractOutgoingMessage(supportsHave bool) (bsmsg.BitSwap
} }
} }
// Add each cancel to the message // Add each broadcast want-have to the message
cancels := mq.cancels.Keys() for i := 0; i < len(bcstEntries) && msgSize < mq.maxMessageSize; i++ {
for i := 0; i < len(cancels) && msgSize < mq.maxMessageSize; i++ { // Broadcast wants are sent as want-have
c := cancels[i] wantType := pb.Message_Wantlist_Have
msgSize += mq.msg.Cancel(c) // If the remote peer doesn't support HAVE / DONT_HAVE messages,
// send a want-block instead
if !supportsHave {
wantType = pb.Message_Wantlist_Block
}
// Clear the cancel - we make a best effort to let peers know about e := bcstEntries[i]
// cancels but won't save them to resend if there's a failure. msgSize += mq.msg.AddEntry(e.Cid, e.Priority, wantType, false)
mq.cancels.Remove(c)
} }
// Called when the message has been successfully sent. // Called when the message has been successfully sent.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment