Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
a8af17a5
Unverified
Commit
a8af17a5
authored
Apr 10, 2020
by
Steven Allen
Committed by
GitHub
Apr 10, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #346 from ipfs/feat/prioritize-wants
feat: prioritize more important wants
parents
6728add5
c444535f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
19 deletions
+21
-19
internal/messagequeue/messagequeue.go
internal/messagequeue/messagequeue.go
+21
-19
No files found.
internal/messagequeue/messagequeue.go
View file @
a8af17a5
...
...
@@ -551,19 +551,18 @@ func (mq *MessageQueue) extractOutgoingMessage(supportsHave bool) (bsmsg.BitSwap
// Size of the message so far
msgSize
:=
0
// Add each broadcast want-have to the message
for
i
:=
0
;
i
<
len
(
bcstEntries
)
&&
msgSize
<
mq
.
maxMessageSize
;
i
++
{
// Broadcast wants are sent as want-have
wantType
:=
pb
.
Message_Wantlist_Have
// Always prioritize cancels, then targeted, then broadcast.
// If the remote peer doesn't support HAVE / DONT_HAVE messages,
// send a want-block instead
if
!
supportsHave
{
wantType
=
pb
.
Message_Wantlist_Block
}
// Add each cancel to the message
cancels
:=
mq
.
cancels
.
Keys
()
for
i
:=
0
;
i
<
len
(
cancels
)
&&
msgSize
<
mq
.
maxMessageSize
;
i
++
{
c
:=
cancels
[
i
]
e
:=
bcstEntries
[
i
]
msgSize
+=
mq
.
msg
.
AddEntry
(
e
.
Cid
,
e
.
Priority
,
wantType
,
false
)
msgSize
+=
mq
.
msg
.
Cancel
(
c
)
// 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
...
...
@@ -578,16 +577,19 @@ func (mq *MessageQueue) extractOutgoingMessage(supportsHave bool) (bsmsg.BitSwap
}
}
// Add each
cancel
to the message
cancels
:=
mq
.
cancels
.
Keys
()
for
i
:=
0
;
i
<
len
(
cancels
)
&&
msgSize
<
mq
.
maxMessageSize
;
i
++
{
c
:=
cancels
[
i
]
// Add each
broadcast want-have
to the message
for
i
:=
0
;
i
<
len
(
bcstEntries
)
&&
msgSize
<
mq
.
maxMessageSize
;
i
++
{
// Broadcast wants are sent as want-have
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
// cancels but won't save them to resend if there's a failure.
mq
.
cancels
.
Remove
(
c
)
e
:=
bcstEntries
[
i
]
msgSize
+=
mq
.
msg
.
AddEntry
(
e
.
Cid
,
e
.
Priority
,
wantType
,
false
)
}
// Called when the message has been successfully sent.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment