summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-11-12 17:02:18 +0000
committerErik Johnston <erik@matrix.org>2014-11-12 17:02:34 +0000
commitf04b3d5042b85fa81efff9b561ca7af8d9709756 (patch)
tree08a37b4e2d62315f1ea6cd5bd0ccba9630594c12
parentAdd more recents service unit tests. (diff)
downloadsynapse-f04b3d5042b85fa81efff9b561ca7af8d9709756.tar.xz
Store all signatures on events rather than just dropping them
-rw-r--r--synapse/storage/__init__.py15
-rw-r--r--synapse/storage/_base.py7
-rw-r--r--synapse/storage/schema/event_signatures.sql6
-rw-r--r--synapse/storage/signatures.py24
4 files changed, 31 insertions, 21 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 72290eb5a0..d8f351a675 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -279,13 +279,14 @@ class DataStore(RoomMemberStore, RoomStore,
             )
 
         if hasattr(event, "signatures"):
-            signatures = event.signatures.get(event.origin, {})
-
-            for key_id, signature_base64 in signatures.items():
-                signature_bytes = decode_base64(signature_base64)
-                self._store_event_origin_signature_txn(
-                    txn, event.event_id, event.origin, key_id, signature_bytes,
-                )
+            logger.debug("sigs: %s", event.signatures)
+            for name, sigs in event.signatures.items():
+                for key_id, signature_base64 in sigs.items():
+                    signature_bytes = decode_base64(signature_base64)
+                    self._store_event_signature_txn(
+                        txn, event.event_id, name, key_id,
+                        signature_bytes,
+                    )
 
         for prev_event_id, prev_hashes in event.prev_events:
             for alg, hash_base64 in prev_hashes.items():
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index a1ee0318f6..670387b04a 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -470,12 +470,15 @@ class SQLBaseStore(object):
         select_event_sql = "SELECT * FROM events WHERE event_id = ?"
 
         for i, ev in enumerate(events):
-            signatures = self._get_event_origin_signatures_txn(
+            signatures = self._get_event_signatures_txn(
                 txn, ev.event_id,
             )
 
             ev.signatures = {
-                k: encode_base64(v) for k, v in signatures.items()
+                n: {
+                    k: encode_base64(v) for k, v in s.items()
+                }
+                for n, s in signatures.items()
             }
 
             prevs = self._get_prev_events_and_state(txn, ev.event_id)
diff --git a/synapse/storage/schema/event_signatures.sql b/synapse/storage/schema/event_signatures.sql
index 5491c7ecec..4efa8a3e63 100644
--- a/synapse/storage/schema/event_signatures.sql
+++ b/synapse/storage/schema/event_signatures.sql
@@ -37,15 +37,15 @@ CREATE INDEX IF NOT EXISTS event_reference_hashes_id ON event_reference_hashes (
 );
 
 
-CREATE TABLE IF NOT EXISTS event_origin_signatures (
+CREATE TABLE IF NOT EXISTS event_signatures (
     event_id TEXT,
-    origin TEXT,
+    signature_name TEXT,
     key_id TEXT,
     signature BLOB,
     CONSTRAINT uniqueness UNIQUE (event_id, key_id)
 );
 
-CREATE INDEX IF NOT EXISTS event_origin_signatures_id ON event_origin_signatures (
+CREATE INDEX IF NOT EXISTS event_signatures_id ON event_signatures (
     event_id
 );
 
diff --git a/synapse/storage/signatures.py b/synapse/storage/signatures.py
index 84a49088a2..d90e08fff1 100644
--- a/synapse/storage/signatures.py
+++ b/synapse/storage/signatures.py
@@ -103,24 +103,30 @@ class SignatureStore(SQLBaseStore):
             or_ignore=True,
         )
 
-
-    def _get_event_origin_signatures_txn(self, txn, event_id):
+    def _get_event_signatures_txn(self, txn, event_id):
         """Get all the signatures for a given PDU.
         Args:
             txn (cursor):
             event_id (str): Id for the Event.
         Returns:
-            A dict of key_id -> signature_bytes.
+            A dict of sig name -> dict(key_id -> signature_bytes)
         """
         query = (
-            "SELECT key_id, signature"
-            " FROM event_origin_signatures"
+            "SELECT signature_name, key_id, signature"
+            " FROM event_signatures"
             " WHERE event_id = ? "
         )
         txn.execute(query, (event_id, ))
-        return dict(txn.fetchall())
+        rows = txn.fetchall()
+
+        res = {}
+
+        for name, key, sig in rows:
+            res.setdefault(name, {})[key] = sig
+
+        return res
 
-    def _store_event_origin_signature_txn(self, txn, event_id, origin, key_id,
+    def _store_event_signature_txn(self, txn, event_id, signature_name, key_id,
                                           signature_bytes):
         """Store a signature from the origin server for a PDU.
         Args:
@@ -132,10 +138,10 @@ class SignatureStore(SQLBaseStore):
         """
         self._simple_insert_txn(
             txn,
-            "event_origin_signatures",
+            "event_signatures",
             {
                 "event_id": event_id,
-                "origin": origin,
+                "signature_name": signature_name,
                 "key_id": key_id,
                 "signature": buffer(signature_bytes),
             },