From 580f84a75f8c3486ad88da5656bc3b43bf50ba4c Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Tue, 11 Aug 2020 18:42:20 -0400 Subject: [PATCH 1/3] fix: queue: switch from using a time based counter to a monotonic one This commit was moved from ipfs/go-ipfs-provider@071d037e32b3589f2065568d981f46a999b43a87 --- provider/queue/queue.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/provider/queue/queue.go b/provider/queue/queue.go index 2c3350256..4e31c8cae 100644 --- a/provider/queue/queue.go +++ b/provider/queue/queue.go @@ -3,8 +3,6 @@ package queue import ( "context" "fmt" - "time" - cid "github.com/ipfs/go-cid" datastore "github.com/ipfs/go-datastore" namespace "github.com/ipfs/go-datastore/namespace" @@ -29,6 +27,8 @@ type Queue struct { enqueue chan cid.Cid close context.CancelFunc closed chan struct{} + + counter int } // NewQueue creates a queue for cids @@ -117,7 +117,8 @@ func (q *Queue) work() { select { case toQueue := <-q.enqueue: - keyPath := fmt.Sprintf("%d/%s", time.Now().UnixNano(), c.String()) + keyPath := fmt.Sprintf("%063d/%s", q.counter, c.String()) + q.counter++ nextKey := datastore.NewKey(keyPath) if err := q.ds.Put(nextKey, toQueue.Bytes()); err != nil { From 3605c1683b7ca482719c534eb781f72caa46f4e0 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Tue, 6 Dec 2022 13:47:01 +0000 Subject: [PATCH 2/3] stop using the deprecated io/ioutil package This commit was moved from ipfs/go-ipfs-provider@93e3121406f147f1b5246359451e005a47eb30ea --- provider/offline.go | 1 + provider/provider.go | 1 + provider/system.go | 1 + 3 files changed, 3 insertions(+) diff --git a/provider/offline.go b/provider/offline.go index 5511364ed..030a70ab1 100644 --- a/provider/offline.go +++ b/provider/offline.go @@ -2,6 +2,7 @@ package provider import ( "context" + "github.com/ipfs/go-cid" ) diff --git a/provider/provider.go b/provider/provider.go index 7dec4c172..3b9c6ba3e 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -2,6 +2,7 @@ package provider import ( "context" + "github.com/ipfs/go-cid" ) diff --git a/provider/system.go b/provider/system.go index b3e17ee40..9fc3e8879 100644 --- a/provider/system.go +++ b/provider/system.go @@ -2,6 +2,7 @@ package provider import ( "context" + "github.com/ipfs/go-cid" ) From 02df8225c4e4071110d2229fd152654d232eb754 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Fri, 9 Dec 2022 12:02:52 +0100 Subject: [PATCH 3/3] fix: multihash keying in the tests This commit was moved from ipfs/go-ipfs-provider@8d650d573dc43033fca464c58856bcaa36c24ec8 --- provider/simple/reprovide_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/provider/simple/reprovide_test.go b/provider/simple/reprovide_test.go index 4d5563b0d..e29d6e408 100644 --- a/provider/simple/reprovide_test.go +++ b/provider/simple/reprovide_test.go @@ -127,6 +127,14 @@ func testReprovide(t *testing.T, trigger func(r *Reprovider, ctx context.Context maxProvs := 100 for _, c := range nodes { + // We provide raw cids because of the multihash keying + // FIXME(@Jorropo): I think this change should be done in the DHT layer, probably an issue with our routing mock. + b := c.Bytes() + b[1] = 0x55 // rewrite the cid to raw + _, c, err := cid.CidFromBytes(b) + if err != nil { + t.Fatal(err) + } provChan := clB.FindProvidersAsync(ctx, c, maxProvs) for p := range provChan { providers = append(providers, p)