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
// Copyright 2020 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package storage
import (
"context"
2022-08-25 12:42:47 +00:00
"github.com/matrix-org/gomatrixserverlib"
2023-04-19 14:50:33 +00:00
"github.com/matrix-org/gomatrixserverlib/spec"
2022-08-25 12:42:47 +00:00
2022-09-30 11:48:10 +00:00
"github.com/matrix-org/dendrite/internal/eventutil"
2022-09-30 15:07:18 +00:00
"github.com/matrix-org/dendrite/internal/sqlutil"
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
"github.com/matrix-org/dendrite/roomserver/api"
2023-04-27 11:54:20 +00:00
rstypes "github.com/matrix-org/dendrite/roomserver/types"
2022-09-30 11:48:10 +00:00
"github.com/matrix-org/dendrite/syncapi/storage/shared"
2023-04-04 17:16:53 +00:00
"github.com/matrix-org/dendrite/syncapi/synctypes"
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
"github.com/matrix-org/dendrite/syncapi/types"
2020-06-16 13:10:55 +00:00
userapi "github.com/matrix-org/dendrite/userapi/api"
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
)
2022-09-30 11:48:10 +00:00
type DatabaseTransaction interface {
2022-09-30 15:07:18 +00:00
sqlutil . Transaction
2022-07-15 15:25:26 +00:00
SharedUsers
2021-01-08 16:59:06 +00:00
MaxStreamPositionForPDUs ( ctx context . Context ) ( types . StreamPosition , error )
MaxStreamPositionForReceipts ( ctx context . Context ) ( types . StreamPosition , error )
MaxStreamPositionForInvites ( ctx context . Context ) ( types . StreamPosition , error )
MaxStreamPositionForAccountData ( ctx context . Context ) ( types . StreamPosition , error )
2021-01-13 17:29:46 +00:00
MaxStreamPositionForSendToDeviceMessages ( ctx context . Context ) ( types . StreamPosition , error )
2022-03-03 11:40:53 +00:00
MaxStreamPositionForNotificationData ( ctx context . Context ) ( types . StreamPosition , error )
2022-09-30 11:48:10 +00:00
MaxStreamPositionForPresence ( ctx context . Context ) ( types . StreamPosition , error )
2022-10-13 13:50:52 +00:00
MaxStreamPositionForRelations ( ctx context . Context ) ( types . StreamPosition , error )
2021-01-08 16:59:06 +00:00
2023-04-27 11:54:20 +00:00
CurrentState ( ctx context . Context , roomID string , stateFilterPart * synctypes . StateFilter , excludeEventIDs [ ] string ) ( [ ] * rstypes . HeaderedEvent , error )
2023-06-07 17:14:35 +00:00
GetStateDeltasForFullStateSync ( ctx context . Context , device * userapi . Device , r types . Range , userID string , stateFilter * synctypes . StateFilter , rsAPI api . SyncRoomserverAPI ) ( [ ] types . StateDelta , [ ] string , error )
GetStateDeltas ( ctx context . Context , device * userapi . Device , r types . Range , userID string , stateFilter * synctypes . StateFilter , rsAPI api . SyncRoomserverAPI ) ( [ ] types . StateDelta , [ ] string , error )
2021-01-08 16:59:06 +00:00
RoomIDsWithMembership ( ctx context . Context , userID string , membership string ) ( [ ] string , error )
2022-04-01 15:14:38 +00:00
MembershipCount ( ctx context . Context , roomID , membership string , pos types . StreamPosition ) ( int , error )
2023-01-12 09:06:03 +00:00
GetRoomSummary ( ctx context . Context , roomID , userID string ) ( summary * types . Summary , err error )
2023-04-04 17:16:53 +00:00
RecentEvents ( ctx context . Context , roomIDs [ ] string , r types . Range , eventFilter * synctypes . RoomEventFilter , chronologicalOrder bool , onlySyncEvents bool ) ( map [ string ] types . RecentEvents , error )
2023-04-27 11:54:20 +00:00
GetBackwardTopologyPos ( ctx context . Context , events [ ] * rstypes . HeaderedEvent ) ( types . TopologyToken , error )
2021-01-08 16:59:06 +00:00
PositionInTopology ( ctx context . Context , eventID string ) ( pos types . StreamPosition , spos types . StreamPosition , err error )
2023-04-27 11:54:20 +00:00
InviteEventsInRange ( ctx context . Context , targetUserID string , r types . Range ) ( map [ string ] * rstypes . HeaderedEvent , map [ string ] * rstypes . HeaderedEvent , types . StreamPosition , error )
2021-01-08 16:59:06 +00:00
PeeksInRange ( ctx context . Context , userID , deviceID string , r types . Range ) ( peeks [ ] types . Peek , err error )
2022-03-29 12:14:35 +00:00
RoomReceiptsAfter ( ctx context . Context , roomIDs [ ] string , streamPos types . StreamPosition ) ( types . StreamPosition , [ ] types . OutputReceiptEvent , error )
2020-04-30 16:15:29 +00:00
// AllJoinedUsersInRooms returns a map of room ID to a list of all joined user IDs.
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
AllJoinedUsersInRooms ( ctx context . Context ) ( map [ string ] [ ] string , error )
2022-04-28 16:53:28 +00:00
// AllJoinedUsersInRoom returns a map of room ID to a list of all joined user IDs for a given room.
AllJoinedUsersInRoom ( ctx context . Context , roomIDs [ ] string ) ( map [ string ] [ ] string , error )
2020-09-10 13:39:18 +00:00
// AllPeekingDevicesInRooms returns a map of room ID to a list of all peeking devices.
AllPeekingDevicesInRooms ( ctx context . Context ) ( map [ string ] [ ] types . PeekingDevice , error )
2020-04-30 16:15:29 +00:00
// Events lookups a list of event by their event ID.
// Returns a list of events matching the requested IDs found in the database.
// If an event is not found in the database then it will be omitted from the list.
// Returns an error if there was a problem talking with the database.
// Does not include any transaction IDs in the returned events.
2023-04-27 11:54:20 +00:00
Events ( ctx context . Context , eventIDs [ ] string ) ( [ ] * rstypes . HeaderedEvent , error )
2020-04-30 16:15:29 +00:00
// GetStateEvent returns the Matrix state event of a given type for a given room with a given state key
// If no event could be found, returns nil
// If there was an issue during the retrieval, returns an error
2023-04-27 11:54:20 +00:00
GetStateEvent ( ctx context . Context , roomID , evType , stateKey string ) ( * rstypes . HeaderedEvent , error )
2020-04-30 16:15:29 +00:00
// GetStateEventsForRoom fetches the state events for a given room.
// Returns an empty slice if no state events could be found for this room.
// Returns an error if there was an issue with the retrieval.
2023-04-27 11:54:20 +00:00
GetStateEventsForRoom ( ctx context . Context , roomID string , stateFilterPart * synctypes . StateFilter ) ( stateEvents [ ] * rstypes . HeaderedEvent , err error )
2020-04-30 16:15:29 +00:00
// GetAccountDataInRange returns all account data for a given user inserted or
// updated between two given positions
// Returns a map following the format data[roomID] = []dataTypes
// If no data is retrieved, returns an empty map
// If there was an issue with the retrieval, returns an error
2023-04-04 17:16:53 +00:00
GetAccountDataInRange ( ctx context . Context , userID string , r types . Range , accountDataFilterPart * synctypes . EventFilter ) ( map [ string ] [ ] string , types . StreamPosition , error )
2022-09-30 11:48:10 +00:00
// GetEventsInTopologicalRange retrieves all of the events on a given ordering using the given extremities and limit. If backwardsOrdering is true, the most recent event must be first, else last.
2023-04-04 17:16:53 +00:00
GetEventsInTopologicalRange ( ctx context . Context , from , to * types . TopologyToken , roomID string , filter * synctypes . RoomEventFilter , backwardOrdering bool ) ( events [ ] types . StreamEvent , err error )
2022-09-30 11:48:10 +00:00
// EventPositionInTopology returns the depth and stream position of the given event.
EventPositionInTopology ( ctx context . Context , eventID string ) ( types . TopologyToken , error )
// BackwardExtremitiesForRoom returns a map of backwards extremity event ID to a list of its prev_events.
BackwardExtremitiesForRoom ( ctx context . Context , roomID string ) ( backwardExtremities map [ string ] [ ] string , err error )
// StreamEventsToEvents converts streamEvent to Event. If device is non-nil and
// matches the streamevent.transactionID device then the transaction ID gets
// added to the unsigned section of the output event.
2023-06-07 17:14:35 +00:00
StreamEventsToEvents ( ctx context . Context , device * userapi . Device , in [ ] types . StreamEvent , rsAPI api . SyncRoomserverAPI ) [ ] * rstypes . HeaderedEvent
2022-09-30 11:48:10 +00:00
// SendToDeviceUpdatesForSync returns a list of send-to-device updates. It returns the
// relevant events within the given ranges for the supplied user ID and device ID.
SendToDeviceUpdatesForSync ( ctx context . Context , userID , deviceID string , from , to types . StreamPosition ) ( pos types . StreamPosition , events [ ] types . SendToDeviceEvent , err error )
// GetRoomReceipts gets all receipts for a given roomID
GetRoomReceipts ( ctx context . Context , roomIDs [ ] string , streamPos types . StreamPosition ) ( [ ] types . OutputReceiptEvent , error )
2023-04-27 11:54:20 +00:00
SelectContextEvent ( ctx context . Context , roomID , eventID string ) ( int , rstypes . HeaderedEvent , error )
SelectContextBeforeEvent ( ctx context . Context , id int , roomID string , filter * synctypes . RoomEventFilter ) ( [ ] * rstypes . HeaderedEvent , error )
SelectContextAfterEvent ( ctx context . Context , id int , roomID string , filter * synctypes . RoomEventFilter ) ( int , [ ] * rstypes . HeaderedEvent , error )
2022-09-30 11:48:10 +00:00
StreamToTopologicalPosition ( ctx context . Context , roomID string , streamPos types . StreamPosition , backwardOrdering bool ) ( types . TopologyToken , error )
IgnoresForUser ( ctx context . Context , userID string ) ( * types . IgnoredUsers , error )
// SelectMembershipForUser returns the membership of the user before and including the given position. If no membership can be found
// returns "leave", the topological position and no error. If an error occurs, other than sql.ErrNoRows, returns that and an empty
// string as the membership.
SelectMembershipForUser ( ctx context . Context , roomID , userID string , pos int64 ) ( membership string , topologicalPos int , err error )
// getUserUnreadNotificationCountsForRooms returns the unread notifications for the given rooms
GetUserUnreadNotificationCountsForRooms ( ctx context . Context , userID string , roomIDs map [ string ] string ) ( map [ string ] * eventutil . NotificationData , error )
2022-12-08 07:25:03 +00:00
GetPresences ( ctx context . Context , userID [ ] string ) ( [ ] * types . PresenceInternal , error )
2023-04-04 17:16:53 +00:00
PresenceAfter ( ctx context . Context , after types . StreamPosition , filter synctypes . EventFilter ) ( map [ string ] * types . PresenceInternal , error )
2022-10-13 13:50:52 +00:00
RelationsFor ( ctx context . Context , roomID , eventID , relType , eventType string , from , to types . StreamPosition , backwards bool , limit int ) ( events [ ] types . StreamEvent , prevBatch , nextBatch string , err error )
2022-09-30 11:48:10 +00:00
}
type Database interface {
Presence
Notifications
NewDatabaseSnapshot ( ctx context . Context ) ( * shared . DatabaseTransaction , error )
NewDatabaseTransaction ( ctx context . Context ) ( * shared . DatabaseTransaction , error )
// Events lookups a list of event by their event ID.
// Returns a list of events matching the requested IDs found in the database.
// If an event is not found in the database then it will be omitted from the list.
// Returns an error if there was a problem talking with the database.
// Does not include any transaction IDs in the returned events.
2023-04-27 11:54:20 +00:00
Events ( ctx context . Context , eventIDs [ ] string ) ( [ ] * rstypes . HeaderedEvent , error )
2022-09-30 11:48:10 +00:00
// WriteEvent into the database. It is not safe to call this function from multiple goroutines, as it would create races
// when generating the sync stream position for this event. Returns the sync stream position for the inserted event.
// Returns an error if there was a problem inserting this event.
2023-04-27 11:54:20 +00:00
WriteEvent ( ctx context . Context , ev * rstypes . HeaderedEvent , addStateEvents [ ] * rstypes . HeaderedEvent ,
2022-09-30 11:48:10 +00:00
addStateEventIDs [ ] string , removeStateEventIDs [ ] string , transactionID * api . TransactionID , excludeFromSync bool ,
historyVisibility gomatrixserverlib . HistoryVisibility ,
) ( types . StreamPosition , error )
// PurgeRoomState completely purges room state from the sync API. This is done when
// receiving an output event that completely resets the state.
PurgeRoomState ( ctx context . Context , roomID string ) error
2023-01-19 20:02:32 +00:00
// PurgeRoom entirely eliminates a room from the sync API, timeline, state and all.
PurgeRoom ( ctx context . Context , roomID string ) error
2020-04-30 16:15:29 +00:00
// UpsertAccountData keeps track of new or updated account data, by saving the type
// of the new/updated data, and the user ID and room ID the data is related to (empty)
// room ID means the data isn't specific to any room)
// If no data with the given type, user ID and room ID exists in the database,
// creates a new row, else update the existing one
// Returns an error if there was an issue with the upsert
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
UpsertAccountData ( ctx context . Context , userID , roomID , dataType string ) ( types . StreamPosition , error )
2020-04-30 16:15:29 +00:00
// AddInviteEvent stores a new invite event for a user.
// If the invite was successfully stored this returns the stream ID it was stored at.
// Returns an error if there was a problem communicating with the database.
2023-04-27 11:54:20 +00:00
AddInviteEvent ( ctx context . Context , inviteEvent * rstypes . HeaderedEvent ) ( types . StreamPosition , error )
2020-06-26 10:07:52 +00:00
// RetireInviteEvent removes an old invite event from the database. Returns the new position of the retired invite.
2020-04-30 16:15:29 +00:00
// Returns an error if there was a problem communicating with the database.
2020-06-26 10:07:52 +00:00
RetireInviteEvent ( ctx context . Context , inviteEventID string ) ( types . StreamPosition , error )
2020-09-10 13:39:18 +00:00
// AddPeek adds a new peek to our DB for a given room by a given user's device.
// Returns an error if there was a problem communicating with the database.
AddPeek ( ctx context . Context , RoomID , UserID , DeviceID string ) ( types . StreamPosition , error )
2020-12-03 11:11:46 +00:00
// DeletePeek removes an existing peek from the database for a given room by a user's device.
// Returns an error if there was a problem communicating with the database.
DeletePeek ( ctx context . Context , roomID , userID , deviceID string ) ( sp types . StreamPosition , err error )
2020-09-10 13:39:18 +00:00
// DeletePeek deletes all peeks for a given room by a given user
// Returns an error if there was a problem communicating with the database.
DeletePeeks ( ctx context . Context , RoomID , UserID string ) ( types . StreamPosition , error )
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 16:50:19 +00:00
// StoreNewSendForDeviceMessage stores a new send-to-device event for a user's device.
2020-12-18 11:11:21 +00:00
StoreNewSendForDeviceMessage ( ctx context . Context , userID , deviceID string , event gomatrixserverlib . SendToDeviceEvent ) ( types . StreamPosition , error )
2021-01-13 17:29:46 +00:00
// CleanSendToDeviceUpdates removes all send-to-device messages BEFORE the specified
// from position, preventing the send-to-device table from growing indefinitely.
CleanSendToDeviceUpdates ( ctx context . Context , userID , deviceID string , before types . StreamPosition ) ( err error )
2022-04-26 15:58:20 +00:00
// GetFilter looks up the filter associated with a given local user and filter ID
// and populates the target filter. Otherwise returns an error if no such filter exists
2020-06-26 14:34:41 +00:00
// or if there was an error talking to the database.
2023-04-04 17:16:53 +00:00
GetFilter ( ctx context . Context , target * synctypes . Filter , localpart string , filterID string ) error
2020-06-26 14:34:41 +00:00
// PutFilter puts the passed filter into the database.
// Returns the filterID as a string. Otherwise returns an error if something
// goes wrong.
2023-04-04 17:16:53 +00:00
PutFilter ( ctx context . Context , localpart string , filter * synctypes . Filter ) ( string , error )
2020-07-08 16:45:39 +00:00
// RedactEvent wipes an event in the database and sets the unsigned.redacted_because key to the redaction event
2023-04-27 11:54:20 +00:00
RedactEvent ( ctx context . Context , redactedEventID string , redactedBecause * rstypes . HeaderedEvent ) error
2020-11-09 18:46:11 +00:00
// StoreReceipt stores new receipt events
2023-04-19 14:50:33 +00:00
StoreReceipt ( ctx context . Context , roomId , receiptType , userId , eventId string , timestamp spec . Timestamp ) ( pos types . StreamPosition , err error )
2022-04-07 14:08:19 +00:00
UpdateIgnoresForUser ( ctx context . Context , userID string , ignores * types . IgnoredUsers ) error
2023-04-27 11:54:20 +00:00
ReIndex ( ctx context . Context , limit , afterID int64 ) ( map [ int64 ] rstypes . HeaderedEvent , error )
UpdateRelations ( ctx context . Context , event * rstypes . HeaderedEvent ) error
2022-10-13 13:50:52 +00:00
RedactRelations ( ctx context . Context , roomID , redactedEventID string ) error
2022-10-25 10:39:10 +00:00
SelectMemberships (
ctx context . Context ,
roomID string , pos types . TopologyToken ,
membership , notMembership * string ,
) ( eventIDs [ ] string , err error )
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
}
2022-04-06 11:11:19 +00:00
type Presence interface {
2022-12-08 07:25:03 +00:00
GetPresences ( ctx context . Context , userIDs [ ] string ) ( [ ] * types . PresenceInternal , error )
2023-04-19 14:50:33 +00:00
UpdatePresence ( ctx context . Context , userID string , presence types . Presence , statusMsg * string , lastActiveTS spec . Timestamp , fromSync bool ) ( types . StreamPosition , error )
2022-04-06 11:11:19 +00:00
}
2022-07-15 15:25:26 +00:00
type SharedUsers interface {
// SharedUsers returns a subset of otherUserIDs that share a room with userID.
SharedUsers ( ctx context . Context , userID string , otherUserIDs [ ] string ) ( [ ] string , error )
}
2022-09-27 13:01:34 +00:00
type Notifications interface {
// UpsertRoomUnreadNotificationCounts updates the notification statistics about a (user, room) key.
UpsertRoomUnreadNotificationCounts ( ctx context . Context , userID , roomID string , notificationCount , highlightCount int ) ( types . StreamPosition , error )
}