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: re-allow disabling of remote gateways #416

Merged
merged 1 commit into from Dec 1, 2023

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Dec 1, 2023

This was tested on ipfs-webui via the following patch:

diff --git a/node_modules/ipld-explorer-components/dist/lib/init-helia.js b/node_modules/ipld-explorer-components/dist/lib/init-helia.js
index e1204a1..53b6218 100644
--- a/node_modules/ipld-explorer-components/dist/lib/init-helia.js
+++ b/node_modules/ipld-explorer-components/dist/lib/init-helia.js
@@ -14,6 +14,17 @@ import { trustlessGateway } from 'helia/block-brokers';
 import { createLibp2p } from 'libp2p';
 import { getHashersForCodes } from './hash-importer.js';
 import { addDagNodeToHelia } from '../lib/helpers.js';
+
+function areRemoteGatewaysEnabled () {
+  const localStorageKey = 'explore.ipld.gatewayEnabled'
+  console.info(
+    `🎛️ Customise whether ipld-explorer-components fetches content from gateways by setting an '${localStorageKey}' value to true/false in localStorage. e.g. localStorage.setItem('explore.ipld.gatewayEnabled', false) -- NOTE: defaults to true`
+  )
+  const gatewayEnabledSetting = localStorage.getItem(localStorageKey)
+
+  return gatewayEnabledSetting != null ? JSON.parse(gatewayEnabledSetting) : true
+}
+
 export default async function initHelia(kuboGatewayOptions) {
   const blockstore = new MemoryBlockstore();
   const datastore = new MemoryDatastore();
@@ -38,12 +49,21 @@ export default async function initHelia(kuboGatewayOptions) {
       delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev')
     }
   });
+
+  // Always add the Kubo gatewawy
+  const trustlessGateways = [
+    trustlessGateway({ gateways: [`${kuboGatewayOptions.protocol ?? 'http'}://${kuboGatewayOptions.host}:${kuboGatewayOptions.port}`] })
+  ]
+
+  if (areRemoteGatewaysEnabled()) {
+    trustlessGateways.push(trustlessGateway())
+  }
+
   const helia = await createHelia({
     blockBrokers: [
-    // no bitswap
-    trustlessGateway(), trustlessGateway({
-      gateways: [`${kuboGatewayOptions.protocol ?? 'http'}://${kuboGatewayOptions.host}:${kuboGatewayOptions.port}`]
-    })],
+      // no bitswap
+      ...trustlessGateways
+    ],
     // #WhenAddingNewHasher
     hashers: await getHashersForCodes(17, 18, 19, 20, 27, 30),
     datastore,

@SgtPooki SgtPooki requested a review from a team as a code owner December 1, 2023 19:55
@SgtPooki SgtPooki merged commit 1fa3025 into master Dec 1, 2023
16 checks passed
@SgtPooki SgtPooki deleted the feat/allow-disabling-remote-gateways branch December 1, 2023 20:04
github-actions bot pushed a commit that referenced this pull request Dec 1, 2023
## [5.2.0](v5.1.2...v5.2.0) (2023-12-01)

### Features

* re-allow disabling of remote gateways ([#416](#416)) ([1fa3025](1fa3025))
SgtPooki added a commit to ipfs/ipfs-webui that referenced this pull request Dec 1, 2023
this allows disabling remote gateways in e2e. see ipfs/ipld-explorer-components#416
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant