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
b4763e26
Commit
b4763e26
authored
Mar 19, 2020
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: small changes to message queue
parent
c5a6db7b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
internal/messagequeue/messagequeue.go
internal/messagequeue/messagequeue.go
+7
-6
No files found.
internal/messagequeue/messagequeue.go
View file @
b4763e26
...
...
@@ -488,10 +488,12 @@ func (mq *MessageQueue) logOutgoingMessage(wantlist []bsmsg.Entry) {
}
}
// Whether there is work to be processed
func
(
mq
*
MessageQueue
)
hasPendingWork
()
bool
{
return
mq
.
pendingWorkCount
()
>
0
}
// The amount of work that is waiting to be processed
func
(
mq
*
MessageQueue
)
pendingWorkCount
()
int
{
mq
.
wllock
.
Lock
()
defer
mq
.
wllock
.
Unlock
()
...
...
@@ -499,9 +501,8 @@ func (mq *MessageQueue) pendingWorkCount() int {
return
mq
.
bcstWants
.
pending
.
Len
()
+
mq
.
peerWants
.
pending
.
Len
()
+
mq
.
cancels
.
Len
()
}
// Convert the lists of wants into a Bitswap message
func
(
mq
*
MessageQueue
)
extractOutgoingMessage
(
supportsHave
bool
)
bsmsg
.
BitSwapMessage
{
msg
:=
mq
.
msg
mq
.
wllock
.
Lock
()
defer
mq
.
wllock
.
Unlock
()
...
...
@@ -524,7 +525,7 @@ func (mq *MessageQueue) extractOutgoingMessage(supportsHave bool) bsmsg.BitSwapM
}
e
:=
bcstEntries
[
i
]
msgSize
+=
msg
.
AddEntry
(
e
.
Cid
,
e
.
Priority
,
wantType
,
false
)
msgSize
+=
mq
.
msg
.
AddEntry
(
e
.
Cid
,
e
.
Priority
,
wantType
,
false
)
}
// Add each regular want-have / want-block to the message
...
...
@@ -535,7 +536,7 @@ func (mq *MessageQueue) extractOutgoingMessage(supportsHave bool) bsmsg.BitSwapM
if
!
supportsHave
&&
e
.
WantType
==
pb
.
Message_Wantlist_Have
{
mq
.
peerWants
.
RemoveType
(
e
.
Cid
,
pb
.
Message_Wantlist_Have
)
}
else
{
msgSize
+=
msg
.
AddEntry
(
e
.
Cid
,
e
.
Priority
,
e
.
WantType
,
true
)
msgSize
+=
mq
.
msg
.
AddEntry
(
e
.
Cid
,
e
.
Priority
,
e
.
WantType
,
true
)
}
}
...
...
@@ -544,14 +545,14 @@ func (mq *MessageQueue) extractOutgoingMessage(supportsHave bool) bsmsg.BitSwapM
for
i
:=
0
;
i
<
len
(
cancels
)
&&
msgSize
<
mq
.
maxMessageSize
;
i
++
{
c
:=
cancels
[
i
]
msgSize
+=
msg
.
Cancel
(
c
)
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
)
}
return
msg
return
mq
.
msg
}
// 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