Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Allow for custom libp2p generator in configuration #1463

Closed
jacobheun opened this issue Jul 24, 2018 · 0 comments
Closed

Allow for custom libp2p generator in configuration #1463

jacobheun opened this issue Jul 24, 2018 · 0 comments
Assignees
Labels
exp/novice Someone with a little familiarity can pick up P2 Medium: Good to have, but can wait until someone steps up

Comments

@jacobheun
Copy link
Contributor

Currently libp2p is being created by configuration when ipfs boots. This makes it difficult for users to do anything custom with libp2p, even just adding transports that require the nodes peerInfo on startup, libp2p/js-libp2p#222.

By allowing users to specify a generator for libp2p we provide more flexibility for them to customize it to their needs.

It would be great if users could do something like this:

const ipfs = new IPFS({
    libp2p: (_ipfs) => {
      /* Fancy stuff here with startup info from the ipfs node */

      return new Libp2p({
        peerInfo: _ipfs._peerInfo,
        peerBook: _ipfs._peerInfoBook,
        config: { /* custom config using the above fancy stuff */ }
      })
    }
  })

Then when ipfs goes to start libp2p, https://github.com/ipfs/js-ipfs/blob/v0.30.1/src/core/components/libp2p.js#L11, we can run the generator which would have access to boot time information like the nodes peerInfo.

@ghost ghost assigned jacobheun Jul 26, 2018
@ghost ghost added the status/in-progress In progress label Jul 26, 2018
@alanshaw alanshaw added exp/novice Someone with a little familiarity can pick up P2 Medium: Good to have, but can wait until someone steps up labels Jul 29, 2018
@ghost ghost removed the status/in-progress In progress label Aug 30, 2018
alanshaw pushed a commit that referenced this issue Aug 30, 2018
Resolves #1463 and libp2p/js-libp2p#222

This adds the ability to pass a libp2p generator function to the ipfs configuration. This makes it easier for users to add custom modules to libp2p that require some startup time properties, like peerInfo (libp2p/js-libp2p#222). 

I have also included an example of how to do this. I think this makes complex libp2p configuration much cleaner and easier to do.

Tests have been added for the old configuration options and the new generator option. I isolated them to avoid spinning up a full ipfs node.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
exp/novice Someone with a little familiarity can pick up P2 Medium: Good to have, but can wait until someone steps up
Projects
None yet
Development

No branches or pull requests

2 participants