Skip to content

Conversation

@tabcat
Copy link
Contributor

@tabcat tabcat commented Nov 19, 2025

Title

feat: ipns libp2p fetch

Description

Adds @libp2p/fetch functionality to the pubsub router of helia/ipns.
The pubsub router will libp2p/fetch the latest local record from new pubsub peers if libp2p.services.fetch is found.

https://specs.ipfs.tech/ipns/ipns-pubsub-router/#layering-persistence-onto-libp2p-pubsub

Closes #893

Notes & open questions

Should get method of the pubsub router wait for a few peers to be queries with fetch, or should the router emit an event when it finds a newer record?

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@tabcat
Copy link
Contributor Author

tabcat commented Nov 19, 2025

Does a lookup function need to be registered with @libp2p/fetch? It seems like it would be needed, but the resources I'm looking at don't use it.

@tabcat
Copy link
Contributor Author

tabcat commented Nov 21, 2025

I'm considering checking the current subscribers for the topic directly before the fetch call. The check would see if we are still pubsub peered with the peerId that is being queried with the fetch call. If not then cancel the fetch and return. This would reduce the possibility of opening a new connection instead of just a new stream.

@hsanjuan
Copy link

Triage:

@tabcat
Copy link
Contributor Author

tabcat commented Dec 27, 2025

I've made some changes to PubSubRouting.

  • The get method always throws. It does not query the localStore, only sets up topic listeners.
  • PubSubRouting emits 'record-update' events.
  • pubsub creator function return type is PubSubRouting

Usage:

const pubsubRouter = pubsub(components)
pubsubRouter.addEventListener('record-update', ({ publicKey, record }) => console.log(`New record for ${publicKey}`))

const names = ipns(components, { routers: [pubsubRouter] })

// init PubSubRouting for names of interest
await names.resolve(ipnsKey)

@tabcat tabcat marked this pull request as ready for review December 27, 2025 05:28
@tabcat tabcat requested a review from a team as a code owner December 27, 2025 05:28
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.

IPNS should use libp2p-fetch to retrieve IPNS records from peers

3 participants