little-bear-labs / ipfs-chromium

19 stars 1 forks source link

Research ways we could leverage /webtransport peers #42

Open lidel opened 1 year ago

lidel commented 1 year ago

This is a placeholder for work that will improve connectivity by leveraging peers that expose HTTP Gateway over WebTransport with certhash.

Not ready yet, but will update this issue as relevant building blocks land in ecosystem.

High level idea

Open questions

lidel commented 1 year ago

@MarcoPolo what would be the absolute minimum amount of libp2p we would have to implement here to:

  1. take /..../webtransport/../p2p/{peerid} multiaddr
  2. connect to it
  3. check if it supports /http* and probe for /ipfs endpoint.
  4. make HTTP rrquests over /webtransport connection that exposes/ipfs` endpoints semantics ?
MarcoPolo commented 1 year ago

At a very high level:

  1. take /..../webtransport/../p2p/{peerid} multiaddr

a. Parse the multiaddr. b. Parse multihash (certhashes). c. Parse the peer id.

  1. connect to it

Right now this requires peer authentication. There's interest to make WebTransport authentication optional in the future, which would simplify this use case.

a. Open a WebTransport connection to https://example.com/.well-known/libp2p-webtransport?type=noise b. Due to peer auth, run a libp2p noise handshake: https://github.com/libp2p/specs/tree/master/noise#the-noise-handshake c. If doing peer auth, verify the certhashes of the peer are what you expect.

  1. check if it supports /http* and probe for /ipfs endpoint.

a. Open a new stream and negotiate /http/1.1 on it. If this worked they support HTTP over libp2p. b. GET the .well-known/libp2p resource and see where the trustless-gateway is mounted.

  1. Get blocks!

a. Open a new stream with /http/1.1 for each HTTP request. b. Use js-libp2p-fetch instead of fetch to get the blocks. (js-libp2p-fetch doesn't actually need js-libp2p, and is almost 0 dependencies except for a js-libp2p quirk requiring a Uint8ArrayList dependency). c. At this point it should be identical to the existing way.

If we prioritize this we could make webtransport auth optional, and thus reduce a lot of complexity around doing the Noise handshake.

lidel commented 11 months ago

Update: Kubo 0.23 will include opt-in "gateway over libp2p" experiment from https://github.com/ipfs/kubo/pull/10108

TLDR

I think it is long term thing, but we should be able to make it work: