Commit graph

696 commits

Author SHA1 Message Date
Neil Alexander ea2fa4a401 Merge branch 'master' into neilalexander/stateresv2 2020-03-10 11:46:36 +00:00
Neil Alexander 176f722d53 Update .gitignore 2020-03-10 11:42:40 +00:00
Neil Alexander 6bf0e69499 Fix a lot of room versions wiring (apart from syncapi) 2020-03-10 11:31:55 +00:00
Kegsay cdc1157785
Improve logging when sending events (#883)
We have some failing sytests on sqlite but it's very difficult to debug
due to lack of useful logging. This adds a log line for when a new event
is sent (incl. logging the event ID) as well as adding a user_id field
for all contextual logs so we know who initiated certain actions.
2020-03-09 14:37:51 +00:00
Neil Alexander 1b52775ccd If room_version isn't specified in the m.room.create event, assume room version 1 2020-03-09 09:10:01 +00:00
Kegsay c31cb02271
bugfix: Fix a race condition when creating guest accounts (#882)
* bugfix: Fix a race condition when creating guest accounts

It was possible to both select the same next numeric ID and then both
attempt to INSERT this into the table. This would cause a UNIQUE violation
which then presented itself as an error in sqlite because it does not
implement `common.IsUniqueConstraintViolationErr`.

The fix here is NOT to implement `common.IsUniqueConstraintViolationErr`
otherwise the 2 users would get the SAME guest account. Instead, all of
these operations should be done inside a transaction. This is what this
PR does.

* Update postgres

* Typo

* Actually use the txn when creating accounts

* bugfix for database is locked on guest reg
2020-03-06 18:00:07 +00:00
Neil Alexander e43d8a17ae Merge branch 'master' into neilalexander/stateresv2 2020-03-06 17:00:15 +00:00
Neil Alexander 6a1111c3d4
Try to recursively find auth events (to a point) if they are missing (#881)
* Try to recursively find auth events (to a point) if they are missing

* Remove recursion limit for now and other review fixes

* Simplify error handling for recursion

* Pass room version 1 only to MakeJoin until room version support comes later
2020-03-06 16:58:10 +00:00
Kegan Dougal 87283e9de7 bugfix: fix sytest 155 by actually returning depth+1 and not 0 2020-03-06 14:31:12 +00:00
Neil Alexander 16365357b7 whoops compile error 2020-03-06 13:58:00 +00:00
Neil Alexander adf2726f20 Fully populate eventIDMap 2020-03-06 13:41:59 +00:00
Neil Alexander 0a3db9e952 Update gomatrixserverlib 2020-03-06 13:01:13 +00:00
Neil Alexander 45f60e7a65 Fix type of room_version in make_join 2020-03-06 12:15:59 +00:00
Neil Alexander fb3f97e9fe Update room version checking code 2020-03-06 11:57:45 +00:00
Neil Alexander a4401e3fb0 Update common.BuildEvent 2020-03-06 11:23:11 +00:00
Neil Alexander 85e658ca06 Update gomatrixserverlib 2020-03-06 11:15:21 +00:00
Neil Alexander 8257c22700 Merge branch 'master' into neilalexander/stateresv2 2020-03-06 10:38:26 +00:00
Kegsay a97b8eafd4
Add peer-to-peer support into Dendrite via libp2p and fetch (#880)
* Use a fork of pq which supports userCurrent on wasm

* Use sqlite3_js driver when running in JS

* Add cmd/dendritejs to pull in sqlite3_js driver for wasm only

* Update to latest go-sqlite-js version

* Replace prometheus with a stub. sigh

* Hard-code a config and don't use opentracing

* Latest go-sqlite3-js version

* Generate a key for now

* Listen for fetch traffic rather than HTTP

* Latest hacks for js

* libp2p support

* More libp2p

* Fork gjson to allow us to enforce auth checks as before

Previously, all events would come down redacted because the hash
checks would fail. They would fail because sjson.DeleteBytes didn't
remove keys not used for hashing. This didn't work because of a build
tag which included a file which no-oped the index returned.

See https://github.com/tidwall/gjson/issues/157

When it's resolved, let's go back to mainline.

* Use gjson@1.6.0 as it fixes https://github.com/tidwall/gjson/issues/157

* Use latest gomatrixserverlib for sig checks

* Fix a bug which could cause exclude_from_sync to not be set

Caused when sending events over federation.

* Use query variadic to make lookups actually work!

* Latest gomatrixserverlib

* Add notes on getting p2p up and running

Partly so I don't forget myself!

* refactor: Move p2p specific stuff to cmd/dendritejs

This is important or else the normal build of dendrite will fail
because the p2p libraries depend on syscall/js which doesn't work
on normal builds.

Also, clean up main.go to read a bit better.

* Update ho-http-js-libp2p to return errors from RoundTrip

* Add an LRU cache around the key DB

We actually need this for P2P because otherwise we can *segfault*
with things like: "runtime: unexpected return pc for runtime.handleEvent"
where the event is a `syscall/js` event, caused by spamming sql.js
caused by "Checking event signatures for 14 events of room state" which
hammers the key DB repeatedly in quick succession.

Using a cache fixes this, though the underlying cause is probably a bug
in the version of Go I'm on (1.13.7)

* breaking: Add Tracing.Enabled to toggle whether we do opentracing

Defaults to false, which is why this is a breaking change. We need
this flag because WASM builds cannot do opentracing.

* Start adding conditional builds for wasm to handle lib/pq

The general idea here is to have the wasm build have a `NewXXXDatabase`
that doesn't import any postgres package and hence we never import
`lib/pq`, which doesn't work under WASM (undefined `userCurrent`).

* Remove lib/pq for wasm for syncapi

* Add conditional building to remaining storage APIs

* Update build script to set env vars correctly for dendritejs

* sqlite bug fixes

* Docs

* Add a no-op main for dendritejs when not building under wasm

* Use the real prometheus, even for WASM

Instead, the dendrite-sw.js must mock out `process.pid` and
`fs.stat` - which must invoke the callback with an error (e.g `EINVAL`)
in order for it to work:

```
    global.process = {
        pid: 1,
    };
    global.fs.stat = function(path, cb) {
        cb({
            code: "EINVAL",
        });
    }
```

* Linting
2020-03-06 10:23:55 +00:00
Neil Alexander f3dee39c9d Implement API for querying room version 2020-03-05 10:22:33 +00:00
Neil Alexander 25cdf733e2 Update gomatrixserverlib 2020-03-04 17:56:55 +00:00
Neil Alexander 3f31c4d5ca Try to establish auth difference for state res v2 2020-03-04 11:37:23 +00:00
Neil Alexander 0ec7403c2d Update gomatrixserverlib 2020-03-03 11:45:55 +00:00
Neil Alexander f69a553ad6 Merge branch 'neilalexander/stateresv2' of github.com:matrix-org/dendrite into neilalexander/stateresv2 2020-03-03 09:22:43 +00:00
Neil Alexander d22067f7d6 Merge branch 'master' into neilalexander/stateresv2 2020-03-02 18:02:13 +00:00
Neil Alexander 0cda3c52d0 Don't fail hard if backward topology position fails, just use 1 instead 2020-03-02 18:01:24 +00:00
Neil Alexander 11e8557529
Merge branch 'master' into neilalexander/stateresv2 2020-03-02 16:21:02 +00:00
Neil Alexander 59a1f4b8ed
Remove httputil.LogThenError so that the line numbers are reported properly - make error reporting slightly more useful (#879) 2020-03-02 16:20:44 +00:00
Neil Alexander 2e8438ee56 Update go.mod/go.sum 2020-02-28 16:40:58 +00:00
Neil Alexander 1ac571973c Try to take room version from createRoomReq 2020-02-28 16:29:42 +00:00
Neil Alexander c5163313e4
Merge branch 'master' into neilalexander/stateresv2 2020-02-28 15:08:26 +00:00
Neil Alexander 72565f2eeb
Fix bug in devices endpoint (#877) 2020-02-28 15:06:16 +00:00
Neil Alexander 6460b3725d
Make sure PDUs and EDUs in transaction don't marshal to null (#876) 2020-02-28 14:54:51 +00:00
Kegan Dougal 420ee15433 Kick CI 2020-02-28 14:46:03 +00:00
Neil Alexander 2f45bc417b Get room version from initial persistence of m.room.create 2020-02-26 17:57:47 +00:00
Neil Alexander 15f9672c7d Try to get room version from m.room.create event at first NID assign 2020-02-26 17:40:17 +00:00
Neil Alexander 892180cb2c Try that again 2020-02-26 17:06:11 +00:00
Neil Alexander 49d3000371 Use default room version correctly 2020-02-26 17:04:15 +00:00
Neil Alexander 3994e4c588 Shift things around, try to use state res v2 for room version 2 2020-02-26 16:55:51 +00:00
Neil Alexander 9d639f5eec Merge branch 'master' into neilalexander/stateresv2 2020-02-20 13:54:56 +00:00
Neil Alexander 0352f250b8 Fix dockerfile 2020-02-20 13:54:50 +00:00
Neil Alexander f198084271 Logging 2020-02-20 13:51:18 +00:00
Neil Alexander 3383d312f5 Try sending supported room versions as part of make_join 2020-02-20 13:41:18 +00:00
Neil Alexander b5900e8d3a Fix unit tests 2020-02-20 13:04:32 +00:00
Neil Alexander 136cb043a5 Dedupe prometheus collectors 2020-02-20 12:15:04 +00:00
Neil Alexander 370d3fc864 Try enabling room version v2 and enabling as default 2020-02-20 12:13:04 +00:00
Neil Alexander 229257a052 Maybe getMembershipsBeforeEventNID and checkServerAllowedToSeeEvent will work now? 2020-02-20 12:11:46 +00:00
Neil Alexander f8e4d5bcb0 Try to get right room version for state res (still need to fix getMembershipsBeforeEventNID and checkServerAllowedToSeeEvent) 2020-02-20 11:52:47 +00:00
Neil Alexander a562d7d793 Squashed commit of the following:
commit 5caae6f3a0
Author: Kegsay <kegan@matrix.org>
Date:   Thu Feb 20 09:28:03 2020 +0000

    sqlite: fixes from sytest (#872)

    * bugfix: fix panic on new invite events from sytest

    I'm unsure why the previous code didn't work, but it's
    clearer, quicker and easier to read the `LastInsertID()` way.
    Previously, the code would panic as the SELECT would fail
    to find the last inserted row ID.

    * sqlite: Fix UNIQUE violations and close more cursors

    - Add missing `defer rows.Close()`
    - Do not have the state block NID as a PRIMARY KEY else it breaks for blocks
      with >1 state event in them. Instead, rejig the queries so we can still
      have monotonically increasing integers without using AUTOINCREMENT (which
      mandates PRIMARY KEY).

    * sqlite: Add missing variadic function

    * Use LastInsertId because empirically it works over the SELECT form (though I don't know why that is)

    * sqlite: Fix invite table by using the global stream pos rather than one specific to invites

    If we don't use the global, clients don't get notified about any invites
    because the position is too low.

    * linting: shadowing

    * sqlite: do not use last rowid, we already know the stream pos!

    * sqlite: Fix account data table in syncapi by commiting insert txns!

    * sqlite: Fix failing federation invite

    Was failing with 'database is locked' due to multiple write txns
    being taken out.

    * sqlite: Ensure we return exactly the number of events found in the database

    Previously we would return exactly the number of *requested* events, which
    meant that several zero-initialised events would bubble through the system,
    failing at JSON serialisation time.

    * sqlite: let's just ignore the problem for now....

    * linting
2020-02-20 11:23:09 +00:00
Kegsay 5caae6f3a0
sqlite: fixes from sytest (#872)
* bugfix: fix panic on new invite events from sytest

I'm unsure why the previous code didn't work, but it's
clearer, quicker and easier to read the `LastInsertID()` way.
Previously, the code would panic as the SELECT would fail
to find the last inserted row ID.

* sqlite: Fix UNIQUE violations and close more cursors

- Add missing `defer rows.Close()`
- Do not have the state block NID as a PRIMARY KEY else it breaks for blocks
  with >1 state event in them. Instead, rejig the queries so we can still
  have monotonically increasing integers without using AUTOINCREMENT (which
  mandates PRIMARY KEY).

* sqlite: Add missing variadic function

* Use LastInsertId because empirically it works over the SELECT form (though I don't know why that is)

* sqlite: Fix invite table by using the global stream pos rather than one specific to invites

If we don't use the global, clients don't get notified about any invites
because the position is too low.

* linting: shadowing

* sqlite: do not use last rowid, we already know the stream pos!

* sqlite: Fix account data table in syncapi by commiting insert txns!

* sqlite: Fix failing federation invite

Was failing with 'database is locked' due to multiple write txns
being taken out.

* sqlite: Ensure we return exactly the number of events found in the database

Previously we would return exactly the number of *requested* events, which
meant that several zero-initialised events would bubble through the system,
failing at JSON serialisation time.

* sqlite: let's just ignore the problem for now....

* linting
2020-02-20 09:28:03 +00:00
Neil Alexander 9d249472fb Duplicate state v1 to state v2 2020-02-14 15:05:58 +00:00