diff --git a/core/corehttp/routing.go b/core/corehttp/routing.go index 25267f8c6480..e5b1edeb0e7a 100644 --- a/core/corehttp/routing.go +++ b/core/corehttp/routing.go @@ -111,11 +111,12 @@ func (it *peerChanIter) Val() types.Record { return nil } - // We don't know what type of protocol this peer provides. It is likely Bitswap - // but it might not be. Therefore, we set an unknown protocol with an unknown schema. rec := &types.PeerRecord{ Schema: types.SchemaPeer, ID: &it.next.ID, + // We need to add this here, otherwise contentrouter will ignore the peer + // as it does not have transport bitswap available. + Protocols: []string{"transport-bitswap"}, } for _, addr := range it.next.Addrs { diff --git a/docs/examples/kubo-as-a-library/go.mod b/docs/examples/kubo-as-a-library/go.mod index 629509ddd690..9c4fa7512bf6 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.20 replace github.com/ipfs/kubo => ./../../.. require ( - github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544 + github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff github.com/ipfs/kubo v0.0.0-00010101000000-000000000000 github.com/libp2p/go-libp2p v0.30.0 github.com/multiformats/go-multiaddr v0.11.0 diff --git a/docs/examples/kubo-as-a-library/go.sum b/docs/examples/kubo-as-a-library/go.sum index ebdc9c9eca9d..79a83b6177b3 100644 --- a/docs/examples/kubo-as-a-library/go.sum +++ b/docs/examples/kubo-as-a-library/go.sum @@ -300,8 +300,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 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.12.1-0.20230824094523-a2001ba61544 h1:XVq+wUNFx1Ufakz35MAWk+Rr5bAC7lwx1NbJ6Mslp48= -github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk= +github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff h1:IpyDgsSCTbMcEqKVsbE8S73lV2e9V2J/Tr82zpYb/mg= +github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk= 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-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY= diff --git a/go.mod b/go.mod index 440a19dd57ca..3614721f425b 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/fsnotify/fsnotify v1.6.0 github.com/google/uuid v1.3.0 github.com/hashicorp/go-multierror v1.1.1 - github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544 + github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff github.com/ipfs/go-block-format v0.1.2 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 9cdf2205cb5d..1563457d2eb2 100644 --- a/go.sum +++ b/go.sum @@ -335,8 +335,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 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.12.1-0.20230824094523-a2001ba61544 h1:XVq+wUNFx1Ufakz35MAWk+Rr5bAC7lwx1NbJ6Mslp48= -github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk= +github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff h1:IpyDgsSCTbMcEqKVsbE8S73lV2e9V2J/Tr82zpYb/mg= +github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk= 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/wrapper.go b/routing/wrapper.go index debc785963de..680aef263d25 100644 --- a/routing/wrapper.go +++ b/routing/wrapper.go @@ -29,9 +29,3 @@ type httpRoutingWrapper struct { func (c *httpRoutingWrapper) Bootstrap(ctx context.Context) error { return nil } - -func (c *httpRoutingWrapper) SearchValue(context.Context, string, ...routing.Option) (<-chan []byte, error) { - out := make(chan []byte) - close(out) - return out, routing.ErrNotSupported -} diff --git a/test/cli/delegated_routing_v1_http_proxy_test.go b/test/cli/delegated_routing_v1_http_proxy_test.go new file mode 100644 index 000000000000..a87fc7781ba5 --- /dev/null +++ b/test/cli/delegated_routing_v1_http_proxy_test.go @@ -0,0 +1,144 @@ +package cli + +import ( + "testing" + + "github.com/ipfs/boxo/ipns" + "github.com/ipfs/kubo/config" + "github.com/ipfs/kubo/test/cli/harness" + "github.com/ipfs/kubo/test/cli/testutils" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestRoutingV1Proxy(t *testing.T) { + t.Parallel() + + setupNodes := func(t *testing.T) harness.Nodes { + nodes := harness.NewT(t).NewNodes(2).Init() + + // Node 0 uses DHT and exposes the Routing API. + nodes[0].UpdateConfig(func(cfg *config.Config) { + cfg.Gateway.ExposeRoutingAPI = config.True + cfg.Routing.Type = config.NewOptionalString("dht") + }) + nodes[0].StartDaemon() + + // Node 1 uses Node 0 as Routing V1 source, no DHT. + nodes[1].UpdateConfig(func(cfg *config.Config) { + cfg.Routing.Type = config.NewOptionalString("custom") + cfg.Routing.Methods = config.Methods{ + config.MethodNameFindPeers: {RouterName: "KuboA"}, + config.MethodNameFindProviders: {RouterName: "KuboA"}, + config.MethodNameGetIPNS: {RouterName: "KuboA"}, + config.MethodNamePutIPNS: {RouterName: "KuboA"}, + config.MethodNameProvide: {RouterName: "KuboA"}, + } + cfg.Routing.Routers = config.Routers{ + "KuboA": config.RouterParser{ + Router: config.Router{ + Type: config.RouterTypeHTTP, + Parameters: &config.HTTPRouterParams{ + Endpoint: nodes[0].GatewayURL(), + }, + }, + }, + } + }) + nodes[1].StartDaemon() + + // Connect them. + nodes.Connect() + + return nodes + } + + t.Run("Kubo can find provider for CID via Routing V1", func(t *testing.T) { + t.Parallel() + nodes := setupNodes(t) + + cidStr := nodes[0].IPFSAddStr(testutils.RandomStr(1000)) + + res := nodes[1].IPFS("routing", "findprovs", cidStr) + assert.Equal(t, nodes[0].PeerID().String(), res.Stdout.Trimmed()) + }) + + t.Run("Kubo can find peer via Routing V1", func(t *testing.T) { + t.Parallel() + nodes := setupNodes(t) + + // Start lonely node that is not connected to other nodes. + node := harness.NewT(t).NewNode().Init() + node.UpdateConfig(func(cfg *config.Config) { + cfg.Routing.Type = config.NewOptionalString("dht") + }) + node.StartDaemon() + + // Connect Node 0 to Lonely Node. + nodes[0].Connect(node) + + // Node 1 must find Lonely Node through Node 0 Routing V1. + res := nodes[1].IPFS("routing", "findpeer", node.PeerID().String()) + assert.Equal(t, node.SwarmAddrs()[0].String(), res.Stdout.Trimmed()) + }) + + t.Run("Kubo can retrieve IPNS record via Routing V1", func(t *testing.T) { + t.Parallel() + nodes := setupNodes(t) + + nodeName := "/ipns/" + ipns.NameFromPeer(nodes[0].PeerID()).String() + + // Can't resolve the name as isn't published yet. + res := nodes[1].RunIPFS("routing", "get", nodeName) + require.Error(t, res.ExitErr) + + // Publish record on Node 0. + path := "/ipfs/" + nodes[0].IPFSAddStr(testutils.RandomStr(1000)) + nodes[0].IPFS("name", "publish", "--allow-offline", path) + + // Get record on Node 1 (no DHT). + res = nodes[1].IPFS("routing", "get", nodeName) + record, err := ipns.UnmarshalRecord(res.Stdout.Bytes()) + require.NoError(t, err) + value, err := record.Value() + require.NoError(t, err) + require.Equal(t, path, value.String()) + }) + + t.Run("Kubo can resolve IPNS name via Routing V1", func(t *testing.T) { + t.Parallel() + nodes := setupNodes(t) + + nodeName := "/ipns/" + ipns.NameFromPeer(nodes[0].PeerID()).String() + + // Can't resolve the name as isn't published yet. + res := nodes[1].RunIPFS("routing", "get", nodeName) + require.Error(t, res.ExitErr) + + // Publish name. + path := "/ipfs/" + nodes[0].IPFSAddStr(testutils.RandomStr(1000)) + nodes[0].IPFS("name", "publish", "--allow-offline", path) + + // Resolve IPNS name + res = nodes[1].IPFS("name", "resolve", nodeName) + require.Equal(t, path, res.Stdout.Trimmed()) + }) + + t.Run("Kubo can provide IPNS record via Routing V1", func(t *testing.T) { + t.Parallel() + nodes := setupNodes(t) + + // Publish something on Node 1 (no DHT). + nodeName := "/ipns/" + ipns.NameFromPeer(nodes[1].PeerID()).String() + path := "/ipfs/" + nodes[1].IPFSAddStr(testutils.RandomStr(1000)) + nodes[1].IPFS("name", "publish", "--allow-offline", path) + + // Retrieve through Node 0. + res := nodes[0].IPFS("routing", "get", nodeName) + record, err := ipns.UnmarshalRecord(res.Stdout.Bytes()) + require.NoError(t, err) + value, err := record.Value() + require.NoError(t, err) + require.Equal(t, path, value.String()) + }) +} diff --git a/test/dependencies/go.mod b/test/dependencies/go.mod index e8db14c75b93..48be332f8749 100644 --- a/test/dependencies/go.mod +++ b/test/dependencies/go.mod @@ -7,7 +7,7 @@ replace github.com/ipfs/kubo => ../../ require ( github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd github.com/golangci/golangci-lint v1.54.1 - github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544 + github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-cidutil v0.1.0 github.com/ipfs/go-datastore v0.6.0 diff --git a/test/dependencies/go.sum b/test/dependencies/go.sum index 0a118c295f86..c0f31d3d65ec 100644 --- a/test/dependencies/go.sum +++ b/test/dependencies/go.sum @@ -396,8 +396,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.12.1-0.20230824094523-a2001ba61544 h1:XVq+wUNFx1Ufakz35MAWk+Rr5bAC7lwx1NbJ6Mslp48= -github.com/ipfs/boxo v0.12.1-0.20230824094523-a2001ba61544/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk= +github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff h1:IpyDgsSCTbMcEqKVsbE8S73lV2e9V2J/Tr82zpYb/mg= +github.com/ipfs/boxo v0.12.1-0.20230825084715-e1cce6e07aff/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk= 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-block-format v0.1.2 h1:GAjkfhVx1f4YTODS6Esrj1wt2HhrtwTnhEr+DyPUaJo=