mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-25 14:52:14 +00:00
update to use no-broadcast option
This commit is contained in:
parent
f02c72d540
commit
04ee593ef6
41
dht_test.go
41
dht_test.go
@ -216,7 +216,7 @@ func TestProvides(t *testing.T) {
|
|||||||
|
|
||||||
for _, k := range testCaseCids {
|
for _, k := range testCaseCids {
|
||||||
log.Debugf("announcing provider for %s", k)
|
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)
|
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.
|
// if minPeers or avgPeers is 0, dont test for it.
|
||||||
func waitForWellFormedTables(t *testing.T, dhts []*IpfsDHT, minPeers, avgPeers int, timeout time.Duration) bool {
|
func waitForWellFormedTables(t *testing.T, dhts []*IpfsDHT, minPeers, avgPeers int, timeout time.Duration) bool {
|
||||||
// test "well-formed-ness" (>= minPeers peers in every routing table)
|
// test "well-formed-ness" (>= minPeers peers in every routing table)
|
||||||
@ -471,7 +506,7 @@ func TestProvidesMany(t *testing.T) {
|
|||||||
providers[c.KeyString()] = dht.self
|
providers[c.KeyString()] = dht.self
|
||||||
|
|
||||||
t.Logf("announcing provider for %s", c)
|
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)
|
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[2])
|
||||||
connect(t, ctx, dhts[1], dhts[3])
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -102,9 +102,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"author": "whyrusleeping",
|
"author": "whyrusleeping",
|
||||||
"hash": "QmafuecpeZp3k3sHJ5mUARHd4795revuadECQMkmHB8LfW",
|
"hash": "QmXiH3yLocPhjkAmL8R29fKRcEKoVXKCaVDbAS9tdTrVEd",
|
||||||
"name": "go-libp2p-routing",
|
"name": "go-libp2p-routing",
|
||||||
"version": "2.2.12"
|
"version": "2.2.13"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"author": "whyrusleeping",
|
"author": "whyrusleeping",
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
cid "github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
|
logging "github.com/ipfs/go-log"
|
||||||
pb "github.com/libp2p/go-libp2p-kad-dht/pb"
|
pb "github.com/libp2p/go-libp2p-kad-dht/pb"
|
||||||
kb "github.com/libp2p/go-libp2p-kbucket"
|
kb "github.com/libp2p/go-libp2p-kbucket"
|
||||||
inet "github.com/libp2p/go-libp2p-net"
|
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.
|
// 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
|
// 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 {
|
func (dht *IpfsDHT) Provide(ctx context.Context, key *cid.Cid, brdcst bool) error {
|
||||||
defer log.EventBegin(ctx, "provide", key).Done()
|
defer log.EventBegin(ctx, "provide", key, logging.LoggableMap{"broadcast": brdcst}).Done()
|
||||||
|
|
||||||
// add self locally
|
// add self locally
|
||||||
dht.providers.AddProvider(ctx, key, dht.self)
|
dht.providers.AddProvider(ctx, key, dht.self)
|
||||||
|
if !brdcst {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
peers, err := dht.GetClosestPeers(ctx, key.KeyString())
|
peers, err := dht.GetClosestPeers(ctx, key.KeyString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user