remove delay from udp write

This commit is contained in:
Jack Robison 2018-03-27 21:08:01 -04:00
parent 5bab6f7d39
commit eabf4a0e40
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 2 additions and 27 deletions

View file

@ -1,21 +0,0 @@
class Delay(object):
maxToSendDelay = 10 ** -3 # 0.05
minToSendDelay = 10 ** -5 # 0.01
def __init__(self, start=0, getTime=None):
self._next = start
if not getTime:
from time import time as getTime
self._getTime = getTime
# TODO: explain why this logic is like it is. And add tests that
# show that it actually does what it needs to do.
def __call__(self):
ts = self._getTime()
if ts >= self._next:
delay = self.minToSendDelay
self._next = ts + self.minToSendDelay
else:
delay = (self._next - ts) + self.maxToSendDelay
self._next += self.maxToSendDelay
return delay

View file

@ -11,7 +11,6 @@ import msgtypes
import msgformat
from contact import Contact
from error import BUILTIN_EXCEPTIONS, UnknownRemoteException, TimeoutError
from delay import Delay
log = logging.getLogger(__name__)
@ -28,7 +27,6 @@ class KademliaProtocol(protocol.DatagramProtocol):
self._sentMessages = {}
self._partialMessages = {}
self._partialMessagesProgress = {}
self._delay = Delay(0, self._node.clock.seconds)
def sendRPC(self, contact, method, args, rawResponse=False):
""" Sends an RPC to the specified contact
@ -208,11 +206,9 @@ class KademliaProtocol(protocol.DatagramProtocol):
def _scheduleSendNext(self, txData, address):
"""Schedule the sending of the next UDP packet """
delay = self._delay()
key = object()
delayed_call, _ = self._node.reactor_callLater(delay, self._write_and_remove, key, txData, address)
delayed_call, _ = self._node.reactor_callLater(0, self._write, txData, address)
def _write_and_remove(self, key, txData, address):
def _write(self, txData, address):
if self.transport:
try:
self.transport.write(txData, address)