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

2 Likes

I am looking for this information as well. I’ve moved my back-end IPFS network to a private network of go-ipfs nodes using a swarm.key, by following these directions. I’m aware of the requirements to use secure websockets when connecting between a browser and a go-ipfs node. But how do I implement the swarm.key into a browser node running js-ipfs?

If anyone has a link to an example, gist, documentation, or whatever, please add it.

Brave Browser has an integrated IPFS node.



Just create a swarm.key

echo -e "/key/swarm/psk/1.0.0/\n/base16/\n`tr -dc 'a-f0-9' < /dev/random | head -c64`"

and place it in the IPFS data directory. On my GNU/Linux system, that directory is:

~/.config/BraveSoftware/Brave-Browser/brave_ipfs