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

Support private networks via shared swarm.key #4005

Closed
revichnr opened this issue Jan 5, 2022 · 7 comments
Closed

Support private networks via shared swarm.key #4005

revichnr opened this issue Jan 5, 2022 · 7 comments
Assignees
Labels
effort/days Estimated to take multiple days, but less than a week exp/intermediate Prior experience is likely helpful help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature kind/maybe-in-helia P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked topic/libp2p Topic libp2p

Comments

@revichnr
Copy link

revichnr commented Jan 5, 2022

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

@revichnr revichnr added the need/triage Needs initial labeling and prioritization label Jan 5, 2022
@welcome

This comment was marked as resolved.

@lidel
Copy link
Member

lidel commented Feb 4, 2022

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 🙏

@lidel lidel changed the title How to connect js-ipfs to a Private network Feature request: private network based on a shared swarm.key secret Feb 4, 2022
@lidel lidel added exp/intermediate Prior experience is likely helpful help wanted Seeking public contribution on this issue P2 Medium: Good to have, but can wait until someone steps up effort/days Estimated to take multiple days, but less than a week topic/libp2p Topic libp2p status/ready Ready to be worked and removed need/triage Needs initial labeling and prioritization labels Feb 4, 2022
@lidel lidel changed the title Feature request: private network based on a shared swarm.key secret Support private networks via shared swarm.key Feb 4, 2022
@lidel lidel added the kind/enhancement A net-new feature or improvement to an existing feature label Feb 4, 2022
@AlexMesser
Copy link

AlexMesser commented Mar 17, 2022

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.

@lidel
Copy link
Member

lidel commented Apr 22, 2022

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

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

@tbmcabc
Copy link

tbmcabc commented Jan 16, 2023

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!

@SgtPooki SgtPooki self-assigned this May 17, 2023
@SgtPooki SgtPooki moved this to 🥞 Todo in js-ipfs deprecation May 17, 2023
@SgtPooki SgtPooki moved this from 🥞 Todo to 🛑 Blocked in js-ipfs deprecation May 17, 2023
@SgtPooki
Copy link
Member

js-ipfs is being deprecated in favor of Helia. You can #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 #4336).

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

@SgtPooki SgtPooki assigned achingbrain and unassigned SgtPooki May 26, 2023
@achingbrain
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
effort/days Estimated to take multiple days, but less than a week exp/intermediate Prior experience is likely helpful help wanted Seeking public contribution on this issue kind/enhancement A net-new feature or improvement to an existing feature kind/maybe-in-helia P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked topic/libp2p Topic libp2p
Projects
No open projects
Status: Done
Development

No branches or pull requests

6 participants