chatmail / chatmail/core

Add WebSocket support

Open
#8,559 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
929
Forks
143
Avg merge
1d 20h
Merged PRs (30d)
53

Description

There is a corresponding chatmail relay PR that adds the ability to connect to chatmail relays over WebSocket: https://github.com/chatmail/relay/pull/1030

As a first step to make it usable, we need core to support connecting over WebSocket.

First, need to extend "socket security" enum that already has Ssl (implicit TLS) and Starttls (STARTTLS) with a new "WebSocket" variant.

Then, login parameters (entered by the user in advanced settings) needs to be extended with a websocket path, likely right after the port: https://github.com/chatmail/core/blob/c3563f73e43cfdc031ab7a0c7bbd8fe385187a12/src/login_param.rs#L72-L75
It is not going to be used (and probably should not be accepted) if socket security is not set to WebSocket.

Configured parameters should be extended similarly here:
https://github.com/chatmail/core/blob/c3563f73e43cfdc031ab7a0c7bbd8fe385187a12/src/configure/server_params.rs#L17-L21

This will make it possible to configure websocket manually for testing. `DCLOGIN` QR code scheme can also be extended to support passing websocket path.

For implementation, there are two libraries:
- https://github.com/websockets-rs/rust-websocket, used by websocat, but unmaintained
- https://github.com/snapview/tungstenite-rs and https://github.com/snapview/tokio-tungstenite

tungstenite looks good, the main difficulty is using our own connection establishment code. We want to use our own DNS, proxy and TLS connector, so cannot use tokio-tungstenite as in examples.

Once there is a possibility to configure websockets manually, we can also test it together with https://github.com/chatmail/relay/pull/1030 and think about discovery later.

For reference, [XMPP](https://wiki.xmpp.org/web/Tech_pages/BOSH_and_Websocket) and [IRC](https://ircv3.net/specs/extensions/websocket) support websockets too. I have looked a bit into what they do, they both use message/frame structure of websockets, but in our case it's fine to ignore it and use websockets for streams. No need to try to put SMTP/IMAP commands into separate messages. IRC also uses WebSocket subprotocols, I don't think we are going to use them and don't need to allow selecting them. For IRC it just complicated things, IMO IRC should have defined a single binary protocol and make the client deal with invalid UTF-8 locally.

Contributor guide

Open the contributing guide

Research direction

Start by reading the socket security enum and the parameter definitions in src/login_param.rs and src/configure/server_params.rs, then trace the existing connection-establishment code. Add manual WebSocket configuration, including the DCLOGIN path, while preserving the project’s DNS, proxy, and TLS handling. Done means core can connect to the relay WebSocket endpoint and be tested with chatmail/relay#1030.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design, networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.