Store all signatures on events rather than just dropping them
This commit is contained in:
parent
59cf6f5ec9
commit
f04b3d5042
|
@ -279,13 +279,14 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||||
)
|
)
|
||||||
|
|
||||||
if hasattr(event, "signatures"):
|
if hasattr(event, "signatures"):
|
||||||
signatures = event.signatures.get(event.origin, {})
|
logger.debug("sigs: %s", event.signatures)
|
||||||
|
for name, sigs in event.signatures.items():
|
||||||
for key_id, signature_base64 in signatures.items():
|
for key_id, signature_base64 in sigs.items():
|
||||||
signature_bytes = decode_base64(signature_base64)
|
signature_bytes = decode_base64(signature_base64)
|
||||||
self._store_event_origin_signature_txn(
|
self._store_event_signature_txn(
|
||||||
txn, event.event_id, event.origin, key_id, signature_bytes,
|
txn, event.event_id, name, key_id,
|
||||||
)
|
signature_bytes,
|
||||||
|
)
|
||||||
|
|
||||||
for prev_event_id, prev_hashes in event.prev_events:
|
for prev_event_id, prev_hashes in event.prev_events:
|
||||||
for alg, hash_base64 in prev_hashes.items():
|
for alg, hash_base64 in prev_hashes.items():
|
||||||
|
|
|
@ -470,12 +470,15 @@ class SQLBaseStore(object):
|
||||||
select_event_sql = "SELECT * FROM events WHERE event_id = ?"
|
select_event_sql = "SELECT * FROM events WHERE event_id = ?"
|
||||||
|
|
||||||
for i, ev in enumerate(events):
|
for i, ev in enumerate(events):
|
||||||
signatures = self._get_event_origin_signatures_txn(
|
signatures = self._get_event_signatures_txn(
|
||||||
txn, ev.event_id,
|
txn, ev.event_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
ev.signatures = {
|
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)
|
prevs = self._get_prev_events_and_state(txn, ev.event_id)
|
||||||
|
|
|
@ -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,
|
event_id TEXT,
|
||||||
origin TEXT,
|
signature_name TEXT,
|
||||||
key_id TEXT,
|
key_id TEXT,
|
||||||
signature BLOB,
|
signature BLOB,
|
||||||
CONSTRAINT uniqueness UNIQUE (event_id, key_id)
|
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
|
event_id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -103,24 +103,30 @@ class SignatureStore(SQLBaseStore):
|
||||||
or_ignore=True,
|
or_ignore=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _get_event_signatures_txn(self, txn, event_id):
|
||||||
def _get_event_origin_signatures_txn(self, txn, event_id):
|
|
||||||
"""Get all the signatures for a given PDU.
|
"""Get all the signatures for a given PDU.
|
||||||
Args:
|
Args:
|
||||||
txn (cursor):
|
txn (cursor):
|
||||||
event_id (str): Id for the Event.
|
event_id (str): Id for the Event.
|
||||||
Returns:
|
Returns:
|
||||||
A dict of key_id -> signature_bytes.
|
A dict of sig name -> dict(key_id -> signature_bytes)
|
||||||
"""
|
"""
|
||||||
query = (
|
query = (
|
||||||
"SELECT key_id, signature"
|
"SELECT signature_name, key_id, signature"
|
||||||
" FROM event_origin_signatures"
|
" FROM event_signatures"
|
||||||
" WHERE event_id = ? "
|
" WHERE event_id = ? "
|
||||||
)
|
)
|
||||||
txn.execute(query, (event_id, ))
|
txn.execute(query, (event_id, ))
|
||||||
return dict(txn.fetchall())
|
rows = txn.fetchall()
|
||||||
|
|
||||||
def _store_event_origin_signature_txn(self, txn, event_id, origin, key_id,
|
res = {}
|
||||||
|
|
||||||
|
for name, key, sig in rows:
|
||||||
|
res.setdefault(name, {})[key] = sig
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
def _store_event_signature_txn(self, txn, event_id, signature_name, key_id,
|
||||||
signature_bytes):
|
signature_bytes):
|
||||||
"""Store a signature from the origin server for a PDU.
|
"""Store a signature from the origin server for a PDU.
|
||||||
Args:
|
Args:
|
||||||
|
@ -132,10 +138,10 @@ class SignatureStore(SQLBaseStore):
|
||||||
"""
|
"""
|
||||||
self._simple_insert_txn(
|
self._simple_insert_txn(
|
||||||
txn,
|
txn,
|
||||||
"event_origin_signatures",
|
"event_signatures",
|
||||||
{
|
{
|
||||||
"event_id": event_id,
|
"event_id": event_id,
|
||||||
"origin": origin,
|
"signature_name": signature_name,
|
||||||
"key_id": key_id,
|
"key_id": key_id,
|
||||||
"signature": buffer(signature_bytes),
|
"signature": buffer(signature_bytes),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue