Private Network in Browser

I am trying to create a Private network between a browser (chrome) and a go-node. I have created a custom libp2p bundle and in it defined a Connection Protector (with my swarm key). The IPFS node does not seem to pick it up. Has anyone successfully created a private network in browser? For now I am running it as a full node on the page, and later plan to put it in a service worker.

Thanks,

It’s take me a while but I was able to get this to work with a custom libp2p and protector. You then need to make sure your go-node has ws port accessible so the js-ipfs browser node can communicate with it. If you need additional help let me know

1 Like

Is there any way that you can provide an example of this?

I have been trying to get this to work for some time now and the best I have is an instance of libp2p connecting to the node with a custom protector, but when I try to pass that instance or bundle into IPFS, IPFS won’t connect.

I have also tried this example from IPFS https://github.com/ipfs/js-ipfs/tree/master/examples/custom-libp2p, but when adding a custom protector I am met with: “connProtector is not allowed”

Maybe i’m missing something?

ipfs-js:

const Protector = require('libp2p-pnet')

new Libp2p({
{
   ...
   modules: {
      ...,
      connProtector: new Protector(swarmKeyBuffer),
   },
   config: {
        bootstrap: {
           interval: 10000,
           enabled: true,
           list: ['/ip4/127.0.0.1/tcp/9999/ws/ipfs/Qm...']
        }
    }    
    ...
})

new IPFS({
  libp2p: libp2pBundle,
  config: {
    Bootstrap: ['/ip4/127.0.0.1/tcp/9999/ws/ipfs/Qm...']
  },
  ...
})

ipfs config Addresses:

{
  "API": "/ip4/0.0.0.0/tcp/5002",
  "Announce": [],
  "Gateway": "/ip4/0.0.0.0/tcp/9001",
  "NoAnnounce": [],
  "Swarm": [
    "/ip4/0.0.0.0/tcp/4001",
    "/ip6/::/tcp/4001",
    "/ip4/0.0.0.0/tcp/9999/ws"
  ]
}

I’ve succeeded on it. just setting

new IPFS({
  libp2p: libp2pBundle,
  config: {
    Bootstrap: ['/ip4/127.0.0.1/tcp/9999/ws/ipfs/Qm...']
  },
  ...
})

and make libp2pBundle have a protector of libp2p-pnet will do.

it might be because different version of libp2p. My js-ipfs node can add connProtector but custom-libp2p example cannot. I have to manually add

connProtector: Joi.object().keys({
protect: Joi.func().required()
}).unknown(),

into libp2p\src\config.js
unfortunately this just switch off warnings. connProtector hasn’t been accepted anyway. upgrade libp2p to 0.23.0 resolves the problem

Can you show me exactly how to do it?

You might find the tutorial at https://github.com/libp2p/js-libp2p/tree/master/examples/pnet-ipfs#private-networking-with-ipfs to be helpful :slight_smile:

Hi there, does anyone have a working example of connecting a browser node to a private node using swarm keys ?

I’ve tried various examples, and i end up with connection.getPeerInfo is not a function when adding a connProtector to ipfs.libp2p

1 Like