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

Method run

src/class_singleWorker.py:54–146  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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
97 if state.shutdown == 0:
98 # just in case there are any pending tasks for msg
99 # messages that have yet to be sent.
100 queues.workerQueue.put(('sendmessage', ''))
101 # just in case there are any tasks for Broadcasts
102 # that have yet to be sent.
103 queues.workerQueue.put(('sendbroadcast', ''))
104
105 while state.shutdown == 0:
106 self.busy = 0
107 command, data = queues.workerQueue.get()
108 self.busy = 1
109 if command == 'sendmessage':
110 try:
111 self.sendMsg()

Callers 7

doPOWForMyV2PubkeyMethod · 0.45
sendBroadcastMethod · 0.45
sendMsgMethod · 0.45
requestPubKeyMethod · 0.45

Calls 13

sendMsgMethod · 0.95
sendBroadcastMethod · 0.95
doPOWForMyV2PubkeyMethod · 0.95
sqlQueryFunction · 0.85
decodeAddressFunction · 0.85
encodeVarintFunction · 0.85
sqlExecuteFunction · 0.85
waitMethod · 0.80
putMethod · 0.80
task_doneMethod · 0.80

Tested by

no test coverage detected