From 94794485e0d9c82ef2f04d658846bb7cb217c7b2 Mon Sep 17 00:00:00 2001 From: SUMUKHA-PK Date: Fri, 18 Oct 2019 20:04:39 +0530 Subject: [PATCH] Some changes --- docker/postgres/create_db.sh | 7 +------ encryptoapi/routing/keys.go | 8 +++++++- syncapi/sync/keyextension.go | 5 +++-- syncapi/sync/requestpool.go | 7 +++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/docker/postgres/create_db.sh b/docker/postgres/create_db.sh index 66d05251f..2e0a1e284 100644 --- a/docker/postgres/create_db.sh +++ b/docker/postgres/create_db.sh @@ -1,10 +1,5 @@ #!/bin/bash -<<<<<<< HEAD -for db in account device mediaapi syncapi roomserver serverkey federationsender publicroomsapi appservice naffka; do - createdb -U dendrite -O dendrite dendrite_$db -======= -for db in account device mediaapi syncapi roomserver serverkey federationsender publicroomsapi naffka encryptapi; do +for db in account device mediaapi syncapi roomserver serverkey federationsender publicroomsapi appservice naffka encryptapi; do createdb -O dendrite dendrite_$db ->>>>>>> 8b4b3c6fc46900e9bfe5e234eda309200662b34a done diff --git a/encryptoapi/routing/keys.go b/encryptoapi/routing/keys.go index 7685891ce..9995ffe5d 100644 --- a/encryptoapi/routing/keys.go +++ b/encryptoapi/routing/keys.go @@ -78,12 +78,18 @@ func UploadPKeys( &keySpecific, userID, deviceID) // numMap is algorithm-num map - numMap := (QueryOneTimeKeys( + numMap, ok := (QueryOneTimeKeys( req.Context(), TYPESUM, userID, deviceID, encryptionDB)).(map[string]int) + if !ok { + return util.JSONResponse{ + Code: http.StatusInternalServerError, + JSON: struct{}{}, + } + } if err != nil { return util.JSONResponse{ Code: http.StatusBadGateway, diff --git a/syncapi/sync/keyextension.go b/syncapi/sync/keyextension.go index 7643ec797..d111d1395 100644 --- a/syncapi/sync/keyextension.go +++ b/syncapi/sync/keyextension.go @@ -16,9 +16,10 @@ package sync import ( "context" + "sync" + encryptoapi "github.com/matrix-org/dendrite/encryptoapi/storage" "github.com/matrix-org/dendrite/syncapi/types" - "sync" ) type keyCounter struct { @@ -55,10 +56,10 @@ func KeyCountEXT( respOut = &respIn // when extension works at the very beginning resp, err := encryptionDB.SyncOneTimeCount(ctx, userID, deviceID) - CounterWrite(userID, resp) if err != nil { return } + CounterWrite(userID, resp) respOut.SignNum = resp return } diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 0a82565ff..4aefb9aad 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -46,7 +46,7 @@ func NewRequestPool(db *storage.SyncServerDatasource, n *Notifier, adb *accounts // called in a dedicated goroutine for this request. This function will block the goroutine // until a response is ready, or it times out. func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtypes.Device, encryptDB *encryptoapi.Database) util.JSONResponse { - var syncData *types.Response + var syncData *types.Response // Extract values from request logger := util.GetLogger(req.Context()) userID := device.UserID @@ -115,12 +115,11 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype // of calculating the sync only to get timed out before we // can respond - // syncData, err = rp.currentSyncForUser(*syncReq, currPos) - syncData, err := rp.currentSyncForUser(*syncReq, currPos) + syncData, err = rp.currentSyncForUser(*syncReq, currPos) // std extension consideration // Have to check which "position" must be used here - // syncData = storage.StdEXT(syncReq.ctx, rp.db, *syncData, syncReq.device.UserID, syncReq.device.ID, int64(currPos)) + syncData = storage.StdEXT(syncReq.ctx, rp.db, *syncData, syncReq.device.UserID, syncReq.device.ID, currPos.TypingPosition) // int64(currPos)) syncData = KeyCountEXT(syncReq.ctx, encryptDB, *syncData, syncReq.device.UserID, syncReq.device.ID) if err != nil {