From 76c9af193cb46337cd1e618b46508d7f0ee912e7 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 7 Nov 2017 13:32:35 +0000 Subject: [PATCH] Revert "Merge branch 'master' of github.com:matrix-org/synapse into develop" This reverts commit f9b255cd62fe724e16b2222f6af623b2d39282ab, reversing changes made to 1bd654dabde776bbb7ee365c115b307cd6a110b8. --- synapse/groups/attestations.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/synapse/groups/attestations.py b/synapse/groups/attestations.py index 784af9cbc..1fb709e6c 100644 --- a/synapse/groups/attestations.py +++ b/synapse/groups/attestations.py @@ -53,6 +53,11 @@ logger = logging.getLogger(__name__) # Default validity duration for new attestations we create DEFAULT_ATTESTATION_LENGTH_MS = 3 * 24 * 60 * 60 * 1000 +# We add some jitter to the validity duration of attestations so that if we +# add lots of users at once we don't need to renew them all at once. +# The jitter is a multiplier picked randomly between the first and second number +DEFAULT_ATTESTATION_JITTER = (0.9, 1.3) + # Start trying to update our attestations when they come this close to expiring UPDATE_ATTESTATION_TIME_MS = 1 * 24 * 60 * 60 * 1000 @@ -101,10 +106,14 @@ class GroupAttestationSigning(object): """Create an attestation for the group_id and user_id with default validity length. """ + validity_period = DEFAULT_ATTESTATION_LENGTH_MS + validity_period *= random.uniform(*DEFAULT_ATTESTATION_JITTER) + valid_until_ms = int(self.clock.time_msec() + validity_period) + return sign_json({ "group_id": group_id, "user_id": user_id, - "valid_until_ms": self.clock.time_msec() + DEFAULT_ATTESTATION_LENGTH_MS, + "valid_until_ms": valid_until_ms, }, self.server_name, self.signing_key)