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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/lib/init-helia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ import { getHashersForCodes } from './hash-importer.js'
import { addDagNodeToHelia } from '../lib/helpers.js'
import type { KuboGatewayOptions } from '../types.d.js'

function areRemoteGatewaysEnabled (): boolean {
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: KuboGatewayOptions): Promise<Helia> {
const blockstore = new MemoryBlockstore()
const datastore = new MemoryDatastore()
Expand Down Expand Up @@ -53,11 +63,19 @@ export default async function initHelia (kuboGatewayOptions: KuboGatewayOptions)
}
})

// 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}`] })
...trustlessGateways
],
// #WhenAddingNewHasher
hashers: await getHashersForCodes(17, 18, 19, 20, 27, 30),
Expand Down
Loading