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: create @helia/http library without bitswap/libp2p deps #289

Closed
3 of 4 tasks
SgtPooki opened this issue Oct 23, 2023 · 11 comments · Fixed by #372
Closed
3 of 4 tasks

feat: create @helia/http library without bitswap/libp2p deps #289

SgtPooki opened this issue Oct 23, 2023 · 11 comments · Fixed by #372
Assignees

Comments

@SgtPooki
Copy link
Member

SgtPooki commented Oct 23, 2023

Helia consumers should be able to use Helia without depending on the p2p network. Ideally, users could use Helia modularly, with trustless-http-gateway (or other source of getting blocks) and validate those blocks, using only the IPFS portion of Helia.

Current

It doesn't seem like we can "remove" libp2p entirely, but we can disable it:

const helia = await createHelia({
  blockBrokers: [
    trustlessGateway()
  ],
  libp2p: {
    start: false,
    connectionManager: {
      minConnections: 0,
    },
  }
})

Future (with @helia/http)

No runtime js-libp2p deps are pulled in with this module

import type { Helia } from '@helia/interface'
import { createHttpOnlyHelia } from '@helia/http' // export name to be decided. should probably be `createHelia`
import { unixfs } from '@helia/unixfs'

const helia: Helia<null> = createHttpOnlyHelia() 

const fs = unixfs(helia)

// ...

Tasks

  1. meandavejustice
@achingbrain
Copy link
Member

Maybe we should accept false for libp2p for this?

const helia = await createHelia({
  blockBrokers: [
    trustlessGateway()
  ],
  libp2p: false
})

@achingbrain
Copy link
Member

Thinking about this a bit more, if there's no libp2p/bitswap then you're pulling in a whole lot of extra deps for zero benefit and I wonder if this is even Helia any more.

It might be another implementation of the Helia interface? This keeps it compatible with @helia/unixfs etc.

@SgtPooki
Copy link
Member Author

SgtPooki commented Oct 24, 2023

I think Helia can be Helia even without libp2p (people don't want to do p2p stuff, but they do want to do content-addressing stuff), but I agree it feels odd.

It might be another implementation of the Helia interface? This keeps it compatible with @helia/unixfs etc.

@achingbrain are you thinking of going with something like

import {type HeliaRaw} from '@helia/interface`
import {createHelia} from 'helia'

const helia: HeliaRaw = await createHelia({
  blockBrokers: [
    trustlessGateway()
  ],
  libp2p: false
})

so modules like @helia/unixfs can indicate whether they support Helia without libp2p or not?

@achingbrain
Copy link
Member

modules like @helia/unixfs can indicate whether they support Helia without libp2p or not?

Yes! The factory for @helia/unixfs only requires a blockstore for this exact reason.

So it's more like:

import type { Helia } from '@helia/interface'
import { createHeliaThatOnlyUsesGateways } from '@helia/http'
import { unixfs } from '@helia/unixfs'

const helia = createHeliaThatOnlyUsesGateways()
const fs = unixfs(helia)

// ...do unixfs stuff

The Helia type is already there so you don't need HeliaRaw and it's generic for the libp2p type so you can make it unknown or perhaps we'd remove it entirely.

@SgtPooki
Copy link
Member Author

SgtPooki commented Oct 24, 2023

Got it, so we can create @helia/http and import that instead of helia, and that would handle the appropriate configuration of the Helia interface. I think that makes sense.. and putting it in a separate package would mean we can ensure other deps (libp2p/bitswap/others) are not pulled in exported.

Sounds good to me, going to update this title to reflect this? but I still imagine this is low-priority.

@SgtPooki SgtPooki changed the title feat: write documentation on how to utilize helia without libp2p feat: create @helia/http library without bitswap/libp2p deps Oct 24, 2023
@SgtPooki
Copy link
Member Author

SgtPooki commented Dec 8, 2023

I've added what I think to be the general action items for this into the issue description

@BigLep
Copy link
Contributor

BigLep commented Dec 8, 2023

Thanks @SgtPooki - sounds good. Lets also make sure there is accompanying information too. There should probably be a Helia readme item for something like "want an even lighterweight Helia that still has the goodness of CIDs and verifiable retrieval? see..."

@meandavejustice
Copy link
Contributor

Instead of modifying Helia interface we could extend and omit the libp2p bits

interface HeliaHTTP extends Omit<Helia, 'start'|'stop'|'libp2p'> {}

@meandavejustice
Copy link
Contributor

@SgtPooki I have a branch where I'm working on this. Can you assign to me?

@2color
Copy link
Member

2color commented Jan 3, 2024

Currently @meandavejustice is working on this in https://github.com/meandavejustice/helia-http/

@SgtPooki
Copy link
Member Author

This is now being covered by #372

@SgtPooki SgtPooki linked a pull request Jan 15, 2024 that will close this issue
achingbrain added a commit that referenced this issue Jan 17, 2024
Adds code from https://github.com/meandavejustice/helia-http to the monorepo.

Fixes: #289 and #344

BREAKING CHANGE: the `libp2p` property has been removed from the `Helia` interface in `@helia/interface` - it is still present on the return type of `createHelia` from the `helia` module

---------

Co-authored-by: David Justice <work@justice.engineering>
Co-authored-by: Daniel Norman <1992255+2color@users.noreply.github.com>
Co-authored-by: Daniel N <2color@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: 🏃‍♀️ In Progress
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants