Skip to content

feat: improve helia 101 example #456

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

Merged
merged 14 commits into from
Mar 26, 2025
Merged

feat: improve helia 101 example #456

merged 14 commits into from
Mar 26, 2025

Conversation

2color
Copy link
Contributor

@2color 2color commented Mar 14, 2025

What

  • 101: adapt example to the changes introduced by fix!: require path in addFile call ipfs/helia#754
  • 101: add more examples on how to use UnixFS in 101, including nuances around bytes/files/directories
  • 201: change to focus on a single node and different block stores
  • 201: use helia/http since we don't care about providing
  • 401: add new example showing gc, providing, and pinning
  • README: update for the example. Move code specific docs inline rather than README.

Additions for a followup

  • Configuring block brokers & routers
  • CAR files
  • MFS

TODO

@2color 2color changed the title feat: more usage examples for helia unixfs feat: more unixfs usage examples in 101 Mar 14, 2025
@2color 2color requested a review from achingbrain March 14, 2025 14:04
@2color 2color changed the title feat: more unixfs usage examples in 101 feat: improve helia 101 example Mar 18, 2025
@2color
Copy link
Contributor Author

2color commented Mar 18, 2025

@achingbrain When running the new 401 example my node hangs indefinitely when calling provide() for a CID:

cid = await fs.addFile({
content: encoder.encode(text),
path: './hello-world.txt',
})
console.log('Added file again:', cid.toString())
// Pin the block and add some metadata
for await (const pinnedCid of helia.pins.add(cid, {
metadata: {
added: new Date().toISOString(),
addedBy: '401-providing example',
},
})) {
console.log('Pinned CID to prevent garbage collection:', pinnedCid.toString())
}
const pin = await helia.pins.get(cid)
console.log('Pin:', pin)
// Provide the block to the DHT so that other nodes can find and retrieve it
await helia.routing.provide(cid)

  • Helia is started with the defaults
  • To debug I ran DEBUG="libp2p:upnp-nat*,libp2p:auto-nat*" node 401-providing.js
  • I'm doing this on a network with upnp enabled. AutoTLS works with Kubo. The router is a Ubiquiti one.
  • The full log
    • What's interesting is that in the logs it prints multiple times: libp2p:upnp-nat gateway search finished, found 0 gateways +5s
    • However, it seems that it succeeds getting a port mapping, given all the log lines libp2p:auto-nat /ip4/87.x.x155/udp/61391 success 0 failure 6 +11s where 87.x.x.155 is in fact the correct public IP.

I'm not too familiar with the @libp2p/upnp-nat, but maybe you have some insights?

Update 19.3

  • I ran the same example as above on a different network (my home)
  • helia outputs multiple times: libp2p:upnp-nat gateway search finished, found 0 gateways +5s
  • It seems to be able to create a port mapping, but for some reason AutoNATfails
  • Logs

@2color 2color requested a review from achingbrain March 24, 2025 15:46
Copy link
Contributor

@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a couple of comments inline.

@2color 2color merged commit 47ac55b into main Mar 26, 2025
21 checks passed
@2color 2color deleted the improve-101-example branch March 26, 2025 17:02
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.

4 participants