Skip to content

A Peer-to-Peer chat using re-frame, reagent and libp2p

Notifications You must be signed in to change notification settings

techascent/p2p-chat

Repository files navigation

P2P Chat

What is it? P2P chat is a very simple example of leveraging the libp2p library from clojurescript.

Why? As a quick demonstration of how we can build P2P applications in Reagent / Re-Frame with a data-binding backed by a pub/sub model provided by the libp2p framework.

How does it work?

  • Static files for the initial page, javascript and css are provided by the server.
  • Next, each browser window connects to a bootstrapped peer list using libp2p and then subscribes to a "topic"
  • Under the covers, libp2p uses web-sockets to connect the client to a set of distributed peers -- meanting it doesn't need a centralized server for communiations.
  • Messages that are sent are published and each node "subscribes" to these updates.
  • When the node gets an update, it populates its own local "app db" in re-frame with the relevant message
  • The messages view then gets the update and shows it to each of the users.

NOTE libp2p is very experimental and subject to change. This project was meant as a toy exploration and not meant as a production solution.

Caveats

This solution isn't without caveats. Notably, the compiled code is several megabytes which is a substantial hit on first load. Additionally, the previous messages are not stored so when a client connects it only gets new updates.

Alt text

Installation

  1. Clone this repo
  2. Run ./scripts/install.sh to obtain the libp2p library (warning: experimental)
  3. Run lein cljsbuild once to build the javascript
  4. Run lein garden once to build the css
  5. Run lein repl and (-main) to start the server (only serves static files)

Releases

No releases published

Packages

No packages published