mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-24 12:41:34 +00:00
Use PDU not *Event in HeaderedEvent (#3073)
Requires https://github.com/matrix-org/gomatrixserverlib/pull/376 This has numerous upsides: - Less type casting to `*Event` is required. - Making Dendrite work with `PDU` interfaces means we can swap out Event impls more easily. - Tests which represent weird event shapes are easier to write. Part of a series of refactors on GMSL.
This commit is contained in:
parent
696cbb70b8
commit
f5b3144dc3
@ -190,7 +190,7 @@ func (s *OutputRoomEventConsumer) sendEvents(
|
|||||||
|
|
||||||
// If txnID is not defined, generate one from the events.
|
// If txnID is not defined, generate one from the events.
|
||||||
if txnID == "" {
|
if txnID == "" {
|
||||||
txnID = fmt.Sprintf("%d_%d", events[0].Event.OriginServerTS(), len(transaction))
|
txnID = fmt.Sprintf("%d_%d", events[0].PDU.OriginServerTS(), len(transaction))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the transaction to the appservice.
|
// Send the transaction to the appservice.
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -48,11 +49,12 @@ func GetAliases(
|
|||||||
visibility := gomatrixserverlib.HistoryVisibilityInvited
|
visibility := gomatrixserverlib.HistoryVisibilityInvited
|
||||||
if historyVisEvent, ok := stateRes.StateEvents[stateTuple]; ok {
|
if historyVisEvent, ok := stateRes.StateEvents[stateTuple]; ok {
|
||||||
var err error
|
var err error
|
||||||
visibility, err = historyVisEvent.HistoryVisibility()
|
var content gomatrixserverlib.HistoryVisibilityContent
|
||||||
if err != nil {
|
if err = json.Unmarshal(historyVisEvent.Content(), &content); err != nil {
|
||||||
util.GetLogger(req.Context()).WithError(err).Error("historyVisEvent.HistoryVisibility failed")
|
util.GetLogger(req.Context()).WithError(err).Error("historyVisEvent.HistoryVisibility failed")
|
||||||
return util.ErrorResponse(fmt.Errorf("historyVisEvent.HistoryVisibility: %w", err))
|
return util.ErrorResponse(fmt.Errorf("historyVisEvent.HistoryVisibility: %w", err))
|
||||||
}
|
}
|
||||||
|
visibility = content.HistoryVisibility
|
||||||
}
|
}
|
||||||
if visibility != spec.WorldReadable {
|
if visibility != spec.WorldReadable {
|
||||||
queryReq := api.QueryMembershipForUserRequest{
|
queryReq := api.QueryMembershipForUserRequest{
|
||||||
|
@ -466,7 +466,7 @@ func createRoom(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the event to the list of auth events
|
// Add the event to the list of auth events
|
||||||
builtEvents = append(builtEvents, &types.HeaderedEvent{Event: ev})
|
builtEvents = append(builtEvents, &types.HeaderedEvent{PDU: ev})
|
||||||
err = authEvents.AddEvent(ev)
|
err = authEvents.AddEvent(ev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(ctx).WithError(err).Error("authEvents.AddEvent failed")
|
util.GetLogger(ctx).WithError(err).Error("authEvents.AddEvent failed")
|
||||||
@ -536,7 +536,7 @@ func createRoom(
|
|||||||
case spec.MRoomMember:
|
case spec.MRoomMember:
|
||||||
fallthrough
|
fallthrough
|
||||||
case spec.MRoomJoinRules:
|
case spec.MRoomJoinRules:
|
||||||
ev := event.Event
|
ev := event.PDU
|
||||||
globalStrippedState = append(
|
globalStrippedState = append(
|
||||||
globalStrippedState,
|
globalStrippedState,
|
||||||
fclient.NewInviteV2StrippedState(ev),
|
fclient.NewInviteV2StrippedState(ev),
|
||||||
@ -558,7 +558,7 @@ func createRoom(
|
|||||||
}
|
}
|
||||||
inviteStrippedState := append(
|
inviteStrippedState := append(
|
||||||
globalStrippedState,
|
globalStrippedState,
|
||||||
fclient.NewInviteV2StrippedState(inviteEvent.Event),
|
fclient.NewInviteV2StrippedState(inviteEvent.PDU),
|
||||||
)
|
)
|
||||||
// Send the invite event to the roomserver.
|
// Send the invite event to the roomserver.
|
||||||
event := inviteEvent
|
event := inviteEvent
|
||||||
|
@ -291,7 +291,7 @@ func SetVisibility(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NOTSPEC: Check if the user's power is greater than power required to change m.room.canonical_alias event
|
// NOTSPEC: Check if the user's power is greater than power required to change m.room.canonical_alias event
|
||||||
power, _ := gomatrixserverlib.NewPowerLevelContentFromEvent(queryEventsRes.StateEvents[0].Event)
|
power, _ := gomatrixserverlib.NewPowerLevelContentFromEvent(queryEventsRes.StateEvents[0].PDU)
|
||||||
if power.UserLevel(dev.UserID) < power.EventLevel(spec.MRoomCanonicalAlias, true) {
|
if power.UserLevel(dev.UserID) < power.EventLevel(spec.MRoomCanonicalAlias, true) {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusForbidden,
|
Code: http.StatusForbidden,
|
||||||
|
@ -185,7 +185,7 @@ func SendEvent(
|
|||||||
req.Context(), rsAPI,
|
req.Context(), rsAPI,
|
||||||
api.KindNew,
|
api.KindNew,
|
||||||
[]*types.HeaderedEvent{
|
[]*types.HeaderedEvent{
|
||||||
&types.HeaderedEvent{Event: e},
|
&types.HeaderedEvent{PDU: e},
|
||||||
},
|
},
|
||||||
device.UserDomain(),
|
device.UserDomain(),
|
||||||
domain,
|
domain,
|
||||||
@ -259,7 +259,7 @@ func generateSendEvent(
|
|||||||
cfg *config.ClientAPI,
|
cfg *config.ClientAPI,
|
||||||
rsAPI api.ClientRoomserverAPI,
|
rsAPI api.ClientRoomserverAPI,
|
||||||
evTime time.Time,
|
evTime time.Time,
|
||||||
) (*gomatrixserverlib.Event, *util.JSONResponse) {
|
) (gomatrixserverlib.PDU, *util.JSONResponse) {
|
||||||
// parse the incoming http request
|
// parse the incoming http request
|
||||||
userID := device.UserID
|
userID := device.UserID
|
||||||
|
|
||||||
@ -313,12 +313,12 @@ func generateSendEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check to see if this user can perform this operation
|
// check to see if this user can perform this operation
|
||||||
stateEvents := make([]*gomatrixserverlib.Event, len(queryRes.StateEvents))
|
stateEvents := make([]gomatrixserverlib.PDU, len(queryRes.StateEvents))
|
||||||
for i := range queryRes.StateEvents {
|
for i := range queryRes.StateEvents {
|
||||||
stateEvents[i] = queryRes.StateEvents[i].Event
|
stateEvents[i] = queryRes.StateEvents[i].PDU
|
||||||
}
|
}
|
||||||
provider := gomatrixserverlib.NewAuthEvents(gomatrixserverlib.ToPDUs(stateEvents))
|
provider := gomatrixserverlib.NewAuthEvents(gomatrixserverlib.ToPDUs(stateEvents))
|
||||||
if err = gomatrixserverlib.Allowed(e.Event, &provider); err != nil {
|
if err = gomatrixserverlib.Allowed(e.PDU, &provider); err != nil {
|
||||||
return nil, &util.JSONResponse{
|
return nil, &util.JSONResponse{
|
||||||
Code: http.StatusForbidden,
|
Code: http.StatusForbidden,
|
||||||
JSON: jsonerror.Forbidden(err.Error()), // TODO: Is this error string comprehensible to the client?
|
JSON: jsonerror.Forbidden(err.Error()), // TODO: Is this error string comprehensible to the client?
|
||||||
@ -343,5 +343,5 @@ func generateSendEvent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return e.Event, nil
|
return e.PDU, nil
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ func SendServerNotice(
|
|||||||
ctx, rsAPI,
|
ctx, rsAPI,
|
||||||
api.KindNew,
|
api.KindNew,
|
||||||
[]*types.HeaderedEvent{
|
[]*types.HeaderedEvent{
|
||||||
&types.HeaderedEvent{Event: e},
|
&types.HeaderedEvent{PDU: e},
|
||||||
},
|
},
|
||||||
device.UserDomain(),
|
device.UserDomain(),
|
||||||
cfgClient.Matrix.ServerName,
|
cfgClient.Matrix.ServerName,
|
||||||
|
@ -96,9 +96,9 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
events := make(map[types.EventNID]*gomatrixserverlib.Event, len(eventEntries))
|
events := make(map[types.EventNID]gomatrixserverlib.PDU, len(eventEntries))
|
||||||
for _, entry := range eventEntries {
|
for _, entry := range eventEntries {
|
||||||
events[entry.EventNID] = entry.Event
|
events[entry.EventNID] = entry.PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(removed) > 0 {
|
if len(removed) > 0 {
|
||||||
@ -155,9 +155,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
authEventIDMap := make(map[string]struct{})
|
authEventIDMap := make(map[string]struct{})
|
||||||
events := make([]*gomatrixserverlib.Event, len(eventEntries))
|
events := make([]gomatrixserverlib.PDU, len(eventEntries))
|
||||||
for i := range eventEntries {
|
for i := range eventEntries {
|
||||||
events[i] = eventEntries[i].Event
|
events[i] = eventEntries[i].PDU
|
||||||
for _, authEventID := range eventEntries[i].AuthEventIDs() {
|
for _, authEventID := range eventEntries[i].AuthEventIDs() {
|
||||||
authEventIDMap[authEventID] = struct{}{}
|
authEventIDMap[authEventID] = struct{}{}
|
||||||
}
|
}
|
||||||
@ -174,17 +174,15 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
authEvents := make([]*gomatrixserverlib.Event, len(authEventEntries))
|
authEvents := make([]gomatrixserverlib.PDU, len(authEventEntries))
|
||||||
for i := range authEventEntries {
|
for i := range authEventEntries {
|
||||||
authEvents[i] = authEventEntries[i].Event
|
authEvents[i] = authEventEntries[i].PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Resolving state")
|
fmt.Println("Resolving state")
|
||||||
var resolved Events
|
var resolved Events
|
||||||
resolved, err = gomatrixserverlib.ResolveConflicts(
|
resolved, err = gomatrixserverlib.ResolveConflicts(
|
||||||
gomatrixserverlib.RoomVersion(*roomVersion),
|
gomatrixserverlib.RoomVersion(*roomVersion), events, authEvents,
|
||||||
gomatrixserverlib.ToPDUs(events),
|
|
||||||
gomatrixserverlib.ToPDUs(authEvents),
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -187,9 +187,9 @@ func (s *OutputRoomEventConsumer) processMessage(ore api.OutputNewRoomEvent, rew
|
|||||||
addsStateEvents = append(addsStateEvents, eventsRes.Events...)
|
addsStateEvents = append(addsStateEvents, eventsRes.Events...)
|
||||||
}
|
}
|
||||||
|
|
||||||
evs := make([]*gomatrixserverlib.Event, len(addsStateEvents))
|
evs := make([]gomatrixserverlib.PDU, len(addsStateEvents))
|
||||||
for i := range evs {
|
for i := range evs {
|
||||||
evs[i] = addsStateEvents[i].Event
|
evs[i] = addsStateEvents[i].PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
addsJoinedHosts, err := JoinedHostsFromEvents(evs)
|
addsJoinedHosts, err := JoinedHostsFromEvents(evs)
|
||||||
@ -340,7 +340,7 @@ func (s *OutputRoomEventConsumer) joinedHostsAtEvent(
|
|||||||
ore.AddsStateEventIDs, ore.RemovesStateEventIDs,
|
ore.AddsStateEventIDs, ore.RemovesStateEventIDs,
|
||||||
ore.StateBeforeAddsEventIDs, ore.StateBeforeRemovesEventIDs,
|
ore.StateBeforeAddsEventIDs, ore.StateBeforeRemovesEventIDs,
|
||||||
)
|
)
|
||||||
combinedAddsEvents, err := s.lookupStateEvents(combinedAdds, ore.Event.Event)
|
combinedAddsEvents, err := s.lookupStateEvents(combinedAdds, ore.Event.PDU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -374,7 +374,7 @@ func (s *OutputRoomEventConsumer) joinedHostsAtEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handle peeking hosts
|
// handle peeking hosts
|
||||||
inboundPeeks, err := s.db.GetInboundPeeks(s.ctx, ore.Event.Event.RoomID())
|
inboundPeeks, err := s.db.GetInboundPeeks(s.ctx, ore.Event.PDU.RoomID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -394,7 +394,7 @@ func (s *OutputRoomEventConsumer) joinedHostsAtEvent(
|
|||||||
// JoinedHostsFromEvents turns a list of state events into a list of joined hosts.
|
// JoinedHostsFromEvents turns a list of state events into a list of joined hosts.
|
||||||
// This errors if one of the events was invalid.
|
// This errors if one of the events was invalid.
|
||||||
// It should be impossible for an invalid event to get this far in the pipeline.
|
// It should be impossible for an invalid event to get this far in the pipeline.
|
||||||
func JoinedHostsFromEvents(evs []*gomatrixserverlib.Event) ([]types.JoinedHost, error) {
|
func JoinedHostsFromEvents(evs []gomatrixserverlib.PDU) ([]types.JoinedHost, error) {
|
||||||
var joinedHosts []types.JoinedHost
|
var joinedHosts []types.JoinedHost
|
||||||
for _, ev := range evs {
|
for _, ev := range evs {
|
||||||
if ev.Type() != "m.room.member" || ev.StateKey() == nil {
|
if ev.Type() != "m.room.member" || ev.StateKey() == nil {
|
||||||
@ -459,8 +459,8 @@ func combineDeltas(adds1, removes1, adds2, removes2 []string) (adds, removes []s
|
|||||||
|
|
||||||
// lookupStateEvents looks up the state events that are added by a new event.
|
// lookupStateEvents looks up the state events that are added by a new event.
|
||||||
func (s *OutputRoomEventConsumer) lookupStateEvents(
|
func (s *OutputRoomEventConsumer) lookupStateEvents(
|
||||||
addsStateEventIDs []string, event *gomatrixserverlib.Event,
|
addsStateEventIDs []string, event gomatrixserverlib.PDU,
|
||||||
) ([]*gomatrixserverlib.Event, error) {
|
) ([]gomatrixserverlib.PDU, error) {
|
||||||
// Fast path if there aren't any new state events.
|
// Fast path if there aren't any new state events.
|
||||||
if len(addsStateEventIDs) == 0 {
|
if len(addsStateEventIDs) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@ -468,11 +468,11 @@ func (s *OutputRoomEventConsumer) lookupStateEvents(
|
|||||||
|
|
||||||
// Fast path if the only state event added is the event itself.
|
// Fast path if the only state event added is the event itself.
|
||||||
if len(addsStateEventIDs) == 1 && addsStateEventIDs[0] == event.EventID() {
|
if len(addsStateEventIDs) == 1 && addsStateEventIDs[0] == event.EventID() {
|
||||||
return []*gomatrixserverlib.Event{event}, nil
|
return []gomatrixserverlib.PDU{event}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
missing := addsStateEventIDs
|
missing := addsStateEventIDs
|
||||||
var result []*gomatrixserverlib.Event
|
var result []gomatrixserverlib.PDU
|
||||||
|
|
||||||
// Check if event itself is being added.
|
// Check if event itself is being added.
|
||||||
for _, eventID := range missing {
|
for _, eventID := range missing {
|
||||||
@ -497,7 +497,7 @@ func (s *OutputRoomEventConsumer) lookupStateEvents(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, headeredEvent := range eventResp.Events {
|
for _, headeredEvent := range eventResp.Events {
|
||||||
result = append(result, headeredEvent.Event)
|
result = append(result, headeredEvent.PDU)
|
||||||
}
|
}
|
||||||
|
|
||||||
missing = missingEventsFrom(result, addsStateEventIDs)
|
missing = missingEventsFrom(result, addsStateEventIDs)
|
||||||
@ -511,7 +511,7 @@ func (s *OutputRoomEventConsumer) lookupStateEvents(
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func missingEventsFrom(events []*gomatrixserverlib.Event, required []string) []string {
|
func missingEventsFrom(events []gomatrixserverlib.PDU, required []string) []string {
|
||||||
have := map[string]bool{}
|
have := map[string]bool{}
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
have[event.EventID()] = true
|
have[event.EventID()] = true
|
||||||
|
@ -133,12 +133,12 @@ func (f *fedClient) MakeJoin(ctx context.Context, origin, s spec.ServerName, roo
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (f *fedClient) SendJoin(ctx context.Context, origin, s spec.ServerName, event *gomatrixserverlib.Event) (res fclient.RespSendJoin, err error) {
|
func (f *fedClient) SendJoin(ctx context.Context, origin, s spec.ServerName, event gomatrixserverlib.PDU) (res fclient.RespSendJoin, err error) {
|
||||||
f.fedClientMutex.Lock()
|
f.fedClientMutex.Lock()
|
||||||
defer f.fedClientMutex.Unlock()
|
defer f.fedClientMutex.Unlock()
|
||||||
for _, r := range f.allowJoins {
|
for _, r := range f.allowJoins {
|
||||||
if r.ID == event.RoomID() {
|
if r.ID == event.RoomID() {
|
||||||
r.InsertEvent(f.t, &types.HeaderedEvent{Event: event})
|
r.InsertEvent(f.t, &types.HeaderedEvent{PDU: event})
|
||||||
f.t.Logf("Join event: %v", event.EventID())
|
f.t.Logf("Join event: %v", event.EventID())
|
||||||
res.StateEvents = types.NewEventJSONsFromHeaderedEvents(r.CurrentState())
|
res.StateEvents = types.NewEventJSONsFromHeaderedEvents(r.CurrentState())
|
||||||
res.AuthEvents = types.NewEventJSONsFromHeaderedEvents(r.Events())
|
res.AuthEvents = types.NewEventJSONsFromHeaderedEvents(r.Events())
|
||||||
|
@ -27,7 +27,7 @@ func (a *FederationInternalAPI) MakeJoin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *FederationInternalAPI) SendJoin(
|
func (a *FederationInternalAPI) SendJoin(
|
||||||
ctx context.Context, origin, s spec.ServerName, event *gomatrixserverlib.Event,
|
ctx context.Context, origin, s spec.ServerName, event gomatrixserverlib.PDU,
|
||||||
) (res gomatrixserverlib.SendJoinResponse, err error) {
|
) (res gomatrixserverlib.SendJoinResponse, err error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
|
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -204,7 +204,7 @@ func (r *FederationInternalAPI) performJoinUsingServer(
|
|||||||
user.Domain(),
|
user.Domain(),
|
||||||
roomserverAPI.KindNew,
|
roomserverAPI.KindNew,
|
||||||
response.StateSnapshot,
|
response.StateSnapshot,
|
||||||
&types.HeaderedEvent{Event: response.JoinEvent},
|
&types.HeaderedEvent{PDU: response.JoinEvent},
|
||||||
serverName,
|
serverName,
|
||||||
nil,
|
nil,
|
||||||
false,
|
false,
|
||||||
@ -389,7 +389,7 @@ func (r *FederationInternalAPI) performOutboundPeekUsingServer(
|
|||||||
StateEvents: gomatrixserverlib.NewEventJSONsFromEvents(stateEvents),
|
StateEvents: gomatrixserverlib.NewEventJSONsFromEvents(stateEvents),
|
||||||
AuthEvents: gomatrixserverlib.NewEventJSONsFromEvents(authEvents),
|
AuthEvents: gomatrixserverlib.NewEventJSONsFromEvents(authEvents),
|
||||||
},
|
},
|
||||||
&types.HeaderedEvent{Event: respPeek.LatestEvent},
|
&types.HeaderedEvent{PDU: respPeek.LatestEvent},
|
||||||
serverName,
|
serverName,
|
||||||
nil,
|
nil,
|
||||||
false,
|
false,
|
||||||
@ -536,7 +536,7 @@ func (r *FederationInternalAPI) PerformInvite(
|
|||||||
"destination": destination,
|
"destination": destination,
|
||||||
}).Info("Sending invite")
|
}).Info("Sending invite")
|
||||||
|
|
||||||
inviteReq, err := fclient.NewInviteV2Request(request.Event.Event, request.InviteRoomState)
|
inviteReq, err := fclient.NewInviteV2Request(request.Event.PDU, request.InviteRoomState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("gomatrixserverlib.NewInviteV2Request: %w", err)
|
return fmt.Errorf("gomatrixserverlib.NewInviteV2Request: %w", err)
|
||||||
}
|
}
|
||||||
@ -554,7 +554,7 @@ func (r *FederationInternalAPI) PerformInvite(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("r.federation.SendInviteV2 failed to decode event response: %w", err)
|
return fmt.Errorf("r.federation.SendInviteV2 failed to decode event response: %w", err)
|
||||||
}
|
}
|
||||||
response.Event = &types.HeaderedEvent{Event: inviteEvent}
|
response.Event = &types.HeaderedEvent{PDU: inviteEvent}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,7 +603,7 @@ func (r *FederationInternalAPI) MarkServersAlive(destinations []spec.ServerName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkEventsContainCreateEvent(events []*gomatrixserverlib.Event) error {
|
func checkEventsContainCreateEvent(events []gomatrixserverlib.PDU) error {
|
||||||
// sanity check we have a create event and it has a known room version
|
// sanity check we have a create event and it has a known room version
|
||||||
for _, ev := range events {
|
for _, ev := range events {
|
||||||
if ev.Type() == spec.MRoomCreate && ev.StateKeyEquals("") {
|
if ev.Type() == spec.MRoomCreate && ev.StateKeyEquals("") {
|
||||||
|
@ -109,7 +109,7 @@ func mustCreatePDU(t *testing.T) *types.HeaderedEvent {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create event: %v", err)
|
t.Fatalf("failed to create event: %v", err)
|
||||||
}
|
}
|
||||||
return &types.HeaderedEvent{Event: ev}
|
return &types.HeaderedEvent{PDU: ev}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustCreateEDU(t *testing.T) *gomatrixserverlib.EDU {
|
func mustCreateEDU(t *testing.T) *gomatrixserverlib.EDU {
|
||||||
|
@ -103,18 +103,18 @@ func Backfill(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter any event that's not from the requested room out.
|
// Filter any event that's not from the requested room out.
|
||||||
evs := make([]*gomatrixserverlib.Event, 0)
|
evs := make([]gomatrixserverlib.PDU, 0)
|
||||||
|
|
||||||
var ev *types.HeaderedEvent
|
var ev *types.HeaderedEvent
|
||||||
for _, ev = range res.Events {
|
for _, ev = range res.Events {
|
||||||
if ev.RoomID() == roomID {
|
if ev.RoomID() == roomID {
|
||||||
evs = append(evs, ev.Event)
|
evs = append(evs, ev.PDU)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eventJSONs := []json.RawMessage{}
|
eventJSONs := []json.RawMessage{}
|
||||||
for _, e := range gomatrixserverlib.ReverseTopologicalOrdering(
|
for _, e := range gomatrixserverlib.ReverseTopologicalOrdering(
|
||||||
gomatrixserverlib.ToPDUs(evs),
|
evs,
|
||||||
gomatrixserverlib.TopologicalOrderByPrevEvents,
|
gomatrixserverlib.TopologicalOrderByPrevEvents,
|
||||||
) {
|
) {
|
||||||
eventJSONs = append(eventJSONs, e.JSON())
|
eventJSONs = append(eventJSONs, e.JSON())
|
||||||
|
@ -80,7 +80,7 @@ func allowedToSeeEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetchEvent fetches the event without auth checks. Returns an error if the event cannot be found.
|
// fetchEvent fetches the event without auth checks. Returns an error if the event cannot be found.
|
||||||
func fetchEvent(ctx context.Context, rsAPI api.FederationRoomserverAPI, roomID, eventID string) (*gomatrixserverlib.Event, *util.JSONResponse) {
|
func fetchEvent(ctx context.Context, rsAPI api.FederationRoomserverAPI, roomID, eventID string) (gomatrixserverlib.PDU, *util.JSONResponse) {
|
||||||
var eventsResponse api.QueryEventsByIDResponse
|
var eventsResponse api.QueryEventsByIDResponse
|
||||||
err := rsAPI.QueryEventsByID(
|
err := rsAPI.QueryEventsByID(
|
||||||
ctx,
|
ctx,
|
||||||
@ -99,5 +99,5 @@ func fetchEvent(ctx context.Context, rsAPI api.FederationRoomserverAPI, roomID,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return eventsResponse.Events[0].Event, nil
|
return eventsResponse.Events[0].PDU, nil
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ func InviteV1(
|
|||||||
func processInvite(
|
func processInvite(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
isInviteV2 bool,
|
isInviteV2 bool,
|
||||||
event *gomatrixserverlib.Event,
|
event gomatrixserverlib.PDU,
|
||||||
roomVer gomatrixserverlib.RoomVersion,
|
roomVer gomatrixserverlib.RoomVersion,
|
||||||
strippedState []fclient.InviteV2StrippedState,
|
strippedState []fclient.InviteV2StrippedState,
|
||||||
roomID string,
|
roomID string,
|
||||||
@ -198,7 +198,7 @@ func processInvite(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Add the invite event to the roomserver.
|
// Add the invite event to the roomserver.
|
||||||
inviteEvent := &types.HeaderedEvent{Event: &signedEvent}
|
inviteEvent := &types.HeaderedEvent{PDU: signedEvent}
|
||||||
request := &api.PerformInviteRequest{
|
request := &api.PerformInviteRequest{
|
||||||
Event: inviteEvent,
|
Event: inviteEvent,
|
||||||
InviteRoomState: strippedState,
|
InviteRoomState: strippedState,
|
||||||
|
@ -163,13 +163,13 @@ func MakeJoin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that the join is allowed or not
|
// Check that the join is allowed or not
|
||||||
stateEvents := make([]*gomatrixserverlib.Event, len(queryRes.StateEvents))
|
stateEvents := make([]gomatrixserverlib.PDU, len(queryRes.StateEvents))
|
||||||
for i := range queryRes.StateEvents {
|
for i := range queryRes.StateEvents {
|
||||||
stateEvents[i] = queryRes.StateEvents[i].Event
|
stateEvents[i] = queryRes.StateEvents[i].PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
provider := gomatrixserverlib.NewAuthEvents(gomatrixserverlib.ToPDUs(stateEvents))
|
provider := gomatrixserverlib.NewAuthEvents(stateEvents)
|
||||||
if err = gomatrixserverlib.Allowed(event.Event, &provider); err != nil {
|
if err = gomatrixserverlib.Allowed(event.PDU, &provider); err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusForbidden,
|
Code: http.StatusForbidden,
|
||||||
JSON: jsonerror.Forbidden(err.Error()),
|
JSON: jsonerror.Forbidden(err.Error()),
|
||||||
@ -414,7 +414,7 @@ func SendJoin(
|
|||||||
InputRoomEvents: []api.InputRoomEvent{
|
InputRoomEvents: []api.InputRoomEvent{
|
||||||
{
|
{
|
||||||
Kind: api.KindNew,
|
Kind: api.KindNew,
|
||||||
Event: &types.HeaderedEvent{Event: &signed},
|
Event: &types.HeaderedEvent{PDU: signed},
|
||||||
SendAsServer: string(cfg.Matrix.ServerName),
|
SendAsServer: string(cfg.Matrix.ServerName),
|
||||||
TransactionID: nil,
|
TransactionID: nil,
|
||||||
},
|
},
|
||||||
|
@ -110,12 +110,12 @@ func MakeLeave(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that the leave is allowed or not
|
// Check that the leave is allowed or not
|
||||||
stateEvents := make([]*gomatrixserverlib.Event, len(queryRes.StateEvents))
|
stateEvents := make([]gomatrixserverlib.PDU, len(queryRes.StateEvents))
|
||||||
for i := range queryRes.StateEvents {
|
for i := range queryRes.StateEvents {
|
||||||
stateEvents[i] = queryRes.StateEvents[i].Event
|
stateEvents[i] = queryRes.StateEvents[i].PDU
|
||||||
}
|
}
|
||||||
provider := gomatrixserverlib.NewAuthEvents(gomatrixserverlib.ToPDUs(stateEvents))
|
provider := gomatrixserverlib.NewAuthEvents(stateEvents)
|
||||||
if err = gomatrixserverlib.Allowed(event.Event, &provider); err != nil {
|
if err = gomatrixserverlib.Allowed(event, &provider); err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusForbidden,
|
Code: http.StatusForbidden,
|
||||||
JSON: jsonerror.Forbidden(err.Error()),
|
JSON: jsonerror.Forbidden(err.Error()),
|
||||||
@ -313,7 +313,7 @@ func SendLeave(
|
|||||||
InputRoomEvents: []api.InputRoomEvent{
|
InputRoomEvents: []api.InputRoomEvent{
|
||||||
{
|
{
|
||||||
Kind: api.KindNew,
|
Kind: api.KindNew,
|
||||||
Event: &types.HeaderedEvent{Event: event},
|
Event: &types.HeaderedEvent{PDU: event},
|
||||||
SendAsServer: string(cfg.Matrix.ServerName),
|
SendAsServer: string(cfg.Matrix.ServerName),
|
||||||
TransactionID: nil,
|
TransactionID: nil,
|
||||||
},
|
},
|
||||||
|
@ -91,7 +91,7 @@ func Peek(
|
|||||||
StateEvents: types.NewEventJSONsFromHeaderedEvents(response.StateEvents),
|
StateEvents: types.NewEventJSONsFromHeaderedEvents(response.StateEvents),
|
||||||
AuthEvents: types.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents),
|
AuthEvents: types.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents),
|
||||||
RoomVersion: response.RoomVersion,
|
RoomVersion: response.RoomVersion,
|
||||||
LatestEvent: response.LatestEvent.Event,
|
LatestEvent: response.LatestEvent.PDU,
|
||||||
RenewalInterval: renewalInterval,
|
RenewalInterval: renewalInterval,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ func CreateInvitesFrom3PIDInvites(
|
|||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
if event != nil {
|
if event != nil {
|
||||||
evs = append(evs, &types.HeaderedEvent{Event: event})
|
evs = append(evs, &types.HeaderedEvent{PDU: event})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ func ExchangeThirdPartyInvite(
|
|||||||
httpReq.Context(), rsAPI,
|
httpReq.Context(), rsAPI,
|
||||||
api.KindNew,
|
api.KindNew,
|
||||||
[]*types.HeaderedEvent{
|
[]*types.HeaderedEvent{
|
||||||
{Event: inviteEvent},
|
{PDU: inviteEvent},
|
||||||
},
|
},
|
||||||
request.Destination(),
|
request.Destination(),
|
||||||
request.Origin(),
|
request.Origin(),
|
||||||
@ -325,7 +325,7 @@ func buildMembershipEvent(
|
|||||||
authEvents := gomatrixserverlib.NewAuthEvents(nil)
|
authEvents := gomatrixserverlib.NewAuthEvents(nil)
|
||||||
|
|
||||||
for i := range queryRes.StateEvents {
|
for i := range queryRes.StateEvents {
|
||||||
err = authEvents.AddEvent(queryRes.StateEvents[i].Event)
|
err = authEvents.AddEvent(queryRes.StateEvents[i].PDU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -22,7 +22,7 @@ require (
|
|||||||
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
||||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230428192809-ff52c27efdce
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230502133856-ad26780a085c
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
|
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
|
||||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
||||||
github.com/mattn/go-sqlite3 v1.14.16
|
github.com/mattn/go-sqlite3 v1.14.16
|
||||||
|
10
go.sum
10
go.sum
@ -323,8 +323,14 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw
|
|||||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
|
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230428192809-ff52c27efdce h1:ZdNs5Qj1Cf42GfwUE01oPIZccSiaPJ/HcZP9qxHte8k=
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230428003202-267b4e79f138 h1:zqMuO/4ye8QnSPLhruxTC4cQcXfrvpPwdtT+4kqEgF4=
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230428192809-ff52c27efdce/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230428003202-267b4e79f138/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230428142634-a4fa967eac17 h1:So8d7SZZdKB7+vWFXwmAQ3C+tUkkegMlcGk8n60w2og=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230428142634-a4fa967eac17/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230502101247-782aebf83205 h1:foJFr0V1uZC0oJ3ooenScGtLViq7Hx3rioe1Hf0lnhY=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230502101247-782aebf83205/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230502133856-ad26780a085c h1:5xXMu/08j8tWfiVUvD4yfs6mepz07BgC4kL2i0oGJX4=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230502133856-ad26780a085c/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
|
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
|
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
|
||||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
||||||
|
@ -77,7 +77,7 @@ func BuildEvent(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &types.HeaderedEvent{Event: event}, nil
|
return &types.HeaderedEvent{PDU: event}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// queryRequiredEventsForBuilder queries the roomserver for auth/prev events needed for this builder.
|
// queryRequiredEventsForBuilder queries the roomserver for auth/prev events needed for this builder.
|
||||||
@ -124,7 +124,7 @@ func addPrevEventsToEvent(
|
|||||||
authEvents := gomatrixserverlib.NewAuthEvents(nil)
|
authEvents := gomatrixserverlib.NewAuthEvents(nil)
|
||||||
|
|
||||||
for i := range queryRes.StateEvents {
|
for i := range queryRes.StateEvents {
|
||||||
err = authEvents.AddEvent(queryRes.StateEvents[i].Event)
|
err = authEvents.AddEvent(queryRes.StateEvents[i].PDU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("authEvents.AddEvent: %w", err)
|
return fmt.Errorf("authEvents.AddEvent: %w", err)
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ func truncateAuthAndPrevEvents(auth, prev []gomatrixserverlib.EventReference) (
|
|||||||
|
|
||||||
// RedactEvent redacts the given event and sets the unsigned field appropriately. This should be used by
|
// RedactEvent redacts the given event and sets the unsigned field appropriately. This should be used by
|
||||||
// downstream components to the roomserver when an OutputTypeRedactedEvent occurs.
|
// downstream components to the roomserver when an OutputTypeRedactedEvent occurs.
|
||||||
func RedactEvent(redactionEvent, redactedEvent *gomatrixserverlib.Event) error {
|
func RedactEvent(redactionEvent, redactedEvent gomatrixserverlib.PDU) error {
|
||||||
// sanity check
|
// sanity check
|
||||||
if redactionEvent.Type() != spec.MRoomRedaction {
|
if redactionEvent.Type() != spec.MRoomRedaction {
|
||||||
return fmt.Errorf("RedactEvent: redactionEvent isn't a redaction event, is '%s'", redactionEvent.Type())
|
return fmt.Errorf("RedactEvent: redactionEvent isn't a redaction event, is '%s'", redactionEvent.Type())
|
||||||
|
@ -184,7 +184,7 @@ func (t *TxnReq) ProcessTransaction(ctx context.Context) (*fclient.RespSend, *ut
|
|||||||
t.rsAPI,
|
t.rsAPI,
|
||||||
api.KindNew,
|
api.KindNew,
|
||||||
[]*rstypes.HeaderedEvent{
|
[]*rstypes.HeaderedEvent{
|
||||||
{Event: event},
|
{PDU: event},
|
||||||
},
|
},
|
||||||
t.Destination,
|
t.Destination,
|
||||||
t.Origin,
|
t.Origin,
|
||||||
|
@ -636,7 +636,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic("cannot load test data: " + err.Error())
|
panic("cannot load test data: " + err.Error())
|
||||||
}
|
}
|
||||||
h := &rstypes.HeaderedEvent{Event: e}
|
h := &rstypes.HeaderedEvent{PDU: e}
|
||||||
testEvents = append(testEvents, h)
|
testEvents = append(testEvents, h)
|
||||||
if e.StateKey() != nil {
|
if e.StateKey() != nil {
|
||||||
testStateEvents[gomatrixserverlib.StateKeyTuple{
|
testStateEvents[gomatrixserverlib.StateKeyTuple{
|
||||||
|
@ -63,7 +63,7 @@ func NewServerACLs(db ServerACLDatabase) *ServerACLs {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if state != nil {
|
if state != nil {
|
||||||
acls.OnServerACLUpdate(state.Event)
|
acls.OnServerACLUpdate(state.PDU)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return acls
|
return acls
|
||||||
@ -88,7 +88,7 @@ func compileACLRegex(orig string) (*regexp.Regexp, error) {
|
|||||||
return regexp.Compile(escaped)
|
return regexp.Compile(escaped)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerACLs) OnServerACLUpdate(state *gomatrixserverlib.Event) {
|
func (s *ServerACLs) OnServerACLUpdate(state gomatrixserverlib.PDU) {
|
||||||
acls := &serverACL{}
|
acls := &serverACL{}
|
||||||
if err := json.Unmarshal(state.Content(), &acls.ServerACL); err != nil {
|
if err := json.Unmarshal(state.Content(), &acls.ServerACL); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to unmarshal state content for server ACLs")
|
logrus.WithError(err).Errorf("Failed to unmarshal state content for server ACLs")
|
||||||
|
@ -55,8 +55,7 @@ func SendEventWithState(
|
|||||||
state gomatrixserverlib.StateResponse, event *types.HeaderedEvent,
|
state gomatrixserverlib.StateResponse, event *types.HeaderedEvent,
|
||||||
origin spec.ServerName, haveEventIDs map[string]bool, async bool,
|
origin spec.ServerName, haveEventIDs map[string]bool, async bool,
|
||||||
) error {
|
) error {
|
||||||
outliersPDU := gomatrixserverlib.LineariseStateResponse(event.Version(), state)
|
outliers := gomatrixserverlib.LineariseStateResponse(event.Version(), state)
|
||||||
outliers := gomatrixserverlib.TempCastToEvents(outliersPDU)
|
|
||||||
ires := make([]InputRoomEvent, 0, len(outliers))
|
ires := make([]InputRoomEvent, 0, len(outliers))
|
||||||
for _, outlier := range outliers {
|
for _, outlier := range outliers {
|
||||||
if haveEventIDs[outlier.EventID()] {
|
if haveEventIDs[outlier.EventID()] {
|
||||||
@ -64,7 +63,7 @@ func SendEventWithState(
|
|||||||
}
|
}
|
||||||
ires = append(ires, InputRoomEvent{
|
ires = append(ires, InputRoomEvent{
|
||||||
Kind: KindOutlier,
|
Kind: KindOutlier,
|
||||||
Event: &types.HeaderedEvent{Event: outlier},
|
Event: &types.HeaderedEvent{PDU: outlier},
|
||||||
Origin: origin,
|
Origin: origin,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
func IsServerAllowed(
|
func IsServerAllowed(
|
||||||
serverName spec.ServerName,
|
serverName spec.ServerName,
|
||||||
serverCurrentlyInRoom bool,
|
serverCurrentlyInRoom bool,
|
||||||
authEvents []*gomatrixserverlib.Event,
|
authEvents []gomatrixserverlib.PDU,
|
||||||
) bool {
|
) bool {
|
||||||
// In practice should not happen, but avoids unneeded CPU cycles
|
// In practice should not happen, but avoids unneeded CPU cycles
|
||||||
if serverName == "" || len(authEvents) == 0 {
|
if serverName == "" || len(authEvents) == 0 {
|
||||||
@ -55,7 +55,7 @@ func IsServerAllowed(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func HistoryVisibilityForRoom(authEvents []*gomatrixserverlib.Event) gomatrixserverlib.HistoryVisibility {
|
func HistoryVisibilityForRoom(authEvents []gomatrixserverlib.PDU) gomatrixserverlib.HistoryVisibility {
|
||||||
// https://matrix.org/docs/spec/client_server/r0.6.0#id87
|
// https://matrix.org/docs/spec/client_server/r0.6.0#id87
|
||||||
// By default if no history_visibility is set, or if the value is not understood, the visibility is assumed to be shared.
|
// By default if no history_visibility is set, or if the value is not understood, the visibility is assumed to be shared.
|
||||||
visibility := gomatrixserverlib.HistoryVisibilityShared
|
visibility := gomatrixserverlib.HistoryVisibilityShared
|
||||||
@ -70,7 +70,7 @@ func HistoryVisibilityForRoom(authEvents []*gomatrixserverlib.Event) gomatrixser
|
|||||||
return visibility
|
return visibility
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsAnyUserOnServerWithMembership(serverName spec.ServerName, authEvents []*gomatrixserverlib.Event, wantMembership string) bool {
|
func IsAnyUserOnServerWithMembership(serverName spec.ServerName, authEvents []gomatrixserverlib.PDU, wantMembership string) bool {
|
||||||
for _, ev := range authEvents {
|
for _, ev := range authEvents {
|
||||||
if ev.Type() != spec.MRoomMember {
|
if ev.Type() != spec.MRoomMember {
|
||||||
continue
|
continue
|
||||||
|
@ -72,9 +72,9 @@ func TestIsServerAllowed(t *testing.T) {
|
|||||||
if tt.roomFunc == nil {
|
if tt.roomFunc == nil {
|
||||||
t.Fatalf("missing roomFunc")
|
t.Fatalf("missing roomFunc")
|
||||||
}
|
}
|
||||||
var authEvents []*gomatrixserverlib.Event
|
var authEvents []gomatrixserverlib.PDU
|
||||||
for _, ev := range tt.roomFunc().Events() {
|
for _, ev := range tt.roomFunc().Events() {
|
||||||
authEvents = append(authEvents, ev.Event)
|
authEvents = append(authEvents, ev.PDU)
|
||||||
}
|
}
|
||||||
|
|
||||||
if got := IsServerAllowed(tt.serverName, tt.serverCurrentlyInRoom, authEvents); got != tt.want {
|
if got := IsServerAllowed(tt.serverName, tt.serverCurrentlyInRoom, authEvents); got != tt.want {
|
||||||
|
@ -66,7 +66,7 @@ func CheckForSoftFail(
|
|||||||
|
|
||||||
// Work out which of the state events we actually need.
|
// Work out which of the state events we actually need.
|
||||||
stateNeeded := gomatrixserverlib.StateNeededForAuth(
|
stateNeeded := gomatrixserverlib.StateNeededForAuth(
|
||||||
gomatrixserverlib.ToPDUs([]*gomatrixserverlib.Event{event.Event}),
|
[]gomatrixserverlib.PDU{event.PDU},
|
||||||
)
|
)
|
||||||
|
|
||||||
// Load the actual auth events from the database.
|
// Load the actual auth events from the database.
|
||||||
@ -76,7 +76,7 @@ func CheckForSoftFail(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the event is allowed.
|
// Check if the event is allowed.
|
||||||
if err = gomatrixserverlib.Allowed(event.Event, &authEvents); err != nil {
|
if err = gomatrixserverlib.Allowed(event.PDU, &authEvents); err != nil {
|
||||||
// return true, nil
|
// return true, nil
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ func CheckAuthEvents(
|
|||||||
authStateEntries = types.DeduplicateStateEntries(authStateEntries)
|
authStateEntries = types.DeduplicateStateEntries(authStateEntries)
|
||||||
|
|
||||||
// Work out which of the state events we actually need.
|
// Work out which of the state events we actually need.
|
||||||
stateNeeded := gomatrixserverlib.StateNeededForAuth([]gomatrixserverlib.PDU{event.Event})
|
stateNeeded := gomatrixserverlib.StateNeededForAuth([]gomatrixserverlib.PDU{event.PDU})
|
||||||
|
|
||||||
// Load the actual auth events from the database.
|
// Load the actual auth events from the database.
|
||||||
authEvents, err := loadAuthEvents(ctx, db, roomInfo, stateNeeded, authStateEntries)
|
authEvents, err := loadAuthEvents(ctx, db, roomInfo, stateNeeded, authStateEntries)
|
||||||
@ -109,7 +109,7 @@ func CheckAuthEvents(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the event is allowed.
|
// Check if the event is allowed.
|
||||||
if err = gomatrixserverlib.Allowed(event.Event, &authEvents); err != nil {
|
if err = gomatrixserverlib.Allowed(event.PDU, &authEvents); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ func (ae *authEvents) lookupEventWithEmptyStateKey(typeNID types.EventTypeNID) g
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return event.Event
|
return event.PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ae *authEvents) lookupEvent(typeNID types.EventTypeNID, stateKey string) gomatrixserverlib.PDU {
|
func (ae *authEvents) lookupEvent(typeNID types.EventTypeNID, stateKey string) gomatrixserverlib.PDU {
|
||||||
@ -189,7 +189,7 @@ func (ae *authEvents) lookupEvent(typeNID types.EventTypeNID, stateKey string) g
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return event.Event
|
return event.PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadAuthEvents loads the events needed for authentication from the supplied room state.
|
// loadAuthEvents loads the events needed for authentication from the supplied room state.
|
||||||
|
@ -45,7 +45,7 @@ func UpdateToInviteMembership(
|
|||||||
updates = append(updates, api.OutputEvent{
|
updates = append(updates, api.OutputEvent{
|
||||||
Type: api.OutputTypeNewInviteEvent,
|
Type: api.OutputTypeNewInviteEvent,
|
||||||
NewInviteEvent: &api.OutputNewInviteEvent{
|
NewInviteEvent: &api.OutputNewInviteEvent{
|
||||||
Event: &types.HeaderedEvent{Event: add.Event},
|
Event: &types.HeaderedEvent{PDU: add.PDU},
|
||||||
RoomVersion: roomVersion,
|
RoomVersion: roomVersion,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -90,9 +90,9 @@ func IsServerCurrentlyInRoom(ctx context.Context, db storage.Database, serverNam
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
gmslEvents := make([]*gomatrixserverlib.Event, len(events))
|
gmslEvents := make([]gomatrixserverlib.PDU, len(events))
|
||||||
for i := range events {
|
for i := range events {
|
||||||
gmslEvents[i] = events[i].Event
|
gmslEvents[i] = events[i].PDU
|
||||||
}
|
}
|
||||||
return auth.IsAnyUserOnServerWithMembership(serverName, gmslEvents, spec.Join), nil
|
return auth.IsAnyUserOnServerWithMembership(serverName, gmslEvents, spec.Join), nil
|
||||||
}
|
}
|
||||||
@ -234,22 +234,22 @@ func MembershipAtEvent(ctx context.Context, db storage.RoomDatabase, info *types
|
|||||||
|
|
||||||
func LoadEvents(
|
func LoadEvents(
|
||||||
ctx context.Context, db storage.RoomDatabase, roomInfo *types.RoomInfo, eventNIDs []types.EventNID,
|
ctx context.Context, db storage.RoomDatabase, roomInfo *types.RoomInfo, eventNIDs []types.EventNID,
|
||||||
) ([]*gomatrixserverlib.Event, error) {
|
) ([]gomatrixserverlib.PDU, error) {
|
||||||
stateEvents, err := db.Events(ctx, roomInfo, eventNIDs)
|
stateEvents, err := db.Events(ctx, roomInfo, eventNIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make([]*gomatrixserverlib.Event, len(stateEvents))
|
result := make([]gomatrixserverlib.PDU, len(stateEvents))
|
||||||
for i := range stateEvents {
|
for i := range stateEvents {
|
||||||
result[i] = stateEvents[i].Event
|
result[i] = stateEvents[i].PDU
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadStateEvents(
|
func LoadStateEvents(
|
||||||
ctx context.Context, db storage.RoomDatabase, roomInfo *types.RoomInfo, stateEntries []types.StateEntry,
|
ctx context.Context, db storage.RoomDatabase, roomInfo *types.RoomInfo, stateEntries []types.StateEntry,
|
||||||
) ([]*gomatrixserverlib.Event, error) {
|
) ([]gomatrixserverlib.PDU, error) {
|
||||||
eventNIDs := make([]types.EventNID, len(stateEntries))
|
eventNIDs := make([]types.EventNID, len(stateEntries))
|
||||||
for i := range stateEntries {
|
for i := range stateEntries {
|
||||||
eventNIDs[i] = stateEntries[i].EventNID
|
eventNIDs[i] = stateEntries[i].EventNID
|
||||||
@ -287,7 +287,7 @@ func CheckServerAllowedToSeeEvent(
|
|||||||
|
|
||||||
func slowGetHistoryVisibilityState(
|
func slowGetHistoryVisibilityState(
|
||||||
ctx context.Context, db storage.Database, info *types.RoomInfo, eventID string, serverName spec.ServerName,
|
ctx context.Context, db storage.Database, info *types.RoomInfo, eventID string, serverName spec.ServerName,
|
||||||
) ([]*gomatrixserverlib.Event, error) {
|
) ([]gomatrixserverlib.PDU, error) {
|
||||||
roomState := state.NewStateResolution(db, info)
|
roomState := state.NewStateResolution(db, info)
|
||||||
stateEntries, err := roomState.LoadStateAtEvent(ctx, eventID)
|
stateEntries, err := roomState.LoadStateAtEvent(ctx, eventID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -479,7 +479,7 @@ func QueryLatestEventsAndState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{Event: event})
|
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{PDU: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -41,7 +41,7 @@ func TestIsInvitePendingWithoutNID(t *testing.T) {
|
|||||||
var authNIDs []types.EventNID
|
var authNIDs []types.EventNID
|
||||||
for _, x := range room.Events() {
|
for _, x := range room.Events() {
|
||||||
|
|
||||||
roomInfo, err := db.GetOrCreateRoomInfo(context.Background(), x.Event)
|
roomInfo, err := db.GetOrCreateRoomInfo(context.Background(), x.PDU)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, roomInfo)
|
assert.NotNil(t, roomInfo)
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ func TestIsInvitePendingWithoutNID(t *testing.T) {
|
|||||||
eventStateKeyNID, err := db.GetOrCreateEventStateKeyNID(context.Background(), x.StateKey())
|
eventStateKeyNID, err := db.GetOrCreateEventStateKeyNID(context.Background(), x.StateKey())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
evNID, _, err := db.StoreEvent(context.Background(), x.Event, roomInfo, eventTypeNID, eventStateKeyNID, authNIDs, false)
|
evNID, _, err := db.StoreEvent(context.Background(), x.PDU, roomInfo, eventTypeNID, eventStateKeyNID, authNIDs, false)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
authNIDs = append(authNIDs, evNID)
|
authNIDs = append(authNIDs, evNID)
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func (r *Inputer) processRoomEvent(
|
|||||||
|
|
||||||
// Parse and validate the event JSON
|
// Parse and validate the event JSON
|
||||||
headered := input.Event
|
headered := input.Event
|
||||||
event := headered.Event
|
event := headered.PDU
|
||||||
logger := util.GetLogger(ctx).WithFields(logrus.Fields{
|
logger := util.GetLogger(ctx).WithFields(logrus.Fields{
|
||||||
"event_id": event.EventID(),
|
"event_id": event.EventID(),
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID(),
|
||||||
@ -232,7 +232,7 @@ func (r *Inputer) processRoomEvent(
|
|||||||
roomsMu: internal.NewMutexByRoom(),
|
roomsMu: internal.NewMutexByRoom(),
|
||||||
servers: serverRes.ServerNames,
|
servers: serverRes.ServerNames,
|
||||||
hadEvents: map[string]bool{},
|
hadEvents: map[string]bool{},
|
||||||
haveEvents: map[string]*gomatrixserverlib.Event{},
|
haveEvents: map[string]gomatrixserverlib.PDU{},
|
||||||
}
|
}
|
||||||
var stateSnapshot *parsedRespState
|
var stateSnapshot *parsedRespState
|
||||||
if stateSnapshot, err = missingState.processEventWithMissingState(ctx, event, headered.Version()); err != nil {
|
if stateSnapshot, err = missingState.processEventWithMissingState(ctx, event, headered.Version()); err != nil {
|
||||||
@ -389,8 +389,8 @@ func (r *Inputer) processRoomEvent(
|
|||||||
// we do this after calculating state for this event as we may need to get power levels
|
// we do this after calculating state for this event as we may need to get power levels
|
||||||
var (
|
var (
|
||||||
redactedEventID string
|
redactedEventID string
|
||||||
redactionEvent *gomatrixserverlib.Event
|
redactionEvent gomatrixserverlib.PDU
|
||||||
redactedEvent *gomatrixserverlib.Event
|
redactedEvent gomatrixserverlib.PDU
|
||||||
)
|
)
|
||||||
if !isRejected && !isCreateEvent {
|
if !isRejected && !isCreateEvent {
|
||||||
resolver := state.NewStateResolution(r.DB, roomInfo)
|
resolver := state.NewStateResolution(r.DB, roomInfo)
|
||||||
@ -467,7 +467,7 @@ func (r *Inputer) processRoomEvent(
|
|||||||
Type: api.OutputTypeRedactedEvent,
|
Type: api.OutputTypeRedactedEvent,
|
||||||
RedactedEvent: &api.OutputRedactedEvent{
|
RedactedEvent: &api.OutputRedactedEvent{
|
||||||
RedactedEventID: redactedEventID,
|
RedactedEventID: redactedEventID,
|
||||||
RedactedBecause: &types.HeaderedEvent{Event: redactionEvent},
|
RedactedBecause: &types.HeaderedEvent{PDU: redactionEvent},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -490,7 +490,7 @@ func (r *Inputer) processRoomEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handleRemoteRoomUpgrade updates published rooms and room aliases
|
// handleRemoteRoomUpgrade updates published rooms and room aliases
|
||||||
func (r *Inputer) handleRemoteRoomUpgrade(ctx context.Context, event *gomatrixserverlib.Event) error {
|
func (r *Inputer) handleRemoteRoomUpgrade(ctx context.Context, event gomatrixserverlib.PDU) error {
|
||||||
oldRoomID := event.RoomID()
|
oldRoomID := event.RoomID()
|
||||||
newRoomID := gjson.GetBytes(event.Content(), "replacement_room").Str
|
newRoomID := gjson.GetBytes(event.Content(), "replacement_room").Str
|
||||||
return r.DB.UpgradeRoom(ctx, oldRoomID, newRoomID, event.Sender())
|
return r.DB.UpgradeRoom(ctx, oldRoomID, newRoomID, event.Sender())
|
||||||
@ -509,9 +509,9 @@ func (r *Inputer) processStateBefore(
|
|||||||
missingPrev bool,
|
missingPrev bool,
|
||||||
) (historyVisibility gomatrixserverlib.HistoryVisibility, rejectionErr error, err error) {
|
) (historyVisibility gomatrixserverlib.HistoryVisibility, rejectionErr error, err error) {
|
||||||
historyVisibility = gomatrixserverlib.HistoryVisibilityShared // Default to shared.
|
historyVisibility = gomatrixserverlib.HistoryVisibilityShared // Default to shared.
|
||||||
event := input.Event.Event
|
event := input.Event.PDU
|
||||||
isCreateEvent := event.Type() == spec.MRoomCreate && event.StateKeyEquals("")
|
isCreateEvent := event.Type() == spec.MRoomCreate && event.StateKeyEquals("")
|
||||||
var stateBeforeEvent []*gomatrixserverlib.Event
|
var stateBeforeEvent []gomatrixserverlib.PDU
|
||||||
switch {
|
switch {
|
||||||
case isCreateEvent:
|
case isCreateEvent:
|
||||||
// There's no state before a create event so there is nothing
|
// There's no state before a create event so there is nothing
|
||||||
@ -524,9 +524,9 @@ func (r *Inputer) processStateBefore(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, fmt.Errorf("r.DB.EventsFromIDs: %w", err)
|
return "", nil, fmt.Errorf("r.DB.EventsFromIDs: %w", err)
|
||||||
}
|
}
|
||||||
stateBeforeEvent = make([]*gomatrixserverlib.Event, 0, len(stateEvents))
|
stateBeforeEvent = make([]gomatrixserverlib.PDU, 0, len(stateEvents))
|
||||||
for _, entry := range stateEvents {
|
for _, entry := range stateEvents {
|
||||||
stateBeforeEvent = append(stateBeforeEvent, entry.Event)
|
stateBeforeEvent = append(stateBeforeEvent, entry.PDU)
|
||||||
}
|
}
|
||||||
case missingPrev:
|
case missingPrev:
|
||||||
// We don't know all of the prev events, so we can't work out
|
// We don't know all of the prev events, so we can't work out
|
||||||
@ -567,9 +567,9 @@ func (r *Inputer) processStateBefore(
|
|||||||
rejectionErr = fmt.Errorf("prev events of %q are not known", event.EventID())
|
rejectionErr = fmt.Errorf("prev events of %q are not known", event.EventID())
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
stateBeforeEvent = make([]*gomatrixserverlib.Event, len(stateBeforeRes.StateEvents))
|
stateBeforeEvent = make([]gomatrixserverlib.PDU, len(stateBeforeRes.StateEvents))
|
||||||
for i := range stateBeforeRes.StateEvents {
|
for i := range stateBeforeRes.StateEvents {
|
||||||
stateBeforeEvent[i] = stateBeforeRes.StateEvents[i].Event
|
stateBeforeEvent[i] = stateBeforeRes.StateEvents[i].PDU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -626,7 +626,7 @@ func (r *Inputer) fetchAuthEvents(
|
|||||||
|
|
||||||
for _, authEventID := range authEventIDs {
|
for _, authEventID := range authEventIDs {
|
||||||
authEvents, err := r.DB.EventsFromIDs(ctx, roomInfo, []string{authEventID})
|
authEvents, err := r.DB.EventsFromIDs(ctx, roomInfo, []string{authEventID})
|
||||||
if err != nil || len(authEvents) == 0 || authEvents[0].Event == nil {
|
if err != nil || len(authEvents) == 0 || authEvents[0].PDU == nil {
|
||||||
unknown[authEventID] = struct{}{}
|
unknown[authEventID] = struct{}{}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -641,7 +641,7 @@ func (r *Inputer) fetchAuthEvents(
|
|||||||
}
|
}
|
||||||
known[authEventID] = &ev // don't take the pointer of the iterated event
|
known[authEventID] = &ev // don't take the pointer of the iterated event
|
||||||
if !isRejected {
|
if !isRejected {
|
||||||
if err = auth.AddEvent(ev.Event); err != nil {
|
if err = auth.AddEvent(ev.PDU); err != nil {
|
||||||
return fmt.Errorf("auth.AddEvent: %w", err)
|
return fmt.Errorf("auth.AddEvent: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -745,7 +745,7 @@ nextAuthEvent:
|
|||||||
// Now we know about this event, it was stored and the signatures were OK.
|
// Now we know about this event, it was stored and the signatures were OK.
|
||||||
known[authEvent.EventID()] = &types.Event{
|
known[authEvent.EventID()] = &types.Event{
|
||||||
EventNID: eventNID,
|
EventNID: eventNID,
|
||||||
Event: authEvent.(*gomatrixserverlib.Event),
|
PDU: authEvent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -757,7 +757,7 @@ func (r *Inputer) calculateAndSetState(
|
|||||||
input *api.InputRoomEvent,
|
input *api.InputRoomEvent,
|
||||||
roomInfo *types.RoomInfo,
|
roomInfo *types.RoomInfo,
|
||||||
stateAtEvent *types.StateAtEvent,
|
stateAtEvent *types.StateAtEvent,
|
||||||
event *gomatrixserverlib.Event,
|
event gomatrixserverlib.PDU,
|
||||||
isRejected bool,
|
isRejected bool,
|
||||||
) error {
|
) error {
|
||||||
trace, ctx := internal.StartRegion(ctx, "calculateAndSetState")
|
trace, ctx := internal.StartRegion(ctx, "calculateAndSetState")
|
||||||
@ -799,7 +799,7 @@ func (r *Inputer) calculateAndSetState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// kickGuests kicks guests users from m.room.guest_access rooms, if guest access is now prohibited.
|
// kickGuests kicks guests users from m.room.guest_access rooms, if guest access is now prohibited.
|
||||||
func (r *Inputer) kickGuests(ctx context.Context, event *gomatrixserverlib.Event, roomInfo *types.RoomInfo) error {
|
func (r *Inputer) kickGuests(ctx context.Context, event gomatrixserverlib.PDU, roomInfo *types.RoomInfo) error {
|
||||||
membershipNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, roomInfo.RoomNID, true, true)
|
membershipNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, roomInfo.RoomNID, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -18,21 +18,21 @@ func Test_EventAuth(t *testing.T) {
|
|||||||
room2 := test.NewRoom(t, alice, test.RoomPreset(test.PresetPublicChat))
|
room2 := test.NewRoom(t, alice, test.RoomPreset(test.PresetPublicChat))
|
||||||
|
|
||||||
authEventIDs := make([]string, 0, 4)
|
authEventIDs := make([]string, 0, 4)
|
||||||
authEvents := []*gomatrixserverlib.Event{}
|
authEvents := []gomatrixserverlib.PDU{}
|
||||||
|
|
||||||
// Add the legal auth events from room2
|
// Add the legal auth events from room2
|
||||||
for _, x := range room2.Events() {
|
for _, x := range room2.Events() {
|
||||||
if x.Type() == spec.MRoomCreate {
|
if x.Type() == spec.MRoomCreate {
|
||||||
authEventIDs = append(authEventIDs, x.EventID())
|
authEventIDs = append(authEventIDs, x.EventID())
|
||||||
authEvents = append(authEvents, x.Event)
|
authEvents = append(authEvents, x.PDU)
|
||||||
}
|
}
|
||||||
if x.Type() == spec.MRoomPowerLevels {
|
if x.Type() == spec.MRoomPowerLevels {
|
||||||
authEventIDs = append(authEventIDs, x.EventID())
|
authEventIDs = append(authEventIDs, x.EventID())
|
||||||
authEvents = append(authEvents, x.Event)
|
authEvents = append(authEvents, x.PDU)
|
||||||
}
|
}
|
||||||
if x.Type() == spec.MRoomJoinRules {
|
if x.Type() == spec.MRoomJoinRules {
|
||||||
authEventIDs = append(authEventIDs, x.EventID())
|
authEventIDs = append(authEventIDs, x.EventID())
|
||||||
authEvents = append(authEvents, x.Event)
|
authEvents = append(authEvents, x.PDU)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ func Test_EventAuth(t *testing.T) {
|
|||||||
for _, x := range room1.Events() {
|
for _, x := range room1.Events() {
|
||||||
if x.Type() == spec.MRoomMember {
|
if x.Type() == spec.MRoomMember {
|
||||||
authEventIDs = append(authEventIDs, x.EventID())
|
authEventIDs = append(authEventIDs, x.EventID())
|
||||||
authEvents = append(authEvents, x.Event)
|
authEvents = append(authEvents, x.PDU)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ func Test_EventAuth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finally check that the event is NOT allowed
|
// Finally check that the event is NOT allowed
|
||||||
if err := gomatrixserverlib.Allowed(ev.Event, &allower); err == nil {
|
if err := gomatrixserverlib.Allowed(ev.PDU, &allower); err == nil {
|
||||||
t.Fatalf("event should not be allowed, but it was")
|
t.Fatalf("event should not be allowed, but it was")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ func (r *Inputer) updateLatestEvents(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
roomInfo *types.RoomInfo,
|
roomInfo *types.RoomInfo,
|
||||||
stateAtEvent types.StateAtEvent,
|
stateAtEvent types.StateAtEvent,
|
||||||
event *gomatrixserverlib.Event,
|
event gomatrixserverlib.PDU,
|
||||||
sendAsServer string,
|
sendAsServer string,
|
||||||
transactionID *api.TransactionID,
|
transactionID *api.TransactionID,
|
||||||
rewritesState bool,
|
rewritesState bool,
|
||||||
@ -101,7 +101,7 @@ type latestEventsUpdater struct {
|
|||||||
updater *shared.RoomUpdater
|
updater *shared.RoomUpdater
|
||||||
roomInfo *types.RoomInfo
|
roomInfo *types.RoomInfo
|
||||||
stateAtEvent types.StateAtEvent
|
stateAtEvent types.StateAtEvent
|
||||||
event *gomatrixserverlib.Event
|
event gomatrixserverlib.PDU
|
||||||
transactionID *api.TransactionID
|
transactionID *api.TransactionID
|
||||||
rewritesState bool
|
rewritesState bool
|
||||||
// Which server to send this event as.
|
// Which server to send this event as.
|
||||||
@ -326,7 +326,7 @@ func (u *latestEventsUpdater) latestState() error {
|
|||||||
// true if the new event is included in those extremites, false otherwise.
|
// true if the new event is included in those extremites, false otherwise.
|
||||||
func (u *latestEventsUpdater) calculateLatest(
|
func (u *latestEventsUpdater) calculateLatest(
|
||||||
oldLatest []types.StateAtEventAndReference,
|
oldLatest []types.StateAtEventAndReference,
|
||||||
newEvent *gomatrixserverlib.Event,
|
newEvent gomatrixserverlib.PDU,
|
||||||
newStateAndRef types.StateAtEventAndReference,
|
newStateAndRef types.StateAtEventAndReference,
|
||||||
) (bool, error) {
|
) (bool, error) {
|
||||||
trace, _ := internal.StartRegion(u.ctx, "calculateLatest")
|
trace, _ := internal.StartRegion(u.ctx, "calculateLatest")
|
||||||
@ -393,7 +393,7 @@ func (u *latestEventsUpdater) makeOutputNewRoomEvent() (*api.OutputEvent, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ore := api.OutputNewRoomEvent{
|
ore := api.OutputNewRoomEvent{
|
||||||
Event: &types.HeaderedEvent{Event: u.event},
|
Event: &types.HeaderedEvent{PDU: u.event},
|
||||||
RewritesState: u.rewritesState,
|
RewritesState: u.rewritesState,
|
||||||
LastSentEventID: u.lastEventIDSent,
|
LastSentEventID: u.lastEventIDSent,
|
||||||
LatestEventIDs: latestEventIDs,
|
LatestEventIDs: latestEventIDs,
|
||||||
|
@ -22,19 +22,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type parsedRespState struct {
|
type parsedRespState struct {
|
||||||
AuthEvents []*gomatrixserverlib.Event
|
AuthEvents []gomatrixserverlib.PDU
|
||||||
StateEvents []*gomatrixserverlib.Event
|
StateEvents []gomatrixserverlib.PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parsedRespState) Events() []gomatrixserverlib.PDU {
|
func (p *parsedRespState) Events() []gomatrixserverlib.PDU {
|
||||||
eventsByID := make(map[string]*gomatrixserverlib.Event, len(p.AuthEvents)+len(p.StateEvents))
|
eventsByID := make(map[string]gomatrixserverlib.PDU, len(p.AuthEvents)+len(p.StateEvents))
|
||||||
for i, event := range p.AuthEvents {
|
for i, event := range p.AuthEvents {
|
||||||
eventsByID[event.EventID()] = p.AuthEvents[i]
|
eventsByID[event.EventID()] = p.AuthEvents[i]
|
||||||
}
|
}
|
||||||
for i, event := range p.StateEvents {
|
for i, event := range p.StateEvents {
|
||||||
eventsByID[event.EventID()] = p.StateEvents[i]
|
eventsByID[event.EventID()] = p.StateEvents[i]
|
||||||
}
|
}
|
||||||
allEvents := make([]*gomatrixserverlib.Event, 0, len(eventsByID))
|
allEvents := make([]gomatrixserverlib.PDU, 0, len(eventsByID))
|
||||||
for _, event := range eventsByID {
|
for _, event := range eventsByID {
|
||||||
allEvents = append(allEvents, event)
|
allEvents = append(allEvents, event)
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ type missingStateReq struct {
|
|||||||
servers []spec.ServerName
|
servers []spec.ServerName
|
||||||
hadEvents map[string]bool
|
hadEvents map[string]bool
|
||||||
hadEventsMutex sync.Mutex
|
hadEventsMutex sync.Mutex
|
||||||
haveEvents map[string]*gomatrixserverlib.Event
|
haveEvents map[string]gomatrixserverlib.PDU
|
||||||
haveEventsMutex sync.Mutex
|
haveEventsMutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ type missingStateReq struct {
|
|||||||
// request, as called from processRoomEvent.
|
// request, as called from processRoomEvent.
|
||||||
// nolint:gocyclo
|
// nolint:gocyclo
|
||||||
func (t *missingStateReq) processEventWithMissingState(
|
func (t *missingStateReq) processEventWithMissingState(
|
||||||
ctx context.Context, e *gomatrixserverlib.Event, roomVersion gomatrixserverlib.RoomVersion,
|
ctx context.Context, e gomatrixserverlib.PDU, roomVersion gomatrixserverlib.RoomVersion,
|
||||||
) (*parsedRespState, error) {
|
) (*parsedRespState, error) {
|
||||||
trace, ctx := internal.StartRegion(ctx, "processEventWithMissingState")
|
trace, ctx := internal.StartRegion(ctx, "processEventWithMissingState")
|
||||||
defer trace.EndRegion()
|
defer trace.EndRegion()
|
||||||
@ -107,7 +107,7 @@ func (t *missingStateReq) processEventWithMissingState(
|
|||||||
for _, newEvent := range newEvents {
|
for _, newEvent := range newEvents {
|
||||||
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
||||||
Kind: api.KindOld,
|
Kind: api.KindOld,
|
||||||
Event: &types.HeaderedEvent{Event: newEvent},
|
Event: &types.HeaderedEvent{PDU: newEvent},
|
||||||
Origin: t.origin,
|
Origin: t.origin,
|
||||||
SendAsServer: api.DoNotSendToOtherServers,
|
SendAsServer: api.DoNotSendToOtherServers,
|
||||||
})
|
})
|
||||||
@ -156,7 +156,7 @@ func (t *missingStateReq) processEventWithMissingState(
|
|||||||
}
|
}
|
||||||
outlierRoomEvents = append(outlierRoomEvents, api.InputRoomEvent{
|
outlierRoomEvents = append(outlierRoomEvents, api.InputRoomEvent{
|
||||||
Kind: api.KindOutlier,
|
Kind: api.KindOutlier,
|
||||||
Event: &types.HeaderedEvent{Event: outlier.(*gomatrixserverlib.Event)},
|
Event: &types.HeaderedEvent{PDU: outlier},
|
||||||
Origin: t.origin,
|
Origin: t.origin,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ func (t *missingStateReq) processEventWithMissingState(
|
|||||||
|
|
||||||
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
||||||
Kind: api.KindOld,
|
Kind: api.KindOld,
|
||||||
Event: &types.HeaderedEvent{Event: backwardsExtremity},
|
Event: &types.HeaderedEvent{PDU: backwardsExtremity},
|
||||||
Origin: t.origin,
|
Origin: t.origin,
|
||||||
HasState: true,
|
HasState: true,
|
||||||
StateEventIDs: stateIDs,
|
StateEventIDs: stateIDs,
|
||||||
@ -205,7 +205,7 @@ func (t *missingStateReq) processEventWithMissingState(
|
|||||||
for _, newEvent := range newEvents {
|
for _, newEvent := range newEvents {
|
||||||
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
||||||
Kind: api.KindOld,
|
Kind: api.KindOld,
|
||||||
Event: &types.HeaderedEvent{Event: newEvent},
|
Event: &types.HeaderedEvent{PDU: newEvent},
|
||||||
Origin: t.origin,
|
Origin: t.origin,
|
||||||
SendAsServer: api.DoNotSendToOtherServers,
|
SendAsServer: api.DoNotSendToOtherServers,
|
||||||
})
|
})
|
||||||
@ -243,7 +243,7 @@ func (t *missingStateReq) processEventWithMissingState(
|
|||||||
return resolvedState, nil
|
return resolvedState, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *missingStateReq) lookupResolvedStateBeforeEvent(ctx context.Context, e *gomatrixserverlib.Event, roomVersion gomatrixserverlib.RoomVersion) (*parsedRespState, error) {
|
func (t *missingStateReq) lookupResolvedStateBeforeEvent(ctx context.Context, e gomatrixserverlib.PDU, roomVersion gomatrixserverlib.RoomVersion) (*parsedRespState, error) {
|
||||||
trace, ctx := internal.StartRegion(ctx, "lookupResolvedStateBeforeEvent")
|
trace, ctx := internal.StartRegion(ctx, "lookupResolvedStateBeforeEvent")
|
||||||
defer trace.EndRegion()
|
defer trace.EndRegion()
|
||||||
|
|
||||||
@ -368,7 +368,7 @@ func (t *missingStateReq) lookupStateAfterEvent(ctx context.Context, roomVersion
|
|||||||
return respState, false, nil
|
return respState, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *missingStateReq) cacheAndReturn(ev *gomatrixserverlib.Event) *gomatrixserverlib.Event {
|
func (t *missingStateReq) cacheAndReturn(ev gomatrixserverlib.PDU) gomatrixserverlib.PDU {
|
||||||
t.haveEventsMutex.Lock()
|
t.haveEventsMutex.Lock()
|
||||||
defer t.haveEventsMutex.Unlock()
|
defer t.haveEventsMutex.Unlock()
|
||||||
if cached, exists := t.haveEvents[ev.EventID()]; exists {
|
if cached, exists := t.haveEvents[ev.EventID()]; exists {
|
||||||
@ -403,11 +403,11 @@ func (t *missingStateReq) lookupStateAfterEventLocally(ctx context.Context, even
|
|||||||
t.log.WithError(err).Warnf("failed to load state events locally")
|
t.log.WithError(err).Warnf("failed to load state events locally")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
res.StateEvents = make([]*gomatrixserverlib.Event, 0, len(stateEvents))
|
res.StateEvents = make([]gomatrixserverlib.PDU, 0, len(stateEvents))
|
||||||
for _, ev := range stateEvents {
|
for _, ev := range stateEvents {
|
||||||
// set the event from the haveEvents cache - this means we will share pointers with other prev_event branches for this
|
// set the event from the haveEvents cache - this means we will share pointers with other prev_event branches for this
|
||||||
// processEvent request, which is better for memory.
|
// processEvent request, which is better for memory.
|
||||||
res.StateEvents = append(res.StateEvents, t.cacheAndReturn(ev.Event))
|
res.StateEvents = append(res.StateEvents, t.cacheAndReturn(ev.PDU))
|
||||||
t.hadEvent(ev.EventID())
|
t.hadEvent(ev.EventID())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +415,7 @@ func (t *missingStateReq) lookupStateAfterEventLocally(ctx context.Context, even
|
|||||||
stateEvents, stateEventNIDs, stateEntries, stateAtEvents = nil, nil, nil, nil // nolint:ineffassign
|
stateEvents, stateEventNIDs, stateEntries, stateAtEvents = nil, nil, nil, nil // nolint:ineffassign
|
||||||
|
|
||||||
missingAuthEvents := map[string]bool{}
|
missingAuthEvents := map[string]bool{}
|
||||||
res.AuthEvents = make([]*gomatrixserverlib.Event, 0, len(stateEvents)*3)
|
res.AuthEvents = make([]gomatrixserverlib.PDU, 0, len(stateEvents)*3)
|
||||||
for _, ev := range stateEvents {
|
for _, ev := range stateEvents {
|
||||||
t.haveEventsMutex.Lock()
|
t.haveEventsMutex.Lock()
|
||||||
for _, ae := range ev.AuthEventIDs() {
|
for _, ae := range ev.AuthEventIDs() {
|
||||||
@ -440,7 +440,7 @@ func (t *missingStateReq) lookupStateAfterEventLocally(ctx context.Context, even
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for i, ev := range events {
|
for i, ev := range events {
|
||||||
res.AuthEvents = append(res.AuthEvents, t.cacheAndReturn(events[i].Event))
|
res.AuthEvents = append(res.AuthEvents, t.cacheAndReturn(events[i].PDU))
|
||||||
t.hadEvent(ev.EventID())
|
t.hadEvent(ev.EventID())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,12 +459,12 @@ func (t *missingStateReq) lookupStateBeforeEvent(ctx context.Context, roomVersio
|
|||||||
return t.lookupMissingStateViaStateIDs(ctx, roomID, eventID, roomVersion)
|
return t.lookupMissingStateViaStateIDs(ctx, roomID, eventID, roomVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *missingStateReq) resolveStatesAndCheck(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, states []*parsedRespState, backwardsExtremity *gomatrixserverlib.Event) (*parsedRespState, error) {
|
func (t *missingStateReq) resolveStatesAndCheck(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, states []*parsedRespState, backwardsExtremity gomatrixserverlib.PDU) (*parsedRespState, error) {
|
||||||
trace, ctx := internal.StartRegion(ctx, "resolveStatesAndCheck")
|
trace, ctx := internal.StartRegion(ctx, "resolveStatesAndCheck")
|
||||||
defer trace.EndRegion()
|
defer trace.EndRegion()
|
||||||
|
|
||||||
var authEventList []*gomatrixserverlib.Event
|
var authEventList []gomatrixserverlib.PDU
|
||||||
var stateEventList []*gomatrixserverlib.Event
|
var stateEventList []gomatrixserverlib.PDU
|
||||||
for _, state := range states {
|
for _, state := range states {
|
||||||
authEventList = append(authEventList, state.AuthEvents...)
|
authEventList = append(authEventList, state.AuthEvents...)
|
||||||
stateEventList = append(stateEventList, state.StateEvents...)
|
stateEventList = append(stateEventList, state.StateEvents...)
|
||||||
@ -485,7 +485,7 @@ retryAllowedState:
|
|||||||
case verifySigError:
|
case verifySigError:
|
||||||
return &parsedRespState{
|
return &parsedRespState{
|
||||||
AuthEvents: authEventList,
|
AuthEvents: authEventList,
|
||||||
StateEvents: gomatrixserverlib.TempCastToEvents(resolvedStateEvents),
|
StateEvents: resolvedStateEvents,
|
||||||
}, nil
|
}, nil
|
||||||
case nil:
|
case nil:
|
||||||
// do nothing
|
// do nothing
|
||||||
@ -501,13 +501,13 @@ retryAllowedState:
|
|||||||
}
|
}
|
||||||
return &parsedRespState{
|
return &parsedRespState{
|
||||||
AuthEvents: authEventList,
|
AuthEvents: authEventList,
|
||||||
StateEvents: gomatrixserverlib.TempCastToEvents(resolvedStateEvents),
|
StateEvents: resolvedStateEvents,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// get missing events for `e`. If `isGapFilled`=true then `newEvents` contains all the events to inject,
|
// get missing events for `e`. If `isGapFilled`=true then `newEvents` contains all the events to inject,
|
||||||
// without `e`. If `isGapFilled=false` then `newEvents` contains the response to /get_missing_events
|
// without `e`. If `isGapFilled=false` then `newEvents` contains the response to /get_missing_events
|
||||||
func (t *missingStateReq) getMissingEvents(ctx context.Context, e *gomatrixserverlib.Event, roomVersion gomatrixserverlib.RoomVersion) (newEvents []*gomatrixserverlib.Event, isGapFilled, prevStateKnown bool, err error) {
|
func (t *missingStateReq) getMissingEvents(ctx context.Context, e gomatrixserverlib.PDU, roomVersion gomatrixserverlib.RoomVersion) (newEvents []gomatrixserverlib.PDU, isGapFilled, prevStateKnown bool, err error) {
|
||||||
trace, ctx := internal.StartRegion(ctx, "getMissingEvents")
|
trace, ctx := internal.StartRegion(ctx, "getMissingEvents")
|
||||||
defer trace.EndRegion()
|
defer trace.EndRegion()
|
||||||
|
|
||||||
@ -560,7 +560,7 @@ func (t *missingStateReq) getMissingEvents(ctx context.Context, e *gomatrixserve
|
|||||||
|
|
||||||
// Make sure events from the missingResp are using the cache - missing events
|
// Make sure events from the missingResp are using the cache - missing events
|
||||||
// will be added and duplicates will be removed.
|
// will be added and duplicates will be removed.
|
||||||
missingEvents := make([]*gomatrixserverlib.Event, 0, len(missingResp.Events))
|
missingEvents := make([]gomatrixserverlib.PDU, 0, len(missingResp.Events))
|
||||||
for _, ev := range missingResp.Events.UntrustedEvents(roomVersion) {
|
for _, ev := range missingResp.Events.UntrustedEvents(roomVersion) {
|
||||||
if err = gomatrixserverlib.VerifyEventSignatures(ctx, ev, t.keys); err != nil {
|
if err = gomatrixserverlib.VerifyEventSignatures(ctx, ev, t.keys); err != nil {
|
||||||
continue
|
continue
|
||||||
@ -570,9 +570,8 @@ func (t *missingStateReq) getMissingEvents(ctx context.Context, e *gomatrixserve
|
|||||||
logger.Debugf("get_missing_events returned %d events (%d passed signature checks)", len(missingResp.Events), len(missingEvents))
|
logger.Debugf("get_missing_events returned %d events (%d passed signature checks)", len(missingResp.Events), len(missingEvents))
|
||||||
|
|
||||||
// topologically sort and sanity check that we are making forward progress
|
// topologically sort and sanity check that we are making forward progress
|
||||||
newEventsPDUs := gomatrixserverlib.ReverseTopologicalOrdering(
|
newEvents = gomatrixserverlib.ReverseTopologicalOrdering(
|
||||||
gomatrixserverlib.ToPDUs(missingEvents), gomatrixserverlib.TopologicalOrderByPrevEvents)
|
gomatrixserverlib.ToPDUs(missingEvents), gomatrixserverlib.TopologicalOrderByPrevEvents)
|
||||||
newEvents = gomatrixserverlib.TempCastToEvents(newEventsPDUs)
|
|
||||||
shouldHaveSomeEventIDs := e.PrevEventIDs()
|
shouldHaveSomeEventIDs := e.PrevEventIDs()
|
||||||
hasPrevEvent := false
|
hasPrevEvent := false
|
||||||
Event:
|
Event:
|
||||||
@ -618,7 +617,7 @@ Event:
|
|||||||
return newEvents, true, t.isPrevStateKnown(ctx, e), nil
|
return newEvents, true, t.isPrevStateKnown(ctx, e), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *missingStateReq) isPrevStateKnown(ctx context.Context, e *gomatrixserverlib.Event) bool {
|
func (t *missingStateReq) isPrevStateKnown(ctx context.Context, e gomatrixserverlib.PDU) bool {
|
||||||
expected := len(e.PrevEventIDs())
|
expected := len(e.PrevEventIDs())
|
||||||
state, err := t.db.StateAtEventIDs(ctx, e.PrevEventIDs())
|
state, err := t.db.StateAtEventIDs(ctx, e.PrevEventIDs())
|
||||||
if err != nil || len(state) != expected {
|
if err != nil || len(state) != expected {
|
||||||
@ -707,7 +706,7 @@ func (t *missingStateReq) lookupMissingStateViaStateIDs(ctx context.Context, roo
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, ev := range events {
|
for i, ev := range events {
|
||||||
events[i].Event = t.cacheAndReturn(events[i].Event)
|
events[i].PDU = t.cacheAndReturn(events[i].PDU)
|
||||||
t.hadEvent(ev.EventID())
|
t.hadEvent(ev.EventID())
|
||||||
evID := events[i].EventID()
|
evID := events[i].EventID()
|
||||||
if missing[evID] {
|
if missing[evID] {
|
||||||
@ -839,7 +838,7 @@ func (t *missingStateReq) createRespStateFromStateIDs(
|
|||||||
return &respState, nil
|
return &respState, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *missingStateReq) lookupEvent(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, _, missingEventID string, localFirst bool) (*gomatrixserverlib.Event, error) {
|
func (t *missingStateReq) lookupEvent(ctx context.Context, roomVersion gomatrixserverlib.RoomVersion, _, missingEventID string, localFirst bool) (gomatrixserverlib.PDU, error) {
|
||||||
trace, ctx := internal.StartRegion(ctx, "lookupEvent")
|
trace, ctx := internal.StartRegion(ctx, "lookupEvent")
|
||||||
defer trace.EndRegion()
|
defer trace.EndRegion()
|
||||||
|
|
||||||
@ -854,7 +853,7 @@ func (t *missingStateReq) lookupEvent(ctx context.Context, roomVersion gomatrixs
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.log.Warnf("Failed to query roomserver for missing event %s: %s - falling back to remote", missingEventID, err)
|
t.log.Warnf("Failed to query roomserver for missing event %s: %s - falling back to remote", missingEventID, err)
|
||||||
} else if len(events) == 1 {
|
} else if len(events) == 1 {
|
||||||
return events[0].Event, nil
|
return events[0].PDU, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var event *gomatrixserverlib.Event
|
var event *gomatrixserverlib.Event
|
||||||
@ -894,7 +893,7 @@ func (t *missingStateReq) lookupEvent(ctx context.Context, roomVersion gomatrixs
|
|||||||
return t.cacheAndReturn(event), nil
|
return t.cacheAndReturn(event), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkAllowedByState(e *gomatrixserverlib.Event, stateEvents []gomatrixserverlib.PDU) error {
|
func checkAllowedByState(e gomatrixserverlib.PDU, stateEvents []gomatrixserverlib.PDU) error {
|
||||||
authUsingState := gomatrixserverlib.NewAuthEvents(nil)
|
authUsingState := gomatrixserverlib.NewAuthEvents(nil)
|
||||||
for i := range stateEvents {
|
for i := range stateEvents {
|
||||||
err := authUsingState.AddEvent(stateEvents[i])
|
err := authUsingState.AddEvent(stateEvents[i])
|
||||||
|
@ -45,7 +45,7 @@ func TestSingleTransactionOnInput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
in := api.InputRoomEvent{
|
in := api.InputRoomEvent{
|
||||||
Kind: api.KindOutlier, // don't panic if we generate an output event
|
Kind: api.KindOutlier, // don't panic if we generate an output event
|
||||||
Event: &types.HeaderedEvent{Event: event},
|
Event: &types.HeaderedEvent{PDU: event},
|
||||||
}
|
}
|
||||||
|
|
||||||
inputter := &input.Inputer{
|
inputter := &input.Inputer{
|
||||||
|
@ -248,8 +248,8 @@ func (r *Admin) PerformAdminDownloadState(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
authEventMap := map[string]*gomatrixserverlib.Event{}
|
authEventMap := map[string]gomatrixserverlib.PDU{}
|
||||||
stateEventMap := map[string]*gomatrixserverlib.Event{}
|
stateEventMap := map[string]gomatrixserverlib.PDU{}
|
||||||
|
|
||||||
for _, fwdExtremity := range fwdExtremities {
|
for _, fwdExtremity := range fwdExtremities {
|
||||||
var state gomatrixserverlib.StateResponse
|
var state gomatrixserverlib.StateResponse
|
||||||
@ -276,10 +276,10 @@ func (r *Admin) PerformAdminDownloadState(
|
|||||||
stateIDs := make([]string, 0, len(stateEventMap))
|
stateIDs := make([]string, 0, len(stateEventMap))
|
||||||
|
|
||||||
for _, authEvent := range authEventMap {
|
for _, authEvent := range authEventMap {
|
||||||
authEvents = append(authEvents, &types.HeaderedEvent{Event: authEvent})
|
authEvents = append(authEvents, &types.HeaderedEvent{PDU: authEvent})
|
||||||
}
|
}
|
||||||
for _, stateEvent := range stateEventMap {
|
for _, stateEvent := range stateEventMap {
|
||||||
stateEvents = append(stateEvents, &types.HeaderedEvent{Event: stateEvent})
|
stateEvents = append(stateEvents, &types.HeaderedEvent{PDU: stateEvent})
|
||||||
stateIDs = append(stateIDs, stateEvent.EventID())
|
stateIDs = append(stateIDs, stateEvent.EventID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ func (r *Backfiller) PerformBackfill(
|
|||||||
|
|
||||||
// Retrieve events from the list that was filled previously. If we fail to get
|
// Retrieve events from the list that was filled previously. If we fail to get
|
||||||
// events from the database then attempt once to get them from federation instead.
|
// events from the database then attempt once to get them from federation instead.
|
||||||
var loadedEvents []*gomatrixserverlib.Event
|
var loadedEvents []gomatrixserverlib.PDU
|
||||||
loadedEvents, err = helpers.LoadEvents(ctx, r.DB, info, resultNIDs)
|
loadedEvents, err = helpers.LoadEvents(ctx, r.DB, info, resultNIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(types.MissingEventError); ok {
|
if _, ok := err.(types.MissingEventError); ok {
|
||||||
@ -99,7 +99,7 @@ func (r *Backfiller) PerformBackfill(
|
|||||||
if _, ok := redactEventIDs[event.EventID()]; ok {
|
if _, ok := redactEventIDs[event.EventID()]; ok {
|
||||||
event.Redact()
|
event.Redact()
|
||||||
}
|
}
|
||||||
response.Events = append(response.Events, &types.HeaderedEvent{Event: event})
|
response.Events = append(response.Events, &types.HeaderedEvent{PDU: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@ -133,7 +133,7 @@ func (r *Backfiller) backfillViaFederation(ctx context.Context, req *api.Perform
|
|||||||
logrus.WithError(err).WithField("room_id", req.RoomID).Infof("backfilled %d events", len(events))
|
logrus.WithError(err).WithField("room_id", req.RoomID).Infof("backfilled %d events", len(events))
|
||||||
|
|
||||||
// persist these new events - auth checks have already been done
|
// persist these new events - auth checks have already been done
|
||||||
roomNID, backfilledEventMap := persistEvents(ctx, r.DB, gomatrixserverlib.TempCastToEvents(events))
|
roomNID, backfilledEventMap := persistEvents(ctx, r.DB, events)
|
||||||
|
|
||||||
for _, ev := range backfilledEventMap {
|
for _, ev := range backfilledEventMap {
|
||||||
// now add state for these events
|
// now add state for these events
|
||||||
@ -170,7 +170,7 @@ func (r *Backfiller) backfillViaFederation(ctx context.Context, req *api.Perform
|
|||||||
|
|
||||||
res.Events = make([]*types.HeaderedEvent, len(events))
|
res.Events = make([]*types.HeaderedEvent, len(events))
|
||||||
for i := range events {
|
for i := range events {
|
||||||
res.Events[i] = &types.HeaderedEvent{Event: events[i].(*gomatrixserverlib.Event)}
|
res.Events[i] = &types.HeaderedEvent{PDU: events[i]}
|
||||||
}
|
}
|
||||||
res.HistoryVisibility = requester.historyVisiblity
|
res.HistoryVisibility = requester.historyVisiblity
|
||||||
return nil
|
return nil
|
||||||
@ -230,15 +230,15 @@ func (r *Backfiller) fetchAndStoreMissingEvents(ctx context.Context, roomVer gom
|
|||||||
logger.WithError(err).Warn("event failed PDU checks")
|
logger.WithError(err).Warn("event failed PDU checks")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
missingMap[id] = &types.HeaderedEvent{Event: res.Event.(*gomatrixserverlib.Event)}
|
missingMap[id] = &types.HeaderedEvent{PDU: res.Event}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var newEvents []*gomatrixserverlib.Event
|
var newEvents []gomatrixserverlib.PDU
|
||||||
for _, ev := range missingMap {
|
for _, ev := range missingMap {
|
||||||
if ev != nil {
|
if ev != nil {
|
||||||
newEvents = append(newEvents, ev.Event)
|
newEvents = append(newEvents, ev.PDU)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
util.GetLogger(ctx).Infof("Persisting %d new events", len(newEvents))
|
util.GetLogger(ctx).Infof("Persisting %d new events", len(newEvents))
|
||||||
@ -540,7 +540,7 @@ func (b *backfillRequester) ProvideEvents(roomVer gomatrixserverlib.RoomVersion,
|
|||||||
}
|
}
|
||||||
events := make([]gomatrixserverlib.PDU, len(eventsWithNids))
|
events := make([]gomatrixserverlib.PDU, len(eventsWithNids))
|
||||||
for i := range eventsWithNids {
|
for i := range eventsWithNids {
|
||||||
events[i] = eventsWithNids[i].Event
|
events[i] = eventsWithNids[i].PDU
|
||||||
}
|
}
|
||||||
return events, nil
|
return events, nil
|
||||||
}
|
}
|
||||||
@ -569,9 +569,9 @@ func joinEventsFromHistoryVisibility(
|
|||||||
// feels more secure here.
|
// feels more secure here.
|
||||||
return nil, gomatrixserverlib.HistoryVisibilityJoined, err
|
return nil, gomatrixserverlib.HistoryVisibilityJoined, err
|
||||||
}
|
}
|
||||||
events := make([]*gomatrixserverlib.Event, len(stateEvents))
|
events := make([]gomatrixserverlib.PDU, len(stateEvents))
|
||||||
for i := range stateEvents {
|
for i := range stateEvents {
|
||||||
events[i] = stateEvents[i].Event
|
events[i] = stateEvents[i].PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can we see events in the room?
|
// Can we see events in the room?
|
||||||
@ -590,7 +590,7 @@ func joinEventsFromHistoryVisibility(
|
|||||||
return evs, visibility, err
|
return evs, visibility, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixserverlib.Event) (types.RoomNID, map[string]types.Event) {
|
func persistEvents(ctx context.Context, db storage.Database, events []gomatrixserverlib.PDU) (types.RoomNID, map[string]types.Event) {
|
||||||
var roomNID types.RoomNID
|
var roomNID types.RoomNID
|
||||||
var eventNID types.EventNID
|
var eventNID types.EventNID
|
||||||
backfilledEventMap := make(map[string]types.Event)
|
backfilledEventMap := make(map[string]types.Event)
|
||||||
@ -648,7 +648,7 @@ func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixs
|
|||||||
}
|
}
|
||||||
backfilledEventMap[ev.EventID()] = types.Event{
|
backfilledEventMap[ev.EventID()] = types.Event{
|
||||||
EventNID: eventNID,
|
EventNID: eventNID,
|
||||||
Event: ev,
|
PDU: ev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return roomNID, backfilledEventMap
|
return roomNID, backfilledEventMap
|
||||||
|
@ -56,7 +56,7 @@ func (r *InboundPeeker) PerformInboundPeek(
|
|||||||
response.RoomExists = true
|
response.RoomExists = true
|
||||||
response.RoomVersion = info.RoomVersion
|
response.RoomVersion = info.RoomVersion
|
||||||
|
|
||||||
var stateEvents []*gomatrixserverlib.Event
|
var stateEvents []gomatrixserverlib.PDU
|
||||||
|
|
||||||
var currentStateSnapshotNID types.StateSnapshotNID
|
var currentStateSnapshotNID types.StateSnapshotNID
|
||||||
latestEventRefs, currentStateSnapshotNID, _, err :=
|
latestEventRefs, currentStateSnapshotNID, _, err :=
|
||||||
@ -70,13 +70,13 @@ func (r *InboundPeeker) PerformInboundPeek(
|
|||||||
}
|
}
|
||||||
var sortedLatestEvents []gomatrixserverlib.PDU
|
var sortedLatestEvents []gomatrixserverlib.PDU
|
||||||
for _, ev := range latestEvents {
|
for _, ev := range latestEvents {
|
||||||
sortedLatestEvents = append(sortedLatestEvents, ev.Event)
|
sortedLatestEvents = append(sortedLatestEvents, ev.PDU)
|
||||||
}
|
}
|
||||||
sortedLatestEvents = gomatrixserverlib.ReverseTopologicalOrdering(
|
sortedLatestEvents = gomatrixserverlib.ReverseTopologicalOrdering(
|
||||||
sortedLatestEvents,
|
sortedLatestEvents,
|
||||||
gomatrixserverlib.TopologicalOrderByPrevEvents,
|
gomatrixserverlib.TopologicalOrderByPrevEvents,
|
||||||
)
|
)
|
||||||
response.LatestEvent = &types.HeaderedEvent{Event: sortedLatestEvents[0].(*gomatrixserverlib.Event)}
|
response.LatestEvent = &types.HeaderedEvent{PDU: sortedLatestEvents[0]}
|
||||||
|
|
||||||
// XXX: do we actually need to do a state resolution here?
|
// XXX: do we actually need to do a state resolution here?
|
||||||
roomState := state.NewStateResolution(r.DB, info)
|
roomState := state.NewStateResolution(r.DB, info)
|
||||||
@ -106,11 +106,11 @@ func (r *InboundPeeker) PerformInboundPeek(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{Event: event})
|
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{PDU: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range authEvents {
|
for _, event := range authEvents {
|
||||||
response.AuthChainEvents = append(response.AuthChainEvents, &types.HeaderedEvent{Event: event})
|
response.AuthChainEvents = append(response.AuthChainEvents, &types.HeaderedEvent{PDU: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
err = r.Inputer.OutputProducer.ProduceRoomEvents(request.RoomID, []api.OutputEvent{
|
err = r.Inputer.OutputProducer.ProduceRoomEvents(request.RoomID, []api.OutputEvent{
|
||||||
|
@ -110,7 +110,7 @@ func (r *Inviter) PerformInvite(
|
|||||||
}
|
}
|
||||||
outputUpdates, err = helpers.UpdateToInviteMembership(updater, &types.Event{
|
outputUpdates, err = helpers.UpdateToInviteMembership(updater, &types.Event{
|
||||||
EventNID: 0,
|
EventNID: 0,
|
||||||
Event: event.Event,
|
PDU: event.PDU,
|
||||||
}, outputUpdates, req.Event.Version())
|
}, outputUpdates, req.Event.Version())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("updateToInviteMembership: %w", err)
|
return nil, fmt.Errorf("updateToInviteMembership: %w", err)
|
||||||
@ -274,11 +274,11 @@ func buildInviteStrippedState(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
inviteState := []fclient.InviteV2StrippedState{
|
inviteState := []fclient.InviteV2StrippedState{
|
||||||
fclient.NewInviteV2StrippedState(input.Event.Event),
|
fclient.NewInviteV2StrippedState(input.Event.PDU),
|
||||||
}
|
}
|
||||||
stateEvents = append(stateEvents, types.Event{Event: input.Event.Event})
|
stateEvents = append(stateEvents, types.Event{PDU: input.Event.PDU})
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
inviteState = append(inviteState, fclient.NewInviteV2StrippedState(event.Event))
|
inviteState = append(inviteState, fclient.NewInviteV2StrippedState(event.PDU))
|
||||||
}
|
}
|
||||||
return inviteState, nil
|
return inviteState, nil
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ func (r *Upgrader) sendInitialEvents(ctx context.Context, evTime time.Time, user
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the event to the list of auth events
|
// Add the event to the list of auth events
|
||||||
builtEvents = append(builtEvents, &types.HeaderedEvent{Event: event})
|
builtEvents = append(builtEvents, &types.HeaderedEvent{PDU: event})
|
||||||
err = authEvents.AddEvent(event)
|
err = authEvents.AddEvent(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to add new %q event to auth set: %w", builder.Type, err)
|
return fmt.Errorf("failed to add new %q event to auth set: %w", builder.Type, err)
|
||||||
@ -555,12 +555,12 @@ func (r *Upgrader) makeHeaderedEvent(ctx context.Context, evTime time.Time, user
|
|||||||
return nil, fmt.Errorf("failed to build new %q event: %w", builder.Type, err)
|
return nil, fmt.Errorf("failed to build new %q event: %w", builder.Type, err)
|
||||||
}
|
}
|
||||||
// check to see if this user can perform this operation
|
// check to see if this user can perform this operation
|
||||||
stateEvents := make([]*gomatrixserverlib.Event, len(queryRes.StateEvents))
|
stateEvents := make([]gomatrixserverlib.PDU, len(queryRes.StateEvents))
|
||||||
for i := range queryRes.StateEvents {
|
for i := range queryRes.StateEvents {
|
||||||
stateEvents[i] = queryRes.StateEvents[i].Event
|
stateEvents[i] = queryRes.StateEvents[i].PDU
|
||||||
}
|
}
|
||||||
provider := gomatrixserverlib.NewAuthEvents(gomatrixserverlib.ToPDUs(stateEvents))
|
provider := gomatrixserverlib.NewAuthEvents(stateEvents)
|
||||||
if err = gomatrixserverlib.Allowed(headeredEvent.Event, &provider); err != nil {
|
if err = gomatrixserverlib.Allowed(headeredEvent.PDU, &provider); err != nil {
|
||||||
return nil, api.ErrNotAllowed{Err: fmt.Errorf("failed to auth new %q event: %w", builder.Type, err)} // TODO: Is this error string comprehensible to the client?
|
return nil, api.ErrNotAllowed{Err: fmt.Errorf("failed to auth new %q event: %w", builder.Type, err)} // TODO: Is this error string comprehensible to the client?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,17 +121,16 @@ func (r *Queryer) QueryStateAfterEvents(
|
|||||||
return fmt.Errorf("getAuthChain: %w", err)
|
return fmt.Errorf("getAuthChain: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stateEventsPDU, err := gomatrixserverlib.ResolveConflicts(
|
stateEvents, err = gomatrixserverlib.ResolveConflicts(
|
||||||
info.RoomVersion, gomatrixserverlib.ToPDUs(stateEvents), gomatrixserverlib.ToPDUs(authEvents),
|
info.RoomVersion, gomatrixserverlib.ToPDUs(stateEvents), gomatrixserverlib.ToPDUs(authEvents),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("state.ResolveConflictsAdhoc: %w", err)
|
return fmt.Errorf("state.ResolveConflictsAdhoc: %w", err)
|
||||||
}
|
}
|
||||||
stateEvents = gomatrixserverlib.TempCastToEvents(stateEventsPDU)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{Event: event})
|
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{PDU: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -176,7 +175,7 @@ func (r *Queryer) QueryEventsByID(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
response.Events = append(response.Events, &types.HeaderedEvent{Event: event.Event})
|
response.Events = append(response.Events, &types.HeaderedEvent{PDU: event.PDU})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -310,7 +309,7 @@ func (r *Queryer) QueryMembershipAtEvent(
|
|||||||
for i := range memberships {
|
for i := range memberships {
|
||||||
ev := memberships[i]
|
ev := memberships[i]
|
||||||
if ev.Type() == spec.MRoomMember && ev.StateKeyEquals(request.UserID) {
|
if ev.Type() == spec.MRoomMember && ev.StateKeyEquals(request.UserID) {
|
||||||
response.Membership[eventID] = &types.HeaderedEvent{Event: ev.Event}
|
response.Membership[eventID] = &types.HeaderedEvent{PDU: ev.PDU}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,7 +349,7 @@ func (r *Queryer) QueryMembershipsForRoom(
|
|||||||
return fmt.Errorf("r.DB.Events: %w", err)
|
return fmt.Errorf("r.DB.Events: %w", err)
|
||||||
}
|
}
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
clientEvent := synctypes.ToClientEvent(event.Event, synctypes.FormatAll)
|
clientEvent := synctypes.ToClientEvent(event.PDU, synctypes.FormatAll)
|
||||||
response.JoinEvents = append(response.JoinEvents, clientEvent)
|
response.JoinEvents = append(response.JoinEvents, clientEvent)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -399,7 +398,7 @@ func (r *Queryer) QueryMembershipsForRoom(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
clientEvent := synctypes.ToClientEvent(event.Event, synctypes.FormatAll)
|
clientEvent := synctypes.ToClientEvent(event.PDU, synctypes.FormatAll)
|
||||||
response.JoinEvents = append(response.JoinEvents, clientEvent)
|
response.JoinEvents = append(response.JoinEvents, clientEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +526,7 @@ func (r *Queryer) QueryMissingEvents(
|
|||||||
if _, ok := redactEventIDs[event.EventID()]; ok {
|
if _, ok := redactEventIDs[event.EventID()]; ok {
|
||||||
event.Redact()
|
event.Redact()
|
||||||
}
|
}
|
||||||
response.Events = append(response.Events, &types.HeaderedEvent{Event: event})
|
response.Events = append(response.Events, &types.HeaderedEvent{PDU: event})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,18 +553,18 @@ func (r *Queryer) QueryStateAndAuthChain(
|
|||||||
// the entire current state of the room
|
// the entire current state of the room
|
||||||
// TODO: this probably means it should be a different query operation...
|
// TODO: this probably means it should be a different query operation...
|
||||||
if request.OnlyFetchAuthChain {
|
if request.OnlyFetchAuthChain {
|
||||||
var authEvents []*gomatrixserverlib.Event
|
var authEvents []gomatrixserverlib.PDU
|
||||||
authEvents, err = GetAuthChain(ctx, r.DB.EventsFromIDs, info, request.AuthEventIDs)
|
authEvents, err = GetAuthChain(ctx, r.DB.EventsFromIDs, info, request.AuthEventIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, event := range authEvents {
|
for _, event := range authEvents {
|
||||||
response.AuthChainEvents = append(response.AuthChainEvents, &types.HeaderedEvent{Event: event})
|
response.AuthChainEvents = append(response.AuthChainEvents, &types.HeaderedEvent{PDU: event})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var stateEvents []*gomatrixserverlib.Event
|
var stateEvents []gomatrixserverlib.PDU
|
||||||
stateEvents, rejected, stateMissing, err := r.loadStateAtEventIDs(ctx, info, request.PrevEventIDs)
|
stateEvents, rejected, stateMissing, err := r.loadStateAtEventIDs(ctx, info, request.PrevEventIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -588,28 +587,27 @@ func (r *Queryer) QueryStateAndAuthChain(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if request.ResolveState {
|
if request.ResolveState {
|
||||||
stateEventsPDU, err2 := gomatrixserverlib.ResolveConflicts(
|
stateEvents, err = gomatrixserverlib.ResolveConflicts(
|
||||||
info.RoomVersion, gomatrixserverlib.ToPDUs(stateEvents), gomatrixserverlib.ToPDUs(authEvents),
|
info.RoomVersion, gomatrixserverlib.ToPDUs(stateEvents), gomatrixserverlib.ToPDUs(authEvents),
|
||||||
)
|
)
|
||||||
if err2 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
stateEvents = gomatrixserverlib.TempCastToEvents(stateEventsPDU)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{Event: event})
|
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{PDU: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range authEvents {
|
for _, event := range authEvents {
|
||||||
response.AuthChainEvents = append(response.AuthChainEvents, &types.HeaderedEvent{Event: event})
|
response.AuthChainEvents = append(response.AuthChainEvents, &types.HeaderedEvent{PDU: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// first bool: is rejected, second bool: state missing
|
// first bool: is rejected, second bool: state missing
|
||||||
func (r *Queryer) loadStateAtEventIDs(ctx context.Context, roomInfo *types.RoomInfo, eventIDs []string) ([]*gomatrixserverlib.Event, bool, bool, error) {
|
func (r *Queryer) loadStateAtEventIDs(ctx context.Context, roomInfo *types.RoomInfo, eventIDs []string) ([]gomatrixserverlib.PDU, bool, bool, error) {
|
||||||
roomState := state.NewStateResolution(r.DB, roomInfo)
|
roomState := state.NewStateResolution(r.DB, roomInfo)
|
||||||
prevStates, err := r.DB.StateAtEventIDs(ctx, eventIDs)
|
prevStates, err := r.DB.StateAtEventIDs(ctx, eventIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -651,13 +649,13 @@ type eventsFromIDs func(context.Context, *types.RoomInfo, []string) ([]types.Eve
|
|||||||
// given events. Will *not* error if we don't have all auth events.
|
// given events. Will *not* error if we don't have all auth events.
|
||||||
func GetAuthChain(
|
func GetAuthChain(
|
||||||
ctx context.Context, fn eventsFromIDs, roomInfo *types.RoomInfo, authEventIDs []string,
|
ctx context.Context, fn eventsFromIDs, roomInfo *types.RoomInfo, authEventIDs []string,
|
||||||
) ([]*gomatrixserverlib.Event, error) {
|
) ([]gomatrixserverlib.PDU, error) {
|
||||||
// List of event IDs to fetch. On each pass, these events will be requested
|
// List of event IDs to fetch. On each pass, these events will be requested
|
||||||
// from the database and the `eventsToFetch` will be updated with any new
|
// from the database and the `eventsToFetch` will be updated with any new
|
||||||
// events that we have learned about and need to find. When `eventsToFetch`
|
// events that we have learned about and need to find. When `eventsToFetch`
|
||||||
// is eventually empty, we should have reached the end of the chain.
|
// is eventually empty, we should have reached the end of the chain.
|
||||||
eventsToFetch := authEventIDs
|
eventsToFetch := authEventIDs
|
||||||
authEventsMap := make(map[string]*gomatrixserverlib.Event)
|
authEventsMap := make(map[string]gomatrixserverlib.PDU)
|
||||||
|
|
||||||
for len(eventsToFetch) > 0 {
|
for len(eventsToFetch) > 0 {
|
||||||
// Try to retrieve the events from the database.
|
// Try to retrieve the events from the database.
|
||||||
@ -673,14 +671,14 @@ func GetAuthChain(
|
|||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
// Store the event in the event map - this prevents us from requesting it
|
// Store the event in the event map - this prevents us from requesting it
|
||||||
// from the database again.
|
// from the database again.
|
||||||
authEventsMap[event.EventID()] = event.Event
|
authEventsMap[event.EventID()] = event.PDU
|
||||||
|
|
||||||
// Extract all of the auth events from the newly obtained event. If we
|
// Extract all of the auth events from the newly obtained event. If we
|
||||||
// don't already have a record of the event, record it in the list of
|
// don't already have a record of the event, record it in the list of
|
||||||
// events we want to request for the next pass.
|
// events we want to request for the next pass.
|
||||||
for _, authEvent := range event.AuthEvents() {
|
for _, authEventID := range event.AuthEventIDs() {
|
||||||
if _, ok := authEventsMap[authEvent.EventID]; !ok {
|
if _, ok := authEventsMap[authEventID]; !ok {
|
||||||
eventsToFetch = append(eventsToFetch, authEvent.EventID)
|
eventsToFetch = append(eventsToFetch, authEventID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -688,7 +686,7 @@ func GetAuthChain(
|
|||||||
|
|
||||||
// We've now retrieved all of the events we can. Flatten them down into an
|
// We've now retrieved all of the events we can. Flatten them down into an
|
||||||
// array and return them.
|
// array and return them.
|
||||||
var authEvents []*gomatrixserverlib.Event
|
var authEvents []gomatrixserverlib.PDU
|
||||||
for _, event := range authEventsMap {
|
for _, event := range authEventsMap {
|
||||||
authEvents = append(authEvents, event)
|
authEvents = append(authEvents, event)
|
||||||
}
|
}
|
||||||
@ -854,7 +852,7 @@ func (r *Queryer) QueryAuthChain(ctx context.Context, req *api.QueryAuthChainReq
|
|||||||
}
|
}
|
||||||
hchain := make([]*types.HeaderedEvent, len(chain))
|
hchain := make([]*types.HeaderedEvent, len(chain))
|
||||||
for i := range chain {
|
for i := range chain {
|
||||||
hchain[i] = &types.HeaderedEvent{Event: chain[i]}
|
hchain[i] = &types.HeaderedEvent{PDU: chain[i]}
|
||||||
}
|
}
|
||||||
res.AuthChain = hchain
|
res.AuthChain = hchain
|
||||||
return nil
|
return nil
|
||||||
|
@ -84,7 +84,7 @@ func (db *getEventDB) EventsFromIDs(ctx context.Context, roomInfo *types.RoomInf
|
|||||||
for _, evID := range eventIDs {
|
for _, evID := range eventIDs {
|
||||||
res = append(res, types.Event{
|
res = append(res, types.Event{
|
||||||
EventNID: 0,
|
EventNID: 0,
|
||||||
Event: db.eventMap[evID],
|
PDU: db.eventMap[evID],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ func (r *RoomEventProducer) ProduceRoomEvents(roomID string, updates []api.Outpu
|
|||||||
}
|
}
|
||||||
|
|
||||||
if eventType == "m.room.server_acl" && update.NewRoomEvent.Event.StateKeyEquals("") {
|
if eventType == "m.room.server_acl" && update.NewRoomEvent.Event.StateKeyEquals("") {
|
||||||
ev := update.NewRoomEvent.Event.Event
|
ev := update.NewRoomEvent.Event.PDU
|
||||||
defer r.ACLs.OnServerACLUpdate(ev)
|
defer r.ACLs.OnServerACLUpdate(ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -421,7 +421,7 @@ func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *types.HeaderedEve
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("mustCreateEvent: failed to sign event: %s", err)
|
t.Fatalf("mustCreateEvent: failed to sign event: %s", err)
|
||||||
}
|
}
|
||||||
h := &types.HeaderedEvent{Event: signedEvent}
|
h := &types.HeaderedEvent{PDU: signedEvent}
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,7 +534,7 @@ func TestRedaction(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, ev := range room.Events() {
|
for _, ev := range room.Events() {
|
||||||
roomInfo, err = db.GetOrCreateRoomInfo(ctx, ev.Event)
|
roomInfo, err = db.GetOrCreateRoomInfo(ctx, ev.PDU)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, roomInfo)
|
assert.NotNil(t, roomInfo)
|
||||||
evTypeNID, err := db.GetOrCreateEventTypeNID(ctx, ev.Type())
|
evTypeNID, err := db.GetOrCreateEventTypeNID(ctx, ev.Type())
|
||||||
@ -543,7 +543,7 @@ func TestRedaction(t *testing.T) {
|
|||||||
stateKeyNID, err := db.GetOrCreateEventStateKeyNID(ctx, ev.StateKey())
|
stateKeyNID, err := db.GetOrCreateEventStateKeyNID(ctx, ev.StateKey())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
eventNID, stateAtEvent, err := db.StoreEvent(ctx, ev.Event, roomInfo, evTypeNID, stateKeyNID, authEvents, false)
|
eventNID, stateAtEvent, err := db.StoreEvent(ctx, ev.PDU, roomInfo, evTypeNID, stateKeyNID, authEvents, false)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if ev.StateKey() != nil {
|
if ev.StateKey() != nil {
|
||||||
authEvents = append(authEvents, eventNID)
|
authEvents = append(authEvents, eventNID)
|
||||||
@ -551,7 +551,7 @@ func TestRedaction(t *testing.T) {
|
|||||||
|
|
||||||
// Calculate the snapshotNID etc.
|
// Calculate the snapshotNID etc.
|
||||||
plResolver := state.NewStateResolution(db, roomInfo)
|
plResolver := state.NewStateResolution(db, roomInfo)
|
||||||
stateAtEvent.BeforeStateSnapshotNID, err = plResolver.CalculateAndStoreStateBeforeEvent(ctx, ev.Event, false)
|
stateAtEvent.BeforeStateSnapshotNID, err = plResolver.CalculateAndStoreStateBeforeEvent(ctx, ev.PDU, false)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Update the room
|
// Update the room
|
||||||
@ -562,7 +562,7 @@ func TestRedaction(t *testing.T) {
|
|||||||
err = updater.Commit()
|
err = updater.Commit()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, redactedEvent, err := db.MaybeRedactEvent(ctx, roomInfo, eventNID, ev.Event, &plResolver)
|
_, redactedEvent, err := db.MaybeRedactEvent(ctx, roomInfo, eventNID, ev.PDU, &plResolver)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if redactedEvent != nil {
|
if redactedEvent != nil {
|
||||||
assert.Equal(t, ev.Redacts(), redactedEvent.EventID())
|
assert.Equal(t, ev.Redacts(), redactedEvent.EventID())
|
||||||
|
@ -48,14 +48,14 @@ type StateResolutionStorage interface {
|
|||||||
type StateResolution struct {
|
type StateResolution struct {
|
||||||
db StateResolutionStorage
|
db StateResolutionStorage
|
||||||
roomInfo *types.RoomInfo
|
roomInfo *types.RoomInfo
|
||||||
events map[types.EventNID]*gomatrixserverlib.Event
|
events map[types.EventNID]gomatrixserverlib.PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStateResolution(db StateResolutionStorage, roomInfo *types.RoomInfo) StateResolution {
|
func NewStateResolution(db StateResolutionStorage, roomInfo *types.RoomInfo) StateResolution {
|
||||||
return StateResolution{
|
return StateResolution{
|
||||||
db: db,
|
db: db,
|
||||||
roomInfo: roomInfo,
|
roomInfo: roomInfo,
|
||||||
events: make(map[types.EventNID]*gomatrixserverlib.Event),
|
events: make(map[types.EventNID]gomatrixserverlib.PDU),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,7 +702,7 @@ func init() {
|
|||||||
// Returns a numeric ID for the snapshot of the state before the event.
|
// Returns a numeric ID for the snapshot of the state before the event.
|
||||||
func (v *StateResolution) CalculateAndStoreStateBeforeEvent(
|
func (v *StateResolution) CalculateAndStoreStateBeforeEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
event *gomatrixserverlib.Event,
|
event gomatrixserverlib.PDU,
|
||||||
isRejected bool,
|
isRejected bool,
|
||||||
) (types.StateSnapshotNID, error) {
|
) (types.StateSnapshotNID, error) {
|
||||||
trace, ctx := internal.StartRegion(ctx, "StateResolution.CalculateAndStoreStateBeforeEvent")
|
trace, ctx := internal.StartRegion(ctx, "StateResolution.CalculateAndStoreStateBeforeEvent")
|
||||||
@ -995,7 +995,7 @@ func (v *StateResolution) resolveConflictsV2(
|
|||||||
|
|
||||||
// For each conflicted event, we will add a new set of auth events. Auth
|
// For each conflicted event, we will add a new set of auth events. Auth
|
||||||
// events may be duplicated across these sets but that's OK.
|
// events may be duplicated across these sets but that's OK.
|
||||||
authSets := make(map[string][]*gomatrixserverlib.Event, len(conflicted))
|
authSets := make(map[string][]gomatrixserverlib.PDU, len(conflicted))
|
||||||
authEvents := make([]gomatrixserverlib.PDU, 0, estimate*3)
|
authEvents := make([]gomatrixserverlib.PDU, 0, estimate*3)
|
||||||
gotAuthEvents := make(map[string]struct{}, estimate*3)
|
gotAuthEvents := make(map[string]struct{}, estimate*3)
|
||||||
knownAuthEvents := make(map[string]types.Event, estimate*3)
|
knownAuthEvents := make(map[string]types.Event, estimate*3)
|
||||||
@ -1144,9 +1144,9 @@ func (v *StateResolution) loadStateEvents(
|
|||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Errorf("corrupt DB: Missing event numeric ID %d", entry.EventNID))
|
panic(fmt.Errorf("corrupt DB: Missing event numeric ID %d", entry.EventNID))
|
||||||
}
|
}
|
||||||
result = append(result, event.Event)
|
result = append(result, event.PDU)
|
||||||
eventIDMap[event.Event.EventID()] = entry
|
eventIDMap[event.PDU.EventID()] = entry
|
||||||
v.events[entry.EventNID] = event.Event
|
v.events[entry.EventNID] = event.PDU
|
||||||
}
|
}
|
||||||
return result, eventIDMap, nil
|
return result, eventIDMap, nil
|
||||||
}
|
}
|
||||||
@ -1164,7 +1164,7 @@ type authEventLoader struct {
|
|||||||
// along with a map that contains state entries for all of the auth events.
|
// along with a map that contains state entries for all of the auth events.
|
||||||
func (l *authEventLoader) loadAuthEvents(
|
func (l *authEventLoader) loadAuthEvents(
|
||||||
ctx context.Context, roomInfo *types.RoomInfo, event gomatrixserverlib.PDU, eventMap map[string]types.Event,
|
ctx context.Context, roomInfo *types.RoomInfo, event gomatrixserverlib.PDU, eventMap map[string]types.Event,
|
||||||
) ([]*gomatrixserverlib.Event, map[string]types.StateEntry, error) {
|
) ([]gomatrixserverlib.PDU, map[string]types.StateEntry, error) {
|
||||||
l.Lock()
|
l.Lock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
authEvents := []types.Event{} // our returned list
|
authEvents := []types.Event{} // our returned list
|
||||||
@ -1265,9 +1265,9 @@ func (l *authEventLoader) loadAuthEvents(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nakedEvents := make([]*gomatrixserverlib.Event, 0, len(authEvents))
|
nakedEvents := make([]gomatrixserverlib.PDU, 0, len(authEvents))
|
||||||
for _, authEvent := range authEvents {
|
for _, authEvent := range authEvents {
|
||||||
nakedEvents = append(nakedEvents, authEvent.Event)
|
nakedEvents = append(nakedEvents, authEvent.PDU)
|
||||||
}
|
}
|
||||||
return nakedEvents, stateEntryMap, nil
|
return nakedEvents, stateEntryMap, nil
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ type Database interface {
|
|||||||
) (types.StateSnapshotNID, error)
|
) (types.StateSnapshotNID, error)
|
||||||
|
|
||||||
MissingAuthPrevEvents(
|
MissingAuthPrevEvents(
|
||||||
ctx context.Context, e *gomatrixserverlib.Event,
|
ctx context.Context, e gomatrixserverlib.PDU,
|
||||||
) (missingAuth, missingPrev []string, err error)
|
) (missingAuth, missingPrev []string, err error)
|
||||||
|
|
||||||
// Look up the state of a room at each event for a list of string event IDs.
|
// Look up the state of a room at each event for a list of string event IDs.
|
||||||
@ -171,7 +171,7 @@ type Database interface {
|
|||||||
// ForgetRoom sets a flag in the membership table, that the user wishes to forget a specific room
|
// ForgetRoom sets a flag in the membership table, that the user wishes to forget a specific room
|
||||||
ForgetRoom(ctx context.Context, userID, roomID string, forget bool) error
|
ForgetRoom(ctx context.Context, userID, roomID string, forget bool) error
|
||||||
|
|
||||||
GetHistoryVisibilityState(ctx context.Context, roomInfo *types.RoomInfo, eventID string, domain string) ([]*gomatrixserverlib.Event, error)
|
GetHistoryVisibilityState(ctx context.Context, roomInfo *types.RoomInfo, eventID string, domain string) ([]gomatrixserverlib.PDU, error)
|
||||||
GetLeftUsers(ctx context.Context, userIDs []string) ([]string, error)
|
GetLeftUsers(ctx context.Context, userIDs []string) ([]string, error)
|
||||||
PurgeRoom(ctx context.Context, roomID string) error
|
PurgeRoom(ctx context.Context, roomID string) error
|
||||||
UpgradeRoom(ctx context.Context, oldRoomID, newRoomID, eventSender string) error
|
UpgradeRoom(ctx context.Context, oldRoomID, newRoomID, eventSender string) error
|
||||||
@ -186,8 +186,8 @@ type Database interface {
|
|||||||
GetOrCreateEventTypeNID(ctx context.Context, eventType string) (eventTypeNID types.EventTypeNID, err error)
|
GetOrCreateEventTypeNID(ctx context.Context, eventType string) (eventTypeNID types.EventTypeNID, err error)
|
||||||
GetOrCreateEventStateKeyNID(ctx context.Context, eventStateKey *string) (types.EventStateKeyNID, error)
|
GetOrCreateEventStateKeyNID(ctx context.Context, eventStateKey *string) (types.EventStateKeyNID, error)
|
||||||
MaybeRedactEvent(
|
MaybeRedactEvent(
|
||||||
ctx context.Context, roomInfo *types.RoomInfo, eventNID types.EventNID, event *gomatrixserverlib.Event, plResolver state.PowerLevelResolver,
|
ctx context.Context, roomInfo *types.RoomInfo, eventNID types.EventNID, event gomatrixserverlib.PDU, plResolver state.PowerLevelResolver,
|
||||||
) (*gomatrixserverlib.Event, *gomatrixserverlib.Event, error)
|
) (gomatrixserverlib.PDU, gomatrixserverlib.PDU, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type RoomDatabase interface {
|
type RoomDatabase interface {
|
||||||
@ -197,7 +197,7 @@ type RoomDatabase interface {
|
|||||||
RoomInfoByNID(ctx context.Context, roomNID types.RoomNID) (*types.RoomInfo, error)
|
RoomInfoByNID(ctx context.Context, roomNID types.RoomNID) (*types.RoomInfo, error)
|
||||||
// IsEventRejected returns true if the event is known and rejected.
|
// IsEventRejected returns true if the event is known and rejected.
|
||||||
IsEventRejected(ctx context.Context, roomNID types.RoomNID, eventID string) (rejected bool, err error)
|
IsEventRejected(ctx context.Context, roomNID types.RoomNID, eventID string) (rejected bool, err error)
|
||||||
MissingAuthPrevEvents(ctx context.Context, e *gomatrixserverlib.Event) (missingAuth, missingPrev []string, err error)
|
MissingAuthPrevEvents(ctx context.Context, e gomatrixserverlib.PDU) (missingAuth, missingPrev []string, err error)
|
||||||
UpgradeRoom(ctx context.Context, oldRoomID, newRoomID, eventSender string) error
|
UpgradeRoom(ctx context.Context, oldRoomID, newRoomID, eventSender string) error
|
||||||
GetRoomUpdater(ctx context.Context, roomInfo *types.RoomInfo) (*shared.RoomUpdater, error)
|
GetRoomUpdater(ctx context.Context, roomInfo *types.RoomInfo) (*shared.RoomUpdater, error)
|
||||||
GetMembershipEventNIDsForRoom(ctx context.Context, roomNID types.RoomNID, joinOnly bool, localOnly bool) ([]types.EventNID, error)
|
GetMembershipEventNIDsForRoom(ctx context.Context, roomNID types.RoomNID, joinOnly bool, localOnly bool) ([]types.EventNID, error)
|
||||||
@ -228,7 +228,7 @@ type EventDatabase interface {
|
|||||||
// MaybeRedactEvent returns the redaction event and the redacted event if this call resulted in a redaction, else an error
|
// MaybeRedactEvent returns the redaction event and the redacted event if this call resulted in a redaction, else an error
|
||||||
// (nil if there was nothing to do)
|
// (nil if there was nothing to do)
|
||||||
MaybeRedactEvent(
|
MaybeRedactEvent(
|
||||||
ctx context.Context, roomInfo *types.RoomInfo, eventNID types.EventNID, event *gomatrixserverlib.Event, plResolver state.PowerLevelResolver,
|
ctx context.Context, roomInfo *types.RoomInfo, eventNID types.EventNID, event gomatrixserverlib.PDU, plResolver state.PowerLevelResolver,
|
||||||
) (*gomatrixserverlib.Event, *gomatrixserverlib.Event, error)
|
) (gomatrixserverlib.PDU, gomatrixserverlib.PDU, error)
|
||||||
StoreEvent(ctx context.Context, event gomatrixserverlib.PDU, roomInfo *types.RoomInfo, eventTypeNID types.EventTypeNID, eventStateKeyNID types.EventStateKeyNID, authEventNIDs []types.EventNID, isRejected bool) (types.EventNID, types.StateAtEvent, error)
|
StoreEvent(ctx context.Context, event gomatrixserverlib.PDU, roomInfo *types.RoomInfo, eventTypeNID types.EventTypeNID, eventStateKeyNID types.EventStateKeyNID, authEventNIDs []types.EventNID, isRejected bool) (types.EventNID, types.StateAtEvent, error)
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ func (s *stateSnapshotStatements) BulkSelectMembershipForHistoryVisibility(
|
|||||||
// not fatal
|
// not fatal
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
he := &types.HeaderedEvent{Event: event}
|
he := &types.HeaderedEvent{PDU: event}
|
||||||
result[eventID] = he
|
result[eventID] = he
|
||||||
knownEvents[membershipEventID] = he
|
knownEvents[membershipEventID] = he
|
||||||
}
|
}
|
||||||
|
@ -562,7 +562,7 @@ func (d *EventDatabase) events(
|
|||||||
}
|
}
|
||||||
results = append(results, types.Event{
|
results = append(results, types.Event{
|
||||||
EventNID: nid,
|
EventNID: nid,
|
||||||
Event: event,
|
PDU: event,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if !redactionsArePermanent {
|
if !redactionsArePermanent {
|
||||||
@ -604,7 +604,7 @@ func (d *EventDatabase) events(
|
|||||||
}
|
}
|
||||||
results = append(results, types.Event{
|
results = append(results, types.Event{
|
||||||
EventNID: nid,
|
EventNID: nid,
|
||||||
Event: event,
|
PDU: event,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if !redactionsArePermanent {
|
if !redactionsArePermanent {
|
||||||
@ -817,7 +817,7 @@ func (d *Database) GetPublishedRooms(ctx context.Context, networkID string, incl
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) MissingAuthPrevEvents(
|
func (d *Database) MissingAuthPrevEvents(
|
||||||
ctx context.Context, e *gomatrixserverlib.Event,
|
ctx context.Context, e gomatrixserverlib.PDU,
|
||||||
) (missingAuth, missingPrev []string, err error) {
|
) (missingAuth, missingPrev []string, err error) {
|
||||||
authEventNIDs, err := d.EventNIDs(ctx, e.AuthEventIDs())
|
authEventNIDs, err := d.EventNIDs(ctx, e.AuthEventIDs())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -949,8 +949,8 @@ func extractRoomVersionFromCreateEvent(event gomatrixserverlib.PDU) (
|
|||||||
//
|
//
|
||||||
// Returns the redaction event and the redacted event if this call resulted in a redaction.
|
// Returns the redaction event and the redacted event if this call resulted in a redaction.
|
||||||
func (d *EventDatabase) MaybeRedactEvent(
|
func (d *EventDatabase) MaybeRedactEvent(
|
||||||
ctx context.Context, roomInfo *types.RoomInfo, eventNID types.EventNID, event *gomatrixserverlib.Event, plResolver state.PowerLevelResolver,
|
ctx context.Context, roomInfo *types.RoomInfo, eventNID types.EventNID, event gomatrixserverlib.PDU, plResolver state.PowerLevelResolver,
|
||||||
) (*gomatrixserverlib.Event, *gomatrixserverlib.Event, error) {
|
) (gomatrixserverlib.PDU, gomatrixserverlib.PDU, error) {
|
||||||
var (
|
var (
|
||||||
redactionEvent, redactedEvent *types.Event
|
redactionEvent, redactedEvent *types.Event
|
||||||
err error
|
err error
|
||||||
@ -1044,12 +1044,12 @@ func (d *EventDatabase) MaybeRedactEvent(
|
|||||||
if ignoreRedaction || redactionEvent == nil || redactedEvent == nil {
|
if ignoreRedaction || redactionEvent == nil || redactedEvent == nil {
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
return redactionEvent.Event, redactedEvent.Event, nil
|
return redactionEvent.PDU, redactedEvent.PDU, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadRedactionPair returns both the redaction event and the redacted event, else nil.
|
// loadRedactionPair returns both the redaction event and the redacted event, else nil.
|
||||||
func (d *EventDatabase) loadRedactionPair(
|
func (d *EventDatabase) loadRedactionPair(
|
||||||
ctx context.Context, txn *sql.Tx, roomInfo *types.RoomInfo, eventNID types.EventNID, event *gomatrixserverlib.Event,
|
ctx context.Context, txn *sql.Tx, roomInfo *types.RoomInfo, eventNID types.EventNID, event gomatrixserverlib.PDU,
|
||||||
) (*types.Event, *types.Event, bool, error) {
|
) (*types.Event, *types.Event, bool, error) {
|
||||||
var redactionEvent, redactedEvent *types.Event
|
var redactionEvent, redactedEvent *types.Event
|
||||||
var info *tables.RedactionInfo
|
var info *tables.RedactionInfo
|
||||||
@ -1061,13 +1061,13 @@ func (d *EventDatabase) loadRedactionPair(
|
|||||||
eventBeingRedacted = event.Redacts()
|
eventBeingRedacted = event.Redacts()
|
||||||
redactionEvent = &types.Event{
|
redactionEvent = &types.Event{
|
||||||
EventNID: eventNID,
|
EventNID: eventNID,
|
||||||
Event: event,
|
PDU: event,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eventBeingRedacted = event.EventID() // maybe, we'll see if we have info
|
eventBeingRedacted = event.EventID() // maybe, we'll see if we have info
|
||||||
redactedEvent = &types.Event{
|
redactedEvent = &types.Event{
|
||||||
EventNID: eventNID,
|
EventNID: eventNID,
|
||||||
Event: event,
|
PDU: event,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1117,7 +1117,7 @@ func (d *EventDatabase) loadEvent(ctx context.Context, roomInfo *types.RoomInfo,
|
|||||||
return &evs[0]
|
return &evs[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) GetHistoryVisibilityState(ctx context.Context, roomInfo *types.RoomInfo, eventID string, domain string) ([]*gomatrixserverlib.Event, error) {
|
func (d *Database) GetHistoryVisibilityState(ctx context.Context, roomInfo *types.RoomInfo, eventID string, domain string) ([]gomatrixserverlib.PDU, error) {
|
||||||
eventStates, err := d.EventsTable.BulkSelectStateAtEventByID(ctx, nil, []string{eventID})
|
eventStates, err := d.EventsTable.BulkSelectStateAtEventByID(ctx, nil, []string{eventID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1138,7 +1138,7 @@ func (d *Database) GetHistoryVisibilityState(ctx context.Context, roomInfo *type
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
events := make([]*gomatrixserverlib.Event, 0, len(eventNIDs))
|
events := make([]gomatrixserverlib.PDU, 0, len(eventNIDs))
|
||||||
for _, eventNID := range eventNIDs {
|
for _, eventNID := range eventNIDs {
|
||||||
data, err := d.EventJSONTable.BulkSelectEventJSON(ctx, nil, []types.EventNID{eventNID})
|
data, err := d.EventJSONTable.BulkSelectEventJSON(ctx, nil, []types.EventNID{eventNID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1207,7 +1207,7 @@ func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey s
|
|||||||
if e.EventTypeNID == eventTypeNID && e.EventStateKeyNID == stateKeyNID {
|
if e.EventTypeNID == eventTypeNID && e.EventStateKeyNID == stateKeyNID {
|
||||||
cachedEvent, ok := d.Cache.GetRoomServerEvent(e.EventNID)
|
cachedEvent, ok := d.Cache.GetRoomServerEvent(e.EventNID)
|
||||||
if ok {
|
if ok {
|
||||||
return &types.HeaderedEvent{Event: cachedEvent}, nil
|
return &types.HeaderedEvent{PDU: cachedEvent}, nil
|
||||||
}
|
}
|
||||||
data, err := d.EventJSONTable.BulkSelectEventJSON(ctx, nil, []types.EventNID{e.EventNID})
|
data, err := d.EventJSONTable.BulkSelectEventJSON(ctx, nil, []types.EventNID{e.EventNID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1220,7 +1220,7 @@ func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &types.HeaderedEvent{Event: ev}, nil
|
return &types.HeaderedEvent{PDU: ev}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1281,7 +1281,7 @@ func (d *Database) GetStateEventsWithEventType(ctx context.Context, roomID, evTy
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result = append(result, &types.HeaderedEvent{Event: ev})
|
result = append(result, &types.HeaderedEvent{PDU: ev})
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
@ -1409,7 +1409,7 @@ func (d *Database) GetBulkStateContent(ctx context.Context, roomIDs []string, tu
|
|||||||
EventType: ev.Type(),
|
EventType: ev.Type(),
|
||||||
RoomID: ev.RoomID(),
|
RoomID: ev.RoomID(),
|
||||||
StateKey: *ev.StateKey(),
|
StateKey: *ev.StateKey(),
|
||||||
ContentValue: tables.ExtractContentValue(&types.HeaderedEvent{Event: ev}),
|
ContentValue: tables.ExtractContentValue(&types.HeaderedEvent{PDU: ev}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,18 +15,28 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HeaderedEvent is an Event which serialises to the headered form, which includes
|
// HeaderedEvent is an Event which serialises to the headered form, which includes
|
||||||
// _room_version and _event_id fields.
|
// _room_version and _event_id fields.
|
||||||
type HeaderedEvent struct {
|
type HeaderedEvent struct {
|
||||||
*gomatrixserverlib.Event
|
gomatrixserverlib.PDU
|
||||||
Visibility gomatrixserverlib.HistoryVisibility
|
Visibility gomatrixserverlib.HistoryVisibility
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HeaderedEvent) CacheCost() int {
|
||||||
|
return int(unsafe.Sizeof(*h)) +
|
||||||
|
len(h.EventID()) +
|
||||||
|
(cap(h.JSON()) * 2) +
|
||||||
|
len(h.Version()) +
|
||||||
|
1 // redacted bool
|
||||||
|
}
|
||||||
|
|
||||||
func (h *HeaderedEvent) MarshalJSON() ([]byte, error) {
|
func (h *HeaderedEvent) MarshalJSON() ([]byte, error) {
|
||||||
return h.Event.ToHeaderedJSON()
|
return h.PDU.ToHeaderedJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *HeaderedEvent) UnmarshalJSON(data []byte) error {
|
func (j *HeaderedEvent) UnmarshalJSON(data []byte) error {
|
||||||
@ -34,7 +44,7 @@ func (j *HeaderedEvent) UnmarshalJSON(data []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
j.Event = ev
|
j.PDU = ev
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ func (s StateAtEventAndReferences) EventIDs() string {
|
|||||||
// It is when performing bulk event lookup in the database.
|
// It is when performing bulk event lookup in the database.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
EventNID EventNID
|
EventNID EventNID
|
||||||
*gomatrixserverlib.Event
|
gomatrixserverlib.PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -89,8 +89,8 @@ type EventRelationshipResponse struct {
|
|||||||
|
|
||||||
type MSC2836EventRelationshipsResponse struct {
|
type MSC2836EventRelationshipsResponse struct {
|
||||||
fclient.MSC2836EventRelationshipsResponse
|
fclient.MSC2836EventRelationshipsResponse
|
||||||
ParsedEvents []*gomatrixserverlib.Event
|
ParsedEvents []gomatrixserverlib.PDU
|
||||||
ParsedAuthChain []*gomatrixserverlib.Event
|
ParsedAuthChain []gomatrixserverlib.PDU
|
||||||
}
|
}
|
||||||
|
|
||||||
func toClientResponse(res *MSC2836EventRelationshipsResponse) *EventRelationshipResponse {
|
func toClientResponse(res *MSC2836EventRelationshipsResponse) *EventRelationshipResponse {
|
||||||
@ -306,11 +306,11 @@ func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONRespo
|
|||||||
)
|
)
|
||||||
returnEvents = append(returnEvents, events...)
|
returnEvents = append(returnEvents, events...)
|
||||||
}
|
}
|
||||||
res.ParsedEvents = make([]*gomatrixserverlib.Event, len(returnEvents))
|
res.ParsedEvents = make([]gomatrixserverlib.PDU, len(returnEvents))
|
||||||
for i, ev := range returnEvents {
|
for i, ev := range returnEvents {
|
||||||
// for each event, extract the children_count | hash and add it as unsigned data.
|
// for each event, extract the children_count | hash and add it as unsigned data.
|
||||||
rc.addChildMetadata(ev)
|
rc.addChildMetadata(ev)
|
||||||
res.ParsedEvents[i] = ev.Event
|
res.ParsedEvents[i] = ev.PDU
|
||||||
}
|
}
|
||||||
res.Limited = remaining == 0 || walkLimited
|
res.Limited = remaining == 0 || walkLimited
|
||||||
return &res, nil
|
return &res, nil
|
||||||
@ -373,7 +373,7 @@ func (rc *reqCtx) fetchUnknownEvent(eventID, roomID string) *types.HeaderedEvent
|
|||||||
rc.injectResponseToRoomserver(res)
|
rc.injectResponseToRoomserver(res)
|
||||||
for _, ev := range res.ParsedEvents {
|
for _, ev := range res.ParsedEvents {
|
||||||
if ev.EventID() == eventID {
|
if ev.EventID() == eventID {
|
||||||
return &types.HeaderedEvent{Event: ev}
|
return &types.HeaderedEvent{PDU: ev}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -603,7 +603,7 @@ func (rc *reqCtx) lookForEvent(eventID string) *types.HeaderedEvent {
|
|||||||
rc.injectResponseToRoomserver(queryRes)
|
rc.injectResponseToRoomserver(queryRes)
|
||||||
for _, ev := range queryRes.ParsedEvents {
|
for _, ev := range queryRes.ParsedEvents {
|
||||||
if ev.EventID() == eventID && rc.req.RoomID == ev.RoomID() {
|
if ev.EventID() == eventID && rc.req.RoomID == ev.RoomID() {
|
||||||
return &types.HeaderedEvent{Event: ev}
|
return &types.HeaderedEvent{PDU: ev}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -665,7 +665,7 @@ func (rc *reqCtx) injectResponseToRoomserver(res *MSC2836EventRelationshipsRespo
|
|||||||
for _, outlier := range append(eventsInOrder, messageEvents...) {
|
for _, outlier := range append(eventsInOrder, messageEvents...) {
|
||||||
ires = append(ires, roomserver.InputRoomEvent{
|
ires = append(ires, roomserver.InputRoomEvent{
|
||||||
Kind: roomserver.KindOutlier,
|
Kind: roomserver.KindOutlier,
|
||||||
Event: &types.HeaderedEvent{Event: outlier.(*gomatrixserverlib.Event)},
|
Event: &types.HeaderedEvent{PDU: outlier},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// we've got the data by this point so use a background context
|
// we've got the data by this point so use a background context
|
||||||
|
@ -397,7 +397,7 @@ func newReq(t *testing.T, jsonBody map[string]interface{}) *msc2836.EventRelatio
|
|||||||
func runServer(t *testing.T, router *mux.Router) func() {
|
func runServer(t *testing.T, router *mux.Router) func() {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
externalServ := &http.Server{
|
externalServ := &http.Server{
|
||||||
Addr: string(":8009"),
|
Addr: string("127.0.0.1:8009"),
|
||||||
WriteTimeout: 60 * time.Second,
|
WriteTimeout: 60 * time.Second,
|
||||||
Handler: router,
|
Handler: router,
|
||||||
}
|
}
|
||||||
@ -602,6 +602,6 @@ func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *types.HeaderedEve
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("mustCreateEvent: failed to sign event: %s", err)
|
t.Fatalf("mustCreateEvent: failed to sign event: %s", err)
|
||||||
}
|
}
|
||||||
h := &types.HeaderedEvent{Event: signedEvent}
|
h := &types.HeaderedEvent{PDU: signedEvent}
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
@ -693,7 +693,7 @@ func (w *walker) childReferences(roomID string) ([]fclient.MSC2946StrippedEvent,
|
|||||||
// else we'll incorrectly walk redacted events (as the link
|
// else we'll incorrectly walk redacted events (as the link
|
||||||
// is in the state_key)
|
// is in the state_key)
|
||||||
if content.Get("via").Exists() {
|
if content.Get("via").Exists() {
|
||||||
strip := stripped(ev.Event)
|
strip := stripped(ev.PDU)
|
||||||
if strip == nil {
|
if strip == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -723,7 +723,7 @@ func (s set) isSet(val string) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func stripped(ev *gomatrixserverlib.Event) *fclient.MSC2946StrippedEvent {
|
func stripped(ev gomatrixserverlib.PDU) *fclient.MSC2946StrippedEvent {
|
||||||
if ev.StateKey() == nil {
|
if ev.StateKey() == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -526,7 +526,7 @@ func (s *OutputRoomEventConsumer) updateStateEvent(event *rstypes.HeaderedEvent)
|
|||||||
PrevSender: prevEvent.Sender(),
|
PrevSender: prevEvent.Sender(),
|
||||||
}
|
}
|
||||||
|
|
||||||
event.Event, err = event.SetUnsigned(prev)
|
event.PDU, err = event.SetUnsigned(prev)
|
||||||
succeeded = true
|
succeeded = true
|
||||||
return event, err
|
return event, err
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ func Relations(
|
|||||||
for _, event := range filteredEvents {
|
for _, event := range filteredEvents {
|
||||||
res.Chunk = append(
|
res.Chunk = append(
|
||||||
res.Chunk,
|
res.Chunk,
|
||||||
synctypes.ToClientEvent(event.Event, synctypes.FormatAll),
|
synctypes.ToClientEvent(event.PDU, synctypes.FormatAll),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,13 +352,13 @@ func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, reda
|
|||||||
logrus.WithField("event_id", redactedEventID).WithField("redaction_event", redactedBecause.EventID()).Warnf("missing redacted event for redaction")
|
logrus.WithField("event_id", redactedEventID).WithField("redaction_event", redactedBecause.EventID()).Warnf("missing redacted event for redaction")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
eventToRedact := redactedEvents[0].Event
|
eventToRedact := redactedEvents[0].PDU
|
||||||
redactionEvent := redactedBecause.Event
|
redactionEvent := redactedBecause.PDU
|
||||||
if err = eventutil.RedactEvent(redactionEvent, eventToRedact); err != nil {
|
if err = eventutil.RedactEvent(redactionEvent, eventToRedact); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
newEvent := &rstypes.HeaderedEvent{Event: eventToRedact}
|
newEvent := &rstypes.HeaderedEvent{PDU: eventToRedact}
|
||||||
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
return d.OutputEvents.UpdateEventJSON(ctx, txn, newEvent)
|
return d.OutputEvents.UpdateEventJSON(ctx, txn, newEvent)
|
||||||
})
|
})
|
||||||
@ -493,7 +493,7 @@ func (d *Database) CleanSendToDeviceUpdates(
|
|||||||
|
|
||||||
// getMembershipFromEvent returns the value of content.membership iff the event is a state event
|
// getMembershipFromEvent returns the value of content.membership iff the event is a state event
|
||||||
// with type 'm.room.member' and state_key of userID. Otherwise, an empty string is returned.
|
// with type 'm.room.member' and state_key of userID. Otherwise, an empty string is returned.
|
||||||
func getMembershipFromEvent(ev *gomatrixserverlib.Event, userID string) (string, string) {
|
func getMembershipFromEvent(ev gomatrixserverlib.PDU, userID string) (string, string) {
|
||||||
if ev.Type() != "m.room.member" || !ev.StateKeyEquals(userID) {
|
if ev.Type() != "m.room.member" || !ev.StateKeyEquals(userID) {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
|
@ -429,7 +429,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
|
|||||||
for _, ev := range stateStreamEvents {
|
for _, ev := range stateStreamEvents {
|
||||||
// Look for our membership in the state events and skip over any
|
// Look for our membership in the state events and skip over any
|
||||||
// membership events that are not related to us.
|
// membership events that are not related to us.
|
||||||
membership, prevMembership := getMembershipFromEvent(ev.Event, userID)
|
membership, prevMembership := getMembershipFromEvent(ev.PDU, userID)
|
||||||
if membership == "" {
|
if membership == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -555,7 +555,7 @@ func (d *DatabaseTransaction) GetStateDeltasForFullStateSync(
|
|||||||
|
|
||||||
for roomID, stateStreamEvents := range state {
|
for roomID, stateStreamEvents := range state {
|
||||||
for _, ev := range stateStreamEvents {
|
for _, ev := range stateStreamEvents {
|
||||||
if membership, _ := getMembershipFromEvent(ev.Event, userID); membership != "" {
|
if membership, _ := getMembershipFromEvent(ev.PDU, userID); membership != "" {
|
||||||
if membership != spec.Join { // We've already added full state for all joined rooms above.
|
if membership != spec.Join { // We've already added full state for all joined rooms above.
|
||||||
deltas[roomID] = types.StateDelta{
|
deltas[roomID] = types.StateDelta{
|
||||||
Membership: membership,
|
Membership: membership,
|
||||||
|
@ -552,7 +552,7 @@ func NewInviteResponse(event *types.HeaderedEvent) *InviteResponse {
|
|||||||
|
|
||||||
// Then we'll see if we can create a partial of the invite event itself.
|
// Then we'll see if we can create a partial of the invite event itself.
|
||||||
// This is needed for clients to work out *who* sent the invite.
|
// This is needed for clients to work out *who* sent the invite.
|
||||||
inviteEvent := synctypes.ToClientEvent(event.Event, synctypes.FormatSync)
|
inviteEvent := synctypes.ToClientEvent(event.PDU, synctypes.FormatSync)
|
||||||
inviteEvent.Unsigned = nil
|
inviteEvent.Unsigned = nil
|
||||||
if ev, err := json.Marshal(inviteEvent); err == nil {
|
if ev, err := json.Marshal(inviteEvent); err == nil {
|
||||||
res.InviteState.Events = append(res.InviteState.Events, ev)
|
res.InviteState.Events = append(res.InviteState.Events, ev)
|
||||||
|
@ -56,7 +56,7 @@ func TestNewInviteResponse(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
res := NewInviteResponse(&types.HeaderedEvent{Event: ev})
|
res := NewInviteResponse(&types.HeaderedEvent{PDU: ev})
|
||||||
j, err := json.Marshal(res)
|
j, err := json.Marshal(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -52,7 +52,7 @@ func NewRequest(t *testing.T, method, path string, opts ...HTTPRequestOpt) *http
|
|||||||
// ListenAndServe will listen on a random high-numbered port and attach the given router.
|
// ListenAndServe will listen on a random high-numbered port and attach the given router.
|
||||||
// Returns the base URL to send requests to. Call `cancel` to shutdown the server, which will block until it has closed.
|
// Returns the base URL to send requests to. Call `cancel` to shutdown the server, which will block until it has closed.
|
||||||
func ListenAndServe(t *testing.T, router http.Handler, withTLS bool) (apiURL string, cancel func()) {
|
func ListenAndServe(t *testing.T, router http.Handler, withTLS bool) (apiURL string, cancel func()) {
|
||||||
listener, err := net.Listen("tcp", ":0")
|
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to listen: %s", err)
|
t.Fatalf("failed to listen: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ func (r *Room) CreateEvent(t *testing.T, creator *User, eventType string, conten
|
|||||||
if err = gomatrixserverlib.Allowed(ev, &r.authEvents); err != nil {
|
if err = gomatrixserverlib.Allowed(ev, &r.authEvents); err != nil {
|
||||||
t.Fatalf("CreateEvent[%s]: failed to verify event was allowed: %s", eventType, err)
|
t.Fatalf("CreateEvent[%s]: failed to verify event was allowed: %s", eventType, err)
|
||||||
}
|
}
|
||||||
headeredEvent := &rstypes.HeaderedEvent{Event: ev}
|
headeredEvent := &rstypes.HeaderedEvent{PDU: ev}
|
||||||
headeredEvent.Visibility = r.visibility
|
headeredEvent.Visibility = r.visibility
|
||||||
return headeredEvent
|
return headeredEvent
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ func (r *Room) InsertEvent(t *testing.T, he *rstypes.HeaderedEvent) {
|
|||||||
// Add the event to the list of auth/state events
|
// Add the event to the list of auth/state events
|
||||||
r.events = append(r.events, he)
|
r.events = append(r.events, he)
|
||||||
if he.StateKey() != nil {
|
if he.StateKey() != nil {
|
||||||
err := r.authEvents.AddEvent(he.Event)
|
err := r.authEvents.AddEvent(he.PDU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("InsertEvent: failed to add event to auth events: %s", err)
|
t.Fatalf("InsertEvent: failed to add event to auth events: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -650,7 +650,7 @@ func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *
|
|||||||
roomSize: roomSize,
|
roomSize: roomSize,
|
||||||
}
|
}
|
||||||
eval := pushrules.NewRuleSetEvaluator(ec, &ruleSets.Global)
|
eval := pushrules.NewRuleSetEvaluator(ec, &ruleSets.Global)
|
||||||
rule, err := eval.MatchEvent(event.Event)
|
rule, err := eval.MatchEvent(event.PDU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -698,7 +698,7 @@ func (rse *ruleSetEvalContext) HasPowerLevel(userID, levelKey string) (bool, err
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
plc, err := gomatrixserverlib.NewPowerLevelContentFromEvent(ev.Event)
|
plc, err := gomatrixserverlib.NewPowerLevelContentFromEvent(ev.PDU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ func mustCreateEvent(t *testing.T, content string) *types.HeaderedEvent {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create event: %v", err)
|
t.Fatalf("failed to create event: %v", err)
|
||||||
}
|
}
|
||||||
return &types.HeaderedEvent{Event: ev}
|
return &types.HeaderedEvent{PDU: ev}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_evaluatePushRules(t *testing.T) {
|
func Test_evaluatePushRules(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user