aboutsummaryrefslogtreecommitdiff
path: root/setup
diff options
context:
space:
mode:
authorkegsay <kegan@matrix.org>2023-04-27 12:54:20 +0100
committerGitHub <noreply@github.com>2023-04-27 12:54:20 +0100
commitb189edf4f43ff34b69d6c60aeb0efb60dd549c86 (patch)
tree4c08aeda694f3e1cf17c66cf0e4b2b306af6a8df /setup
parent2475cf4b61747e76a524af6f71a4eb7e112812af (diff)
Remove gmsl.HeaderedEvent (#3068)
Replaced with types.HeaderedEvent _for now_. In reality we want to move them all to gmsl.Event and only use HeaderedEvent when we _need_ to bundle the version/event ID with the event (seriailsation boundaries, and even then only when we don't have the room version). Requires https://github.com/matrix-org/gomatrixserverlib/pull/373
Diffstat (limited to 'setup')
-rw-r--r--setup/mscs/msc2836/msc2836.go35
-rw-r--r--setup/mscs/msc2836/msc2836_test.go13
-rw-r--r--setup/mscs/msc2836/storage.go16
-rw-r--r--setup/mscs/msc2946/msc2946.go5
4 files changed, 36 insertions, 33 deletions
diff --git a/setup/mscs/msc2836/msc2836.go b/setup/mscs/msc2836/msc2836.go
index 460b731e..b106a246 100644
--- a/setup/mscs/msc2836/msc2836.go
+++ b/setup/mscs/msc2836/msc2836.go
@@ -33,6 +33,7 @@ import (
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/internal/sqlutil"
roomserver "github.com/matrix-org/dendrite/roomserver/api"
+ "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/syncapi/synctypes"
userapi "github.com/matrix-org/dendrite/userapi/api"
@@ -112,7 +113,7 @@ func Enable(
}
hooks.Enable()
hooks.Attach(hooks.KindNewEventPersisted, func(headeredEvent interface{}) {
- he := headeredEvent.(*gomatrixserverlib.HeaderedEvent)
+ he := headeredEvent.(*types.HeaderedEvent)
hookErr := db.StoreRelation(context.Background(), he)
if hookErr != nil {
util.GetLogger(context.Background()).WithError(hookErr).WithField("event_id", he.EventID()).Error(
@@ -255,7 +256,7 @@ func federatedEventRelationship(
func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONResponse) {
var res MSC2836EventRelationshipsResponse
- var returnEvents []*gomatrixserverlib.HeaderedEvent
+ var returnEvents []*types.HeaderedEvent
// Can the user see (according to history visibility) event_id? If no, reject the request, else continue.
event := rc.getLocalEvent(rc.req.RoomID, rc.req.EventID)
if event == nil {
@@ -299,7 +300,7 @@ func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONRespo
for _, ev := range returnEvents {
included[ev.EventID()] = true
}
- var events []*gomatrixserverlib.HeaderedEvent
+ var events []*types.HeaderedEvent
events, walkLimited = walkThread(
rc.ctx, rc.db, rc, included, remaining,
)
@@ -309,7 +310,7 @@ func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONRespo
for i, ev := range returnEvents {
// for each event, extract the children_count | hash and add it as unsigned data.
rc.addChildMetadata(ev)
- res.ParsedEvents[i] = ev.Unwrap()
+ res.ParsedEvents[i] = ev.Event
}
res.Limited = remaining == 0 || walkLimited
return &res, nil
@@ -318,7 +319,7 @@ func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONRespo
// fetchUnknownEvent retrieves an unknown event from the room specified. This server must
// be joined to the room in question. This has the side effect of injecting surround threaded
// events into the roomserver.
-func (rc *reqCtx) fetchUnknownEvent(eventID, roomID string) *gomatrixserverlib.HeaderedEvent {
+func (rc *reqCtx) fetchUnknownEvent(eventID, roomID string) *types.HeaderedEvent {
if rc.isFederatedRequest || roomID == "" {
// we don't do fed hits for fed requests, and we can't ask servers without a room ID!
return nil
@@ -372,7 +373,7 @@ func (rc *reqCtx) fetchUnknownEvent(eventID, roomID string) *gomatrixserverlib.H
rc.injectResponseToRoomserver(res)
for _, ev := range res.ParsedEvents {
if ev.EventID() == eventID {
- return ev.Headered(ev.Version())
+ return &types.HeaderedEvent{Event: ev}
}
}
}
@@ -382,7 +383,7 @@ func (rc *reqCtx) fetchUnknownEvent(eventID, roomID string) *gomatrixserverlib.H
// If include_parent: true and there is a valid m.relationship field in the event,
// retrieve the referenced event. Apply history visibility check to that event and if it passes, add it to the response array.
-func (rc *reqCtx) includeParent(childEvent *gomatrixserverlib.HeaderedEvent) (parent *gomatrixserverlib.HeaderedEvent) {
+func (rc *reqCtx) includeParent(childEvent *types.HeaderedEvent) (parent *types.HeaderedEvent) {
parentID, _, _ := parentChildEventIDs(childEvent)
if parentID == "" {
return nil
@@ -393,7 +394,7 @@ func (rc *reqCtx) includeParent(childEvent *gomatrixserverlib.HeaderedEvent) (pa
// If include_children: true, lookup all events which have event_id as an m.relationship
// Apply history visibility checks to all these events and add the ones which pass into the response array,
// honouring the recent_first flag and the limit.
-func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recentFirst bool) ([]*gomatrixserverlib.HeaderedEvent, *util.JSONResponse) {
+func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recentFirst bool) ([]*types.HeaderedEvent, *util.JSONResponse) {
if rc.hasUnexploredChildren(parentID) {
// we need to do a remote request to pull in the children as we are missing them locally.
serversToQuery := rc.getServersForEventID(parentID)
@@ -430,7 +431,7 @@ func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recen
resErr := jsonerror.InternalServerError()
return nil, &resErr
}
- var childEvents []*gomatrixserverlib.HeaderedEvent
+ var childEvents []*types.HeaderedEvent
for _, child := range children {
childEvent := rc.lookForEvent(child.EventID)
if childEvent != nil {
@@ -447,8 +448,8 @@ func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recen
// honouring the limit, max_depth and max_breadth values according to the following rules
func walkThread(
ctx context.Context, db Database, rc *reqCtx, included map[string]bool, limit int,
-) ([]*gomatrixserverlib.HeaderedEvent, bool) {
- var result []*gomatrixserverlib.HeaderedEvent
+) ([]*types.HeaderedEvent, bool) {
+ var result []*types.HeaderedEvent
eventWalker := walker{
ctx: ctx,
req: rc.req,
@@ -510,7 +511,7 @@ func (rc *reqCtx) MSC2836EventRelationships(eventID string, srv spec.ServerName,
// authorisedToSeeEvent checks that the user or server is allowed to see this event. Returns true if allowed to
// see this request. This only needs to be done once per room at present as we just check for joined status.
-func (rc *reqCtx) authorisedToSeeEvent(event *gomatrixserverlib.HeaderedEvent) bool {
+func (rc *reqCtx) authorisedToSeeEvent(event *types.HeaderedEvent) bool {
if rc.isFederatedRequest {
// make sure the server is in this room
var res fs.QueryJoinedHostServerNamesInRoomResponse
@@ -593,7 +594,7 @@ func (rc *reqCtx) remoteEventRelationships(eventID string) *MSC2836EventRelation
// lookForEvent returns the event for the event ID given, by trying to query remote servers
// if the event ID is unknown via /event_relationships.
-func (rc *reqCtx) lookForEvent(eventID string) *gomatrixserverlib.HeaderedEvent {
+func (rc *reqCtx) lookForEvent(eventID string) *types.HeaderedEvent {
event := rc.getLocalEvent(rc.req.RoomID, eventID)
if event == nil {
queryRes := rc.remoteEventRelationships(eventID)
@@ -602,7 +603,7 @@ func (rc *reqCtx) lookForEvent(eventID string) *gomatrixserverlib.HeaderedEvent
rc.injectResponseToRoomserver(queryRes)
for _, ev := range queryRes.ParsedEvents {
if ev.EventID() == eventID && rc.req.RoomID == ev.RoomID() {
- return ev.Headered(ev.Version())
+ return &types.HeaderedEvent{Event: ev}
}
}
}
@@ -624,7 +625,7 @@ func (rc *reqCtx) lookForEvent(eventID string) *gomatrixserverlib.HeaderedEvent
return nil
}
-func (rc *reqCtx) getLocalEvent(roomID, eventID string) *gomatrixserverlib.HeaderedEvent {
+func (rc *reqCtx) getLocalEvent(roomID, eventID string) *types.HeaderedEvent {
var queryEventsRes roomserver.QueryEventsByIDResponse
err := rc.rsAPI.QueryEventsByID(rc.ctx, &roomserver.QueryEventsByIDRequest{
RoomID: roomID,
@@ -664,7 +665,7 @@ func (rc *reqCtx) injectResponseToRoomserver(res *MSC2836EventRelationshipsRespo
for _, outlier := range append(eventsInOrder, messageEvents...) {
ires = append(ires, roomserver.InputRoomEvent{
Kind: roomserver.KindOutlier,
- Event: outlier.Headered(outlier.Version()),
+ Event: &types.HeaderedEvent{Event: outlier},
})
}
// we've got the data by this point so use a background context
@@ -683,7 +684,7 @@ func (rc *reqCtx) injectResponseToRoomserver(res *MSC2836EventRelationshipsRespo
}
}
-func (rc *reqCtx) addChildMetadata(ev *gomatrixserverlib.HeaderedEvent) {
+func (rc *reqCtx) addChildMetadata(ev *types.HeaderedEvent) {
count, hash := rc.getChildMetadata(ev.EventID())
if count == 0 {
return
diff --git a/setup/mscs/msc2836/msc2836_test.go b/setup/mscs/msc2836/msc2836_test.go
index a06b7211..78aff310 100644
--- a/setup/mscs/msc2836/msc2836_test.go
+++ b/setup/mscs/msc2836/msc2836_test.go
@@ -24,6 +24,7 @@ import (
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/internal/sqlutil"
roomserver "github.com/matrix-org/dendrite/roomserver/api"
+ "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/setup/mscs/msc2836"
userapi "github.com/matrix-org/dendrite/userapi/api"
@@ -171,7 +172,7 @@ func TestMSC2836(t *testing.T) {
bob: {roomID},
charlie: {roomID},
},
- events: map[string]*gomatrixserverlib.HeaderedEvent{
+ events: map[string]*types.HeaderedEvent{
eventA.EventID(): eventA,
eventB.EventID(): eventB,
eventC.EventID(): eventC,
@@ -182,7 +183,7 @@ func TestMSC2836(t *testing.T) {
eventH.EventID(): eventH,
},
}
- router := injectEvents(t, nopUserAPI, nopRsAPI, []*gomatrixserverlib.HeaderedEvent{
+ router := injectEvents(t, nopUserAPI, nopRsAPI, []*types.HeaderedEvent{
eventA, eventB, eventC, eventD, eventE, eventF, eventG, eventH,
})
cancel := runServer(t, router)
@@ -521,7 +522,7 @@ type testRoomserverAPI struct {
// We'll override the functions we care about.
roomserver.RoomserverInternalAPI
userToJoinedRooms map[string][]string
- events map[string]*gomatrixserverlib.HeaderedEvent
+ events map[string]*types.HeaderedEvent
}
func (r *testRoomserverAPI) QueryEventsByID(ctx context.Context, req *roomserver.QueryEventsByIDRequest, res *roomserver.QueryEventsByIDResponse) error {
@@ -547,7 +548,7 @@ func (r *testRoomserverAPI) QueryMembershipForUser(ctx context.Context, req *roo
return nil
}
-func injectEvents(t *testing.T, userAPI userapi.UserInternalAPI, rsAPI roomserver.RoomserverInternalAPI, events []*gomatrixserverlib.HeaderedEvent) *mux.Router {
+func injectEvents(t *testing.T, userAPI userapi.UserInternalAPI, rsAPI roomserver.RoomserverInternalAPI, events []*types.HeaderedEvent) *mux.Router {
t.Helper()
cfg := &config.Dendrite{}
cfg.Defaults(config.DefaultOpts{
@@ -579,7 +580,7 @@ type fledglingEvent struct {
RoomID string
}
-func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *gomatrixserverlib.HeaderedEvent) {
+func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *types.HeaderedEvent) {
t.Helper()
roomVer := gomatrixserverlib.RoomVersionV6
seed := make([]byte, ed25519.SeedSize) // zero seed
@@ -601,6 +602,6 @@ func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *gomatrixserverlib
if err != nil {
t.Fatalf("mustCreateEvent: failed to sign event: %s", err)
}
- h := signedEvent.Headered(roomVer)
+ h := &types.HeaderedEvent{Event: signedEvent}
return h
}
diff --git a/setup/mscs/msc2836/storage.go b/setup/mscs/msc2836/storage.go
index 4f348192..6a45f08a 100644
--- a/setup/mscs/msc2836/storage.go
+++ b/setup/mscs/msc2836/storage.go
@@ -8,8 +8,8 @@ import (
"encoding/json"
"github.com/matrix-org/dendrite/internal/sqlutil"
+ "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/setup/config"
- "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
)
@@ -23,7 +23,7 @@ type eventInfo struct {
type Database interface {
// StoreRelation stores the parent->child and child->parent relationship for later querying.
// Also stores the event metadata e.g timestamp
- StoreRelation(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent) error
+ StoreRelation(ctx context.Context, ev *types.HeaderedEvent) error
// ChildrenForParent returns the events who have the given `eventID` as an m.relationship with the
// provided `relType`. The returned slice is sorted by origin_server_ts according to whether
// `recentFirst` is true or false.
@@ -35,7 +35,7 @@ type Database interface {
// UpdateChildMetadata persists the children_count and children_hash from this event if and only if
// the count is greater than what was previously there. If the count is updated, the event will be
// updated to be unexplored.
- UpdateChildMetadata(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent) error
+ UpdateChildMetadata(ctx context.Context, ev *types.HeaderedEvent) error
// ChildMetadata returns the children_count and children_hash for the event ID in question.
// Also returns the `explored` flag, which is set to true when MarkChildrenExplored is called and is set
// back to `false` when a larger count is inserted via UpdateChildMetadata.
@@ -222,7 +222,7 @@ func newSQLiteDatabase(conMan sqlutil.Connections, dbOpts *config.DatabaseOption
return &d, nil
}
-func (p *DB) StoreRelation(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent) error {
+func (p *DB) StoreRelation(ctx context.Context, ev *types.HeaderedEvent) error {
parent, child, relType := parentChildEventIDs(ev)
if parent == "" || child == "" {
return nil
@@ -244,7 +244,7 @@ func (p *DB) StoreRelation(ctx context.Context, ev *gomatrixserverlib.HeaderedEv
})
}
-func (p *DB) UpdateChildMetadata(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent) error {
+func (p *DB) UpdateChildMetadata(ctx context.Context, ev *types.HeaderedEvent) error {
eventCount, eventHash := extractChildMetadata(ev)
if eventCount == 0 {
return nil // nothing to update with
@@ -315,7 +315,7 @@ func (p *DB) ParentForChild(ctx context.Context, eventID, relType string) (*even
return &ei, nil
}
-func parentChildEventIDs(ev *gomatrixserverlib.HeaderedEvent) (parent, child, relType string) {
+func parentChildEventIDs(ev *types.HeaderedEvent) (parent, child, relType string) {
if ev == nil {
return
}
@@ -334,7 +334,7 @@ func parentChildEventIDs(ev *gomatrixserverlib.HeaderedEvent) (parent, child, re
return body.Relationship.EventID, ev.EventID(), body.Relationship.RelType
}
-func roomIDAndServers(ev *gomatrixserverlib.HeaderedEvent) (roomID string, servers []string) {
+func roomIDAndServers(ev *types.HeaderedEvent) (roomID string, servers []string) {
servers = []string{}
if ev == nil {
return
@@ -349,7 +349,7 @@ func roomIDAndServers(ev *gomatrixserverlib.HeaderedEvent) (roomID string, serve
return body.RoomID, body.Servers
}
-func extractChildMetadata(ev *gomatrixserverlib.HeaderedEvent) (count int, hash []byte) {
+func extractChildMetadata(ev *types.HeaderedEvent) (count int, hash []byte) {
unsigned := struct {
Counts map[string]int `json:"children"`
Hash spec.Base64Bytes `json:"children_hash"`
diff --git a/setup/mscs/msc2946/msc2946.go b/setup/mscs/msc2946/msc2946.go
index 80d6c598..1795858b 100644
--- a/setup/mscs/msc2946/msc2946.go
+++ b/setup/mscs/msc2946/msc2946.go
@@ -33,6 +33,7 @@ import (
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/httputil"
roomserver "github.com/matrix-org/dendrite/roomserver/api"
+ "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
@@ -388,7 +389,7 @@ func (w *walker) walk() util.JSONResponse {
}
}
-func (w *walker) stateEvent(roomID, evType, stateKey string) *gomatrixserverlib.HeaderedEvent {
+func (w *walker) stateEvent(roomID, evType, stateKey string) *types.HeaderedEvent {
var queryRes roomserver.QueryCurrentStateResponse
tuple := gomatrixserverlib.StateKeyTuple{
EventType: evType,
@@ -636,7 +637,7 @@ func (w *walker) authorisedUser(roomID, parentRoomID string) (authed bool, isJoi
return false, false
}
-func (w *walker) restrictedJoinRuleAllowedRooms(joinRuleEv *gomatrixserverlib.HeaderedEvent, allowType string) (allows []string) {
+func (w *walker) restrictedJoinRuleAllowedRooms(joinRuleEv *types.HeaderedEvent, allowType string) (allows []string) {
rule, _ := joinRuleEv.JoinRule()
if rule != spec.Restricted {
return nil