Mirror of https://github.com/ssbc/go-ssb-room/ to add Docker image builds with Drone
Go to file
2021-02-25 18:18:58 +02:00
.github/workflows github actions: bump go version to 1.16 2021-02-22 15:55:59 +01:00
admindb fix HTML list 2021-02-25 10:27:26 +01:00
cmd list, set and get pinned notices 2021-02-25 10:07:47 +01:00
handlers seperate room state from muxrpc handler 2021-02-11 15:30:51 +01:00
internal internal/broadcasts: fix test fluke 2021-02-15 15:26:50 +01:00
roomsrv small cleanup 2021-02-15 15:08:34 +01:00
roomstate various fixes 2021-02-11 15:31:45 +01:00
test route with query params instead of named routers 2021-02-15 14:43:55 +01:00
web format the HTML in allow-list.tmpl 2021-02-25 18:18:58 +02:00
.gitignore fix css flash-of-unstyled-content 2021-02-12 17:34:20 +02:00
errors.go room sever skeleton 2021-01-25 13:50:51 +01:00
go.mod (Pinned)Notices 2021-02-25 10:07:44 +01:00
go.sum (Pinned)Notices 2021-02-25 10:07:44 +01:00
README.md change name to go-ssb-room 2021-02-09 17:38:51 +01:00

Go-SSB Room

This repository contains code for a Secure-Scuttlebutt Room v2 server writen in Go.

It not only includes the secret-handshake+boxstream setup and muxrpc handlers for tunneling connections but also a fully embedded http/html interface for administering the room.

Features

  • Rooms v1 (tunnel.connect, tunnel.endpoints, etc.)
  • Sign-in with SSB
  • Simple allow-listing Currently via .ssb-go-rooms/authorized_keys. To be replaced with a authorization list on the dashboard.
  • Alias managment

Development

The basics just need a recent version of Go. v1.14 and onward should be sufficient.

To build the server and see a list of it's options, run the following:

$ cd cmd/server
$ go build
$ ./server -h
Usage of ./server:
  -dbg string
    	listen addr for metrics and pprof HTTP server (default "localhost:6078")
  -lishttp string
    	address to listen on for HTTP requests (default ":3000")
  -lismux string
    	address to listen on for secret-handshake+muxrpc (default ":8008")
  -nounixsock
    	disable the UNIX socket RPC interface
  -logs string
    	where to write debug output to (default is just stderr)
  -repo string
    	where to put the log and indexes (default "/home/cryptix/.ssb-go-room")
  -shscap string
    	secret-handshake app-key (or capability) (default "1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s=")
  -version
    	print version number and build date

If you are working on the sqlite migrations, html templates or website assets, build the server with go build -tags dev. This way it won't use the assets that are embedded in the binary but read them directly from the local filesystem.

Once you are done with your changes run go generate in the changed packages to update them.

Tooling

mocks

counterfeiter enables generating mocks for defined interfaces. To update them run go generate in package admindb.

TODO: setup tool as dependency (no manual install)

Database schema

This project uses sql-migrate to upgrate the sqlite database when necessary.

Just create a new file in admindb/sqlite/migrations with your changes but be reminded: Similar to the web assets, you need to use go test -tags dev to test them. Afterwards run go generate to embedd them in the code and thus the resulting server binary.

No ORM

We use sqlboiler to generate type-safe Go code code directly from SQL statements and table definitions. This approach suits the programming language much more then classical ORM approaches, which usually rely havily on reflection for (un)packing structs.

To generate them run the following commands. This will populate admindb/sqlite/models: (TODO: automate this with go generate)

# also included as generate_models.sh
cd admindb/sqlite
go test
sqlboiler sqlite3 --wipe

The generated package admindb/sqlite/models is then used to implemente the custom logic of the different services in admindb/sqlite.

Aside: I would have used sqlc since it's a bit more minimal and uses hand written SQL queries instead of generic query builders but it currently doesn't support sqlite.

Development user creation

cmd/insert-user contains code to create a fallback user. Build it and point it too your database with a username, like so:

cd $src/cmd/insert-user
go build
./insert-user $HOME/.ssb-go-room/roomdb my-user

Then repeat your password twice and you are all set for development.

Testing

Rooms

The folder tests/nodejs contains tests against the JavaScript implementation. To run them, install node and npm and run the following:

cd tests/nodejs
npm ci
go test

Web Dashboard

The folders web/handlers contain the HTTP handlers for the dashboard. Each subfolder comes with unit tests for the specific area (like auth, news, etc.). Simply run go test in one of them or run go test ./web/... in the root of the repo to test them all.

Authors

  • cryptix (@p13zSAiOpguI9nsawkGijsnMfWmFd5rlUNpzekEE+vI=.ed25519)

License

MIT