Delta Chat introduces realtime Peer-to-Peer networking

November 20, 2024 by olgax,l,r10s,adb,hocuri,jag,simon

Are you interested in enshittification-resistant application development? After almost two years of collaboration with the wonderful Iroh team, and years of discussions with numerous experts in the decentralization space, we are happy to announce that Delta Chat 1.48 apps on all platforms contain state-of-the-art Peer-to-Peer networking support, including hole punching and forward-secret end-to-end encryption. Concretely, Delta Chat now establishes private Peer-to-Peer gossipping networks between users who start a webxdc app that uses the new joinRealtimeChannel() API.

In the following sections, we discuss the “Pixel app” shown in the video and other realtime example apps, before providing more technical background and a closing note on the importance of protocols and specifications in our endeavours. If you want to try out any webxdc app, including the realtime ones:

  1. Install Delta Chat, create a profile and establish a chat with someone

  2. Tap this invitelink to the xstore bot and wait until you receive the store app

  3. Start the store app, pick an app for download and then share it to any chat

Pixel app: small, offline-first and realtime

pixel1-screenshot

The source code of the pixel app shown in the above video

The pixel app achieves its hybrid offline-first and realtime connectivity by using two separate webxdc messaging APIs:

To learn the theory behind how the pixel app achieves “eventual synchronization for all users”, we suggest to dive into our Shared Web Application state chapter and then re-read the 241 lines of Javascript with a particular eye to “Lamport Clocks” – no framework or dependency needed to use this science-fiction-sounding technology ;)

If you want to improve the app, please fork and submit your variant. There already is a Color Pixel app fork where each participant draws pixels in a different color.

Pong app: realtime-only and implements clock synchronization

The pong app repository provides a simple two-player implementation of the classic pong game. UX-wise it’s rudimentary but it does implement basic “clock synchronization” which is an important consideration for any realtime networked gaming app.

Wouldn’t it be nice to have more original or more modern versions of Pong? Maybe also with sounds and colors? Also, to provide a “rollback algorithm” you might look at a 3rd party WebRTC-based Pong development writeup to understand what’s involved.

In any case, if you want to improve on this little Pong classic game, please fork and submit your variant.

Realtime Editor: cursor positions and immediate collab

The realtime editor app is a collaborative editor that can show realtime cursors and changes. However, it’s also behaving as an offline-first app, similar to the pixel app above. If you join a chat-shared realtime editor app later, you’ll see all changes consistently combined. The realtime editor is a fork of the basic webxdc editor but with realtime capabilities added.

Wouldn’t it be nice if there would be coloring of edits? Maybe provide a slider that allows to go back in document history? Or maybe a way to import a picture into the realtime pad?

Again, if you can improve this editor tool you are more than welcome. Please fork and submit your variant.

Unix terminal app: realtime with a chat bot

The xdcterm app demo allows to run a chat bot in Javascript and then establish contact with it from your chat profile. The bot will create a group where you can add more members all of which can see a shared terminal (it’s as if screen-sharing is built-in).

If you want to play with or improve this rudimentary terminal app, please fork and feel free to let us know. You can not submit it to the webxdc app store because it requires a running chat bot on some unix-ish server.

Live Chat: realtime chat in a chat :)

The LiveChat app provides ephemeral chatting with realtime typing-indicators between anyone in a chat group who starts the live chat. Messages are not persisted and all history is cleared when you close the app. If all users have closed the app all content is gone. There you go. Fully ephemeral, end-to-end encrypted P2P chat at your fingertips :)

You may use a Live Chat app in a larger existing chat group to host a fast “ephemeral side conversation” that will not cause any network traffic for other chat group members who don’t join the live chat.

Get ready, player two!

Webxdc Logo

To get started on webxdc app development, we recommend the following readings:

Please don’t hesitate to get back to our fediverse account, the webxdc support forum category or other contact addresses.

Technical background on our Iroh/P2P integration

Iroh Logo

A joint focus with the Iroh team has been to support all platforms reliably, including mobile platforms. For the last half year Delta apps had an opt-in experimental “webxdc realtime” setting which, after extensive testing and bug fixing, is now enabled by default.

How private P2P networking is established

Only if you start an app that uses the webxdc.joinRealtimeChannel() API will Delta Chat initiate participation of your device in a P2P network. Delta Chat will send an end-to-end encrypted “system” chat message to a group chat that contains an Iroh Ticket. When receiving devices also join the realtime channel, they can establish a direct connection immediately because the ticket is already on record. No lookup in a global distributed hash table slows down or complicates the initial connection. The federated e-mail system is used to bootstrap an ephemeral Peer-to-Peer network.

You may download the Realtime Check app and share it into a chat to perform network latency analysis between realtime messaging peers. You can already run it in “Saved Messages” between two devices in a multi-device setup.

To establish a direct P2P connection, two interested devices will use an Iroh Relay which typically runs on every chatmail server, mirroring the existing e-mail federation. If your chat profile is using a classic e-mail server then a global default relay is used, operated kindly by the Iroh team.

The Iroh relay server combines both STUN and TURN functionality, to allow peers to discover and directly connect. Additionally it relays messages as long as no direct connection is established. For more details please check our Rust deltachat::peer_channels docs.

Identity on the P2P network is ephemeral, and encryption is forward-secret

Delta Chat uses ephemeral cryptographic identities for any P2P messaging. When Delta Chat is closed or stopped by the operating system, then a new ephemeral identity will be created on the next start. Moreover, Iroh uses QUIC on the networking layer which implements Forward Secrecy.

Ephemeral identities and forward-secret encryption shield against an attacker that collects encrypted network traffic and later compromises your device to try to decrypt past recorded traffic. Not only the Live Chat app but all realtime webxdc apps benefit from the ephemeral and end-to-end-encrypted Peer-to-Peer messaging provided by the Iroh stack and its Delta Chat integration on all platforms.

A privacy note on IP-addresses

Delta Chat does not store IP-addresses anywhere and it does not expose IP addresses in the user interface or to webxdc apps. Iroh relay servers do not see all the IP addresses that user devices advertise to each other (for example relays don’t see peer’s WLAN addresses), and relays also do not store any IP addresses when facilitating a P2P connection.

However, chat partners may learn about your IP address if they deploy some network monitoring tool or use a modified version of Delta Chat. If using webxdc apps with a potentially hostile chat partner is a concern for you you may disable the “webxdc realtime” setting in “advanced settings” to be sure that Delta Chat will never attempt any Peer-to-Peer connection with anyone. Don’t forget to then also be careful when clicking on any HTTPS-link in a chat as a hostile sender could use it to extract your IP-address as well.

Specifications, protocols and the freedom to exit

When other webxdc-supporting XMPP messengers like Cheogram and Monocles implement the new webxdc realtime API, they are not required to use Iroh but can instead use other existing XMPP ephemeral messaging capabilities.

The webxdc.joinRealtimeChannel() API is a minimal high-level API that is easier to use than the classic WebRTC Browser P2P API because a webxdc messenger implementor carries the burden to manage all dynamic connectivity, discovery and network routing aspects.

In fact Delta Chat apps themselves could evolve to use a different implementation for webxdc realtime communications. We’ve noted in the Fediverse lately that Protocols and specifications provide freedom of exit and the new realtime API specification is a practical example for that.

Thanks to NLNET and NGI for support and vision!

NLNet Logo
Our introduction of the webxdc realtime API has been supported by NLnet, themselves funded by the European Commission’s Next Generation Internet programme.


Show Comments


You can reply on any Fediverse (Mastodon, Pleroma, etc.) website or app by pasting this URL into the search field of your client:

https://chaos.social/@delta/113514874537852340