(self)
| 44 | self.initStop() |
| 45 | |
| 46 | def run(self): |
| 47 | gc.disable() |
| 48 | timeWeLastClearedInventoryAndPubkeysTables = 0 |
| 49 | try: |
| 50 | shared.maximumLengthOfTimeToBotherResendingMessages = (float(BMConfigParser().get('bitmessagesettings', 'stopresendingafterxdays')) * 24 * 60 * 60) + (float(BMConfigParser().get('bitmessagesettings', 'stopresendingafterxmonths')) * (60 * 60 * 24 *365)/12) |
| 51 | except: |
| 52 | # Either the user hasn't set stopresendingafterxdays and stopresendingafterxmonths yet or the options are missing from the config file. |
| 53 | shared.maximumLengthOfTimeToBotherResendingMessages = float('inf') |
| 54 | |
| 55 | # initial wait |
| 56 | if state.shutdown == 0: |
| 57 | self.stop.wait(singleCleaner.cycleLength) |
| 58 | |
| 59 | while state.shutdown == 0: |
| 60 | queues.UISignalQueue.put(( |
| 61 | 'updateStatusBar', 'Doing housekeeping (Flushing inventory in memory to disk...)')) |
| 62 | Inventory().flush() |
| 63 | queues.UISignalQueue.put(('updateStatusBar', '')) |
| 64 | |
| 65 | # If we are running as a daemon then we are going to fill up the UI |
| 66 | # queue which will never be handled by a UI. We should clear it to |
| 67 | # save memory. |
| 68 | if shared.thisapp.daemon: |
| 69 | queues.UISignalQueue.queue.clear() |
| 70 | if timeWeLastClearedInventoryAndPubkeysTables < int(time.time()) - 7380: |
| 71 | timeWeLastClearedInventoryAndPubkeysTables = int(time.time()) |
| 72 | Inventory().clean() |
| 73 | # pubkeys |
| 74 | sqlExecute( |
| 75 | '''DELETE FROM pubkeys WHERE time<? AND usedpersonally='no' ''', |
| 76 | int(time.time()) - shared.lengthOfTimeToHoldOnToAllPubkeys) |
| 77 | |
| 78 | # Let us resend getpubkey objects if we have not yet heard a pubkey, and also msg objects if we have not yet heard an acknowledgement |
| 79 | queryreturn = sqlQuery( |
| 80 | '''select toaddress, ackdata, status FROM sent WHERE ((status='awaitingpubkey' OR status='msgsent') AND folder='sent' AND sleeptill<? AND senttime>?) ''', |
| 81 | int(time.time()), |
| 82 | int(time.time()) - shared.maximumLengthOfTimeToBotherResendingMessages) |
| 83 | for row in queryreturn: |
| 84 | if len(row) < 2: |
| 85 | logger.error('Something went wrong in the singleCleaner thread: a query did not return the requested fields. ' + repr(row)) |
| 86 | self.stop.wait(3) |
| 87 | break |
| 88 | toAddress, ackData, status = row |
| 89 | if status == 'awaitingpubkey': |
| 90 | resendPubkeyRequest(toAddress) |
| 91 | elif status == 'msgsent': |
| 92 | resendMsg(ackData) |
| 93 | |
| 94 | # cleanup old nodes |
| 95 | now = int(time.time()) |
| 96 | with knownnodes.knownNodesLock: |
| 97 | for stream in knownnodes.knownNodes: |
| 98 | keys = knownnodes.knownNodes[stream].keys() |
| 99 | for node in keys: |
| 100 | try: |
| 101 | # scrap old nodes |
| 102 | if now - knownnodes.knownNodes[stream][node]["lastseen"] > 2419200: # 28 days |
| 103 | shared.needToWriteKnownNodesToDisk = True |
nothing calls this directly
no test coverage detected