js-ipfsd-ctl icon indicating copy to clipboard operation
js-ipfsd-ctl copied to clipboard

how to provide a custom libp2p instance?

Open pleerock opened this issue 1 year ago • 2 comments

I expected something like this is going to work:

    const customLibp2p = await createLibp2p({
      addresses: {
        listen: [`/ip4/127.0.0.1/tcp/8000/ws`],
      },
      transports: [new WebSockets()],
      connectionEncryption: [new Noise()],
      streamMuxers: [new Mplex()],
    })

    const ipfsd = await createController({
      type: "go",
      remote: false,
      disposable: false,
      ipfsHttpModule,
      ipfsBin: goIpfsModule.path(),
      ipfsOptions: {
        EXPERIMENTAL: {
          ipnsPubsub: true,
        },
        libp2p: customLibp2p, // NOTICE HERE PLEASE. IT LOOKS LIKE ITS BEING COMPLETELY IGNORED
        repo: repoPath,
        init: false,
        start: false,
      },
    })

but "libp2p" option is being ignored. Maybe types are wrong and there is another way how to provide a custom libp2p instance implementation?

pleerock avatar Oct 13 '22 21:10 pleerock

When the type of the controller is go we shell out to kubo which cannot use js-libp2p in this fashion.

This could be improved by checking the value of ipfsOptions and throwing an error if any options are passed that are incompatible with the style of daemon being created. The libp2p option for example would only work with an in-proc daemon.

Would you like to submit a PR that improves this?

achingbrain avatar Oct 14 '22 14:10 achingbrain

Because of this issue I had to switch to ipfs-core for now. If I'll return back to this package, I'll consider to add this improvement. Thanks for your answer.

pleerock avatar Oct 14 '22 18:10 pleerock

And what is the point to use proc mode? If I can directly use js-ipfs package? I'm trying to understand the motivation behind this option.

pleerock avatar Oct 15 '22 22:10 pleerock

The point of this module is to be able to seamlessly switch between go, and js implementations, and for js as in-process or running as a separate process.

This is useful for testing compatibility between the different implementations.

If your only requirement is to have an IPFS node as part of your app, you should use ipfs-core directly.

achingbrain avatar Oct 16 '22 11:10 achingbrain

Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days.

github-actions[bot] avatar Oct 23 '22 00:10 github-actions[bot]

This issue was closed because it is missing author input.

github-actions[bot] avatar Oct 31 '22 00:10 github-actions[bot]