Commit fe048093 authored by Jeromy's avatar Jeromy

ensure sending of wantlist to friendly peers

parent be976cc5
......@@ -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
}
......
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"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment