aboutsummaryrefslogtreecommitdiff
path: root/federationapi
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-08-05 13:41:16 +0100
committerGitHub <noreply@github.com>2020-08-05 13:41:16 +0100
commit642f9cb964b20f52133e11c52e40733f7bc07320 (patch)
treee48f667d681161a9694b45cb08feded569e539b4 /federationapi
parent15dc1f4d0361da736339653ca8e6ba26ed103792 (diff)
Process inbound device list updates from federation (#1240)
* Add InputDeviceListUpdate * Unbreak unit tests * Process inbound device list updates from federation - Persist the keys in the keyserver and produce key changes - Does not currently fetch keys from the remote server if the prev IDs are missing * Linting
Diffstat (limited to 'federationapi')
-rw-r--r--federationapi/routing/routing.go2
-rw-r--r--federationapi/routing/send.go21
2 files changed, 22 insertions, 1 deletions
diff --git a/federationapi/routing/routing.go b/federationapi/routing/routing.go
index 9808d623..30a65271 100644
--- a/federationapi/routing/routing.go
+++ b/federationapi/routing/routing.go
@@ -82,7 +82,7 @@ func Setup(
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
return Send(
httpReq, request, gomatrixserverlib.TransactionID(vars["txnID"]),
- cfg, rsAPI, eduAPI, keys, federation,
+ cfg, rsAPI, eduAPI, keyAPI, keys, federation,
)
},
)).Methods(http.MethodPut, http.MethodOptions)
diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go
index 680eaccd..903a2f22 100644
--- a/federationapi/routing/send.go
+++ b/federationapi/routing/send.go
@@ -23,6 +23,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/jsonerror"
eduserverAPI "github.com/matrix-org/dendrite/eduserver/api"
"github.com/matrix-org/dendrite/internal/config"
+ keyapi "github.com/matrix-org/dendrite/keyserver/api"
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
@@ -37,6 +38,7 @@ func Send(
cfg *config.Dendrite,
rsAPI api.RoomserverInternalAPI,
eduAPI eduserverAPI.EDUServerInputAPI,
+ keyAPI keyapi.KeyInternalAPI,
keys gomatrixserverlib.JSONVerifier,
federation *gomatrixserverlib.FederationClient,
) util.JSONResponse {
@@ -48,6 +50,7 @@ func Send(
federation: federation,
haveEvents: make(map[string]*gomatrixserverlib.HeaderedEvent),
newEvents: make(map[string]bool),
+ keyAPI: keyAPI,
}
var txnEvents struct {
@@ -100,6 +103,7 @@ type txnReq struct {
context context.Context
rsAPI api.RoomserverInternalAPI
eduAPI eduserverAPI.EDUServerInputAPI
+ keyAPI keyapi.KeyInternalAPI
keys gomatrixserverlib.JSONVerifier
federation txnFederationClient
// local cache of events for auth checks, etc - this may include events
@@ -308,12 +312,29 @@ func (t *txnReq) processEDUs(edus []gomatrixserverlib.EDU) {
}
}
}
+ case gomatrixserverlib.MDeviceListUpdate:
+ t.processDeviceListUpdate(e)
default:
util.GetLogger(t.context).WithField("type", e.Type).Warn("unhandled edu")
}
}
}
+func (t *txnReq) processDeviceListUpdate(e gomatrixserverlib.EDU) {
+ var payload gomatrixserverlib.DeviceListUpdateEvent
+ if err := json.Unmarshal(e.Content, &payload); err != nil {
+ util.GetLogger(t.context).WithError(err).Error("Failed to unmarshal device list update event")
+ return
+ }
+ var inputRes keyapi.InputDeviceListUpdateResponse
+ t.keyAPI.InputDeviceListUpdate(context.Background(), &keyapi.InputDeviceListUpdateRequest{
+ Event: payload,
+ }, &inputRes)
+ if inputRes.Error != nil {
+ util.GetLogger(t.context).WithError(inputRes.Error).WithField("user_id", payload.UserID).Error("failed to InputDeviceListUpdate")
+ }
+}
+
func (t *txnReq) processEvent(e gomatrixserverlib.Event, isInboundTxn bool) error {
prevEventIDs := e.PrevEventIDs()