Remove command chosing ladder in the singleWorker
This commit is contained in:
parent
d1bf8dc711
commit
1c3b3f5487
|
@ -149,52 +149,31 @@ class singleWorker(StoppableThread):
|
||||||
self.busy = 0
|
self.busy = 0
|
||||||
command, data = self.queue.get()
|
command, data = self.queue.get()
|
||||||
self.busy = 1
|
self.busy = 1
|
||||||
if command == 'sendmessage':
|
|
||||||
try:
|
if command == 'resetPoW':
|
||||||
self.sendMsg()
|
|
||||||
except: # noqa:E722
|
|
||||||
self.logger.warning("sendMsg didn't work")
|
|
||||||
elif command == 'sendbroadcast':
|
|
||||||
try:
|
|
||||||
self.sendBroadcast()
|
|
||||||
except: # noqa:E722
|
|
||||||
self.logger.warning("sendBroadcast didn't work")
|
|
||||||
elif command == 'doPOWForMyV2Pubkey':
|
|
||||||
try:
|
|
||||||
self.doPOWForMyV2Pubkey(data)
|
|
||||||
except: # noqa:E722
|
|
||||||
self.logger.warning("doPOWForMyV2Pubkey didn't work")
|
|
||||||
elif command == 'sendOutOrStoreMyV3Pubkey':
|
|
||||||
try:
|
|
||||||
self.sendOutOrStoreMyV3Pubkey(data)
|
|
||||||
except: # noqa:E722
|
|
||||||
self.logger.warning("sendOutOrStoreMyV3Pubkey didn't work")
|
|
||||||
elif command == 'sendOutOrStoreMyV4Pubkey':
|
|
||||||
try:
|
|
||||||
self.sendOutOrStoreMyV4Pubkey(data)
|
|
||||||
except: # noqa:E722
|
|
||||||
self.logger.warning("sendOutOrStoreMyV4Pubkey didn't work")
|
|
||||||
elif command == 'sendOnionPeerObj':
|
|
||||||
try:
|
|
||||||
self.sendOnionPeerObj(data)
|
|
||||||
except: # noqa:E722
|
|
||||||
self.logger.warning("sendOnionPeerObj didn't work")
|
|
||||||
elif command == 'resetPoW':
|
|
||||||
try:
|
try:
|
||||||
proofofwork.resetPoW()
|
proofofwork.resetPoW()
|
||||||
except: # noqa:E722
|
except Exception:
|
||||||
self.logger.warning("proofofwork.resetPoW didn't work")
|
self.logger.warning("resetPoW failed", exc_info=True)
|
||||||
|
self.queue.task_done()
|
||||||
|
continue
|
||||||
elif command == 'stopThread':
|
elif command == 'stopThread':
|
||||||
self.busy = 0
|
self.busy = 0
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
|
try:
|
||||||
|
getattr(self, 'handle_{0}'.format(command))(data)
|
||||||
|
except AttributeError:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
'Probable programming error: The command sent'
|
'Probable programming error: The command sent'
|
||||||
' to the workerThread is weird. It is: %s\n',
|
' to the workerThread is weird. It is: %s\n', command)
|
||||||
command
|
except Exception:
|
||||||
)
|
self.logger.error(
|
||||||
|
"Exception in the command handler for %s!",
|
||||||
|
command, exc_info=True)
|
||||||
|
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|
||||||
self.logger.info("Quitting...")
|
self.logger.info("Quitting...")
|
||||||
|
|
||||||
def _getKeysForAddress(self, address):
|
def _getKeysForAddress(self, address):
|
||||||
|
@ -252,7 +231,7 @@ class singleWorker(StoppableThread):
|
||||||
payload = pack('>Q', nonce) + payload
|
payload = pack('>Q', nonce) + payload
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
def doPOWForMyV2Pubkey(self, adressHash):
|
def handle_doPOWForMyV2Pubkey(self, adressHash):
|
||||||
""" This function also broadcasts out the pubkey
|
""" This function also broadcasts out the pubkey
|
||||||
message once it is done with the POW"""
|
message once it is done with the POW"""
|
||||||
# Look up my stream number based on my address hash
|
# Look up my stream number based on my address hash
|
||||||
|
@ -311,7 +290,7 @@ class singleWorker(StoppableThread):
|
||||||
except: # noqa:E722
|
except: # noqa:E722
|
||||||
self.logger.warning("BMConfigParser().set didn't work")
|
self.logger.warning("BMConfigParser().set didn't work")
|
||||||
|
|
||||||
def sendOutOrStoreMyV3Pubkey(self, adressHash):
|
def handle_sendOutOrStoreMyV3Pubkey(self, adressHash):
|
||||||
"""
|
"""
|
||||||
If this isn't a chan address, this function assembles the pubkey data, does the necessary POW and sends it out.
|
If this isn't a chan address, this function assembles the pubkey data, does the necessary POW and sends it out.
|
||||||
If it *is* a chan then it assembles the pubkey and stores is in the pubkey table so that we can send messages
|
If it *is* a chan then it assembles the pubkey and stores is in the pubkey table so that we can send messages
|
||||||
|
@ -397,7 +376,7 @@ class singleWorker(StoppableThread):
|
||||||
except: # noqa:E722
|
except: # noqa:E722
|
||||||
self.logger.warning("BMConfigParser().set didn't work")
|
self.logger.warning("BMConfigParser().set didn't work")
|
||||||
|
|
||||||
def sendOutOrStoreMyV4Pubkey(self, myAddress):
|
def handle_sendOutOrStoreMyV4Pubkey(self, myAddress):
|
||||||
"""
|
"""
|
||||||
It doesn't send directly anymore. It put is to a queue for another thread to send at an appropriate time,
|
It doesn't send directly anymore. It put is to a queue for another thread to send at an appropriate time,
|
||||||
whereas in the past it directly appended it to the outgoing buffer, I think. Same with all the other methods in
|
whereas in the past it directly appended it to the outgoing buffer, I think. Same with all the other methods in
|
||||||
|
@ -489,7 +468,7 @@ class singleWorker(StoppableThread):
|
||||||
' to the keys.dat file. Error message: %s', err
|
' to the keys.dat file. Error message: %s', err
|
||||||
)
|
)
|
||||||
|
|
||||||
def sendOnionPeerObj(self, peer=None):
|
def handle_sendOnionPeerObj(self, peer=None):
|
||||||
"""Send onionpeer object representing peer"""
|
"""Send onionpeer object representing peer"""
|
||||||
if not peer: # find own onionhostname
|
if not peer: # find own onionhostname
|
||||||
for peer in state.ownAddresses:
|
for peer in state.ownAddresses:
|
||||||
|
@ -527,7 +506,7 @@ class singleWorker(StoppableThread):
|
||||||
hexlify(inventoryHash))
|
hexlify(inventoryHash))
|
||||||
queues.UISignalQueue.put(('updateStatusBar', ''))
|
queues.UISignalQueue.put(('updateStatusBar', ''))
|
||||||
|
|
||||||
def sendBroadcast(self):
|
def handle_sendbroadcast(self, _):
|
||||||
"""Send a broadcast-type object (assemble the object, perform PoW and put it to the inv announcement queue)"""
|
"""Send a broadcast-type object (assemble the object, perform PoW and put it to the inv announcement queue)"""
|
||||||
# Reset just in case
|
# Reset just in case
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
|
@ -712,7 +691,7 @@ class singleWorker(StoppableThread):
|
||||||
inventoryHash, 'broadcastsent', int(time.time()), ackdata
|
inventoryHash, 'broadcastsent', int(time.time()), ackdata
|
||||||
)
|
)
|
||||||
|
|
||||||
def sendMsg(self):
|
def handle_sendmessage(self, _):
|
||||||
"""Send a message-type object (assemble the object, perform PoW and put it to the inv announcement queue)"""
|
"""Send a message-type object (assemble the object, perform PoW and put it to the inv announcement queue)"""
|
||||||
# pylint: disable=too-many-nested-blocks
|
# pylint: disable=too-many-nested-blocks
|
||||||
# Reset just in case
|
# Reset just in case
|
||||||
|
|
Reference in New Issue
Block a user