From 74c85b4a9e5a61450c23aeabca9b410b7b80ed8b Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sat, 25 Feb 2017 23:40:37 +0100 Subject: [PATCH] Retransmit timing changes - makes it behave more like in the description - partial for #847 --- src/class_singleWorker.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index 863fbde9..0190e1c5 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -609,11 +609,9 @@ class singleWorker(threading.Thread, StoppableThread): # At this point we know that we have the necessary pubkey in the pubkeys table. - if retryNumber == 0: - if TTL > 28 * 24 * 60 * 60: - TTL = 28 * 24 * 60 * 60 - else: - TTL = 28 * 24 * 60 * 60 + TTL *= 2**retryNumber + if TTL > 28 * 24 * 60 * 60: + TTL = 28 * 24 * 60 * 60 TTL = int(TTL + random.randrange(-300, 300))# add some randomness to the TTL embeddedTime = int(time.time() + TTL) @@ -834,10 +832,8 @@ class singleWorker(threading.Thread, StoppableThread): newStatus = 'msgsentnoackexpected' else: newStatus = 'msgsent' - if retryNumber == 0: - sleepTill = int(time.time()) + TTL - else: - sleepTill = int(time.time()) + 28*24*60*60 * 2**retryNumber + # wait 10% past expiration + sleepTill = int(time.time() + TTL * 1.1) sqlExecute('''UPDATE sent SET msgid=?, status=?, retrynumber=?, sleeptill=?, lastactiontime=? WHERE ackdata=?''', inventoryHash, newStatus, @@ -896,9 +892,9 @@ class singleWorker(threading.Thread, StoppableThread): if tag not in state.neededPubkeys: state.neededPubkeys[tag] = (toAddress, highlevelcrypto.makeCryptor(hexlify(privEncryptionKey))) # We'll need this for when we receive a pubkey reply: it will be encrypted and we'll need to decrypt it. - if retryNumber == 0: - TTL = 2.5*24*60*60 # 2.5 days. This was chosen fairly arbitrarily. - else: + TTL = 2.5*24*60*60 # 2.5 days. This was chosen fairly arbitrarily. + TTL *= 2**retryNumber + if TTL > 28*24*60*60: TTL = 28*24*60*60 TTL = TTL + random.randrange(-300, 300) # add some randomness to the TTL embeddedTime = int(time.time() + TTL) @@ -934,10 +930,8 @@ class singleWorker(threading.Thread, StoppableThread): protocol.broadcastToSendDataQueues(( streamNumber, 'advertiseobject', inventoryHash)) - if retryNumber == 0: - sleeptill = int(time.time()) + TTL - else: - sleeptill = int(time.time()) + 28*24*60*60 * 2**retryNumber + # wait 10% past expiration + sleeptill = int(time.time() + TTL * 1.1) sqlExecute( '''UPDATE sent SET lastactiontime=?, status='awaitingpubkey', retrynumber=?, sleeptill=? WHERE toaddress=? AND (status='doingpubkeypow' OR status='awaitingpubkey') ''', int(time.time()),