From 922c1a3fee62389132da428ea488834f74e85907 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 8 May 2024 10:47:07 +0200 Subject: [PATCH] chore: upgrade boxo with delegated provide --- core/corehttp/routing.go | 13 +++++++----- docs/examples/kubo-as-a-library/go.mod | 2 +- docs/examples/kubo-as-a-library/go.sum | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- routing/delegated.go | 7 +++++-- test/cli/content_routing_http_test.go | 21 ++++++++++++------- .../delegated_routing_v1_http_client_test.go | 16 +++++++------- test/dependencies/go.mod | 2 +- test/dependencies/go.sum | 4 ++-- 10 files changed, 44 insertions(+), 31 deletions(-) diff --git a/core/corehttp/routing.go b/core/corehttp/routing.go index 9a2591d32be..70a14b4665a 100644 --- a/core/corehttp/routing.go +++ b/core/corehttp/routing.go @@ -44,11 +44,6 @@ func (r *contentRouter) FindProviders(ctx context.Context, key cid.Cid, limit in }), nil } -// nolint deprecated -func (r *contentRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { - return 0, routing.ErrNotSupported -} - func (r *contentRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -96,6 +91,14 @@ func (r *contentRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipn return r.n.Routing.PutValue(ctx, string(name.RoutingKey()), raw) } +func (r *contentRouter) Provide(ctx context.Context, req *types.AnnouncementRecord) (time.Duration, error) { + return 0, routing.ErrNotSupported +} + +func (r *contentRouter) ProvidePeer(ctx context.Context, req *types.AnnouncementRecord) (time.Duration, error) { + return 0, routing.ErrNotSupported +} + type peerChanIter struct { ch <-chan peer.AddrInfo cancel context.CancelFunc diff --git a/docs/examples/kubo-as-a-library/go.mod b/docs/examples/kubo-as-a-library/go.mod index 7f43fcd5685..e2c712f4804 100644 --- a/docs/examples/kubo-as-a-library/go.mod +++ b/docs/examples/kubo-as-a-library/go.mod @@ -9,7 +9,7 @@ toolchain go1.22.0 replace github.com/ipfs/kubo => ./../../.. require ( - github.com/ipfs/boxo v0.19.1-0.20240415103851-7f9506844904 + github.com/ipfs/boxo v0.19.1-0.20240508083100-abf64fcd93a9 github.com/ipfs/kubo v0.0.0-00010101000000-000000000000 github.com/libp2p/go-libp2p v0.33.2 github.com/multiformats/go-multiaddr v0.12.3 diff --git a/docs/examples/kubo-as-a-library/go.sum b/docs/examples/kubo-as-a-library/go.sum index f3644a0f571..f03637df1c1 100644 --- a/docs/examples/kubo-as-a-library/go.sum +++ b/docs/examples/kubo-as-a-library/go.sum @@ -268,8 +268,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.19.1-0.20240415103851-7f9506844904 h1:HqjqN6oADXh1UNw8xKnBP50B3ZQDC/RStiBFPp6W+9Y= -github.com/ipfs/boxo v0.19.1-0.20240415103851-7f9506844904/go.mod h1:hA9Ou/YnfMZOG2nQhngsbBiYt6fiJ1EhWSmccZfV+M0= +github.com/ipfs/boxo v0.19.1-0.20240508083100-abf64fcd93a9 h1:zo800iXCJgIKt/s4R51/FFWdZS1KdyUONw3FrUt92e8= +github.com/ipfs/boxo v0.19.1-0.20240508083100-abf64fcd93a9/go.mod h1:hA9Ou/YnfMZOG2nQhngsbBiYt6fiJ1EhWSmccZfV+M0= 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 18548e25c16..7a05c88a9cd 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/hashicorp/go-multierror v1.1.1 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.19.1-0.20240415103851-7f9506844904 + github.com/ipfs/boxo v0.19.1-0.20240508083100-abf64fcd93a9 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 5e2d0d86a28..74278d95033 100644 --- a/go.sum +++ b/go.sum @@ -329,8 +329,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.19.1-0.20240415103851-7f9506844904 h1:HqjqN6oADXh1UNw8xKnBP50B3ZQDC/RStiBFPp6W+9Y= -github.com/ipfs/boxo v0.19.1-0.20240415103851-7f9506844904/go.mod h1:hA9Ou/YnfMZOG2nQhngsbBiYt6fiJ1EhWSmccZfV+M0= +github.com/ipfs/boxo v0.19.1-0.20240508083100-abf64fcd93a9 h1:zo800iXCJgIKt/s4R51/FFWdZS1KdyUONw3FrUt92e8= +github.com/ipfs/boxo v0.19.1-0.20240508083100-abf64fcd93a9/go.mod h1:hA9Ou/YnfMZOG2nQhngsbBiYt6fiJ1EhWSmccZfV+M0= 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/routing/delegated.go b/routing/delegated.go index e830c1aa197..65058c1e13e 100644 --- a/routing/delegated.go +++ b/routing/delegated.go @@ -23,6 +23,7 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" ma "github.com/multiformats/go-multiaddr" + "github.com/multiformats/go-multicodec" "go.opencensus.io/stats/view" ) @@ -203,8 +204,10 @@ func httpRoutingFromConfig(conf config.Router, extraHTTP *ExtraHTTPParams) (rout cli, err := drclient.New( params.Endpoint, drclient.WithHTTPClient(delegateHTTPClient), - drclient.WithIdentity(key), - drclient.WithProviderInfo(addrInfo.ID, addrInfo.Addrs), + drclient.WithProviderInfo(key, addrInfo.ID, addrInfo.Addrs, []string{ + multicodec.TransportBitswap.String(), + multicodec.TransportIpfsGatewayHttp.String(), + }), drclient.WithUserAgent(version.GetUserAgentVersion()), ) if err != nil { diff --git a/test/cli/content_routing_http_test.go b/test/cli/content_routing_http_test.go index aea5c41caeb..e2cd5ca1108 100644 --- a/test/cli/content_routing_http_test.go +++ b/test/cli/content_routing_http_test.go @@ -22,10 +22,11 @@ import ( ) type fakeHTTPContentRouter struct { - m sync.Mutex - provideBitswapCalls int - findProvidersCalls int - findPeersCalls int + m sync.Mutex + provideCalls int + providePeerCalls int + findProvidersCalls int + findPeersCalls int } func (r *fakeHTTPContentRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { @@ -35,11 +36,17 @@ func (r *fakeHTTPContentRouter) FindProviders(ctx context.Context, key cid.Cid, return iter.FromSlice([]iter.Result[types.Record]{}), nil } -// nolint deprecated -func (r *fakeHTTPContentRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { +func (r *fakeHTTPContentRouter) Provide(ctx context.Context, rec *types.AnnouncementRecord) (time.Duration, error) { r.m.Lock() defer r.m.Unlock() - r.provideBitswapCalls++ + r.provideCalls++ + return 0, nil +} + +func (r *fakeHTTPContentRouter) ProvidePeer(ctx context.Context, rec *types.AnnouncementRecord) (time.Duration, error) { + r.m.Lock() + defer r.m.Unlock() + r.providePeerCalls++ return 0, nil } diff --git a/test/cli/delegated_routing_v1_http_client_test.go b/test/cli/delegated_routing_v1_http_client_test.go index 44e62246bef..2e2cd80f19b 100644 --- a/test/cli/delegated_routing_v1_http_client_test.go +++ b/test/cli/delegated_routing_v1_http_client_test.go @@ -90,10 +90,10 @@ func TestHTTPDelegatedRouting(t *testing.T) { server := fakeServer("application/json", ToJSONStr(JSONObj{ "Providers": []JSONObj{ { - "Schema": "bitswap", // Legacy bitswap schema. - "Protocol": "transport-bitswap", - "ID": provs[1], - "Addrs": []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/tcp/4002"}, + "Schema": "peer", + "Protocols": []string{"transport-bitswap"}, + "ID": provs[1], + "Addrs": []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/tcp/4002"}, }, { "Schema": "peer", @@ -137,10 +137,10 @@ func TestHTTPDelegatedRouting(t *testing.T) { "ID": provs[0], "Addrs": []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/tcp/4002"}, }), ToJSONStr(JSONObj{ - "Schema": "bitswap", // Legacy bitswap schema. - "Protocol": "transport-bitswap", - "ID": provs[1], - "Addrs": []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/tcp/4002"}, + "Schema": "peer", + "Protocols": []string{"transport-bitswap"}, + "ID": provs[1], + "Addrs": []string{"/ip4/0.0.0.0/tcp/4001", "/ip4/0.0.0.0/tcp/4002"}, })) t.Cleanup(server.Close) diff --git a/test/dependencies/go.mod b/test/dependencies/go.mod index 86f0b73363e..0c20c598c74 100644 --- a/test/dependencies/go.mod +++ b/test/dependencies/go.mod @@ -105,7 +105,7 @@ require ( github.com/hexops/gotextdiff v1.0.3 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/ipfs/bbloom v0.0.4 // indirect - github.com/ipfs/boxo v0.19.1-0.20240415103851-7f9506844904 // indirect + github.com/ipfs/boxo v0.19.1-0.20240508083100-abf64fcd93a9 // indirect github.com/ipfs/go-block-format v0.2.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect diff --git a/test/dependencies/go.sum b/test/dependencies/go.sum index 14bb2aa25d4..27f4c70debd 100644 --- a/test/dependencies/go.sum +++ b/test/dependencies/go.sum @@ -362,8 +362,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2 github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= 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.19.1-0.20240415103851-7f9506844904 h1:HqjqN6oADXh1UNw8xKnBP50B3ZQDC/RStiBFPp6W+9Y= -github.com/ipfs/boxo v0.19.1-0.20240415103851-7f9506844904/go.mod h1:hA9Ou/YnfMZOG2nQhngsbBiYt6fiJ1EhWSmccZfV+M0= +github.com/ipfs/boxo v0.19.1-0.20240508083100-abf64fcd93a9 h1:zo800iXCJgIKt/s4R51/FFWdZS1KdyUONw3FrUt92e8= +github.com/ipfs/boxo v0.19.1-0.20240508083100-abf64fcd93a9/go.mod h1:hA9Ou/YnfMZOG2nQhngsbBiYt6fiJ1EhWSmccZfV+M0= github.com/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs= github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=