mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-12-15 16:21:00 -05:00
Start implementing auth chains
This commit is contained in:
parent
8421cabb9d
commit
bf6b72eb55
8 changed files with 115 additions and 6 deletions
|
|
@ -19,7 +19,6 @@ from synapse.api.events.room import (
|
|||
RoomMemberEvent, RoomTopicEvent, FeedbackEvent,
|
||||
RoomNameEvent,
|
||||
RoomJoinRulesEvent,
|
||||
RoomPowerLevelsEvent,
|
||||
RoomRedactionEvent,
|
||||
)
|
||||
|
||||
|
|
@ -302,6 +301,17 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||
txn, event.event_id, prev_event_id, alg, hash_bytes
|
||||
)
|
||||
|
||||
for auth_id, _ in event.auth_events:
|
||||
self._simple_insert_txn(
|
||||
txn,
|
||||
table="event_auth",
|
||||
values={
|
||||
"event_id": event.event_id,
|
||||
"room_id": event.room_id,
|
||||
"auth_id": auth_id,
|
||||
},
|
||||
)
|
||||
|
||||
(ref_alg, ref_hash_bytes) = compute_event_reference_hash(event)
|
||||
self._store_event_reference_hash_txn(
|
||||
txn, event.event_id, ref_alg, ref_hash_bytes
|
||||
|
|
|
|||
|
|
@ -474,6 +474,8 @@ class SQLBaseStore(object):
|
|||
if is_state == 0
|
||||
]
|
||||
|
||||
ev.auth_events = self._get_auth_events(txn, ev.event_id)
|
||||
|
||||
if hasattr(ev, "state_key"):
|
||||
ev.prev_state = [
|
||||
(e_id, h)
|
||||
|
|
|
|||
|
|
@ -139,6 +139,27 @@ class EventFederationStore(SQLBaseStore):
|
|||
|
||||
return results
|
||||
|
||||
def _get_auth_events(self, txn, event_id):
|
||||
auth_ids = self._simple_select_onecol_txn(
|
||||
txn,
|
||||
table="event_auth",
|
||||
keyvalues={
|
||||
"event_id": event_id,
|
||||
},
|
||||
retcol="auth_id",
|
||||
)
|
||||
|
||||
results = []
|
||||
for auth_id in auth_ids:
|
||||
hashes = self._get_event_reference_hashes_txn(txn, auth_id)
|
||||
prev_hashes = {
|
||||
k: encode_base64(v) for k, v in hashes.items()
|
||||
if k == "sha256"
|
||||
}
|
||||
results.append((auth_id, prev_hashes))
|
||||
|
||||
return results
|
||||
|
||||
def get_min_depth(self, room_id):
|
||||
return self.runInteraction(
|
||||
"get_min_depth",
|
||||
|
|
|
|||
|
|
@ -63,3 +63,13 @@ CREATE INDEX IF NOT EXISTS st_extrem_keys ON state_forward_extremities(
|
|||
);
|
||||
CREATE INDEX IF NOT EXISTS st_extrem_id ON state_forward_extremities(event_id);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS event_auth(
|
||||
event_id TEXT NOT NULL,
|
||||
auth_id TEXT NOT NULL,
|
||||
room_id TEXT NOT NULL,
|
||||
CONSTRAINT uniqueness UNIQUE (event_id, auth_id, room_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS evauth_edges_id ON event_auth(event_id);
|
||||
CREATE INDEX IF NOT EXISTS evauth_edges_auth_id ON event_auth(auth_id);
|
||||
|
|
@ -55,6 +55,18 @@ class SignatureStore(SQLBaseStore):
|
|||
or_ignore=True,
|
||||
)
|
||||
|
||||
def get_event_reference_hashes(self, event_ids):
|
||||
def f(txn):
|
||||
return [
|
||||
self._get_event_reference_hashes_txn(txn, ev)
|
||||
for ev in event_ids
|
||||
]
|
||||
|
||||
return self.runInteraction(
|
||||
"get_event_reference_hashes",
|
||||
f
|
||||
)
|
||||
|
||||
def _get_event_reference_hashes_txn(self, txn, event_id):
|
||||
"""Get all the hashes for a given PDU.
|
||||
Args:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue