aboutsummaryrefslogtreecommitdiff
path: root/roomserver/api
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2021-01-22 14:55:08 +0000
committerGitHub <noreply@github.com>2021-01-22 14:55:08 +0000
commit0571d395b51d7788c692b916cd7ba9249a494ed1 (patch)
treeb0b6f2162ee62f9d1259eb57050edc36fdb7be99 /roomserver/api
parent5d8ec0ff1a7a3d40c54e84ba04d0d7d81aa28440 (diff)
Peeking over federation via MSC2444 (#1391)
* a very very WIP first cut of peeking via MSC2753. doesn't yet compile or work. needs to actually add the peeking block into the sync response. checking in now before it gets any bigger, and to gather any initial feedback on the vague shape of it. * make PeekingDeviceSet private * add server_name param * blind stab at adding a `peek` section to /sync * make it build * make it launch * add peeking to getResponseWithPDUsForCompleteSync * cancel any peeks when we join a room * spell out how to runoutside of docker if you want speed * fix SQL * remove unnecessary txn for SelectPeeks * fix s/join/peek/ cargocult fail * HACK: Track goroutine IDs to determine when we write by the wrong thread To use: set `DENDRITE_TRACE_SQL=1` then grep for `unsafe` * Track partition offsets and only log unsafe for non-selects * Put redactions in the writer goroutine * Update filters on writer goroutine * wrap peek storage in goid hack * use exclusive writer, and MarkPeeksAsOld more efficiently * don't log ascii in binary at sql trace... * strip out empty roomd deltas * re-add txn to SelectPeeks * re-add accidentally deleted field * reject peeks for non-worldreadable rooms * move perform_peek * fix package * correctly refactor perform_peek * WIP of implementing MSC2444 * typo * Revert "Merge branch 'kegan/HACK-goid-sqlite-db-is-locked' into matthew/peeking" This reverts commit 3cebd8dbfbccdf82b7930b7b6eda92095ca6ef41, reversing changes made to ed4b3a58a7855acc43530693cc855b439edf9c7c. * (almost) make it build * clean up bad merge * support SendEventWithState with optional event * fix build & lint * fix build & lint * reinstate federated peeks in the roomserver (doh) * fix sql thinko * todo for authenticating state returned by /peek * support returning current state from QueryStateAndAuthChain * handle SS /peek * reimplement SS /peek to prod the RS to tell the FS about the peek * rename RemotePeeks as OutboundPeeks * rename remote_peeks_table as outbound_peeks_table * add perform_handle_remote_peek.go * flesh out federation doc * add inbound peeks table and hook it up * rename ambiguous RemotePeek as InboundPeek * rename FSAPI's PerformPeek as PerformOutboundPeek * setup inbound peeks db correctly * fix api.SendEventWithState with no event * track latestevent on /peek * go fmt * document the peek send stream race better * fix SendEventWithRewrite not to bail if handed a non-state event * add fixme * switch SS /peek to use SendEventWithRewrite * fix comment * use reverse topo ordering to find latest extrem * support postgres for federated peeking * go fmt * back out bogus go.mod change * Fix performOutboundPeekUsingServer * Fix getAuthChain -> GetAuthChain * Fix build issues * Fix build again * Fix getAuthChain -> GetAuthChain * Don't repeat outbound peeks for the same room ID to the same servers * Fix lint * Don't omitempty to appease sytest Co-authored-by: Kegan Dougal <kegan@matrix.org> Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'roomserver/api')
-rw-r--r--roomserver/api/api.go6
-rw-r--r--roomserver/api/api_trace.go10
-rw-r--r--roomserver/api/output.go17
-rw-r--r--roomserver/api/perform.go22
-rw-r--r--roomserver/api/query.go2
-rw-r--r--roomserver/api/wrapper.go2
6 files changed, 57 insertions, 2 deletions
diff --git a/roomserver/api/api.go b/roomserver/api/api.go
index cedd6193..72e406ee 100644
--- a/roomserver/api/api.go
+++ b/roomserver/api/api.go
@@ -56,6 +56,12 @@ type RoomserverInternalAPI interface {
res *PerformPublishResponse,
)
+ PerformInboundPeek(
+ ctx context.Context,
+ req *PerformInboundPeekRequest,
+ res *PerformInboundPeekResponse,
+ ) error
+
QueryPublishedRooms(
ctx context.Context,
req *QueryPublishedRoomsRequest,
diff --git a/roomserver/api/api_trace.go b/roomserver/api/api_trace.go
index 40745975..1a2b9a49 100644
--- a/roomserver/api/api_trace.go
+++ b/roomserver/api/api_trace.go
@@ -88,6 +88,16 @@ func (t *RoomserverInternalAPITrace) PerformPublish(
util.GetLogger(ctx).Infof("PerformPublish req=%+v res=%+v", js(req), js(res))
}
+func (t *RoomserverInternalAPITrace) PerformInboundPeek(
+ ctx context.Context,
+ req *PerformInboundPeekRequest,
+ res *PerformInboundPeekResponse,
+) error {
+ err := t.Impl.PerformInboundPeek(ctx, req, res)
+ util.GetLogger(ctx).Infof("PerformInboundPeek req=%+v res=%+v", js(req), js(res))
+ return err
+}
+
func (t *RoomserverInternalAPITrace) QueryPublishedRooms(
ctx context.Context,
req *QueryPublishedRoomsRequest,
diff --git a/roomserver/api/output.go b/roomserver/api/output.go
index 2993813c..d60d1cc8 100644
--- a/roomserver/api/output.go
+++ b/roomserver/api/output.go
@@ -51,6 +51,8 @@ const (
// OutputTypeNewPeek indicates that the kafka event is an OutputNewPeek
OutputTypeNewPeek OutputType = "new_peek"
+ // OutputTypeNewInboundPeek indicates that the kafka event is an OutputNewInboundPeek
+ OutputTypeNewInboundPeek OutputType = "new_inbound_peek"
// OutputTypeRetirePeek indicates that the kafka event is an OutputRetirePeek
OutputTypeRetirePeek OutputType = "retire_peek"
)
@@ -72,6 +74,8 @@ type OutputEvent struct {
RedactedEvent *OutputRedactedEvent `json:"redacted_event,omitempty"`
// The content of event with type OutputTypeNewPeek
NewPeek *OutputNewPeek `json:"new_peek,omitempty"`
+ // The content of event with type OutputTypeNewInboundPeek
+ NewInboundPeek *OutputNewInboundPeek `json:"new_inbound_peek,omitempty"`
// The content of event with type OutputTypeRetirePeek
RetirePeek *OutputRetirePeek `json:"retire_peek,omitempty"`
}
@@ -245,6 +249,19 @@ type OutputNewPeek struct {
DeviceID string
}
+// An OutputNewInboundPeek is written whenever a server starts peeking into a room
+type OutputNewInboundPeek struct {
+ RoomID string
+ PeekID string
+ // the event ID at which the peek begins (so we can avoid
+ // a race between tracking the state returned by /peek and emitting subsequent
+ // peeked events)
+ LatestEventID string
+ ServerName gomatrixserverlib.ServerName
+ // how often we told the peeking server to renew the peek
+ RenewalInterval int64
+}
+
// An OutputRetirePeek is written whenever a user stops peeking into a room.
type OutputRetirePeek struct {
RoomID string
diff --git a/roomserver/api/perform.go b/roomserver/api/perform.go
index ae2d6d97..51cbcb1a 100644
--- a/roomserver/api/perform.go
+++ b/roomserver/api/perform.go
@@ -172,6 +172,28 @@ type PerformPublishResponse struct {
Error *PerformError
}
+type PerformInboundPeekRequest struct {
+ UserID string `json:"user_id"`
+ RoomID string `json:"room_id"`
+ PeekID string `json:"peek_id"`
+ ServerName gomatrixserverlib.ServerName `json:"server_name"`
+ RenewalInterval int64 `json:"renewal_interval"`
+}
+
+type PerformInboundPeekResponse struct {
+ // Does the room exist on this roomserver?
+ // If the room doesn't exist this will be false and StateEvents will be empty.
+ RoomExists bool `json:"room_exists"`
+ // The room version of the room.
+ RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
+ // The current state and auth chain events.
+ // The lists will be in an arbitrary order.
+ StateEvents []*gomatrixserverlib.HeaderedEvent `json:"state_events"`
+ AuthChainEvents []*gomatrixserverlib.HeaderedEvent `json:"auth_chain_events"`
+ // The event at which this state was captured
+ LatestEvent *gomatrixserverlib.HeaderedEvent `json:"latest_event"`
+}
+
// PerformForgetRequest is a request to PerformForget
type PerformForgetRequest struct {
RoomID string `json:"room_id"`
diff --git a/roomserver/api/query.go b/roomserver/api/query.go
index 43e562a9..43bbfd16 100644
--- a/roomserver/api/query.go
+++ b/roomserver/api/query.go
@@ -221,7 +221,7 @@ type QueryStateAndAuthChainRequest struct {
// The room ID to query the state in.
RoomID string `json:"room_id"`
// The list of prev events for the event. Used to calculate the state at
- // the event
+ // the event.
PrevEventIDs []string `json:"prev_event_ids"`
// The list of auth events for the event. Used to calculate the auth chain
AuthEventIDs []string `json:"auth_event_ids"`
diff --git a/roomserver/api/wrapper.go b/roomserver/api/wrapper.go
index 7779dbde..a6ef735c 100644
--- a/roomserver/api/wrapper.go
+++ b/roomserver/api/wrapper.go
@@ -43,7 +43,7 @@ func SendEvents(
// SendEventWithState writes an event with the specified kind to the roomserver
// with the state at the event as KindOutlier before it. Will not send any event that is
-// marked as `true` in haveEventIDs
+// marked as `true` in haveEventIDs.
func SendEventWithState(
ctx context.Context, rsAPI RoomserverInternalAPI, kind Kind,
state *gomatrixserverlib.RespState, event *gomatrixserverlib.HeaderedEvent,