From 1034a1739f6f56fd5091553632839b945570ba14 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Thu, 21 Nov 2024 15:30:42 +0100 Subject: [PATCH] Update to boxo with refactored providerQueryManager. --- core/commands/bitswap.go | 1 - core/coreapi/pin.go | 2 +- core/coreapi/unixfs.go | 2 +- core/node/bitswap.go | 14 +++++++++----- core/node/groups.go | 4 ++-- docs/examples/kubo-as-a-library/go.mod | 2 +- docs/examples/kubo-as-a-library/go.sum | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 9 files changed, 19 insertions(+), 16 deletions(-) diff --git a/core/commands/bitswap.go b/core/commands/bitswap.go index 07f91fb0f52..cb747232f4b 100644 --- a/core/commands/bitswap.go +++ b/core/commands/bitswap.go @@ -134,7 +134,6 @@ var bitswapStatCmd = &cmds.Command{ human, _ := req.Options[bitswapHumanOptionName].(bool) fmt.Fprintln(w, "bitswap status") - fmt.Fprintf(w, "\tprovides buffer: %d / %d\n", s.ProvideBufLen, bitswap.HasBlockBufferSize) fmt.Fprintf(w, "\tblocks received: %d\n", s.BlocksReceived) fmt.Fprintf(w, "\tblocks sent: %d\n", s.BlocksSent) if human { diff --git a/core/coreapi/pin.go b/core/coreapi/pin.go index 22b3aa25c24..64c65b651c2 100644 --- a/core/coreapi/pin.go +++ b/core/coreapi/pin.go @@ -44,7 +44,7 @@ func (api *PinAPI) Add(ctx context.Context, p path.Path, opts ...caopts.PinAddOp return fmt.Errorf("pin: %s", err) } - if err := api.provider.Provide(dagNode.Cid()); err != nil { + if err := api.provider.Provide(ctx, dagNode.Cid(), true); err != nil { return err } diff --git a/core/coreapi/unixfs.go b/core/coreapi/unixfs.go index e175488f37f..dbeeefda426 100644 --- a/core/coreapi/unixfs.go +++ b/core/coreapi/unixfs.go @@ -173,7 +173,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options } if !settings.OnlyHash { - if err := api.provider.Provide(nd.Cid()); err != nil { + if err := api.provider.Provide(ctx, nd.Cid(), true); err != nil { return path.ImmutablePath{}, err } } diff --git a/core/node/bitswap.go b/core/node/bitswap.go index 4132d5a0186..70c57306463 100644 --- a/core/node/bitswap.go +++ b/core/node/bitswap.go @@ -5,6 +5,7 @@ import ( "time" "github.com/ipfs/boxo/bitswap" + "github.com/ipfs/boxo/bitswap/client" "github.com/ipfs/boxo/bitswap/network" blockstore "github.com/ipfs/boxo/blockstore" exchange "github.com/ipfs/boxo/exchange" @@ -34,7 +35,7 @@ type bitswapOptionsOut struct { // BitswapOptions creates configuration options for Bitswap from the config file // and whether to provide data. -func BitswapOptions(cfg *config.Config, provide bool) interface{} { +func BitswapOptions(cfg *config.Config) interface{} { return func() bitswapOptionsOut { var internalBsCfg config.InternalBitswap if cfg.Internal.Bitswap != nil { @@ -42,7 +43,6 @@ func BitswapOptions(cfg *config.Config, provide bool) interface{} { } opts := []bitswap.Option{ - bitswap.ProvideEnabled(provide), bitswap.ProviderSearchDelay(internalBsCfg.ProviderSearchDelay.WithDefault(DefaultProviderSearchDelay)), // See https://github.com/ipfs/go-ipfs/issues/8807 for rationale bitswap.EngineBlockstoreWorkerCount(int(internalBsCfg.EngineBlockstoreWorkerCount.WithDefault(DefaultEngineBlockstoreWorkerCount))), bitswap.TaskWorkerCount(int(internalBsCfg.TaskWorkerCount.WithDefault(DefaultTaskWorkerCount))), @@ -68,11 +68,15 @@ type onlineExchangeIn struct { // OnlineExchange creates new LibP2P backed block exchange (BitSwap). // Additional options to bitswap.New can be provided via the "bitswap-options" // group. -func OnlineExchange() interface{} { +func OnlineExchange(provide bool) interface{} { return func(in onlineExchangeIn, lc fx.Lifecycle) exchange.Interface { - bitswapNetwork := network.NewFromIpfsHost(in.Host, in.Rt) + bitswapNetwork := network.NewFromIpfsHost(in.Host) - exch := bitswap.New(helpers.LifecycleCtx(in.Mctx, lc), bitswapNetwork, in.Bs, in.BitswapOpts...) + var provider client.ProviderFinder + if provide { + provider = in.Rt + } + exch := bitswap.New(helpers.LifecycleCtx(in.Mctx, lc), bitswapNetwork, provider, in.Bs, in.BitswapOpts...) lc.Append(fx.Hook{ OnStop: func(ctx context.Context) error { return exch.Close() diff --git a/core/node/groups.go b/core/node/groups.go index c74d0be8a2c..a868aa567fe 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -293,8 +293,8 @@ func Online(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part shouldBitswapProvide := !cfg.Experimental.StrategicProviding return fx.Options( - fx.Provide(BitswapOptions(cfg, shouldBitswapProvide)), - fx.Provide(OnlineExchange()), + fx.Provide(BitswapOptions(cfg)), + fx.Provide(OnlineExchange(shouldBitswapProvide)), fx.Provide(DNSResolver), fx.Provide(Namesys(ipnsCacheSize, cfg.Ipns.MaxCacheTTL.WithDefault(config.DefaultIpnsMaxCacheTTL))), fx.Provide(Peering), diff --git a/docs/examples/kubo-as-a-library/go.mod b/docs/examples/kubo-as-a-library/go.mod index d3b7aee834a..d0b49cf89af 100644 --- a/docs/examples/kubo-as-a-library/go.mod +++ b/docs/examples/kubo-as-a-library/go.mod @@ -7,7 +7,7 @@ go 1.23 replace github.com/ipfs/kubo => ./../../.. require ( - github.com/ipfs/boxo v0.24.4-0.20241119153247-5929aca3037f + github.com/ipfs/boxo v0.24.4-0.20241121153214-19cd67f043dc github.com/ipfs/kubo v0.0.0-00010101000000-000000000000 github.com/libp2p/go-libp2p v0.37.0 github.com/multiformats/go-multiaddr v0.13.0 diff --git a/docs/examples/kubo-as-a-library/go.sum b/docs/examples/kubo-as-a-library/go.sum index f4da6f07adc..0ac9b417927 100644 --- a/docs/examples/kubo-as-a-library/go.sum +++ b/docs/examples/kubo-as-a-library/go.sum @@ -298,8 +298,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI= github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/boxo v0.24.4-0.20241119153247-5929aca3037f h1:3qgBUQ6BYfEAPaoSYoH90PKwVT1/iFLX7fDGGkvXZ8Y= -github.com/ipfs/boxo v0.24.4-0.20241119153247-5929aca3037f/go.mod h1:Kxk43F+avGAsJSwhJW4isNYrpGwXHRJCvJ19Pt+MQc4= +github.com/ipfs/boxo v0.24.4-0.20241121153214-19cd67f043dc h1:Im4a0M2v/bOHs2hwCuAfQk1+QFK5tKyzyNjHTVXY4jA= +github.com/ipfs/boxo v0.24.4-0.20241121153214-19cd67f043dc/go.mod h1:Kxk43F+avGAsJSwhJW4isNYrpGwXHRJCvJ19Pt+MQc4= github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA= github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU= github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ= diff --git a/go.mod b/go.mod index 5de417a990e..0b479ede91e 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/hashicorp/go-version v1.7.0 github.com/ipfs-shipyard/nopfs v0.0.12 github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c - github.com/ipfs/boxo v0.24.4-0.20241119153247-5929aca3037f + github.com/ipfs/boxo v0.24.4-0.20241121153214-19cd67f043dc github.com/ipfs/go-block-format v0.2.0 github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-cidutil v0.1.0 diff --git a/go.sum b/go.sum index abf6d83d9b7..f8c6a22ecac 100644 --- a/go.sum +++ b/go.sum @@ -362,8 +362,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI= github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/boxo v0.24.4-0.20241119153247-5929aca3037f h1:3qgBUQ6BYfEAPaoSYoH90PKwVT1/iFLX7fDGGkvXZ8Y= -github.com/ipfs/boxo v0.24.4-0.20241119153247-5929aca3037f/go.mod h1:Kxk43F+avGAsJSwhJW4isNYrpGwXHRJCvJ19Pt+MQc4= +github.com/ipfs/boxo v0.24.4-0.20241121153214-19cd67f043dc h1:Im4a0M2v/bOHs2hwCuAfQk1+QFK5tKyzyNjHTVXY4jA= +github.com/ipfs/boxo v0.24.4-0.20241121153214-19cd67f043dc/go.mod h1:Kxk43F+avGAsJSwhJW4isNYrpGwXHRJCvJ19Pt+MQc4= github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA= github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU= github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ=