Working p2p chat application

Hi folks,

I’ve been working on a chat application to learn more about libp2p and also to practice distributed systems stuff. The chat has a desktop app implemented using Electron and provides installers for Linux and macOS. It works by spawning a local node implemented in Go using go-libp2p.

Chat messages are sent and received via gossipsub and peers can set nicknames for themselves (I’ve used the DHT for that, even though I’m not sure that’s the way to go).

Finally, I also deployed a bootstrap node in a VM on Google Cloud Platform so everyone should be able to connect there and see the app working :slight_smile:.

Code, tools and installers can be found at the project’s repo (I plan to write some simple documentation in the future):

If anyone is interested in helping or discussing, feel free to open an issue (or contact me here :smiley:)

1 Like

Looks neat! I’m trying to figure out the API from reading the code and I was curious about JoinRoomRequest / JoinRoomResponse. Who exactly is responsible for responding to a join-room request, does every user have to be in the “global” room in order to share nickname data? Maybe there is some file I’m not looking at and I should be to understand this level of the API.

Another question - why did you decide to use go-libp2p instead of js-libp2p, given that most of the code in this project is in JavaScript anyways? I’m not criticizing the decision or anything, I was just considering making a similar application myself and not sure whether it would be worth it to use a second language for a possibly-superior libp2p library for some reason so I’m curious how you came to this design decision.

Hey @lacker, thanks!

If I got your first question right:

  • The gRPC API is used to communicate with the “standalone node” (or agent, I don’t really know how to call it) that is implemented in Go. Currently it is used by the Electron app to send commands and get some data
  • Yes, users have to be in a room (not only “global”) to share and received shared nickname data. Nicknames are shared through the pubsub topic (which I called advertising).
  • There’s only the “global” room because I didn’t implemented the UI to support multiple rooms in the Electron app (the go-node supports multiple rooms).

For the second question:

Just to make it clear, I surely didn’t take that as criticizing haha! Super fair question.

I started by just implementing the chat code as a CLI program in Go using go-libp2p. Just after having some of the code implemented I thought about adding an app. So it was not because of the differences in the implementations (Go vs. JavaScript).

In hindsight, building things that way gives me the ability to start a bootstrap node in a VM in Google Cloud without the UI and have users use the app. I was also inspired by how IPFS Desktop is implemented.

Let me know if I made all points clear! I’m glad you found the code useful.

This is super cool!
Do you also have the source code just for the CLI program anywhere?

Thanks, @moratsam :slight_smile:

Sure, here it is: go-libp2p-chat/go-node at main · FelipeRosa/go-libp2p-chat · GitHub

I need to improve the docs a bit.

1 Like

I tried to build the go component on my machine and maybe the paths to your local machine are hard-coded in or maybe I’m missing a step? After “make build”:

$ make build
go build -o chat-gonode cmd/node/main.go
cmd/node/main.go:13:2: cannot find package “

I can open an issue if you prefer…

Hey @lacker,

I think creating an issue is better so we don’t pollute the topic.

In the meanwhile, can you please check your Go installation version by running go version? I think it might be related.

1 Like

Ah yeah it’s an older Go version. I’ll try updating that and follow up with an issue if I still can’t fix it. Thanks!

1 Like