Reduce size of fed transaction IDs

This commit is contained in:
Erik Johnston 2018-11-28 20:09:39 +00:00 committed by Brendan Abolivier
parent 6eca7dc3e8
commit b951f35572
2 changed files with 24 additions and 4 deletions

View file

@ -17,6 +17,7 @@ import logging
import random
import json
import opentracing
import string
from six import itervalues
@ -135,7 +136,7 @@ class TransactionQueue(object):
self.last_device_list_stream_id_by_dest = {}
# HACK to get unique tx id
self._next_txn_id = int(self.clock.time_msec())
self._next_txn_id = 1
self._order = 1
@ -486,7 +487,7 @@ class TransactionQueue(object):
pending_pdus = []
while True:
txn_id = str(self._next_txn_id)
txn_id = _encode_id(self._next_txn_id)
self._next_txn_id += 1
for s in pdu_spans.values():
@ -860,3 +861,19 @@ class TransactionQueue(object):
new_destinations = set(pdu.unsigned.get("destinations", []))
new_destinations.discard(destination)
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)

View file

@ -194,8 +194,11 @@ class _WrappedConnection(object):
# In Twisted >18.4; the TLS connection will be None if it has closed
# which will make abortConnection() throw. Check that the TLS connection
# is not None before trying to close it.
try:
if self.transport.getHandle() is not None:
self.transport.abortConnection()
except:
logger.warning("Failed to abort connection")
def request(self, request):
self.last_request = time.time()