libp2p / specs

Technical specifications for the libp2p networking stack
https://libp2p.io
1.58k stars 275 forks source link

docs: WebTransport and CircuitV2 #523

Closed Winterhuman closed 1 year ago

Winterhuman commented 1 year ago

I was reading https://github.com/libp2p/specs/tree/master/webtransport when I saw:

"The WebTransport URL of a WebTransport server advertising /ip4/192.0.2.0/udp/1443/quic/webtransport/ would be https://192.0.2.0:1443/.well-known/libp2p-webtransport?type=noise."

If the URL is what's actually being tried, doesn't that mean you can't use WebTransport only with CircuitV2 to establish a connection from a browser to a node behind NAT? Should this be documented if so?

marten-seemann commented 1 year ago

WebTransport runs on top of HTTP/3, so there's no way around this.

Winterhuman commented 1 year ago

Thanks for confirming. Do you think it's worth noting somewhere in the documentation that HTTP-based transports are incompatible with CircuitV2?

marten-seemann commented 1 year ago

That applies to all non-TCP transports, doesn't it?

Winterhuman commented 1 year ago

QUIC & WebSocket work don't they?

Winterhuman commented 1 year ago

Ah no, WebSocket wouldn't either since that needs a URL too

Winterhuman commented 1 year ago

I see what you mean now, anything that isn't TCP or QUIC is incompatible with CircuitV2, there would be too many transports to list them all; it's an inherit property of web-available transports. Closing issue

EDIT: Or not? See discussion after

marten-seemann commented 1 year ago

A relayed connection is a single, bidirectional byte stream, so all you can is upgrade that byte stream with a security and muxer protocol, analogous to what you do with a TCP connection.

For the connection to the relay, you can use any transport you like, including WebRTC and WebTransport.

Winterhuman commented 1 year ago

@marten-seemann I'm confused. Just to ask plainly, if there are two nodes, A and B, who are both behind non-symmetric NATs, and who only use WebTransport, can CircuitV2 allow a direct connection between A and B to form? If not, would A having transports other than WebTransport available, but not B, make this work instead?

This is assuming node B is running in a browser, and is subject to the browser's WebTransport API

marten-seemann commented 1 year ago

Circuitv2 doesn't allow direct connection, it allows relayed connections. It is a prerequisite for hole punching though, which then would give you a direct connection.

This should answer you question:

For the connection to the relay, you can use any transport you like, including WebRTC and WebTransport.

Winterhuman commented 1 year ago

No, I'm still confused, you're saying CircuitV2 can give you a direct connection after the holepunching packets are sent, but you also said "WebTransport runs on top of HTTP/3, so there's no way around this." implying WebTransport can't use the holepunched ports?

I'll leave the discussion here though, it's better if I wait until CircuitV2 support is merged in js-libp2p to actually test this