Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add websocket HTTP upgrade/framing support to iroh-relay #2370

Closed
matheus23 opened this issue Jun 17, 2024 · 0 comments · Fixed by #2387
Closed

Add websocket HTTP upgrade/framing support to iroh-relay #2370

matheus23 opened this issue Jun 17, 2024 · 0 comments · Fixed by #2387
Assignees
Milestone

Comments

@matheus23
Copy link
Contributor

This is one of the pieces of work that enables iroh in the browser.

At the moment, relay clients connect via HTTPS and upgrade using the upgrade protocol iroh derp http.
This issue is solved once we add support for websocket as an HTTP upgrade and then talk websocket framing.

Ideally, this upgrade will be backwards-compatible. Clients connecting with iroh derp http should still be able to talk to updated relays, and websocket-based clients should be able to talk to iroh derp http-based clients.

Previous work happened on this branch: main...feat-websockets

@matheus23 matheus23 self-assigned this Jun 17, 2024
@dignifiedquire dignifiedquire added this to the v0.20.0 milestone Jun 28, 2024
github-merge-queue bot pushed a commit that referenced this issue Jun 28, 2024
…2387)

Implements the `websocket` protocol upgrade in iroh-relay and changes
`iroh-net` clients to connect with `websocket` instead of `iroh derp
http`.

State of this is:
- `cargo test -p iroh-net` runs green
- websocket on the relay is supported
- backwards compatibility is tested
- the client also supports connecting using websockets
- (but we're forced to use tungstenites connection establishment, no
custom `MaybeTlsStream`.)
  - It decides this via the URL scheme (`ws(s)://` vs. `http(s)://`) 

TODO:
- [x] Enumify the client so it's possible to keep using the old relay
protocol
- [x] Cleanup!
- [x] Some perf TODOs in the server, less copying.
- [x] Update documentation (e.g. `local_addr` having another case being
`None`)
- [x] Add metrics for websocket-accept & derp-accept counts
- [x] Snapshot tests (using `parse_hexdump`) for "new" wire format

## Description

- Supports clients connecting to iroh-relay with websockets & running
the derp protocol over websocket `Binary` msgs.
- Adds support for the relay answering `Upgrade: websocket` headers
instead of `Upgrade: iroh derp http` appropriately.
- Adds support for `ClientBuilder` to dial via websockets, if the relay
URL is set with a `ws`/`wss` URL scheme.

## Breaking Changes

- Not in the protocol: The old HTTP upgrade & protocol should still be
supported. There's tests to ensure this.
- `Client::local_addr` will now also return `None`, if one connected
using websockets.
- `iroh_net::relay::http::ClientError`: Added a variant `WebsocketError`
for errors when establishing a connection using websockets.

## Notes & open questions

Closes #2370 

## Change checklist

- [x] Self-review.
- [x] Documentation updates if relevant.
- [x] Tests if relevant.
- [x] All breaking changes documented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants