js-ipfs icon indicating copy to clipboard operation
js-ipfs copied to clipboard

Support private networks via shared swarm.key

Open revichnr opened this issue 3 years ago • 4 comments

Hi. I need to connect js-ipfs to a private network. How can I use my swarm.key during installation?

revichnr avatar Jan 05 '22 07:01 revichnr

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

welcome[bot] avatar Jan 05 '22 07:01 welcome[bot]

I don't believe js-ipfs supports Private swarms via swarm.key (afaik it is only an experimental feature of go-ipfs).

It seems all necessary primitives exist, what is missing is detection of secret in ~/.jsipfs/swarm.key (daemon) or config passed to the constructor (programmatic), and enabling connection protector when present (some prior art here). Ideally, we should have interop with private swarm based on go-ipfs.

If anyone wishes to add this to js-ipfs, PR welcome :pray:

lidel avatar Feb 04 '22 15:02 lidel

It seems that libp2p config parameter does not passed to an underlying libp2p.js module.

I tried to create a private IPFS network:

async connect(){
  process.env.LIBP2P_FORCE_PNET = "1" // enable private network
  const swarmKey = await fse.readFile(AppConfig.ipfs.swarmKeyFile)
  const ipfsConfig: any = {
    repo: `./ipfs`,
    EXPERIMENTAL: {
      pubsub: true,
    },
    config: {
      Bootstrap: [],
      Addresses: {
        Swarm: ["/ip4/0.0.0.0/tcp/4002", "/ip4/127.0.0.1/tcp/4003/ws"],
      },
    },
    libp2p: {
      modules: {
        connProtector: new Protector(swarmKey),
      },
    },
  }
  this.node = await IPFS.create(ipfsConfig)
}

It gives me an error Error: Private network is enforced, but no protector was provided

After digging into ipfs-core code i tried to add options: options.libp2p in storage.js and ...options in libp2p.js, under the modules: {}. Network successfully started.

I'm not sure if these are the right places to change and what are the side effects, but if everything is ok I can create a PR.

AlexMesser avatar Mar 17 '22 16:03 AlexMesser

@AlexMesser thank you for poking at this – please open a PR that make priv networks work. :pray: it will be really valuable to have support for private networks in js-ipfs :+1:

We can get js-libp2p team to review/bikeshed details there, if necessary.

lidel avatar Apr 22 '22 14:04 lidel

hello,it looks like that example running at node.js?can I used at browser with swarm.key? hope and waiting the answer please。 best wish!

tbmcabc avatar Jan 16 '23 10:01 tbmcabc

js-ipfs is being deprecated in favor of Helia. You can https://github.com/ipfs/js-ipfs/issues/4336 and read the migration guide.

Please feel to reopen with any comments by 2023-06-02. We will do a final pass on reopened issues afterward (see https://github.com/ipfs/js-ipfs/issues/4336).

@achingbrain to answer if private networks support is available in Helia

SgtPooki avatar May 26 '23 19:05 SgtPooki

This can be accomplished using the pnet module bundled with js-libp2p - please see the docs for how to configure this.

achingbrain avatar May 30 '23 16:05 achingbrain