diff --git a/synapse/events/builder.py b/synapse/events/builder.py index 03ea2ef14f..481eb2d375 100644 --- a/synapse/events/builder.py +++ b/synapse/events/builder.py @@ -14,9 +14,9 @@ # limitations under the License. import copy +import string from synapse.types import EventID -from synapse.util.stringutils import random_string from . import EventBase, FrozenEvent, _event_dict_property @@ -49,10 +49,10 @@ class EventBuilderFactory(object): self.event_id_count = 0 def create_event_id(self): - i = str(self.event_id_count) + i = self.event_id_count self.event_id_count += 1 - local_part = random_string(3) + str(i) + local_part = _encode_id(i) e_id = EventID(local_part, self.hostname) @@ -73,3 +73,19 @@ class EventBuilderFactory(object): key_values["signatures"] = {} return EventBuilder(key_values=key_values,) + + +def _numberToBase(n, b): + if n == 0: + return [0] + digits = [] + while n: + digits.append(int(n % b)) + n //= b + return digits[::-1] + + +def _encode_id(i): + digits = string.digits + string.ascii_letters + val_slice = _numberToBase(i, len(digits)) + return "".join(digits[x] for x in val_slice) diff --git a/synapse/federation/federation_base.py b/synapse/federation/federation_base.py index 85fcd899c3..14b4482a35 100644 --- a/synapse/federation/federation_base.py +++ b/synapse/federation/federation_base.py @@ -26,7 +26,7 @@ from synapse.crypto.event_signing import check_event_content_hash from synapse.events import FrozenEvent from synapse.events.utils import prune_event from synapse.http.servlet import assert_params_in_dict -from synapse.types import get_domain_from_id +from synapse.types import get_domain_from_id, EventID from synapse.util import logcontext, unwrapFirstError logger = logging.getLogger(__name__) @@ -326,6 +326,14 @@ def event_from_pdu_json(pdu_json, outlier=False): elif depth > MAX_DEPTH: raise SynapseError(400, "Depth too large", Codes.BAD_JSON) + event_id = pdu_json["event_id"] + if event_id[0] != "$": + pdu_json["event_id"] = EventID( + event_id, + get_domain_from_id(pdu_json["sender"]), + ).to_string() + event_id = pdu_json["event_id"] + dtab = pdu_json.get("unsigned", {}).pop("dtab", None) if dtab: diff --git a/synapse/federation/units.py b/synapse/federation/units.py index 1f95bb5375..20822414a5 100644 --- a/synapse/federation/units.py +++ b/synapse/federation/units.py @@ -20,6 +20,7 @@ server protocol. import itertools import logging +from synapse.types import get_localpart_from_id from synapse.util.jsonobject import JsonEncodedObject logger = logging.getLogger(__name__) @@ -129,6 +130,8 @@ def _mangle_pdu(pdu_json): pdu_json["auth_events"] = list(_strip_hashes(pdu_json["auth_events"])) pdu_json["prev_events"] = list(_strip_hashes(pdu_json["prev_events"])) + pdu_json["event_id"] = get_localpart_from_id(pdu_json["event_id"]) + destinations = pdu_json["unsigned"].pop("destinations", None) if destinations: new_destinations = {} diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 4b38bfd599..5c6b54721a 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -1442,7 +1442,6 @@ class FederationHandler(BaseHandler): if not joined: logger.error("Giving up on trying to auto-accept invite: too many attempts") - @defer.inlineCallbacks def do_remotely_reject_invite(self, target_hosts, room_id, user_id): origin, event = yield self._make_and_verify_event(