How to achieve Peer to Peer networking in NodeJS

Here is some background on what I’m trying to achieve: I am creating a BlockChain, … Read more How to achieve Peer to Peer networking in NodeJS

Here is some background on what I’m trying to achieve:

I am creating a BlockChain, I am wanting to achieve a network where all NodeJS programs can connect to each other without needing to port forward. I have used SocketIO, UDP Sockets, REST Servers, But all of these need to be port forwarded in order to contact with other connected users. I have considered to just have a setting where users can specify themselves as a "Node", in which case they will need to port forward they’re router, thus allowing "peers" to connect to the node, and share its own copy of the block chain with other Nodes, as well as all of its Peers but i feel like this isn’t the right approach to take for some reason.

I have tried using various libraries, each having its own issues, here is some:

  1. Due to NodeJS being server sided, webrtc is not present and the libraries simply do not work.
  2. I am able to create a "server" (Not sure why i would be needing to make one when this is supposed to be P2P, but there is many libraries that do this) however i am unable to make a client, simply because it doesn’t exist in the library or the same issue as #1
  3. The library has a way to connect to another peer, however you cannot connect to peers outside of your own network simply because the library doesnt have a connect(host, port) method.

These are the libaries i have tried with the issues above i am explaining:

  1. simple-peer (#1 however there was a fix using wrtc NPM package, and #3)
  2. node-p2p / socket.io-p2p (#2 & #3, this was a weird lib)
  3. peerjs (#1)

I had tried various other libraries that havent been updated in years, or just had little to no documentation but i cannot remember theyre names

I had also tried a UDP Hole Punching library called udp-hole-puncher, which worked amazingly on my local PC, however the Server part of it already needed to have a clients IP before the even connected which wouldn’t work in Decentralized BlockChain setting.

Is anyone able to reccomend me any P2P libraries that are maybe a hidden gem and just dont show up on google? Or propor documentation/hacks to get the above libraries to work the way i need them to?

TL;DR Is there any libraries that will allow my to connect 2 NodeJS programs together without port forwarding (P2P or similar)?

Source: JavaSript – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *