tradle / why-hypercore

Exploration of Hypercore's breakthrough designs and capabilities, uncovering its gems that may be scattered across different github accounts (official and community-led), and learning to think from the "first principles" of P2P, while using the best Cloud, AI and blockchain have to offer.
MIT License
81 stars 7 forks source link

Hyperswarm network reliability and fallback #3

Open urbien opened 4 years ago

urbien commented 4 years ago

Problem

See the issue for this. Summary:

  1. No UDP in browsers.

  2. Corporate firewalls may block UDP. Need to bridge to DHT over WebSockets or WebRTC.

  3. No peer discovery on Cell Phone networks. Cellphone networks run symmetric firewalls. So mobile apps or PCs on HotSpot can't establish direct connections (although UDP works, NAT hole punching does not).

  4. DHT state needs stability. Peers that come and go lose DHT state and need to recreate it (although this can be overcome with caching). Peers that change their IP address too often, destabilize DHT.

This solution uses 2 servers for signaling.

Note that WebTorrent works in the browser. Need to investigate how they do it. They have been discussing "DHT over WebRTC" for a long time.

See a number of issues still pending resolution to make Hyperswarm and Hypercore work in react-native

Fallback using Personal Cloud

  1. If in browser, fallback to 2.
  2. check holepunchable indicatior in Hyperswarm. If false, fall back to next ..
  3. get DNS record for bootstrap servers (multiple IPs). Tradle will dynamically populate DNS records using DNS server of the Data Center(s) in runs in.
  4. choose IP randomly (or rely on a DNS client to give one) and request DHT lookup for desired my Personal Cloud (e.g. hash of Identity).
  5. Mutual Authentication that this is our Personal Cloud. If failed, choose another IP.
  6. Cache IP. Response needs a TTL, e.g. 24 hours.
  7. Mutual Authentication that this is our Personal Cloud. If failed, repeat 2.
  8. Forward all Hyperswarm request to that IP.
  9. Read a feed from Personal Cloud with IP addresses of bootstrap servers. This avoid DNS altogether.
  10. Next time IP does not respond or does not Authenticate, repeat 3.

Notes

Future research

To increase privacy, especially for applications like COVID-19 Contact Tracing, we need to add encryption to DHT traffic.

balupton commented 3 years ago

While I am a newb when it comes to low-level p2p, I imagine that the cloudflare workers stack (workers kv for persistent, durable objects for ephemeral) could be used to facilitate a peer discovery service, and multiple workers from different accounts could sync data to facilitate a multi-owner DHT (akin to bittorrent trackers, or scuttlebutt pubs), which could use some form of cryptography to verify what the worker says who is who is actually who is who. Such operating on the edge with cloudflare power would solve a lot of the current performance issues with DHT technology. So clients could specify several of these worker locations to replace the oldschool dht, or supplement it, and update their listing as time goes on.

seems zeronet are somewhat doing this: https://github.com/HelloZeroNet/ZeroNet/issues/1913#issuecomment-466756674