diff --git a/minode/proofofwork.py b/minode/proofofwork.py index a929cbb..d22dc34 100644 --- a/minode/proofofwork.py +++ b/minode/proofofwork.py @@ -11,7 +11,7 @@ import struct import threading import time -from . import shared, structure +from . import message, shared, structure def _pow_worker(target, initial_hash, q): @@ -100,13 +100,26 @@ class Worker(threading.Thread): return obj + @staticmethod + def _publish(obj): + with shared.objects_lock: + shared.objects[obj.vector] = obj + shared.vector_advertise_queue.put(obj.vector) + def run(self): if self.obj: - obj = self.add_pow(self.obj) + self._publish(self.add_pow(self.obj)) + return - with shared.objects_lock: - shared.objects[obj.vector] = obj - shared.vector_advertise_queue.put(obj.vector) + while not shared.shutting_down: + data = shared.objects_queue.get() + + obj = structure.Object.from_message( + message.Message.from_bytes(data)) + if int.from_bytes(obj.nonce, 'big') == 0: + obj = self.add_pow(obj) + + self._publish(obj) def do_pow_and_publish(obj): diff --git a/minode/shared.py b/minode/shared.py index d49786c..6991650 100644 --- a/minode/shared.py +++ b/minode/shared.py @@ -64,3 +64,5 @@ connection_limit = 250 objects = {} objects_lock = threading.Lock() + +objects_queue = queue.Queue()