chore: upgrade boxo with delegated provide

This commit is contained in:
Henrique Dias 2024-05-08 10:47:07 +02:00
parent 2841ec0fcd
commit 922c1a3fee
No known key found for this signature in database
10 changed files with 44 additions and 31 deletions

View File

@ -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

View File

@ -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

View File

@ -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=

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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 {

View File

@ -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
}

View File

@ -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)

View File

@ -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

View File

@ -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=