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
33443d77
Commit
33443d77
authored
Mar 06, 2020
by
Dirk McCormick
Committed by
Steven Allen
Mar 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: block receive shouldn't affect DONT_HAVE count for other peers
parent
2112d90e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
30 deletions
+25
-30
internal/session/sessionwantsender.go
internal/session/sessionwantsender.go
+25
-30
No files found.
internal/session/sessionwantsender.go
View file @
33443d77
...
...
@@ -321,8 +321,15 @@ func (sws *sessionWantSender) processUpdates(updates []update) []cid.Cid {
prunePeers
:=
make
(
map
[
peer
.
ID
]
struct
{})
for
_
,
upd
:=
range
updates
{
for
_
,
c
:=
range
upd
.
dontHaves
{
// If we already received a block for the want, ignore any
// DONT_HAVE for the want
// Track the number of consecutive DONT_HAVEs each peer receives
if
sws
.
peerConsecutiveDontHaves
[
upd
.
from
]
==
peerDontHaveLimit
{
prunePeers
[
upd
.
from
]
=
struct
{}{}
}
else
{
sws
.
peerConsecutiveDontHaves
[
upd
.
from
]
++
}
// If we already received a block for the want, there's no need to
// update block presence etc
if
blkCids
.
Has
(
c
)
{
continue
}
...
...
@@ -341,28 +348,18 @@ func (sws *sessionWantSender) processUpdates(updates []update) []cid.Cid {
sws
.
setWantSentTo
(
c
,
""
)
}
}
// Track the number of consecutive DONT_HAVEs each peer receives
if
sws
.
peerConsecutiveDontHaves
[
upd
.
from
]
==
peerDontHaveLimit
{
prunePeers
[
upd
.
from
]
=
struct
{}{}
}
else
{
sws
.
peerConsecutiveDontHaves
[
upd
.
from
]
++
}
}
}
// Process received HAVEs
for
_
,
upd
:=
range
updates
{
for
_
,
c
:=
range
upd
.
haves
{
// If we already received a block for the want
, ignore any HAVE for
// the want
if
blkCids
.
Has
(
c
)
{
continue
// If we
haven't
already received a block for the want
if
!
blkCids
.
Has
(
c
)
{
// Update the block presence for the peer
sws
.
updateWantBlockPresence
(
c
,
upd
.
from
)
}
// Update the block presence for the peer
sws
.
updateWantBlockPresence
(
c
,
upd
.
from
)
// Clear the consecutive DONT_HAVE count for the peer
delete
(
sws
.
peerConsecutiveDontHaves
,
upd
.
from
)
delete
(
prunePeers
,
upd
.
from
)
...
...
@@ -372,23 +369,21 @@ func (sws *sessionWantSender) processUpdates(updates []update) []cid.Cid {
// If any peers have sent us too many consecutive DONT_HAVEs, remove them
// from the session
if
len
(
prunePeers
)
>
0
{
for
p
:=
range
prunePeers
{
// Before removing the peer from the session, check if the peer
// sent us a HAVE for a block that we want
for
c
:=
range
sws
.
wants
{
if
sws
.
bpm
.
PeerHasBlock
(
p
,
c
)
{
delete
(
prunePeers
,
p
)
break
}
}
}
go
func
()
{
for
p
:=
range
prunePeers
{
// Before removing the peer from the session, check if the peer
// sent us a HAVE for a block that we want
peerHasWantedBlock
:=
false
for
c
:=
range
sws
.
wants
{
if
sws
.
bpm
.
PeerHasBlock
(
p
,
c
)
{
peerHasWantedBlock
=
true
break
}
}
// Peer doesn't have anything we want, so remove it
if
!
peerHasWantedBlock
{
log
.
Infof
(
"peer %s sent too many dont haves"
,
lu
.
P
(
p
))
sws
.
SignalAvailability
(
p
,
false
)
}
log
.
Infof
(
"peer %s sent too many dont haves"
,
lu
.
P
(
p
))
sws
.
SignalAvailability
(
p
,
false
)
}
}()
}
...
...
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