From 2725281a6db147a627c74a98a36bb58e5803f1ea Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Fri, 6 Sep 2013 18:58:56 -0400 Subject: [PATCH] initial testing inv refactorization --- src/class_objectHashHolder.py | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/class_objectHashHolder.py diff --git a/src/class_objectHashHolder.py b/src/class_objectHashHolder.py new file mode 100644 index 00000000..cc636a8d --- /dev/null +++ b/src/class_objectHashHolder.py @@ -0,0 +1,39 @@ +# objectHashHolder is a timer-driven thread. One objectHashHolder thread is used +# by each sendDataThread. It uses it whenever a sendDataThread needs to +# advertise an object to peers. Instead of sending it out immediately, it must +# wait a random number of seconds for each connection so that different peers +# get different objects at different times. Thus an attacker who is +# connecting to many network nodes who receives a message first from Alice +# cannot be sure if Alice is the node who originated the message. + +import random +import time +import threading + +class objectHashHolder(threading.Thread): + def __init__(self, sendDataThreadMailbox): + threading.Thread.__init__(self) + self.shutdown = False + self.sendDataThreadMailbox = sendDataThreadMailbox # This queue is used to submit data back to our associated sendDataThread. + self.collectionOfLists = {} + for i in range(10): + self.collectionOfLists[i] = [] + + def run(self): + print 'objectHashHolder running.' + iterator = 0 + while not self.shutdown: + if len(self.collectionOfLists[iterator]) > 0: + print 'objectHashHolder is submitting', len(self.collectionOfLists[iterator]), 'items to the queue.' + self.sendDataThreadMailbox.put((0, 'sendinv', self.collectionOfLists[iterator])) + self.collectionOfLists[iterator] = [] + iterator += 1 + iterator %= 10 + time.sleep(1) + print 'objectHashHolder shutting down.' + + def holdHash(self,hash): + self.collectionOfLists[random.randrange(0, 10)].append(hash) + + def close(self): + self.shutdown = True \ No newline at end of file