From cc777593c6159ad81c0a2ed21c4af9ef0598a6e4 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 3 May 2018 21:04:12 -0700 Subject: [PATCH] update for routing interface changes Specifically, remove GetValues --- mock/centralized_client.go | 15 +++------------ none/none_client.go | 12 +++++------- offline/offline.go | 26 +++----------------------- offline/offline_test.go | 6 +++--- package.json | 8 ++++---- 5 files changed, 18 insertions(+), 49 deletions(-) diff --git a/mock/centralized_client.go b/mock/centralized_client.go index f00f11a..c0d70f9 100644 --- a/mock/centralized_client.go +++ b/mock/centralized_client.go @@ -15,6 +15,7 @@ import ( pstore "github.com/libp2p/go-libp2p-peerstore" dhtpb "github.com/libp2p/go-libp2p-record/pb" routing "github.com/libp2p/go-libp2p-routing" + ropts "github.com/libp2p/go-libp2p-routing/options" "github.com/libp2p/go-testutil" ma "github.com/multiformats/go-multiaddr" ) @@ -28,7 +29,7 @@ type client struct { } // FIXME(brian): is this method meant to simulate putting a value into the network? -func (c *client) PutValue(ctx context.Context, key string, val []byte) error { +func (c *client) PutValue(ctx context.Context, key string, val []byte, opts ...ropts.Option) error { log.Debugf("PutValue: %s", key) rec := new(dhtpb.Record) rec.Value = val @@ -43,7 +44,7 @@ func (c *client) PutValue(ctx context.Context, key string, val []byte) error { } // FIXME(brian): is this method meant to simulate getting a value from the network? -func (c *client) GetValue(ctx context.Context, key string) ([]byte, error) { +func (c *client) GetValue(ctx context.Context, key string, opts ...ropts.Option) ([]byte, error) { log.Debugf("GetValue: %s", key) v, err := c.datastore.Get(dshelp.NewKeyFromBinary([]byte(key))) if err != nil { @@ -64,16 +65,6 @@ func (c *client) GetValue(ctx context.Context, key string) ([]byte, error) { return rec.GetValue(), nil } -func (c *client) GetValues(ctx context.Context, key string, count int) ([]routing.RecvdVal, error) { - log.Debugf("GetValues: %s", key) - data, err := c.GetValue(ctx, key) - if err != nil { - return nil, err - } - - return []routing.RecvdVal{{Val: data, From: c.peer.ID()}}, nil -} - func (c *client) FindProviders(ctx context.Context, key *cid.Cid) ([]pstore.PeerInfo, error) { return c.server.Providers(key), nil } diff --git a/none/none_client.go b/none/none_client.go index 8935708..a7c1f8f 100644 --- a/none/none_client.go +++ b/none/none_client.go @@ -10,24 +10,22 @@ import ( p2phost "github.com/libp2p/go-libp2p-host" peer "github.com/libp2p/go-libp2p-peer" pstore "github.com/libp2p/go-libp2p-peerstore" + record "github.com/libp2p/go-libp2p-record" routing "github.com/libp2p/go-libp2p-routing" + ropts "github.com/libp2p/go-libp2p-routing/options" ) type nilclient struct { } -func (c *nilclient) PutValue(_ context.Context, _ string, _ []byte) error { +func (c *nilclient) PutValue(_ context.Context, _ string, _ []byte, _ ...ropts.Option) error { return nil } -func (c *nilclient) GetValue(_ context.Context, _ string) ([]byte, error) { +func (c *nilclient) GetValue(_ context.Context, _ string, _ ...ropts.Option) ([]byte, error) { return nil, errors.New("tried GetValue from nil routing") } -func (c *nilclient) GetValues(_ context.Context, _ string, _ int) ([]routing.RecvdVal, error) { - return nil, errors.New("tried GetValues from nil routing") -} - func (c *nilclient) FindPeer(_ context.Context, _ peer.ID) (pstore.PeerInfo, error) { return pstore.PeerInfo{}, nil } @@ -47,7 +45,7 @@ func (c *nilclient) Bootstrap(_ context.Context) error { } // ConstructNilRouting creates an IpfsRouting client which does nothing. -func ConstructNilRouting(_ context.Context, _ p2phost.Host, _ ds.Batching) (routing.IpfsRouting, error) { +func ConstructNilRouting(_ context.Context, _ p2phost.Host, _ ds.Batching, _ record.Validator) (routing.IpfsRouting, error) { return &nilclient{}, nil } diff --git a/offline/offline.go b/offline/offline.go index f008e25..422af8d 100644 --- a/offline/offline.go +++ b/offline/offline.go @@ -17,6 +17,7 @@ import ( record "github.com/libp2p/go-libp2p-record" pb "github.com/libp2p/go-libp2p-record/pb" routing "github.com/libp2p/go-libp2p-routing" + ropts "github.com/libp2p/go-libp2p-routing/options" ) // ErrOffline is returned when trying to perform operations that @@ -41,7 +42,7 @@ type offlineRouting struct { sk ci.PrivKey } -func (c *offlineRouting) PutValue(ctx context.Context, key string, val []byte) error { +func (c *offlineRouting) PutValue(ctx context.Context, key string, val []byte, _ ...ropts.Option) error { rec := record.MakePutRecord(key, val) data, err := proto.Marshal(rec) if err != nil { @@ -51,7 +52,7 @@ func (c *offlineRouting) PutValue(ctx context.Context, key string, val []byte) e return c.datastore.Put(dshelp.NewKeyFromBinary([]byte(key)), data) } -func (c *offlineRouting) GetValue(ctx context.Context, key string) ([]byte, error) { +func (c *offlineRouting) GetValue(ctx context.Context, key string, _ ...ropts.Option) ([]byte, error) { v, err := c.datastore.Get(dshelp.NewKeyFromBinary([]byte(key))) if err != nil { return nil, err @@ -70,27 +71,6 @@ func (c *offlineRouting) GetValue(ctx context.Context, key string) ([]byte, erro return rec.GetValue(), nil } -func (c *offlineRouting) GetValues(ctx context.Context, key string, _ int) ([]routing.RecvdVal, error) { - v, err := c.datastore.Get(dshelp.NewKeyFromBinary([]byte(key))) - if err != nil { - return nil, err - } - - byt, ok := v.([]byte) - if !ok { - return nil, errors.New("value stored in datastore not []byte") - } - rec := new(pb.Record) - err = proto.Unmarshal(byt, rec) - if err != nil { - return nil, err - } - - return []routing.RecvdVal{ - {Val: rec.GetValue()}, - }, nil -} - func (c *offlineRouting) FindPeer(ctx context.Context, pid peer.ID) (pstore.PeerInfo, error) { return pstore.PeerInfo{}, ErrOffline } diff --git a/offline/offline_test.go b/offline/offline_test.go index 548822b..61670f4 100644 --- a/offline/offline_test.go +++ b/offline/offline_test.go @@ -7,6 +7,7 @@ import ( cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" + ropt "github.com/libp2p/go-libp2p-routing/options" testutil "github.com/libp2p/go-testutil" mh "github.com/multiformats/go-multihash" ) @@ -35,17 +36,16 @@ func TestOfflineRouterStorage(t *testing.T) { t.Fatal("Router should throw errors for unfound records") } - recVal, err := offline.GetValues(ctx, "key", 0) + local, err := offline.GetValue(ctx, "key", ropt.Offline) if err != nil { t.Fatal(err) } - _, err = offline.GetValues(ctx, "notHere", 0) + _, err = offline.GetValue(ctx, "notHere", ropt.Offline) if err == nil { t.Fatal("Router should throw errors for unfound records") } - local := recVal[0].Val if !bytes.Equal([]byte("testing 1 2 3"), local) { t.Fatal("OfflineRouter does not properly store") } diff --git a/package.json b/package.json index 4c5b595..cb00b31 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,9 @@ "version": "2.1.7" }, { - "hash": "QmZix3EdeAdc4wnRksRXWEQ6kbqiFAP16h3Sq9JnEiP71N", + "hash": "QmUHRKTeaoASDvDj7cTAXsmjAY7KQ13ErtzkQHZQq6uFUz", "name": "go-libp2p-routing", - "version": "2.2.22" + "version": "2.3.0" }, { "author": "whyrusleeping", @@ -55,9 +55,9 @@ "version": "1.2.1" }, { - "hash": "QmZ9V14gpwKsTUG7y5mHZDnHSF4Fa4rKsXNx7jSTEQ4JWs", + "hash": "QmTUyK82BVPA6LmSzEJpfEunk9uBaQzWtMsNP917tVj4sT", "name": "go-libp2p-record", - "version": "4.0.1" + "version": "4.1.0" }, { "author": "hsanjuan", -- GitLab