(self)
| 527 | |
| 528 | |
| 529 | def sendMsg(self): |
| 530 | # Reset just in case |
| 531 | sqlExecute( |
| 532 | '''UPDATE sent SET status='msgqueued' WHERE status IN ('doingpubkeypow', 'doingmsgpow')''') |
| 533 | queryreturn = sqlQuery( |
| 534 | '''SELECT toaddress, fromaddress, subject, message, ackdata, status, ttl, retrynumber, encodingtype FROM sent WHERE (status='msgqueued' or status='forcepow') and folder='sent' ''') |
| 535 | for row in queryreturn: # while we have a msg that needs some work |
| 536 | toaddress, fromaddress, subject, message, ackdata, status, TTL, retryNumber, encoding = row |
| 537 | toStatus, toAddressVersionNumber, toStreamNumber, toRipe = decodeAddress( |
| 538 | toaddress) |
| 539 | fromStatus, fromAddressVersionNumber, fromStreamNumber, fromRipe = decodeAddress( |
| 540 | fromaddress) |
| 541 | |
| 542 | # We may or may not already have the pubkey for this toAddress. Let's check. |
| 543 | if status == 'forcepow': |
| 544 | # if the status of this msg is 'forcepow' then clearly we have the pubkey already |
| 545 | # because the user could not have overridden the message about the POW being |
| 546 | # too difficult without knowing the required difficulty. |
| 547 | pass |
| 548 | elif status == 'doingmsgpow': |
| 549 | # We wouldn't have set the status to doingmsgpow if we didn't already have the pubkey |
| 550 | # so let's assume that we have it. |
| 551 | pass |
| 552 | # If we are sending a message to ourselves or a chan then we won't need an entry in the pubkeys table; we can calculate the needed pubkey using the private keys in our keys.dat file. |
| 553 | elif BMConfigParser().has_section(toaddress): |
| 554 | sqlExecute( |
| 555 | '''UPDATE sent SET status='doingmsgpow' WHERE toaddress=? AND status='msgqueued' ''', |
| 556 | toaddress) |
| 557 | status='doingmsgpow' |
| 558 | elif status == 'msgqueued': |
| 559 | # Let's see if we already have the pubkey in our pubkeys table |
| 560 | queryreturn = sqlQuery( |
| 561 | '''SELECT address FROM pubkeys WHERE address=?''', toaddress) |
| 562 | if queryreturn != []: # If we have the needed pubkey in the pubkey table already, |
| 563 | # set the status of this msg to doingmsgpow |
| 564 | sqlExecute( |
| 565 | '''UPDATE sent SET status='doingmsgpow' WHERE toaddress=? AND status='msgqueued' ''', |
| 566 | toaddress) |
| 567 | status = 'doingmsgpow' |
| 568 | # mark the pubkey as 'usedpersonally' so that we don't delete it later. If the pubkey version |
| 569 | # is >= 4 then usedpersonally will already be set to yes because we'll only ever have |
| 570 | # usedpersonally v4 pubkeys in the pubkeys table. |
| 571 | sqlExecute( |
| 572 | '''UPDATE pubkeys SET usedpersonally='yes' WHERE address=?''', |
| 573 | toaddress) |
| 574 | else: # We don't have the needed pubkey in the pubkeys table already. |
| 575 | if toAddressVersionNumber <= 3: |
| 576 | toTag = '' |
| 577 | else: |
| 578 | toTag = hashlib.sha512(hashlib.sha512(encodeVarint(toAddressVersionNumber)+encodeVarint(toStreamNumber)+toRipe).digest()).digest()[32:] |
| 579 | if toaddress in state.neededPubkeys or toTag in state.neededPubkeys: |
| 580 | # We already sent a request for the pubkey |
| 581 | sqlExecute( |
| 582 | '''UPDATE sent SET status='awaitingpubkey', sleeptill=? WHERE toaddress=? AND status='msgqueued' ''', |
| 583 | int(time.time()) + 2.5*24*60*60, |
| 584 | toaddress) |
| 585 | queues.UISignalQueue.put(('updateSentItemStatusByToAddress', ( |
| 586 | toaddress, tr._translate("MainWindow",'Encryption key was requested earlier.')))) |
no test coverage detected