Commit Graph

86 Commits (7736e247b7c432c91aeb658ba4446907b7bb8268)

Author SHA1 Message Date
Andrew Morgan 7736e247b7
Send Application Service Events (#477)
* Prevent sql scanning into nil value in accounts_table

Signed-off-by: Andrew Morgan <andrewm@matrix.org>

* Remove uneccessary logging, null checking

* Don't forget to set the localpart

* Simplify error checking

* Store And Send Application Service Events

* Modify INSTALL.md and dendrite-config.yaml for the new appservice database
* Correct all instances of casing on 'application service' to align with
spec
* Store incoming events that an app service is interested in in the
database to be later read by transaction workers.
* Retrieve these events from transaction workers, one per AS.
* Minimal transaction ID data is stored as well to recover after
server failure.
* Send events to AS and exponentially backoff on failure.

Signed-off-by: Andrew Morgan <andrewm@matrix.org>

* Finish my own sentences.

* Fix up database interaction

* Change to event-based AS sending

* Reduce cyclomatic complexity

* Appease the errcheck gods

* Delete by int ID instead of string.

This was causing some events to not be deleted, as < an eventID doesn't
really make much sense.

* Check if there are more events to send before sleeping

* Send same transaction if last send attempt failed

* Don't backoff on non-200s, tight send loop, 1 event query

* Remove tight send loop. Fix events not being deleted

* Additionally order by event id, track main.go

* Return the last txnID, which our events are using

* Remove old main.go file

* Prevent duplicate events from being sent...

* Strip event content if it doesn't contain anything

Signed-off-by: Andrew Morgan <andrewm@matrix.org>

* Update gomatrixserverlib and use Unsigned AS event prop

* Fixes

* Fix sync server comment
* Remove unnecessary printlns
* Use logrus Fields
* Worker state methods
* Remove sillyness

* Fix up event filtering

* Handle transaction event limit in loop

* Switch to using a sequence for transaction IDs

* Don't verify self-signed AS certificates

* Fix logging

* Use gmsl.Event instead of AS-only event in transactions

Also clear up the logic on lookupStateEvents a little bit.

* Change invalid_txn_id to global (for efficiency)

* Use a bool for EventsReady instead of an int
2018-07-05 09:34:59 -07:00
Andrew Morgan 93b7b18646
Add group_id, rate_limit and protocol AS config options (#478)
* Add group_id, rate_limit and protocol AS config options

* We currently just record and error check these options. There are not
currently implemented.

Signed-off-by: Andrew Morgan <andrewm@matrix.org>

* Clean things up and fix yaml declaration

* Warn loudly when app service requests unimplemented options

* Fix comments

* Remove high cyclomatic complexity of appservice checkErrors

* Set default rate limited to true
2018-06-18 02:43:15 -07:00
Andrew Morgan 241b1b5ace
Update gomatrixserverlib version (#476)
Signed-off-by: Andrew Morgan <andrewm@matrix.org>
2018-06-01 17:42:55 +01:00
Andrew Morgan 63dc2141ba Fix typo that caused ASTokens to not be uniquely checked
Signed-off-by: Andrew Morgan <andrewm@matrix.org>
2018-06-01 16:38:38 +01:00
Andrew Morgan 04551becb4
Filter Roomserver Events Based on Application Service (#467)
* Compile room and alias namespace regexs

We'll be needing these for event filtering in the appservice component.

Signed-off-by: Andrew Morgan <andrewm@matrix.org>

* App service filters roomserver events

Doing so based on namespace regexes that each app service has defined.

To get the aliases for a roomID a new aliasAPI endpoint was defined,
GetAliasesFromRoomID, which does exactly what it says on the tin.

Next step is to queue events to be sent off to each homeserver.

* Additionally filter state events for app services

* Fixed context, logging, derps, config handling

* Prevented user from creating more than one regex per namespace type

Got caught out by realizing I had an extra '-' in the config file. This
prevents anyone from making the same mistake :)

* Removed exclusive RoomID namespace regex, as we won't need to check
upon room creation if the ID is reserved exclusively by an AS (as this
is silly and horribly inefficient).

* Fixed all else mentioned
2018-05-30 13:43:13 +01:00
Andrew Morgan c238048599
Update Prometheus metrics tracking (#459)
Signed-off-by: Andrew Morgan <andrewm@matrix.org>
2018-05-23 15:42:08 +01:00
Anant Prakash 8861437c26 Add module for transactions cache (#440)
* Add transactions cache, write tests.

Add a transactions module in dendrite/common. This is needed for idempotent APIs.

Signed-off-by: Anant Prakash <anantprakashjsr@gmail.com>

* Use cycling double map instead, improve code logic, remove unneeded test

Signed-off-by: Anant Prakash <anantprakashjsr@gmail.com>

* Update code comments

Signed-off-by: Anant Prakash <anantprakashjsr@gmail.com>

* Use two constructors for default and custom cleanupPeriod
Add code comments

Signed-off-by: Anant Prakash <anantprakashjsr@gmail.com>
2018-05-16 11:36:40 +01:00
Tristan Claverie 58c10c6d54 Enable debug logs using a configuration parameter and put all logs in a single file (#379) 2018-04-10 13:21:20 +01:00
Scott Raine c9add39768 Use http.Status* and http.Method* where appropriate (#417)
Signed-off-by: Scott Raine <me@nylar.io>
2018-03-13 15:55:45 +00:00
Vincent Glize 6b55972183 Fix error when keyblock is nil (#394) 2018-03-03 12:18:28 +00:00
Andrew Morgan dfcf31f293 Prevent AS user check if no AS registered (#392)
When a user registered on a homeserver with no application services
 registered, registration would check if the meta-regexp object matched
 the proposed user's new username.

 Apparently "" is a regex that matches everything, so every user was
 then barred from registering as they were supposedly registering inside
 an AS' exclusive namespace.

 This change prevents that check from happening by setting the exclusive
 regex to ^$ instead, preventing any matches from occurring.

 We also prevent the check for exclusivity if there are no namespaces
 registered for performance.

Signed-off-by: Andrew Morgan (https://amorgan.xyz) <andrew@amorgan.xyz>
2018-02-27 11:42:10 +00:00
Andrew Morgan 08274bab5a Application Service Registration (#390)
* Add ability for App Services to register users

AS Tokens are pulled from their respective configs, which are then
checked against when an AS tries to register using
m.login.application_service. If the token exists and the new username is
within their specified namespace, then the user is created as a
password-less user.

Signed-off-by: Andrew Morgan (https://amorgan.xyz) <andrew@amorgan.xyz>

* Validate loaded Application Services

* Ensure no two app services have the same token or ID
* Check namespaces are valid regex
* Ensure users can't register inside an exclusive app service namespace
* Ensure exclusive app service namespaces are exclusive with each other
* Precompile application service namespace regexes so we don't need to
do so every time a user is registered

Signed-off-by: Andrew Morgan (https://amorgan.xyz) <andrew@amorgan.xyz>
2018-02-08 11:02:48 +00:00
Erik Johnston d22fb24a66
Factor out component setup from commands (#384)
* Add base component

* Convert clientapi to using base component

* Convert federationapi to using base component

* Convert federationsender to using base component

* Convert mediaapi to using base component

* Convert publicroomsapi to using base component

* Convert roomserver to using base component

* Convert syncapi to using base component

* Convert monolith to using base component

* Split out config parsing and roomserver API creation
2018-01-02 10:26:56 +00:00
Andrew Morgan fa362ecef2 Load Application Service Configuration Files (#377)
Signed-off-by: Andrew Morgan (https://amorgan.xyz) <andrew@amorgan.xyz>
2017-12-19 17:00:44 +00:00
Thibaut CHARLES ec30d143cd User registration return M_USER_IN_USE when username is already taken (#372)
When registering a new user using POST `/_matrix/client/r0/register`, the server was returning a 500 error when user name was already taken.

I added a check in `completeRegistration` to verify if the username is available before inserting it, and return a 400 `M_USER_IN_USE` error if there is a conflict, as [defined in matrix-doc](https://matrix.org/speculator/spec/HEAD/client_server/unstable.html#post-matrix-client-r0-register)

Signed-off-by: Thibaut CHARLES cromfr@gmail.com
2017-12-19 09:49:42 +00:00
Erik Johnston 16f593f786 Fix some linting errors 2017-12-06 13:55:51 +00:00
Erik Johnston 578d8cf492
Add CORS headers to all responses including errors (#364) 2017-12-06 09:36:50 +00:00
Andrew Morgan bc3dd821f9 Implemented ReCaptcha registration method (#343)
Signed-off-by: Andrew (anoa) <anoa@openmailbox.org>
2017-12-05 16:16:14 +00:00
Erik Johnston 7236090989
Add config option to disable registration (#360) 2017-12-04 17:07:45 +00:00
Erik Johnston cc12fc930a Fix typo 2017-11-29 09:48:55 +00:00
Andrew Morgan a4460dd6ee Set up proper registration flow (#354)
* Refactor registration to align with the spec
* We now keep track of sessions and their completed registration stages.
* We only complete registration if the client has completed a full flow.
* New Derived section in config for data derived from config options.
* New config options for captcha.
* Send params back to client for each registration stage.

Signed-off-by: Andrew Morgan (https://amorgan.xyz) <andrew@amorgan.xyz>
2017-11-29 09:43:03 +00:00
Erik Johnston b7a3b92a9f
Implement /make_join and /send_join (#316) 2017-11-29 09:38:56 +00:00
Richard van der Hoff 0786318a04
Bump gomatrixserverlib (#353)
* Bump gomatrixserverlib

Mostly because I want to use Erik's go-faster jsoning.

* Update KeyDB for new KeyFetcher API

we now need to implement FetcherName.

* Attempt to fix integ tests

CanonicalJSON doesn't like the empty string, apparently, and anyway
canonicalising it is pointless.

* More integ test fix
2017-11-27 12:05:14 +00:00
Erik Johnston 8599a36fa6
Use a Postgres database rather than Memory for Naffka (#337)
* Update naffka dep

* User Postgres database rather than Memory for Naffka
2017-11-16 17:35:28 +00:00
Erik Johnston 561315e1d6
Add gofmt linter (#339)
* Check that gofmt has been run

* gofmt files

* Tabs and spaces
2017-11-16 10:12:02 +00:00
Richard van der Hoff 4124ce2ac0
Store keys rather than json in the keydatabase (#330)
* bump gomatrixserverlib

(changes to KeyFetcher and KeyDatabase interfaces)

* Store keys rather than json in the keydatabase

Rather than storing the raw JSON returned from a /keys/v1/query call in the
table, store the key itself.

This makes keydb.Database implement the updated KeyDatabase interface.
2017-11-15 17:46:16 +00:00
Erik Johnston 139fae988e Fix linting errors in go1.9.1 (#336)
Fix linting errors in go1.9.1
2017-11-15 11:13:09 +00:00
Richard van der Hoff bf855a7e5c
Factor out keyring initialisation (#329)
Take the keyring init from the client-api-server and the monolith out to a
shared file
2017-11-13 18:39:09 +00:00
Michael Telatynski 90396b5620 implement voip/turnServer API endpoint (#323)
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
2017-11-09 09:58:45 +00:00
Andrew Morgan b7cfc2e057 Federation: Implement Query Profile API (#317)
* Federation: Implement Query Profile API

Implements the server portion of: `GET
/_matrix/federation/v1/query/profile?user_id=...&field=...`

Closes #278

Signed-off-by: Andrew (anoa) <anoa@openmailbox.org>

* Properly export profile-related structs and fix wording

Signed-off-by: Andrew (anoa) <anoa@openmailbox.org>

* Check provided user's domain matches our own.
2017-11-05 14:03:54 -04:00
Erik Johnston e5944e0fdb Move BuildEvent to common package (#315)
This is in preperation for implementing various federation APIs that
need to build events.
2017-10-25 14:44:33 +01:00
Erik Johnston 464fb5de1c Update vendor libraries and dendrite to s/Sirupsen/sirupsen/ (#304) 2017-10-13 14:42:57 +01:00
Mark Haines 847621bc5d Add config for setting up a jaeger opentracing reporter (#271)
* Add config for setting up a jaeger opentracing reporter

* Remove redundant comment
2017-09-28 17:00:23 +01:00
Mark Haines c4947c2ffb Add opentracing Spans to the HTTP APIs (#270)
* Add opentracing Spans to the HTTP APIs

* Add opentracing spans to the HTTP RPC clients

* Set the span in the request context

* More docstring
2017-09-28 14:50:40 +01:00
Erik Johnston 8dabca0f07 Implement shared secret registration (#257)
* Implement shared secret registration

* Use HexString from gomatrixserverlib

* Correctly check username validility
2017-09-22 16:13:19 +01:00
Mark Haines fef290c47e Add context to the server key database (#248) 2017-09-21 16:16:02 +01:00
Mark Haines a7773d3d3d Add context to the partition offset table (#249) 2017-09-21 15:09:19 +01:00
Erik Johnston 340a84cdc0 Add staticcheck lint (#245) 2017-09-20 14:54:17 +01:00
Erik Johnston 584acbe9a9 Add 'unused' lint (#241)
* Add 'unused' lint

* Keep testdata consts
2017-09-20 14:47:29 +01:00
Erik Johnston cc2f755cb3 Add gosimple linter (#242) 2017-09-20 14:15:38 +01:00
Erik Johnston b72142ace5 Add vet linter (#240) 2017-09-20 13:40:22 +01:00
Erik Johnston 8a36a7e89b Add errcheck linter (#238)
* Add errcheck linter

* Add config for 'fast' linters

* Fix errcheck lint stuff

* Fix errcheck lint
2017-09-20 10:59:19 +01:00
Mark Haines 029e71828a Add context.Context to the federation client (#225)
* Add context.Context to the federation client

* gb vendor update github.com/matrix-org/gomatrixserverlib
2017-09-13 11:03:41 +01:00
Brendan Abolivier f1fce55697 Add config and checks for trusted ID servers (#206)
* Add config for trusted ID servers

* Add new error

* Implement check for trusted ID server

* Complete unfinished comment

* Make comment more explicit in the config file

* Use go standard errors in membership.go

* Use standard errors instead of JSON responses in threepid

* Doc errors

* Remove unused parameter
2017-09-11 19:18:19 +01:00
Brendan Abolivier 4d1d503d43 Processing of pending invites on 3PID binding (#218)
* Add missing file headers

* Move the ID server's signatures verification to common

* Allow verification without specifying a server name

* Add third-party structs to membership events content

* Add processing of 3PID onbind requests

* Use reference for third party invite data

* Fix return arguments order

* Revert "Move the ID server's signatures verification to common"

This reverts commit 93442010316ce71a77ac58ffd3613754ce8fe969.

* Revert "Allow verification without specifying a server name"

This reverts commit fd27afbf82eac50fe9f7b83b26cfce3c66d530d2.

* Remove checks that are already occurring in gomatrixserverlib

* Change return type of createInviteFrom3PIDInvite

* Add doc, add checks in fillDisplayName

* Use MakeFedAPI

* Invert condition

* Use AuthEvents to retrieve the 3PID invite

* Update comment

* Remove unused parameter

* gb vendor update github.com/matrix-org/gomatrixserverlib
2017-09-08 15:17:12 +01:00
Mark Haines 643d05b157 Add function for making authed federation APIs (#208) 2017-09-04 13:14:01 +01:00
Richard van der Hoff 8c2e6273e3 Add command to generate test keys/certs (#204)
Add `generate-keys` command, which can be used to generate TLS keys/certs, and,
more usefully, matrix signing keys.
2017-08-31 12:28:58 +01:00
Brendan Abolivier 2183712e04 Process requests for 3PID invites (#201)
* Structure for 3PID invite

* Generate invite from 3PID known by ID server

* Load user profile in a separate function

* Generate m.room.third_party_invite if the ID server doesn't know the 3PID

* Fix URLs to the spec in comments

* Move third-party invites to a separate package and doc' it

* Handle non-OK status codes on lookup

* Send display name to identity server when asking to store an invite

* Remove join response structure

* Change the way some variables are declared or passed as argument

* Use gomatrixserverlib.Base64String instead of the builtin base64 package

* Don't copy the public keys array
2017-08-29 15:17:26 +01:00
Brendan Abolivier b15ce900ab Implement public rooms APIs (#185)
* Move events contents to common

* Basic database structure

* Complete database update

* Support visibility update and retrieval

* Add HTTP methods for visibility update and retrieval

* Add the database for the new component

* Add a listener for the new component

* Fix attribute update statements

* Create public rooms component

* Fix failing test

* Add roomserver consumer

* Fix a bug in aliases creation

* Add a check on type

* Implement public rooms directory

* Use auth API for visibility update

* Support filtering

* Add component to monolith

* Various fixes

* Fix computation of next public rooms batch

* Retrieve state events from the roomserver query API + avoid dupes on join

* Split update of string or boolean attribute in two separate functions

* Use event type to detect duplicate joins

* Improve the joined members counter computation

* Use event.RoomID()
2017-08-22 11:12:51 +01:00
Mark Haines 808c2e09f6 Make txn *sql.Tx arguments optional everywhere using a utility function (#191)
* Make txn *sql.Tx arguments optional everywhere using a utility function

* Clarify that if the txn is nil the stmt will run outside a transaction
2017-08-21 17:20:23 +01:00