Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: IPIP-378 (delegated provide over HTTP /routing/v1) #10420

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions core/corehttp/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/kubo-as-a-library/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/kubo-as-a-library/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 5 additions & 2 deletions routing/delegated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 14 additions & 7 deletions test/cli/content_routing_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand Down
16 changes: 8 additions & 8 deletions test/cli/delegated_routing_v1_http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion test/dependencies/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/dependencies/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down