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
99fe214a
Commit
99fe214a
authored
Mar 06, 2020
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: block receive shouldn't affect DONT_HAVE count for other peers
parent
32e5cae5
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 @
99fe214a
...
@@ -321,8 +321,15 @@ func (sws *sessionWantSender) processUpdates(updates []update) []cid.Cid {
...
@@ -321,8 +321,15 @@ func (sws *sessionWantSender) processUpdates(updates []update) []cid.Cid {
prunePeers
:=
make
(
map
[
peer
.
ID
]
struct
{})
prunePeers
:=
make
(
map
[
peer
.
ID
]
struct
{})
for
_
,
upd
:=
range
updates
{
for
_
,
upd
:=
range
updates
{
for
_
,
c
:=
range
upd
.
dontHaves
{
for
_
,
c
:=
range
upd
.
dontHaves
{
// If we already received a block for the want, ignore any
// Track the number of consecutive DONT_HAVEs each peer receives
// DONT_HAVE for the want
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
)
{
if
blkCids
.
Has
(
c
)
{
continue
continue
}
}
...
@@ -341,28 +348,18 @@ func (sws *sessionWantSender) processUpdates(updates []update) []cid.Cid {
...
@@ -341,28 +348,18 @@ func (sws *sessionWantSender) processUpdates(updates []update) []cid.Cid {
sws
.
setWantSentTo
(
c
,
""
)
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
// Process received HAVEs
for
_
,
upd
:=
range
updates
{
for
_
,
upd
:=
range
updates
{
for
_
,
c
:=
range
upd
.
haves
{
for
_
,
c
:=
range
upd
.
haves
{
// If we already received a block for the want
, ignore any HAVE for
// If we
haven't
already received a block for the want
// the want
if
!
blkCids
.
Has
(
c
)
{
if blkCids.Has(c) {
// Update the block presence for the peer
continue
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
// Clear the consecutive DONT_HAVE count for the peer
delete
(
sws
.
peerConsecutiveDontHaves
,
upd
.
from
)
delete
(
sws
.
peerConsecutiveDontHaves
,
upd
.
from
)
delete
(
prunePeers
,
upd
.
from
)
delete
(
prunePeers
,
upd
.
from
)
...
@@ -372,23 +369,21 @@ func (sws *sessionWantSender) processUpdates(updates []update) []cid.Cid {
...
@@ -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
// If any peers have sent us too many consecutive DONT_HAVEs, remove them
// from the session
// from the session
if
len
(
prunePeers
)
>
0
{
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
()
{
go
func
()
{
for
p
:=
range
prunePeers
{
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
// Peer doesn't have anything we want, so remove it
if !peerHasWantedBlock {
log
.
Infof
(
"peer %s sent too many dont haves"
,
lu
.
P
(
p
))
log.Infof("peer %s sent too many dont haves", lu.P(p))
sws
.
SignalAvailability
(
p
,
false
)
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