Commit 3c95a274 authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #58 from libp2p/feat/no-broadcast-opt

update to use no-broadcast option
parents f02c72d5 04ee593e
......@@ -216,7 +216,7 @@ func TestProvides(t *testing.T) {
for _, k := range testCaseCids {
log.Debugf("announcing provider for %s", k)
if err := dhts[3].Provide(ctx, k); err != nil {
if err := dhts[3].Provide(ctx, k, true); err != nil {
t.Fatal(err)
}
}
......@@ -247,6 +247,41 @@ func TestProvides(t *testing.T) {
}
}
func TestLocalProvides(t *testing.T) {
// t.Skip("skipping test to debug another")
ctx := context.Background()
_, _, dhts := setupDHTS(ctx, 4, t)
defer func() {
for i := 0; i < 4; i++ {
dhts[i].Close()
defer dhts[i].host.Close()
}
}()
connect(t, ctx, dhts[0], dhts[1])
connect(t, ctx, dhts[1], dhts[2])
connect(t, ctx, dhts[1], dhts[3])
for _, k := range testCaseCids {
log.Debugf("announcing provider for %s", k)
if err := dhts[3].Provide(ctx, k, false); err != nil {
t.Fatal(err)
}
}
time.Sleep(time.Millisecond * 10)
for _, c := range testCaseCids {
for i := 0; i < 3; i++ {
provs := dhts[i].providers.GetProviders(ctx, c)
if len(provs) > 0 {
t.Fatal("shouldnt know this")
}
}
}
}
// if minPeers or avgPeers is 0, dont test for it.
func waitForWellFormedTables(t *testing.T, dhts []*IpfsDHT, minPeers, avgPeers int, timeout time.Duration) bool {
// test "well-formed-ness" (>= minPeers peers in every routing table)
......@@ -471,7 +506,7 @@ func TestProvidesMany(t *testing.T) {
providers[c.KeyString()] = dht.self
t.Logf("announcing provider for %s", c)
if err := dht.Provide(ctx, c); err != nil {
if err := dht.Provide(ctx, c, true); err != nil {
t.Fatal(err)
}
}
......@@ -545,7 +580,7 @@ func TestProvidesAsync(t *testing.T) {
connect(t, ctx, dhts[1], dhts[2])
connect(t, ctx, dhts[1], dhts[3])
err := dhts[3].Provide(ctx, testCaseCids[0])
err := dhts[3].Provide(ctx, testCaseCids[0], true)
if err != nil {
t.Fatal(err)
}
......
......@@ -102,9 +102,9 @@
},
{
"author": "whyrusleeping",
"hash": "QmafuecpeZp3k3sHJ5mUARHd4795revuadECQMkmHB8LfW",
"hash": "QmXiH3yLocPhjkAmL8R29fKRcEKoVXKCaVDbAS9tdTrVEd",
"name": "go-libp2p-routing",
"version": "2.2.12"
"version": "2.2.13"
},
{
"author": "whyrusleeping",
......
......@@ -9,6 +9,7 @@ import (
"time"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
pb "github.com/libp2p/go-libp2p-kad-dht/pb"
kb "github.com/libp2p/go-libp2p-kbucket"
inet "github.com/libp2p/go-libp2p-net"
......@@ -240,11 +241,14 @@ func (dht *IpfsDHT) GetValues(ctx context.Context, key string, nvals int) ([]rou
// This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT.
// Provide makes this node announce that it can provide a value for the given key
func (dht *IpfsDHT) Provide(ctx context.Context, key *cid.Cid) error {
defer log.EventBegin(ctx, "provide", key).Done()
func (dht *IpfsDHT) Provide(ctx context.Context, key *cid.Cid, brdcst bool) error {
defer log.EventBegin(ctx, "provide", key, logging.LoggableMap{"broadcast": brdcst}).Done()
// add self locally
dht.providers.AddProvider(ctx, key, dht.self)
if !brdcst {
return nil
}
peers, err := dht.GetClosestPeers(ctx, key.KeyString())
if err != nil {
......
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