• Stars
    star
    181
  • Rank 205,151 (Top 5 %)
  • Language
    Go
  • License
    Other
  • Created over 8 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple, topic-based PUB/SUB WebSocket server.

Philote: plug-and-play websockets server Build status

Philote is a minimal solution to the websockets server problem, it implements Publish/Subscribe and has a simple authentication mechanism that accomodates browser clients securely as well as server-side or desktop applications.

Simplicity is one of the design goals for Philote, ease of deployment is another: you should be able to drop the binary in any internet-accessible server and have it operational.

For a short demonstration, check out the sample command line Philote client called Jane

Basics

Philote implements a basic topic-based Publish-subscribe pattern, messages sent over the websocket connection are classified into channels, and each connection is given read/write access to a given list of channels at authentication time.

Messages sent over a connection for a given channel (to which it has write permission) will be received by all other connections (that have read permission to the channel in question).

Deploy your own instance

You can play around with Philote by deploying it on Heroku for free, keep in mind that Heroku's free tier dynos are not suited for production Philote usage, however, as sleeping dynos will mean websocket connections are closed.

Deploy

Configuration options

Philote takes configuration options from your environment and attempts to provide sensible defaults, these are the environment variables you can set to change its behaviour:

Environment Variable Default Description
SECRET Secret salt used to sign authentication tokens
PORT 6380 Port in which to serve websocket connections
LOGLEVEL info Verbosity of log output, valid options are [debug,info,warning,error,fatal,panic]
MAX_CONNECTIONS 255 Maximum amount of concurrent websocket connections allowed
READ_BUFFER_SIZE 1024 Size of the websocket read buffer, for most cases the default should be okay.
WRITE_BUFFER_SIZE 1024 Size of the websocket write buffer, for most cases the default should be okay.
CHECK_ORIGIN false Check Origin headers during WebSocket upgrade handshake.

If the defaults work for you, simply running philote will start the server with the default values, or you can just manipulate the environment and run with whatever settings you need.

$ PORT=9424 philote

CLI

There is a trivial implementation of basic Philote interaction called Jane that you can run locally, it can subscribe to a channel on a Philote server, receive and publish messages. It's useful for debugging purposes.

sample

Clients

Authentication

Clients authenticate in Philote using JSON Web Tokens, which consist on a JSON payload detailing the read/write permissions a given connection will have. The payload is hashed with a secret known to Philote so that incoming connections can be verified, this way you can generate tokens in your application backend and use them from the browser client without fear.

Clients in different language will provide methods to generate these tokens, for now, the Go client should be the reference implementation, although you'll notice that it's an extremely simple one so ports to other languages should be trivial to implement provided with a decent JWT library.

For incoming websockets connections, Philote will look to find the authentication token in the Authorization header, but since the native browser JavaScript WebSocket API does not provide a way to manipulate the request headers Philote will also look for the auth query parameter in case it fails to authenticate using the header option.

Install

You can install Philote (and Jane) easily with homebrew.

brew install pote/philote/philote

brew install pote/philote/jane

You can also manually get the binaries from latest release or install from source

Local development

Bootstrap it

You'll need gpm for dependency management.

Set it up

$ source .env.sample # you might want to copy it to .env and source that instead if you plan on changing the settings.
$ make

Run a Philote server

$ make server

Run the test suite

$ make test

Install from source

$ make install

History

The first versions of Philote were powered by Redis, it was initially thought of as a websocket bridge to a Redis instance.

After a while, that design was considered inpractical: redis is a big dependency to have, publish/subscribe was easy to implement in Philote itself and the authentication mechanism was changed to use JSON Web Tokens, making Redis unnecessary.

The result should be a more robust tool that anyone can drop in any operating system and get working trivially, without external dependencies.

License

Released under MIT License, check LICENSE file for details.

More Repositories

1

gpm

Barebones dependency manager for Go.
Shell
1,191
star
2

gvp

Go Versioning Packager
Shell
269
star
3

disc

Simple Disque-powered Ruby Jobs
Ruby
129
star
4

planet.rb

A feed aggregator implementation intended to be used with Octopress
Ruby
66
star
5

hashifiable

Dead simple hash representation declarations.
Ruby
60
star
6

int

Tiny in-browser internationalization.
JavaScript
17
star
7

gohm

Go's Object Hash Mapper
Go
16
star
8

dropshare-landing

My dropshare landing page
JavaScript
12
star
9

gpm-bootstrap

A gpm plugin to kickstart your Go project's dependency versioning.
Shell
11
star
10

homebrew-gpm_plugins

A repository of gpm plugins installable through homebrew.
Ruby
8
star
11

box

A dead easy "inline filesystem" for your ruby scripts
Ruby
8
star
12

disco

An idiomatic Disque client for Go.
Go
7
star
13

dtb

Drinking Typing Bird
Go
5
star
14

philote-js

Browser library for the Philote websockets server
JavaScript
5
star
15

chronicler

A storytelling web toolkit for Go
Go
3
star
16

takeoff

Magically show your presentation's slides in a remote AppleTV or Computer running Airserver
JavaScript
3
star
17

gpm-all

A gpm plugin for per-environment dependency groups
Shell
3
star
18

philote-go

Go client for the Philote websocket server.
Go
2
star
19

wayfinder

A bookkeeping tool for the Pathfinder Role Playing Game.
Ruby
2
star
20

Planet

Code from planetplanet.org [I am not the author, but I needed to do some slight changes to it and decided to open a public repo for that]
Python
2
star
21

hashdot

Cozy Hash Accessors
Ruby
1
star
22

conference-resources

Resources for my conference-related things, talks, profile pictures, bio, etc.
1
star
23

Tamarindo

Time management for the attention span impaired
Python
1
star
24

kosmonaut

The backend protocol client for WebRocket
C
1
star
25

jane

A test CLI chat that uses Philote as it's backend.
Go
1
star
26

philote-chat-app

A stupid simple chat app intended to showcase the philote websocket server.
JavaScript
1
star
27

philote-rb

A Ruby client for the Philote websockets server.
Ruby
1
star
28

Fractions-of-Cakes

A math game for XO (OLPC) laptops
Python
1
star
29

jose-mujica-reddit-ama

We feel it would be super interesting to get Mr. Jose Mujica (Uruguay's current president) to do a reddit IAMA, this repo aims to be the official document with the proposal for him
1
star
30

Buena-Pregunta

Creative commons licensed music - complete or midway through - from my old band.
1
star