Gossip Sync Websocket Protocol

Posted on 16 Oct 2018 by Eric Oestrich

In the last few weeks I started on a new project that is tied to Gossip, the chat network for text-based games (aka MUDs.) This project is called Grapevine. Grapevine is a player site where you can register your characters across any game that is connected to Gossip.

Links for Gossip & Grapevine:

Sync Protocol

For Grapevine, I wanted to have it connect with the standard Elixir client for Gosisp which meant it needed to live on the same socket as a standard game. I went with adding in a Gossip network-level application that pretends to be a game for most parts, but when one connects it gives the socket super powers.

The biggest of those super powers at the moment is recieving sync/* events. When the socket connects it gets a set of sync events for all of the channels and games that Gossip knows about. Each event is bundled up into 10 channels or games, to help out a little bit with network overhead.

A sync event looks similar to this:

{
  "event": "sync/channels",
  "payload": {
    "channels": [
      {"id": 1, "name": "gossip", "description": "...", "hidden": false}
    ]
  }
}

When Grapevine receives this it creates or updates a local version of that remote record. I called this the backbone sync, you can view it here on Gossip's side.

These events also trigger for any creates or updates while the socket is connected. When a new game is made or a game is edited, Gossip broadcasts an internal sync event that the socket is subscribed to. This immediately pushes out and keeps the remote applications up to date always.

Raisin

One of the main reasons for wanting to head this socket route, is that I also wanted other higher privileged applications to live on the network. The next one being Raisin, which will be a moderation tool for the network.

With the start of Raisin, I wanted to reuse the same sync code across both projects. I had previously done this for Rails applications via Rails Engines, but I wasn't sure how to accomplish this. After talking with some fine folks over at the MUD Coders Guild, I think I stumbled across something that works.

I pulled out all of the common code into a new library that Grapevine and Raisin depend on. This library hosts its own ecto repo so it can internally save the data. Configuration wise, it's the same database as Grapevine or Raisin. That lets you use the backbone internal schemas outside of the backbone library.

I'll have more to say about this as I continue to explore it.

Conclusion

It is extremely exciting to watch these sync events propagate. The closest I've seen to this are webhooks, but being connnected to a duplexed socket is another thing entirely.

I hope you all check out the code backing all of this, and maybe even decide to join the network yourself as a player!

comments powered by Disqus
Eric Oestrich
I am:
All posts
Creative Commons License
This site's content is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License unless otherwise specified. Code on this site is licensed under the MIT License unless otherwise specified.