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

Commit

Permalink
Merge branch 'feat/backpressure' of github.com:ipfs/bifrost-gateway i…
Browse files Browse the repository at this point in the history
…nto feat/backpressure
  • Loading branch information
willscott committed Aug 9, 2023
2 parents addb2a1 + 0bbc0c4 commit 4958149
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ipfs/bifrost-gateway
go 1.19

require (
github.com/filecoin-saturn/caboose v0.0.5-0.20230807155604-954108a2dd1d
github.com/filecoin-saturn/caboose v0.0.5-0.20230808125624-a986b542aa10
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru/v2 v2.0.1
github.com/ipfs/boxo v0.11.1-0.20230803093408-3b83506a2ea5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/felixge/httpsnoop v1.0.0/go.mod h1:3+D9sFq0ahK/JeJPhCBUV1xlf4/eIYrUQaxulT0VzX8=
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/filecoin-saturn/caboose v0.0.5-0.20230807155604-954108a2dd1d h1:xLtdKE29tKgMF96S5CtMaV2PKzCUQ1zJC9J7cKJ022k=
github.com/filecoin-saturn/caboose v0.0.5-0.20230807155604-954108a2dd1d/go.mod h1:nmDICK/NKu6r3c6V6W/h6vi7Ep2b+jWbRbEg51ltkHs=
github.com/filecoin-saturn/caboose v0.0.5-0.20230808125624-a986b542aa10 h1:VZhzrXd6IuL52U18KtTQ/q4v48J90a1aDr/maLF3H9Y=
github.com/filecoin-saturn/caboose v0.0.5-0.20230808125624-a986b542aa10/go.mod h1:nmDICK/NKu6r3c6V6W/h6vi7Ep2b+jWbRbEg51ltkHs=
github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ=
github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
Expand Down
7 changes: 5 additions & 2 deletions lib/gateway_traversal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"github.com/filecoin-saturn/caboose"
"io"
"sync"
"time"
Expand All @@ -30,6 +31,8 @@ import (

type getBlock func(ctx context.Context, cid cid.Cid) (blocks.Block, error)

var ErrNilBlock = caboose.ErrInvalidResponse{Message: "received a nil block with no error"}

func carToLinearBlockGetter(ctx context.Context, reader io.Reader, metrics *GraphGatewayMetrics) (getBlock, error) {
cr, err := car.NewCarReaderWithOptions(reader, car.WithErrorOnEmptyRoots(false))
if err != nil {
Expand Down Expand Up @@ -94,11 +97,11 @@ func carToLinearBlockGetter(ctx context.Context, reader io.Reader, metrics *Grap
if blkRead.block != nil {
metrics.carBlocksFetchedMetric.Inc()
if !blkRead.block.Cid().Equals(c) {
return nil, fmt.Errorf("unexpected block received: expected %s, got %s", c, blkRead.block.Cid())
return nil, caboose.ErrInvalidResponse{Message: fmt.Sprintf("received block with cid %s, expected %s", blkRead.block.Cid(), c)}
}
return blkRead.block, nil
}
return nil, fmt.Errorf("received a nil block with no error")
return nil, ErrNilBlock

Check warning on line 104 in lib/gateway_traversal.go

View check run for this annotation

Codecov / codecov/patch

lib/gateway_traversal.go#L104

Added line #L104 was not covered by tests
}, nil
}

Expand Down

0 comments on commit 4958149

Please sign in to comment.