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
fe048093
Commit
fe048093
authored
Nov 22, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure sending of wantlist to friendly peers
parent
be976cc5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
bitswap.go
bitswap.go
+16
-3
bitswap_test.go
bitswap_test.go
+2
-1
No files found.
bitswap.go
View file @
fe048093
...
...
@@ -262,6 +262,7 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
}
}
first
:=
true
for
_
,
key
:=
range
incoming
.
Wantlist
()
{
// TODO: might be better to check if we have the block before checking
// if we should send it to someone
...
...
@@ -272,9 +273,11 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
// Create a separate message to send this block in
blkmsg
:=
bsmsg
.
New
()
// TODO: only send this the first time
for
_
,
k
:=
range
bs
.
wantlist
.
Keys
()
{
blkmsg
.
AddWanted
(
k
)
if
first
{
for
_
,
k
:=
range
bs
.
wantlist
.
Keys
()
{
blkmsg
.
AddWanted
(
k
)
}
first
=
false
}
blkmsg
.
AddBlock
(
block
)
...
...
@@ -284,6 +287,16 @@ func (bs *bitswap) ReceiveMessage(ctx context.Context, p peer.Peer, incoming bsm
}
}
// If they send us a block, we should guarantee that we send
// them our updated want list one way or another
if
len
(
incoming
.
Blocks
())
>
0
&&
first
{
message
:=
bsmsg
.
New
()
for
_
,
k
:=
range
bs
.
wantlist
.
Keys
()
{
message
.
AddWanted
(
k
)
}
return
p
,
message
}
return
nil
,
nil
}
...
...
bitswap_test.go
View file @
fe048093
package
bitswap
package
bitswap
_test
import
(
"bytes"
...
...
@@ -7,6 +7,7 @@ import (
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
.
"github.com/jbenet/go-ipfs/exchange/bitswap"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
ds_sync
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
...
...
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