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
7f9589bc
Commit
7f9589bc
authored
Dec 10, 2018
by
hannahhoward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(sessions): use all of wantBudget
As soon as peers appear, consume all of the want budget
parent
2ea8ba82
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
9 deletions
+20
-9
session/session.go
session/session.go
+10
-2
session/session_test.go
session/session_test.go
+10
-7
No files found.
session/session.go
View file @
7f9589bc
...
...
@@ -341,8 +341,16 @@ func (s *Session) receiveBlock(ctx context.Context, blk blocks.Block) {
s
.
fetchcnt
++
s
.
notif
.
Publish
(
blk
)
if
next
:=
s
.
tofetch
.
Pop
();
next
.
Defined
()
{
s
.
wantBlocks
(
ctx
,
[]
cid
.
Cid
{
next
})
toAdd
:=
s
.
wantBudget
()
if
toAdd
>
s
.
tofetch
.
Len
()
{
toAdd
=
s
.
tofetch
.
Len
()
}
if
toAdd
>
0
{
var
keys
[]
cid
.
Cid
for
i
:=
0
;
i
<
toAdd
;
i
++
{
keys
=
append
(
keys
,
s
.
tofetch
.
Pop
())
}
s
.
wantBlocks
(
ctx
,
keys
)
}
s
.
pastWants
.
Push
(
c
)
...
...
session/session_test.go
View file @
7f9589bc
...
...
@@ -97,8 +97,11 @@ func TestSessionGetBlocks(t *testing.T) {
receivedBlocks
=
append
(
receivedBlocks
,
receivedBlock
)
cancelBlock
:=
<-
cancelReqs
newCancelReqs
=
append
(
newCancelReqs
,
cancelBlock
)
wantBlock
:=
<-
wantReqs
select
{
case
wantBlock
:=
<-
wantReqs
:
newBlockReqs
=
append
(
newBlockReqs
,
wantBlock
)
default
:
}
}
// verify new peers were recorded
...
...
@@ -120,22 +123,22 @@ func TestSessionGetBlocks(t *testing.T) {
t
.
Fatal
(
"did not cancel each block once it was received"
)
}
// new session reqs should be targeted
totalEn
que
u
ed
:=
0
var
newCidsRe
que
st
ed
[]
cid
.
Cid
for
_
,
w
:=
range
newBlockReqs
{
if
len
(
w
.
peers
)
==
0
{
t
.
Fatal
(
"should not have broadcast again after initial broadcast"
)
}
totalEn
que
u
ed
+
=
len
(
w
.
cids
)
newCidsRe
que
st
ed
=
append
(
newCidsRequested
,
w
.
cids
...
)
}
// full new round of cids should be requested
if
totalEn
que
u
ed
!=
broadcastLiveWantsLimit
{
if
len
(
newCidsRe
que
st
ed
)
!=
broadcastLiveWantsLimit
{
t
.
Fatal
(
"new blocks were not requested"
)
}
// receive remaining blocks
for
i
,
p
:=
range
peers
{
session
.
ReceiveBlockFrom
(
p
,
blks
[
testutil
.
IndexOf
(
blks
,
new
BlockReqs
[
i
]
.
cids
[
0
])])
session
.
ReceiveBlockFrom
(
p
,
blks
[
testutil
.
IndexOf
(
blks
,
new
CidsRequested
[
i
])])
receivedBlock
:=
<-
getBlocksCh
receivedBlocks
=
append
(
receivedBlocks
,
receivedBlock
)
cancelBlock
:=
<-
cancelReqs
...
...
@@ -190,7 +193,7 @@ func TestSessionFindMorePeers(t *testing.T) {
// verify a broadcast was made
receivedWantReq
:=
<-
wantReqs
if
len
(
receivedWantReq
.
cids
)
!=
broadcastLiveWantsLimit
{
if
len
(
receivedWantReq
.
cids
)
<
broadcastLiveWantsLimit
{
t
.
Fatal
(
"did not rebroadcast whole live list"
)
}
if
receivedWantReq
.
peers
!=
nil
{
...
...
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