Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Rename get_e2e_device_keys to better reflect its purpose #8205

Merged
merged 2 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8205.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor queries for device keys and cross-signatures.
4 changes: 2 additions & 2 deletions synapse/handlers/e2e_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ async def query_local_devices(
# make sure that each queried user appears in the result dict
result_dict[user_id] = {}

results = await self.store.get_e2e_device_keys(local_query)
results = await self.store.get_e2e_device_keys_for_cs_api(local_query)

# Build the result structure
for user_id, device_keys in results.items():
Expand Down Expand Up @@ -734,7 +734,7 @@ async def _process_self_signatures(self, user_id, signatures):
# fetch our stored devices. This is used to 1. verify
# signatures on the master key, and 2. to compare with what
# was sent if the device was signed
devices = await self.store.get_e2e_device_keys([(user_id, None)])
devices = await self.store.get_e2e_device_keys_for_cs_api([(user_id, None)])

if user_id not in devices:
raise NotFoundError("No device keys found")
Expand Down
20 changes: 6 additions & 14 deletions synapse/storage/databases/main/end_to_end_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from synapse.logging.opentracing import log_kv, set_tag, trace
from synapse.storage._base import SQLBaseStore, db_to_json
from synapse.storage.database import make_in_list_sql_clause
from synapse.types import JsonDict
from synapse.util import json_encoder
from synapse.util.caches.descriptors import cached, cachedList
from synapse.util.iterutils import batch_iter
Expand All @@ -33,17 +34,12 @@

class EndToEndKeyWorkerStore(SQLBaseStore):
@trace
async def get_e2e_device_keys(
self, query_list, include_all_devices=False, include_deleted_devices=False
):
"""Fetch a list of device keys.
async def get_e2e_device_keys_for_cs_api(
self, query_list: List[Tuple[str, Optional[str]]]
) -> Dict[str, Dict[str, JsonDict]]:
"""Fetch a list of device keys, formatted suitably for the C/S API.
Args:
query_list(list): List of pairs of user_ids and device_ids.
include_all_devices (bool): whether to include entries for devices
that don't have device keys
include_deleted_devices (bool): whether to include null entries for
devices which no longer exist (but were in the query_list).
This option only takes effect if include_all_devices is true.
Returns:
Dict mapping from user-id to dict mapping from device_id to
key data. The key data will be a dict in the same format as the
Expand All @@ -54,11 +50,7 @@ async def get_e2e_device_keys(
return {}

results = await self.db_pool.runInteraction(
"get_e2e_device_keys",
self._get_e2e_device_keys_txn,
query_list,
include_all_devices,
include_deleted_devices,
"get_e2e_device_keys", self._get_e2e_device_keys_txn, query_list,
)

# Build the result structure, un-jsonify the results, and add the
Expand Down
8 changes: 5 additions & 3 deletions tests/storage/test_end_to_end_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_key_without_device_name(self):
)

res = yield defer.ensureDeferred(
self.store.get_e2e_device_keys((("user", "device"),))
self.store.get_e2e_device_keys_for_cs_api((("user", "device"),))
)
self.assertIn("user", res)
self.assertIn("device", res["user"])
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_get_key_with_device_name(self):
)

res = yield defer.ensureDeferred(
self.store.get_e2e_device_keys((("user", "device"),))
self.store.get_e2e_device_keys_for_cs_api((("user", "device"),))
)
self.assertIn("user", res)
self.assertIn("device", res["user"])
Expand Down Expand Up @@ -108,7 +108,9 @@ def test_multiple_devices(self):
)

res = yield defer.ensureDeferred(
self.store.get_e2e_device_keys((("user1", "device1"), ("user2", "device2")))
self.store.get_e2e_device_keys_for_cs_api(
(("user1", "device1"), ("user2", "device2"))
)
)
self.assertIn("user1", res)
self.assertIn("device1", res["user1"])
Expand Down