Skip to content

Commit b8ff03a

Browse files
authored
Drop support for FindBatch API (#71)
* Drop support for FindBatch API * Use update go-libipni to latest * Print "index not found" when dh lookup has no provider results * update version
1 parent 00256ac commit b8ff03a

File tree

5 files changed

+20
-67
lines changed

5 files changed

+20
-67
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/ipfs/go-log/v2 v2.5.1
1010
github.com/ipld/go-car/v2 v2.13.1
1111
github.com/ipld/go-ipld-prime v0.21.0
12-
github.com/ipni/go-libipni v0.5.1
12+
github.com/ipni/go-libipni v0.5.2
1313
github.com/libp2p/go-libp2p v0.31.0
1414
github.com/mattn/go-isatty v0.0.19
1515
github.com/montanaflynn/stats v0.7.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ github.com/ipld/go-codec-dagpb v1.6.0/go.mod h1:ANzFhfP2uMJxRBr8CE+WQWs5UsNa0pYt
271271
github.com/ipld/go-ipld-prime v0.21.0 h1:n4JmcpOlPDIxBcY037SVfpd1G+Sj1nKZah0m6QH9C2E=
272272
github.com/ipld/go-ipld-prime v0.21.0/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ=
273273
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20230102063945-1a409dc236dd h1:gMlw/MhNr2Wtp5RwGdsW23cs+yCuj9k2ON7i9MiJlRo=
274-
github.com/ipni/go-libipni v0.5.1 h1:HumuJtKmV8RoDpBakLgxCSl5QPiD2ljTZl/NOyXO6nM=
275-
github.com/ipni/go-libipni v0.5.1/go.mod h1:UnrhEqjVI2Z2HXlaieOBONJmtW557nZkYpB4IIsMD+s=
274+
github.com/ipni/go-libipni v0.5.2 h1:9vaYOnR4dskd8p88NOboqI6yVqBwYPNCQ/zOaRSr59I=
275+
github.com/ipni/go-libipni v0.5.2/go.mod h1:UnrhEqjVI2Z2HXlaieOBONJmtW557nZkYpB4IIsMD+s=
276276
github.com/ipsn/go-secp256k1 v0.0.0-20180726113642-9d62b9f0bc52 h1:QG4CGBqCeuBo6aZlGAamSkxWdgWfZGeE49eUOWJPA4c=
277277
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
278278
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=

pkg/find/find.go

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ package find
22

33
import (
44
"encoding/base64"
5-
"errors"
65
"fmt"
7-
"net/http"
86
"strings"
97

108
"github.com/ipfs/go-cid"
11-
"github.com/ipni/go-libipni/apierror"
129
"github.com/ipni/go-libipni/find/client"
1310
"github.com/ipni/go-libipni/find/model"
1411
"github.com/ipni/go-libipni/metadata"
@@ -115,22 +112,9 @@ func dhFind(cctx *cli.Context, mhs []multihash.Multihash) error {
115112
return err
116113
}
117114

118-
var resp *model.FindResponse
119-
for _, mh := range mhs {
120-
r, err := cl.Find(cctx.Context, mh)
121-
if err != nil {
122-
// TODO: Look for error that specifies double-hashing not supported.
123-
var ae *apierror.Error
124-
if errors.As(err, &ae) && ae.Status() == http.StatusNotFound {
125-
continue
126-
}
127-
return err
128-
}
129-
if resp == nil {
130-
resp = r
131-
} else {
132-
resp.MultihashResults = append(resp.MultihashResults, r.MultihashResults...)
133-
}
115+
resp, err := client.FindBatch(cctx.Context, cl, mhs)
116+
if err != nil {
117+
return err
134118
}
135119
if resp == nil && cctx.Bool("fallback") {
136120
return clearFind(cctx, mhs)
@@ -149,16 +133,10 @@ func clearFind(cctx *cli.Context, mhs []multihash.Multihash) error {
149133
return err
150134
}
151135

152-
var resp *model.FindResponse
153-
if len(mhs) == 1 {
154-
resp, err = cl.Find(cctx.Context, mhs[0])
155-
} else {
156-
resp, err = cl.FindBatch(cctx.Context, mhs)
157-
}
136+
resp, err := client.FindBatch(cctx.Context, cl, mhs)
158137
if err != nil {
159138
return err
160139
}
161-
162140
return printResults(cctx, resp)
163141
}
164142

@@ -184,6 +162,10 @@ func printResults(cctx *cli.Context, resp *model.FindResponse) error {
184162

185163
for i := range resp.MultihashResults {
186164
fmt.Println("Multihash:", resp.MultihashResults[i].Multihash.B58String())
165+
if len(resp.MultihashResults[i].ProviderResults) == 0 {
166+
fmt.Println(" index not found")
167+
continue
168+
}
187169
// Group results by provider.
188170
providers := make(map[string][]model.ProviderResult)
189171
for _, pr := range resp.MultihashResults[i].ProviderResults {

pkg/verify/ingest.go

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package verify
22

33
import (
4-
"context"
54
"errors"
65
"fmt"
76
"math/rand"
@@ -651,26 +650,27 @@ func verifyIngestFromMhs(cctx *cli.Context, find *client.Client, dhFind *client.
651650
}
652651

653652
func verifyIngest(cctx *cli.Context, find *client.Client, dhFind *client.DHashClient, wantProvID peer.ID, mhs []multihash.Multihash) (*verifyResult, error) {
654-
result := &verifyResult{}
655-
mhsCount := len(mhs)
656-
result.TotalMhChecked = mhsCount
653+
result := &verifyResult{
654+
TotalMhChecked: len(mhs),
655+
}
657656

658657
var response *model.FindResponse
659658
var err error
660659
if dhFind != nil {
661-
response, err = doDHFind(cctx.Context, dhFind, mhs)
660+
response, err = client.FindBatch(cctx.Context, dhFind, mhs)
661+
fmt.Println("🔒 Reader privacy enabled")
662662
} else {
663-
response, err = doClearFind(cctx.Context, find, mhs)
663+
response, err = client.FindBatch(cctx.Context, find, mhs)
664664
}
665665
if err != nil {
666-
result.FailedToVerify = mhsCount
666+
result.FailedToVerify = len(mhs)
667667
err = fmt.Errorf("failed to connect to indexer: %w", err)
668668
result.Errs = append(result.Errs, err)
669669
return result, nil
670670
}
671671

672672
if response == nil || len(response.MultihashResults) == 0 {
673-
result.Absent = mhsCount
673+
result.Absent = len(mhs)
674674
return result, nil
675675
}
676676

@@ -701,32 +701,3 @@ func verifyIngest(cctx *cli.Context, find *client.Client, dhFind *client.DHashCl
701701
}
702702
return result, nil
703703
}
704-
705-
func doDHFind(ctx context.Context, cl *client.DHashClient, mhs []multihash.Multihash) (*model.FindResponse, error) {
706-
var resp *model.FindResponse
707-
for _, mh := range mhs {
708-
r, err := cl.Find(ctx, mh)
709-
if err != nil {
710-
// TODO: Look for error that specifies double-hashing not supported.
711-
var ae *apierror.Error
712-
if errors.As(err, &ae) && ae.Status() == http.StatusNotFound {
713-
continue
714-
}
715-
return nil, err
716-
}
717-
if resp == nil {
718-
resp = r
719-
} else {
720-
resp.MultihashResults = append(resp.MultihashResults, r.MultihashResults...)
721-
}
722-
}
723-
fmt.Println("🔒 Reader privacy enabled")
724-
return resp, nil
725-
}
726-
727-
func doClearFind(ctx context.Context, cl *client.Client, mhs []multihash.Multihash) (*model.FindResponse, error) {
728-
if len(mhs) == 1 {
729-
return cl.Find(ctx, mhs[0])
730-
}
731-
return cl.FindBatch(ctx, mhs)
732-
}

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "v0.1.1"
2+
"version": "v0.1.2"
33
}

0 commit comments

Comments
 (0)