summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-10-27 15:09:05 +0100
committerErik Johnston <erik@matrix.org>2017-10-27 15:09:05 +0100
commit6980c4557e846c8a4a7f9d9eccf928f68e66fca8 (patch)
treeefb086925df0f845d3e16bd6cb41adbfc6fe8fd0
parentMerge branch 'erikj/attestation_local_fix' of github.com:matrix-org/synapse i... (diff)
parentAdd jitter to validity period of attestations (diff)
downloadsynapse-6980c4557e846c8a4a7f9d9eccf928f68e66fca8.tar.xz
Merge branch 'erikj/attestation_jitter' of github.com:matrix-org/synapse into develop
-rw-r--r--synapse/groups/attestations.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/synapse/groups/attestations.py b/synapse/groups/attestations.py
index 28bbff9bbb..1fb709e6c3 100644
--- a/synapse/groups/attestations.py
+++ b/synapse/groups/attestations.py
@@ -36,6 +36,7 @@ An attestsation is a signed blob of json that looks like:
 """
 
 import logging
+import random
 
 from twisted.internet import defer
 
@@ -52,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
 
@@ -100,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)