Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn instead of failing in double hashed client #14

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Changes from all commits
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
19 changes: 14 additions & 5 deletions find/client/http/dhash_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

logging "github.com/ipfs/go-log/v2"
"github.com/ipni/go-libipni/apierror"
"github.com/ipni/go-libipni/dhash"
"github.com/ipni/go-libipni/find/model"
Expand All @@ -20,9 +21,12 @@ import (

const (
metadataPath = "metadata"
pcacheTTL = 5 * time.Minute
// pcacheTTL is the time to live for provider info cache.
pcacheTTL = 5 * time.Minute
)

var log = logging.Logger("dhash-client")

type DHashClient struct {
Client

Expand Down Expand Up @@ -126,25 +130,30 @@ func (c *DHashClient) decryptFindResponse(ctx context.Context, resp *model.FindR
}
for _, evk := range encRes.EncryptedValueKeys {
vk, err := dhash.DecryptValueKey(evk, mh)
// skip errors as we don't want to fail the whole query, warn instead. Same applies to the rest of the loop.
if err != nil {
return err
log.Warnw("Error decrypting value key", "multihash", mh.B58String(), "evk", b58.Encode(evk), "err", err)
continue
}

pid, ctxId, err := dhash.SplitValueKey(vk)
if err != nil {
return err
log.Warnw("Error splitting value key", "multihash", mh.B58String(), "evk", b58.Encode(evk), "err", err)
continue
}

// fetch metadata
metadata, err := c.fetchMetadata(ctx, vk)
if err != nil {
return err
log.Warnw("Error fetching metadata", "multihash", mh.B58String(), "evk", b58.Encode(evk), "err", err)
continue
}

// fetch provider info alongside extended providers
results, err := c.pcache.getResults(ctx, pid, ctxId, metadata)
if err != nil {
return err
log.Warnw("Error fetching provider info", "multihash", mh.B58String(), "evk", b58.Encode(evk), "err", err)
continue
}

mhr.ProviderResults = append(mhr.ProviderResults, results...)
Expand Down