From 991f2c382b451e5335fcdfdfbfe7fcac3b0dde2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 31 Aug 2018 14:46:09 +0200 Subject: [PATCH] Implement SearchValue --- mock/centralized_client.go | 7 ++++++- none/none_client.go | 4 ++++ offline/offline.go | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mock/centralized_client.go b/mock/centralized_client.go index 49a3633..7faad9a 100644 --- a/mock/centralized_client.go +++ b/mock/centralized_client.go @@ -34,7 +34,12 @@ func (c *client) GetValue(ctx context.Context, key string, opts ...ropts.Option) return c.vs.GetValue(ctx, key, opts...) } -func (c *client) FindProviders(ctx context.Context, key cid.Cid) ([]pstore.PeerInfo, error) { +func (c *client) SearchValue(ctx context.Context, key string, opts ...ropts.Option) (<-chan []byte, error) { + log.Debugf("SearchValue: %s", key) + return c.vs.SearchValue(ctx, key, opts...) +} + +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 e29ef36..45febc5 100644 --- a/none/none_client.go +++ b/none/none_client.go @@ -26,6 +26,10 @@ func (c *nilclient) GetValue(_ context.Context, _ string, _ ...ropts.Option) ([] return nil, errors.New("tried GetValue from nil routing") } +func (c *nilclient) SearchValue(_ context.Context, _ string, _ ...ropts.Option) (<-chan []byte, error) { + return nil, errors.New("tried SearchValue from nil routing") +} + func (c *nilclient) FindPeer(_ context.Context, _ peer.ID) (pstore.PeerInfo, error) { return pstore.PeerInfo{}, nil } diff --git a/offline/offline.go b/offline/offline.go index 9b94176..d2011fd 100644 --- a/offline/offline.go +++ b/offline/offline.go @@ -90,6 +90,19 @@ func (c *offlineRouting) GetValue(ctx context.Context, key string, _ ...ropts.Op return val, nil } +func (c *offlineRouting) SearchValue(ctx context.Context, key string, _ ...ropts.Option) (<-chan []byte, error) { + out := make(chan []byte) + go func() { + defer close(out) + v, _ := c.GetValue(ctx, key) + select { + case out <- v: + case <-ctx.Done(): + } + }() + return out, nil +} + func (c *offlineRouting) FindPeer(ctx context.Context, pid peer.ID) (pstore.PeerInfo, error) { return pstore.PeerInfo{}, ErrOffline } -- GitLab