Can IPFS pubsub be used for files?

So I just read about pub sub here https://blog.ipfs.io/25-pubsub/

The example in the posts mention how to subscribe to a topic and receive message which is the printed to the console. This is good for basic demonstration but does not have much real life utility.

The questions I had was:

  1. Is it possible to subscribe to a topic and instead of just a “message” sent you have file sent and automatically added to your node?
  2. Or is it possible to subscribe to a “ipns” address as the topic, which means you always get the latest version once new content is published

You can use collaborative clusters for essentially that (cluster.ipfs.io, collab.ipfscluster.io).

Yes, you can do this by enabling IPNS over PubSub (–enable-namesys-pubsub) https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipns-pubsub.

Note: IPNS over PubSub will not spit out the latest update to the CLI, but your node will have the data ready for retrieval when you ask for it.

2 Likes

Thanks for pointing out collaborative clusters. I admit I have ran into ipfs cluster one or more times, but I have essentially ignored it as it looks to me like something I will need “at scale”…while I am only just playing with a node, on my laptop which gets switched for about 8hrs everyday :slight_smile:

Ha, this sounds more like what I can use right away. Thanks for the mentioning this! :slight_smile:

Hi @adin

I am just getting around to trying this…and it does not seem to work…or probably I am not doing it right :slight_smile:

So this is what I have done:

  • Start two instances with ipfs daemon --enable-namesys-pubsub --enable-pubsub-experiment
  • Confirm that I can retrieve contents normally by CID. Ie. add content to one node, go to the other node, and ask for it via CID, now this works.
  • On node1, I created a directory, added stuff to it and added it to IPFS by running ipfs add -r /dire
  • Then I publish to IPNS by running `ipfs name publish <CID_FROM_PREVIOUS_STEP>
  • Now I go to node2, and I do ipfs get /ipns/<PEER_ID_OF_NODE_!> and I get the directory I added to node1
  • Now go to node1, add extra files into the dir, add to ipfs and publish
  • Then I return to node2, I was expecting the directory to be updated via the pubsub mechanism and hence contain the new file I added. But this was not the case.

What am I doing wrong? Or do i have the wrong expectations on how things should work?

Hi @adin any thoughts on the follow up points I am confused about? Thanks :slight_smile:

Unfortunately, IPNS over PubSub is not setup to be that special/different compared to the standard IPNS over DHT. It’s a reasonable feature request though.

In the meanwhile, what you can do is have a script that every so often calls ipfs get /ipns/<IPNS_KEY> in the background. The IPNS to IPFS resolution should be instant because PubSub will have the latest result waiting for you, then it’s just a matter of fetching the IPFS data.

Alternatively, if you don’t want a polling approach and are willing to do a bit of work you should be able to subscribe to the IPNS over PubSub channel for your key and listen for updates (you could use either the ipfs pubsub CLI or HTTP API to do this). When you get the updates you could call ipfs get on the data. Note: if you do this that the IPNS over PubSub topics are not named the same as the IPNS keys themselves, but you can use a tool like GitHub - aschmahmann/ipns-utils: Some utilities for working with IPNS records to figure out the conversions for you.

Edit: It looks like you’re looking for something like ipfs name follow · Issue #4435 · ipfs/kubo · GitHub to be implemented. While this issue is old some of the IPNS improvements have put it on the radar. Unfortunately, it’s not the highest priority item for the core team right now, but IPFS is an open source project that welcomes external contributions so anyone is interested this issue is available :slight_smile:

1 Like