diff --git a/CHANGELOG.md b/CHANGELOG.md index 111044407..1f59cae02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ The following emojis are used to highlight certain changes: ### Added +* `boxo/gateway`: + * A new `WithResolver(...)` option can be used with `NewBlocksBackend(...)` allowing the user to pass their custom `Resolver` implementation. + ### Changed * `boxo/gateway` diff --git a/gateway/blocks_backend.go b/gateway/blocks_backend.go index db5f68924..d4edb8959 100644 --- a/gateway/blocks_backend.go +++ b/gateway/blocks_backend.go @@ -67,6 +67,7 @@ var _ IPFSBackend = (*BlocksBackend)(nil) type blocksBackendOptions struct { ns namesys.NameSystem vs routing.ValueStore + r resolver.Resolver } // WithNameSystem sets the name system to use with the [BlocksBackend]. If not set @@ -87,6 +88,14 @@ func WithValueStore(vs routing.ValueStore) BlocksBackendOption { } } +// WithResolver sets the [resolver.Resolver] to use with the [BlocksBackend]. +func WithResolver(r resolver.Resolver) BlocksBackendOption { + return func(opts *blocksBackendOptions) error { + opts.r = r + return nil + } +} + type BlocksBackendOption func(options *blocksBackendOptions) error func NewBlocksBackend(blockService blockservice.BlockService, opts ...BlocksBackendOption) (*BlocksBackend, error) { @@ -108,13 +117,12 @@ func NewBlocksBackend(blockService blockservice.BlockService, opts ...BlocksBack } return basicnode.Prototype.Any, nil }) - fetcher := fetcherConfig.WithReifier(unixfsnode.Reify) - r := resolver.NewBasicResolver(fetcher) // Setup a name system so that we are able to resolve /ipns links. var ( ns namesys.NameSystem vs routing.ValueStore + r resolver.Resolver ) vs = compiledOptions.vs @@ -135,6 +143,12 @@ func NewBlocksBackend(blockService blockservice.BlockService, opts ...BlocksBack } } + r = compiledOptions.r + if r == nil { + fetcher := fetcherConfig.WithReifier(unixfsnode.Reify) + r = resolver.NewBasicResolver(fetcher) + } + return &BlocksBackend{ blockStore: blockService.Blockstore(), blockService: blockService,