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(helia): helia-ipns #6

Closed
wants to merge 6 commits into from
Closed

feat(helia): helia-ipns #6

wants to merge 6 commits into from

Conversation

whizzzkid
Copy link
Collaborator

@whizzzkid whizzzkid commented Oct 11, 2023

In this PR:

  • Replacing delegated routing API with helia-ipns

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
@achingbrain
Copy link
Member

I cannot push a branch here (see #8) but here are the patches to fix the type problem:

index 4c3194e..29f34f1 100644
--- a/package.json
+++ b/package.json
@@ -47,6 +47,7 @@
   "dependencies": {
     "@helia/ipns": "2.0.1",
     "@helia/unixfs": "1.x",
+    "@libp2p/interface": "^0.1.3",
     "express": "4.x",
     "express-prom-bundle": "6.x",
     "file-type": "18.x",
index 3d2197a..7f52ae6 100644
--- a/src/heliaFetch.ts
+++ b/src/heliaFetch.ts
@@ -8,6 +8,8 @@ import { createHelia, type Helia } from 'helia'
 import { LRUCache } from 'lru-cache'
 import { CID } from 'multiformats/cid'
 import pTryEach from 'p-try-each'
+import type { Libp2p } from '@libp2p/interface'
+import type { PubSub } from '@libp2p/interface/pubsub'
 
 const ROOT_FILE_PATTERNS = [
   'index.html',
@@ -22,7 +24,7 @@ export class HeliaFetch {
   private fs!: UnixFS
   private readonly log: debug.Debugger
   private readonly rootFilePatterns: string[]
-  public node!: Helia
+  public node!: Helia<Libp2p<{ pubsub: PubSub }>>
   public ready: Promise<void>
   private ipns!: ReturnType<typeof ipns>
   private readonly ipnsResolutionCache = new LRUCache<string, string>({
@@ -35,7 +37,7 @@ export class HeliaFetch {
     rootFilePatterns = ROOT_FILE_PATTERNS,
     logger
   }: {
-    node?: Helia
+    node?: Helia<Libp2p<{ pubsub: PubSub }>>
     rootFilePatterns?: string[]
     logger?: debug.Debugger
   } = {}) {
@@ -64,16 +66,7 @@ export class HeliaFetch {
     })
     this.ipns = ipns(this.node, [
       dht(this.node),
-      pubsub({
-        datastore: this.node.datastore,
-        libp2p: {
-          peerId: this.node.libp2p.peerId,
-          services: {
-            // mismatch types
-            pubsub: this.node.libp2p.services.pubsub
-          }
-        }
-      })
+      pubsub(this.node)
     ])
     this.fs = unixfs(this.node)
     this.log('Helia Setup Complete!')

The Helia type is generic and if used like this needs to have the Libp2p type it contains specified.

This is necessary because users can configure their own libp2p instance with their own custom services.

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
@whizzzkid
Copy link
Collaborator Author

@achingbrain that fixes the type issue but looks like it still doesn't work as expected 🤔

* main: (27 commits)
  feat(e2e): add /api/v0/repo/gc test
  chore: disable METRICS on CI e2e test runs
  test: add e2e test for /api/v0/version endpoint
  feat(server): ⚡️ Subdomain Gateway Using Fastify (#31)
  feat: use production level docker settings (#26)
  chore: remove unused playwright init code
  fix: use active LTS in package.json engines
  fix: playwright CI node-version=20
  test: get clinic flame & doctor output from e2e tests
  test: e2e updates
  fix: use HOST constant in healthcheck
  fix: use HOST constant
  test: cleanup playwright test code
  test: add playwright tests
  feat: move HOST,PORT to src/constants.ts
  fix: ✏️  Fixing urls. (#23)
  fix: ✏️ helia-docker -> helia-http-gateway (#22)
  build(deps): Bump @babel/traverse and depcheck (#13)
  feat: add health-check (#21)
  fix(server): 🩹 Using sessionID as a fallback to requests where referer is missing. (#20)
  ...

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
…to feat/helia-ipns

* refs/remotes/origin/feat/helia-ipns:
Signed-off-by: Nishant Arora <1895906+whizzzkid@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
None yet
Development

Successfully merging this pull request may close these issues.

2 participants