Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

feat: plumb through datastore contexts #25

Merged
merged 2 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/hashicorp/golang-lru v0.5.4
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-datastore v0.5.0
github.com/ipfs/go-ipfs-ds-help v0.1.1
github.com/ipfs/go-ipfs-keystore v0.0.2
github.com/ipfs/go-ipfs-routing v0.1.0
github.com/ipfs/go-ipns v0.1.0
github.com/ipfs/go-log v1.0.4
github.com/ipfs/go-ipfs-routing v0.2.1
github.com/ipfs/go-ipns v0.1.2
github.com/ipfs/go-log v1.0.5
github.com/ipfs/go-path v0.0.9
github.com/ipfs/interface-go-ipfs-core v0.4.0
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-libp2p v0.13.0
github.com/libp2p/go-libp2p-core v0.8.0
github.com/libp2p/go-libp2p-kad-dht v0.11.1
github.com/libp2p/go-libp2p-peerstore v0.2.6
github.com/libp2p/go-libp2p v0.16.0
github.com/libp2p/go-libp2p-core v0.11.0
github.com/libp2p/go-libp2p-kad-dht v0.15.0
github.com/libp2p/go-libp2p-peerstore v0.4.0
github.com/libp2p/go-libp2p-record v0.1.3
github.com/libp2p/go-libp2p-testing v0.4.0
github.com/miekg/dns v1.1.41
github.com/multiformats/go-multiaddr v0.3.1
github.com/libp2p/go-libp2p-testing v0.5.0
github.com/miekg/dns v1.1.43
github.com/multiformats/go-multiaddr v0.4.0
github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/multiformats/go-multihash v0.0.15
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc
Expand Down
958 changes: 867 additions & 91 deletions go.sum

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion ipns_resolver_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ func testResolverValidation(t *testing.T, keyType int) {
ctx := context.Background()
rid := testutil.RandIdentityOrFatal(t)
dstore := dssync.MutexWrap(ds.NewMapDatastore())
peerstore := pstoremem.NewPeerstore()
peerstore, err := pstoremem.NewPeerstore()
if err != nil {
t.Fatal(err)
}

vstore := newMockValueStore(rid, dstore, peerstore)
resolver := NewIpnsResolver(vstore)
Expand Down
10 changes: 8 additions & 2 deletions namesys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ func TestPublishWithCache0(t *testing.T) {
if err != nil {
t.Fatal(err)
}
ps := pstoremem.NewPeerstore()
ps, err := pstoremem.NewPeerstore()
if err != nil {
t.Fatal(err)
}
pid, err := peer.IDFromPrivateKey(priv)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -131,7 +134,10 @@ func TestPublishWithTTL(t *testing.T) {
if err != nil {
t.Fatal(err)
}
ps := pstoremem.NewPeerstore()
ps, err := pstoremem.NewPeerstore()
if err != nil {
t.Fatal(err)
}
pid, err := peer.IDFromPrivateKey(priv)
if err != nil {
t.Fatal(err)
Expand Down
8 changes: 4 additions & 4 deletions publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func IpnsDsKey(id peer.ID) ds.Key {
// This method will not search the routing system for records published by other
// nodes.
func (p *IpnsPublisher) ListPublished(ctx context.Context) (map[peer.ID]*pb.IpnsEntry, error) {
query, err := p.ds.Query(dsquery.Query{
query, err := p.ds.Query(ctx, dsquery.Query{
Prefix: ipnsPrefix,
})
if err != nil {
Expand Down Expand Up @@ -112,7 +112,7 @@ func (p *IpnsPublisher) GetPublished(ctx context.Context, id peer.ID, checkRouti
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()

value, err := p.ds.Get(IpnsDsKey(id))
value, err := p.ds.Get(ctx, IpnsDsKey(id))
switch err {
case nil:
case ds.ErrNotFound:
Expand Down Expand Up @@ -179,10 +179,10 @@ func (p *IpnsPublisher) updateRecord(ctx context.Context, k crypto.PrivKey, valu

// Put the new record.
key := IpnsDsKey(id)
if err := p.ds.Put(key, data); err != nil {
if err := p.ds.Put(ctx, key, data); err != nil {
return nil, err
}
if err := p.ds.Sync(key); err != nil {
if err := p.ds.Sync(ctx, key); err != nil {
return nil, err
}
return entry, nil
Expand Down
6 changes: 3 additions & 3 deletions publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func testNamekeyPublisher(t *testing.T, keyType int, expectedErr error, expected

// Also check datastore for completeness
key := dshelp.NewKeyFromBinary([]byte(namekey))
exists, err := dstore.Has(key)
exists, err := dstore.Has(ctx, key)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -150,7 +150,7 @@ type checkSyncDS struct {
syncKeys map[ds.Key]struct{}
}

func (d *checkSyncDS) Sync(prefix ds.Key) error {
func (d *checkSyncDS) Sync(ctx context.Context, prefix ds.Key) error {
d.syncKeys[prefix] = struct{}{}
return d.Datastore.Sync(prefix)
return d.Datastore.Sync(ctx, prefix)
}
6 changes: 3 additions & 3 deletions republisher/repub.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (rp *Republisher) republishEntry(ctx context.Context, priv ic.PrivKey) erro
log.Debugf("republishing ipns entry for %s", id)

// Look for it locally only
e, err := rp.getLastIPNSEntry(id)
e, err := rp.getLastIPNSEntry(ctx, id)
if err != nil {
if err == errNoEntry {
return nil
Expand All @@ -155,9 +155,9 @@ func (rp *Republisher) republishEntry(ctx context.Context, priv ic.PrivKey) erro
return rp.ns.PublishWithEOL(ctx, priv, p, eol)
}

func (rp *Republisher) getLastIPNSEntry(id peer.ID) (*pb.IpnsEntry, error) {
func (rp *Republisher) getLastIPNSEntry(ctx context.Context, id peer.ID) (*pb.IpnsEntry, error) {
// Look for it locally only
val, err := rp.ds.Get(namesys.IpnsDsKey(id))
val, err := rp.ds.Get(ctx, namesys.IpnsDsKey(id))
switch err {
case nil:
case ds.ErrNotFound:
Expand Down
7 changes: 3 additions & 4 deletions republisher/repub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func getMockNode(t *testing.T, ctx context.Context) *mockNode {
dstore := dssync.MutexWrap(ds.NewMapDatastore())
var idht *dht.IpfsDHT
h, err := libp2p.New(
ctx,
libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"),
libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
rt, err := dht.New(ctx, h, dht.Mode(dht.ModeServer))
Expand Down Expand Up @@ -208,7 +207,7 @@ func TestLongEOLRepublish(t *testing.T) {
t.Fatal(err)
}

entry, err := getLastIPNSEntry(publisher.store, publisher.h.ID())
entry, err := getLastIPNSEntry(ctx, publisher.store, publisher.h.ID())
if err != nil {
t.Fatal(err)
}
Expand All @@ -223,9 +222,9 @@ func TestLongEOLRepublish(t *testing.T) {
}
}

func getLastIPNSEntry(dstore ds.Datastore, id peer.ID) (*ipns_pb.IpnsEntry, error) {
func getLastIPNSEntry(ctx context.Context, dstore ds.Datastore, id peer.ID) (*ipns_pb.IpnsEntry, error) {
// Look for it locally only
val, err := dstore.Get(namesys.IpnsDsKey(id))
val, err := dstore.Get(ctx, namesys.IpnsDsKey(id))
if err != nil {
return nil, err
}
Expand Down