MatrixAI / Polykey

Polykey Core Library - Open Source Decentralized Secret Sharing System for Zero Trust Delegation of Authority
https://polykey.com
GNU General Public License v3.0
29 stars 4 forks source link

Network Traversal (by asking the router nicely) - UPNP #536

Open CMCDragonkai opened 11 months ago

CMCDragonkai commented 11 months ago

Specification

Now that we have js-mdns doing the multicast for local network discovery.

Another backup option is PCP/PMP through the UPNP protocol.

This basically communicates with the router in order to open ports. So technically it's about doing network traversal by asking the router nicely rather than punching through or via relays.

The main library I've found that can do all of this is https://github.com/pupnp/pupnp.

There are other JS libraries that are all unmaintained such as: https://github.com/velocityzen/node-upnp - therefore, it's better to instead just rely on the native library and wrap it up like we have done with js-db and js-quic. This sort of stuff has a niche community and there's no way multiple language environments would be developing these libraries together.

Just like js-quic, it would be nice to be able to do this runtime-less. I'm not sure if pupnp offers such an API. But let's see.

Additional context

Tasks

  1. Create a specification how UPnP should be used to open up ports on the router. Which protocols should we be using?
  2. Play with the https://github.com/pupnp/pupnp and try to wrap it within the Node API, it's a C++ library.
  3. Setup the library js-upnp.
  4. Integrate it into Polykey, since this isn't really about discovery, it can be placed into network domain. It would have to be exposed as way for PolykeyAgent to request that certain ports be opened up. However the actual ports that is in-use would depend on the agent to agent QUIC network, which is currently managed in the nodes domain. Prototype the integration and ensure that the lifecycle locations make sense.
tegefaulkes commented 11 months ago

I'm not sure uPNP is what we want exactly. I think uPNP may include NAT-PMP and PCP but we'll need to double check that.

I think NAT-PMP and PCP are simple enough to make requests in the typescript code directly. Some brief research shows that they're pretty simple request-response protocols. I can't say if that's preferable to some already made implementation though.

CMCDragonkai commented 11 months ago

The library covers all those protocols as far as I'm aware.