hyperboria / bugs

Peer-to-peer IPv6 networking, secure and near-zero-conf.
154 stars 17 forks source link

Integrate with IPFS (IPNS) to solve problem of moving peers (dynamic IP addresses) #166

Open pruflyos opened 6 years ago

pruflyos commented 6 years ago

Let's imagine you want to connect to nodes which don't have a static IP address, but are moving or only get dynamic IP addresses assigned which change over time. Especially, what if none of the peers in the meshnet has a static IP address?

Problem: cjdroute.conf doesn't seem to allow to specify hostnames for peers which are resolved via DNS. The "connectTo": {...} sections of the config only allow IPv4 and IPv6 addresses to be specified. Even if hostnames were allowed in the config, you would have to rely on a centralized DynDNS service the peer uses whenever it's public IP address changes.

Here's an idea how this may be solved using IPFS/IPNS

Both, cjdns and ipfs, use Ed25519 keys. So theoretically the same key that is used to derive and secure the cjdns ip6 address, could be used as an ipfs key that controls (and can update) IPNS records. So whenever the public IP address of a peer changes, the peer just needs to add a new record to IPFS and update the IPNS link:

$ echo -n "217.182.195.23" | ipfs add -q
QmXgqbh3FbaW5L6Wdq1b4UCPSurHA499yDTSvMbGrGbHQk

$ ipfs name publish --key=cjdns /ipfs/QmXgqbh3FbaW5L6Wdq1b4UCPSurHA499yDTSvMbGrGbHQk
Published to QmfC3rb8kzDj4JHzZghBi2NVHpNAEpu9ACeFChRqB56Rmt: /ipfs/QmXgqbh3FbaW5L6Wdq1b4UCPSurHA499yDTSvMbGrGbHQk

Now, whenever cjdroute can't connect to a peer that supports this mechanism, it could query IPFS to see if the peer's IP address changed and if so, try again:

$ ipfs name resolve QmfC3rb8kzDj4JHzZghBi2NVHpNAEpu9ACeFChRqB56Rmt
/ipfs/QmXgqbh3FbaW5L6Wdq1b4UCPSurHA499yDTSvMbGrGbHQk

$ ipfs cat /ipfs/QmXgqbh3FbaW5L6Wdq1b4UCPSurHA499yDTSvMbGrGbHQk
217.182.195.23

Further thoughts

progval commented 6 years ago

Note: cjdroute used to support hostnames, but it was removed.

Macil commented 6 years ago

Small tip: you can do ipfs cat /ipns/QmfC3rb8kzDj4JHzZghBi2NVHpNAEpu9ACeFChRqB56Rmt. You don't have to resolve ipns entries in a separate step.

pruflyos commented 6 years ago

@ProgVal Do you know why support for hostnames was removed?

pruflyos commented 6 years ago

@AgentME Check the last item in "Further thoughts" of the original post I just added. You might want to resolve first and check the size of the target before blindly fetching it!?

Kubuxu commented 6 years ago

@pruflyos because it was misleading, it was resolving the hostname when starting cjdns node (when the configuration was being applied) and people were complaining that it should resolve it before every connection attempt.

JhonnyJason commented 3 years ago

Any update on this or hints which research I need to do it myself?