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

Commit 45e8f77

Browse files
authored
Rename get_e2e_device_keys to better reflect its purpose (#8205)
... and to show that it does something slightly different to `_get_e2e_device_keys_txn`. `include_all_devices` and `include_deleted_devices` were never used (and `include_deleted_devices` was broken, since that would cause `None`s in the result which were not handled in the loop below. Add some typing too.
1 parent 8027166 commit 45e8f77

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

changelog.d/8205.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactor queries for device keys and cross-signatures.

synapse/handlers/e2e_keys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ async def query_local_devices(
353353
# make sure that each queried user appears in the result dict
354354
result_dict[user_id] = {}
355355

356-
results = await self.store.get_e2e_device_keys(local_query)
356+
results = await self.store.get_e2e_device_keys_for_cs_api(local_query)
357357

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

739739
if user_id not in devices:
740740
raise NotFoundError("No device keys found")

synapse/storage/databases/main/end_to_end_keys.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from synapse.logging.opentracing import log_kv, set_tag, trace
2424
from synapse.storage._base import SQLBaseStore, db_to_json
2525
from synapse.storage.database import make_in_list_sql_clause
26+
from synapse.types import JsonDict
2627
from synapse.util import json_encoder
2728
from synapse.util.caches.descriptors import cached, cachedList
2829
from synapse.util.iterutils import batch_iter
@@ -33,17 +34,12 @@
3334

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

5652
results = await self.db_pool.runInteraction(
57-
"get_e2e_device_keys",
58-
self._get_e2e_device_keys_txn,
59-
query_list,
60-
include_all_devices,
61-
include_deleted_devices,
53+
"get_e2e_device_keys", self._get_e2e_device_keys_txn, query_list,
6254
)
6355

6456
# Build the result structure, un-jsonify the results, and add the

tests/storage/test_end_to_end_keys.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_key_without_device_name(self):
3737
)
3838

3939
res = yield defer.ensureDeferred(
40-
self.store.get_e2e_device_keys((("user", "device"),))
40+
self.store.get_e2e_device_keys_for_cs_api((("user", "device"),))
4141
)
4242
self.assertIn("user", res)
4343
self.assertIn("device", res["user"])
@@ -76,7 +76,7 @@ def test_get_key_with_device_name(self):
7676
)
7777

7878
res = yield defer.ensureDeferred(
79-
self.store.get_e2e_device_keys((("user", "device"),))
79+
self.store.get_e2e_device_keys_for_cs_api((("user", "device"),))
8080
)
8181
self.assertIn("user", res)
8282
self.assertIn("device", res["user"])
@@ -108,7 +108,9 @@ def test_multiple_devices(self):
108108
)
109109

110110
res = yield defer.ensureDeferred(
111-
self.store.get_e2e_device_keys((("user1", "device1"), ("user2", "device2")))
111+
self.store.get_e2e_device_keys_for_cs_api(
112+
(("user1", "device1"), ("user2", "device2"))
113+
)
112114
)
113115
self.assertIn("user1", res)
114116
self.assertIn("device1", res["user1"])

0 commit comments

Comments
 (0)