Commit Graph

49 Commits

Author SHA1 Message Date
Daniel Sockwell 440d691b0f
Filter toots based on user and domain blocks (#89)
* Read user and domain blocks from Postgres

This commit reads the blocks from pg and stores them in the User
struct; it does not yet actually filter the responses.  It also does
not update the tests.

* Update tests

* Filter out toots involving blocked/muted users

* Add support for domain blocks

* Update test and bump version
2020-03-12 22:44:31 -04:00
Daniel Sockwell 405b5e88e5
Update logging (#85)
* Change "Incoming" log msgs from Warn to Info

* Stop logging err when unix socket closed

* Bump version to 0.4.7
2020-01-10 17:56:19 -05:00
Daniel Sockwell ac75cb54af
Postgres connection pool (#84)
* Upgrade rust-postgres library

* Initial postgres connection pool

* Update tests

* s/pg_conn/pg_pool to match reality
2020-01-10 15:45:16 -05:00
Daniel Sockwell 0462267125
Unix sockets (#81)
* Fix unix socket permission issue

* Add support for Unix sockets

* Update README and bump version
2020-01-09 17:54:57 -05:00
Daniel Sockwell 67c59401fd
Unix sockets WIP (#77)
* Initial WIP Unix socket implementation

* Bump version to v0.4.5

* Update type data
2020-01-08 09:51:25 -05:00
Daniel Sockwell b216a81e26
Add api/v1/streaming/health API endpoint (#74) 2020-01-07 17:27:46 -05:00
Daniel Sockwell 0de3d3c484
Postgres config (#70)
* Add logging for known env variables

* Update postgres config to match other configs

* Update README and bump version to 0.4.2
2020-01-05 21:58:18 -05:00
Daniel Sockwell c281418f25
Enforce type safety in config (#63)
* Add type-safe wrapper types to deployement_cfg

* Before deleting redundnat macros

* Store error messages as data

* Significant progress on type safety

* Add type safety to RedisConfig
2019-10-08 20:35:26 -04:00
Daniel Sockwell 9d96907406
Functional config (#59) 2019-10-03 18:02:23 -04:00
Daniel Sockwell e8145275b5
Config refactor (#57)
* Refactor configuration

* Fix bug with incorrect Host env variable

* Improve logging of REDIS_NAMESPACE

* Update test for Postgres configuration

* Conform Redis config to Postgres changes
2019-10-03 00:34:41 -04:00
Daniel Sockwell 11661d2fdc
Redis config (#56)
* Add most Redis config variables

* Add REDIS_NAMESPACE env var

* Fix Clippy lints
2019-10-02 00:03:18 -04:00
Daniel Sockwell 0dec8c4124
Solve SendErrors (#47)
This commit solves the SendErrors that were triggered by attempting
to use a WebSocket connection after it had been closed by the client
2019-09-11 00:13:45 -04:00
Daniel Sockwell 989c71059e
Remove debug statements (#43) 2019-09-09 14:23:48 -04:00
Daniel Sockwell ecfdda093c
Add tests for websocket routes (#38)
* Refactor organazation of SSE

This commit refactors how SSE requests are handled to bring them into
line with how WS requests are handled and increase consistency.

* Add websocket tests

* Bump version to 0.2.0

Bump version and update name from ragequit to flodgatt.

* Add test for non-existant endpoints

* Update documentation for recent changes``
2019-09-09 13:06:24 -04:00
Daniel Sockwell 90602d17ed
Replace integration tests with unit tests (#37)
* Upgrade postgres dependency to support ssl

* Clean up configuration code

* Add support for SSL with postgres [WIP]

* Add unit tests with mock Postgres
2019-09-04 21:48:29 -04:00
Daniel Sockwell 9ec245ccdb Add additional logging for postgres connection/server status 2019-07-09 22:20:11 -04:00
Daniel Sockwell 866f3ee34d Update documentation and restructure code 2019-07-08 15:21:02 -04:00
Daniel Sockwell d6ae45b292 Code reorganization 2019-07-08 07:31:42 -04:00
Daniel Sockwell 1732008840 Initial cleanup/refactor 2019-07-05 20:08:50 -04:00
Daniel Sockwell f3b86ddac8 Add CORS support
Cross-Origin requests were already implicitly allowed, but this
commit allows them explicitly and prohibits request methods other
than GET.
2019-07-04 14:00:35 -04:00
Daniel Sockwell 1765dc39ee Check oauth scopes and reject unauthorized requests 2019-07-04 13:27:11 -04:00
Daniel Sockwell f8a82caa2d Support passing access tokens via Sec-WebSocket-Protocol header
Previously, the access token needed to be passed via the query string;
with this commit, the token can be passed *either* through the query
string or the Sec-WebSocket-Protocol header.

This was done to correspond to the changes made to the streaming.js
version in [Improve streaming server security](https://github.com/tootsuite/mastodon/pull/10818).
However, I am not sure that it *does* increase security; as explained
at <https://support.ably.io/support/solutions/articles/3000075120-is-it-secure-to-send-the-access-token-as-part-of-the-websocket-url-query-params->,
there is generally no security advantage to passing sensitive information
via websocket headers instead of the query string—the entire connection
is encrypted and is not stored in the browser history, so the typical
reasons to keep sensitive info out of the query string don't apply.

I would welcome any corrections on this/reasons this change improves
security.
2019-07-04 10:57:15 -04:00
Daniel Sockwell 280cc60be9 Add hard-coded "sec-websocket-protocol" response header 2019-07-04 09:33:50 -04:00
Daniel Sockwell a6a7ebeae1 Add dotenv configuration 2019-05-10 06:22:26 -04:00
Daniel Sockwell 8ae9bbfac5 Revised WebSocket implementation 2019-05-10 01:47:29 -04:00
Daniel Sockwell 54ad55e0c0 Basic WebSocket support 2019-05-09 11:52:05 -04:00
Daniel Sockwell 6d037dd5af Working WS implemetation, but not cleaned up 2019-05-08 23:02:01 -04:00
Daniel Sockwell 4649f89442 Add unit tests, (some) integration tests, and documentation 2019-04-30 18:41:13 -04:00
Daniel Sockwell 62db7ae0ff Share a single Redis connection
This commit revises the code structure to share a single connection
to Redis (with multiple subscriptions on that connection) rather than
mutiple connections (each with one subscription).  It also simplifies the code based on that change.
2019-04-30 09:44:51 -04:00
Daniel Sockwell 9e921c1c97 Add ability for multiple clients to connect to the same pub/sub connection 2019-04-28 17:28:57 -04:00
Daniel Sockwell 425a9d0aae Allow seperate SSE responses to share Redis pubsub
This commit implements a shared stream of data from Redis, which
allows all SSE connections that send the same data to the client
to share a single connection to Redis.  (Previously, each client
got their own connection, which would significantly increase the
number of open Redis connections—especially since nearly all clients
will subscribe to `/public`.)
2019-04-26 20:00:11 -04:00
Daniel Sockwell f676e51ce4 Add limit on number of active streams
This commit tracks the number of active Pub/Sub streams and adds code to
keep the total number of streams below 400.  (When additional users
attempt to connect past that point, the server will wait for an slot
to open up).  This prevents "too many open file" panics and makes the
server better behaved in general.  However, we may need to revisit it
based on what capacity we want the server to have.

This commit also includes some general refactoring.
2019-04-23 14:07:49 -04:00
Daniel Sockwell 4832f59f2f Fixup
This code should have been included with the previous PR
2019-04-21 09:31:16 -04:00
Daniel Sockwell e1257146cd Close Redis connections when SSE stream ends
This commit tracks the existence of the SSE stream and closes the
connection to the redis pub/sub channel when the stream is closed.  This
prevents the number of redis connections from growing over time.

Note, however, that the current code still subscribes to one redis
channel per SSE connection rather than reusing existing subscriptions.
This will need to be fixed in a later PR.
2019-04-21 09:21:44 -04:00
Daniel Sockwell 5011abaf77 Add language and notification filters 2019-04-19 17:06:29 -04:00
Daniel Sockwell ff957bd407 Minor refactoring
Improved clarity, concision, and ergonomics of the codebase.
2019-04-19 12:16:03 -04:00
Daniel Sockwell 6746514f9a Finish building out postgres auth 2019-04-18 19:02:29 -04:00
Daniel Sockwell debf01770e Complete header-based auth 2019-04-18 17:07:31 -04:00
Daniel Sockwell 13d9cf17f6 Connect to postgres for basic auth 2019-04-18 15:47:08 -04:00
Daniel Sockwell 9434260fa7 Add logging with `pretty_env_log`
This commit adds basic logging at both the `info` level (for establishing
a new stream) and at the `debug` level (for streaming JSON).
2019-04-18 10:10:01 -04:00
Daniel Sockwell 23eaa4a270 Implement basic Server Sent Events with Warp
This commit rolls up several days of work that took place in a side repo
which was originally intended to be a test/proof-of-concept repo but
that grew into a full implementation.

This implementation switches to Warp as the framework for the primary
web server (in large part because Warp offers built-in support for
SSE and several other advantages).  This implementation relies on
a custom Redis interface built on Tokio (because the current Redis
Rust crate does not support asnyc PubSub).  Using a custom interface
should also be faster, since it does not contain logic for anything
other than pubsub—which is all we need.

Finally, I note that the SSE support is currently as feature-complete
as it is possible to be without having yet added the Postgress interface
this means that all of the endpoints are present and are accessible
on localhost.  However, none of the endpoints have authentication yet,
and the endpoints that should provide user-specific data (e.g.,
`/api/v1/streaming/user`) are currently hard-coded to provide data for
user 1 (the admin).  Other than those limitations, however, the SSE
implementation is feature complete.
2019-04-15 14:22:44 -04:00
Daniel Sockwell 4842475b18 Rustfmt all code
Revise all code to comply with rustfmt
2019-03-05 09:23:44 -05:00
Julian Laubstein bfec0327d6 Use redis environment for connection 2019-02-19 22:57:01 +01:00
Julian Laubstein dfafec963b Added structures for env variables 2019-02-19 20:29:32 +01:00
Julian Laubstein dcc0283078 Fixed cors and added health endpoint 2019-02-15 22:59:21 +01:00
Julian Laubstein 88492aac36 Lots of basic stuff 2019-02-15 10:22:35 +01:00
Julian Laubstein 524935c441 Added all routes as mock 2019-02-11 21:00:07 +01:00
Julian Laubstein 1339784112 Added all endpoints 2019-02-11 18:58:51 +01:00
Julian Laubstein 7caa714891 Initial project files 2019-02-11 09:45:14 +01:00