feat(pinner): support pre-created Libp2p instance#1100
Merged
Conversation
Helia v7's createHelia() calls withLibp2p(helia) without passing the libp2p option through — init.libp2p is silently ignored. This causes Helia to always invoke createLibp2p() / libp2pDefaults(), which configures WebRTC and UPnP transports that crash in environments without native addons (e.g. GitHub Actions). When config.libp2p is provided, getHelia() now manually composes the pipeline: createHeliaLight → withHTTP → withLibp2p(helia, libp2p) → withBitswap. The pre-created instance passes the isLibp2p() check in getLibp2p(), skipping createLibp2p() entirely. - Add libp2p field to PinnerConfig and CarConfig - Flow libp2p through UploadManager → configureCar - Add @helia/bitswap, @helia/libp2p, @ipld/dag-cbor, @ipld/dag-json, @libp2p/interface as dependencies - Backward compatible: when libp2p is not provided, createHelia() is used as before
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Helia v7's
createHelia()callswithLibp2p(helia)without passing thelibp2poption through —init.libp2pis silently ignored. This causes Helia to always invokecreateLibp2p()/libp2pDefaults(), which configures WebRTC and UPnP transports that crash in environments without native addons (e.g. GitHub Actions runners).The downstream effect:
WebRTCDirectTransport.start()→loadOrCreatePrivateKey()→keychain.exportKey()→UnstorageDatastore.get()throws a plainErrorinstead ofNotFoundError→Datastore item not found: /pkcs8/webrtc-direct-certificate-private-keycrash.Solution
When
config.libp2pis provided,getHelia()bypassescreateHelia()and manually composes the same pipeline:The pre-created instance passes the
isLibp2p()check ingetLibp2p(), socreateLibp2p()/libp2pDefaults()is skipped entirely — no WebRTC, no UPnP, no native addons loaded.Changes
config.ts— Addlibp2p?: Libp2ptoPinnerConfigcar.ts— Addlibp2p?: Libp2ptoCarConfig;getHelia()uses manual composition whenconfig.libp2pis provided, falls back tocreateHelia()otherwisemanager.ts— Passlibp2pthroughUploadManager→configureCar()package.json— Add@helia/bitswap,@helia/libp2p,@ipld/dag-cbor,@ipld/dag-json,@libp2p/interfaceas dependenciespnpm-workspace.yaml— Add catalog entries for new depsBackward Compatibility
Fully backward compatible. When
libp2pis not provided,createHelia()is used as before — no behavior change for existing consumers.This pull request adds support for passing a pre-created Libp2p instance into the Pinner's Helia configuration. When a Libp2p instance is provided, the Pinner bypasses Helia's internal
createLibp2p()/libp2pDefaults()flow and instead manually composes a lightweight Helia pipeline (createHeliaLight→withHTTP→withLibp2p→withBitswap). This avoids loading unnecessary transports such as WebRTC and UPnP, reducing overhead and giving callers full control over the Libp2p node used by Helia.Key changes:
libp2pproperty to bothPinnerConfigandCarConfiginterfaces.createHelia()otherwise.libp2pconfig option through theUploadManagerto the CAR configuration.@helia/bitswap,@helia/libp2p,@ipld/dag-cbor,@ipld/dag-json,@libp2p/interface) and updated the lockfile and workspace catalog.