MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / singleWorker

Class singleWorker

src/class_singleWorker.py:39–997  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37 return "%.1f%s%s" % (num, 'Yi', suffix)
38
39class singleWorker(threading.Thread, StoppableThread):
40
41 def __init__(self):
42 # QThread.__init__(self, parent)
43 threading.Thread.__init__(self, name="singleWorker")
44 self.initStop()
45 proofofwork.init()
46
47 def stopThread(self):
48 try:
49 queues.workerQueue.put(("stopThread", "data"))
50 except:
51 pass
52 super(singleWorker, self).stopThread()
53
54 def run(self):
55
56 while not state.sqlReady and state.shutdown == 0:
57 self.stop.wait(2)
58 if state.shutdown > 0:
59 return
60
61 # Initialize the neededPubkeys dictionary.
62 queryreturn = sqlQuery(
63 '''SELECT DISTINCT toaddress FROM sent WHERE (status='awaitingpubkey' AND folder='sent')''')
64 for row in queryreturn:
65 toAddress, = row
66 toStatus, toAddressVersionNumber, toStreamNumber, toRipe = decodeAddress(toAddress)
67 if toAddressVersionNumber <= 3 :
68 state.neededPubkeys[toAddress] = 0
69 elif toAddressVersionNumber >= 4:
70 doubleHashOfAddressData = hashlib.sha512(hashlib.sha512(encodeVarint(
71 toAddressVersionNumber) + encodeVarint(toStreamNumber) + toRipe).digest()).digest()
72 privEncryptionKey = doubleHashOfAddressData[:32] # Note that this is the first half of the sha512 hash.
73 tag = doubleHashOfAddressData[32:]
74 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.
75
76 # Initialize the shared.ackdataForWhichImWatching data structure
77 queryreturn = sqlQuery(
78 '''SELECT ackdata FROM sent WHERE status = 'msgsent' ''')
79 for row in queryreturn:
80 ackdata, = row
81 logger.info('Watching for ackdata ' + hexlify(ackdata))
82 shared.ackdataForWhichImWatching[ackdata] = 0
83
84 # Fix legacy (headerless) watched ackdata to include header
85 for oldack in shared.ackdataForWhichImWatching.keys():
86 if (len(oldack)==32):
87 # attach legacy header, always constant (msg/1/1)
88 newack = '\x00\x00\x00\x02\x01\x01' + oldack
89 shared.ackdataForWhichImWatching[newack] = 0
90 sqlExecute('UPDATE sent SET ackdata=? WHERE ackdata=?',
91 newack, oldack )
92 del shared.ackdataForWhichImWatching[oldack]
93
94 self.stop.wait(
95 10) # give some time for the GUI to start before we start on existing POW tasks.
96

Callers 1

startMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected