mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-19 01:21:09 +03:00
Reduce size of fed transaction IDs
This commit is contained in:
parent
6eca7dc3e8
commit
b951f35572
2 changed files with 24 additions and 4 deletions
|
@ -17,6 +17,7 @@ import logging
|
||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
import opentracing
|
import opentracing
|
||||||
|
import string
|
||||||
|
|
||||||
from six import itervalues
|
from six import itervalues
|
||||||
|
|
||||||
|
@ -135,7 +136,7 @@ class TransactionQueue(object):
|
||||||
self.last_device_list_stream_id_by_dest = {}
|
self.last_device_list_stream_id_by_dest = {}
|
||||||
|
|
||||||
# HACK to get unique tx id
|
# HACK to get unique tx id
|
||||||
self._next_txn_id = int(self.clock.time_msec())
|
self._next_txn_id = 1
|
||||||
|
|
||||||
self._order = 1
|
self._order = 1
|
||||||
|
|
||||||
|
@ -486,7 +487,7 @@ class TransactionQueue(object):
|
||||||
|
|
||||||
pending_pdus = []
|
pending_pdus = []
|
||||||
while True:
|
while True:
|
||||||
txn_id = str(self._next_txn_id)
|
txn_id = _encode_id(self._next_txn_id)
|
||||||
self._next_txn_id += 1
|
self._next_txn_id += 1
|
||||||
|
|
||||||
for s in pdu_spans.values():
|
for s in pdu_spans.values():
|
||||||
|
@ -860,3 +861,19 @@ class TransactionQueue(object):
|
||||||
new_destinations = set(pdu.unsigned.get("destinations", []))
|
new_destinations = set(pdu.unsigned.get("destinations", []))
|
||||||
new_destinations.discard(destination)
|
new_destinations.discard(destination)
|
||||||
yield self._send_pdu(pdu, list(new_destinations), span)
|
yield self._send_pdu(pdu, list(new_destinations), span)
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
|
@ -194,8 +194,11 @@ class _WrappedConnection(object):
|
||||||
# In Twisted >18.4; the TLS connection will be None if it has closed
|
# In Twisted >18.4; the TLS connection will be None if it has closed
|
||||||
# which will make abortConnection() throw. Check that the TLS connection
|
# which will make abortConnection() throw. Check that the TLS connection
|
||||||
# is not None before trying to close it.
|
# is not None before trying to close it.
|
||||||
|
try:
|
||||||
if self.transport.getHandle() is not None:
|
if self.transport.getHandle() is not None:
|
||||||
self.transport.abortConnection()
|
self.transport.abortConnection()
|
||||||
|
except:
|
||||||
|
logger.warning("Failed to abort connection")
|
||||||
|
|
||||||
def request(self, request):
|
def request(self, request):
|
||||||
self.last_request = time.time()
|
self.last_request = time.time()
|
||||||
|
|
Loading…
Reference in a new issue