fix some bugs related to the migration to Python3

Now getpubkey and one-to-one messaging works.
This commit is contained in:
Kashiko Koibumi 2024-05-16 02:56:36 +09:00
parent ba9734e979
commit 6a090e802e
No known key found for this signature in database
GPG Key ID: 8F06E069E37C40C4
4 changed files with 13 additions and 14 deletions

View File

@ -153,8 +153,8 @@ class objectProcessor(threading.Thread):
data[readPosition:], data[readPosition:],
_translate( _translate(
"MainWindow", "MainWindow",
"Acknowledgement of the message received %1" "Acknowledgement of the message received {}"
).arg(l10n.formatTimestamp())) ).format(l10n.formatTimestamp()))
)) ))
else: else:
logger.debug('This object is not an acknowledgement bound for me.') logger.debug('This object is not an acknowledgement bound for me.')
@ -214,11 +214,11 @@ class objectProcessor(threading.Thread):
return logger.debug( return logger.debug(
'The length of the requested hash is not 20 bytes.' 'The length of the requested hash is not 20 bytes.'
' Something is wrong. Ignoring.') ' Something is wrong. Ignoring.')
hex_hash = hexlify(requestedHash).decode('ascii')
logger.info( logger.info(
'the hash requested in this getpubkey request is: %s', 'the hash requested in this getpubkey request is: %s',
hexlify(requestedHash)) hex_hash)
# if this address hash is one of mine # if this address hash is one of mine
hex_hash = hexlify(requestedHash).decode('ascii')
if hex_hash in shared.myAddressesByHash: if hex_hash in shared.myAddressesByHash:
myAddress = shared.myAddressesByHash[hex_hash] myAddress = shared.myAddressesByHash[hex_hash]
elif requestedAddressVersionNumber >= 4: elif requestedAddressVersionNumber >= 4:
@ -317,7 +317,7 @@ class objectProcessor(threading.Thread):
dataToStore = data[20:readPosition] dataToStore = data[20:readPosition]
sha = hashlib.new('sha512') sha = hashlib.new('sha512')
sha.update( sha.update(
'\x04' + publicSigningKey + '\x04' + publicEncryptionKey) b'\x04' + publicSigningKey + b'\x04' + publicEncryptionKey)
ripe = RIPEMD160Hash(sha.digest()).digest() ripe = RIPEMD160Hash(sha.digest()).digest()
if logger.isEnabledFor(logging.DEBUG): if logger.isEnabledFor(logging.DEBUG):
@ -808,9 +808,9 @@ class objectProcessor(threading.Thread):
logger.info( logger.info(
'EC decryption successful using key associated' 'EC decryption successful using key associated'
' with ripe hash: %s', key) ' with ripe hash: %s', key)
except Exception: except Exception as ex:
logger.debug( logger.debug(
'cryptorObject.decrypt Exception:', exc_info=True) 'cryptorObject.decrypt Exception: {}'.format(ex))
if not initialDecryptionSuccessful: if not initialDecryptionSuccessful:
# This is not a broadcast I am interested in. # This is not a broadcast I am interested in.
return logger.debug( return logger.debug(
@ -1062,8 +1062,8 @@ class objectProcessor(threading.Thread):
if checksum != hashlib.sha512(payload).digest()[0:4]: if checksum != hashlib.sha512(payload).digest()[0:4]:
logger.info('ackdata checksum wrong. Not sending ackdata.') logger.info('ackdata checksum wrong. Not sending ackdata.')
return False return False
command = command.rstrip('\x00') command = command.rstrip(b'\x00')
if command != 'object': if command != b'object':
return False return False
return True return True

View File

@ -74,13 +74,12 @@ class Dandelion: # pylint: disable=old-style-class
def removeHash(self, hashId, reason="no reason specified"): def removeHash(self, hashId, reason="no reason specified"):
"""Switch inventory vector from stem to fluff mode""" """Switch inventory vector from stem to fluff mode"""
hex_hash = hexlify(hashId).decode('ascii')
if logger.isEnabledFor(logging.DEBUG): if logger.isEnabledFor(logging.DEBUG):
logger.debug( logger.debug(
'%s entering fluff mode due to %s.', '%s entering fluff mode due to %s.', hex_hash, reason)
''.join('%02x' % ord(i) for i in hashId), reason)
with self.lock: with self.lock:
try: try:
hex_hash = hexlify(hashId).decode('ascii')
del self.hashMap[hex_hash] del self.hashMap[hex_hash]
except KeyError: except KeyError:
pass pass

View File

@ -483,7 +483,7 @@ def decryptAndCheckPubkeyPayload(data, address):
readPosition += 32 readPosition += 32
# the time through the tag. More data is appended onto # the time through the tag. More data is appended onto
# signedData below after the decryption. # signedData below after the decryption.
signedData = data[8:readPosition] signedData = bytes(data[8:readPosition])
encryptedData = data[readPosition:] encryptedData = data[readPosition:]
# Let us try to decrypt the pubkey # Let us try to decrypt the pubkey

View File

@ -65,7 +65,7 @@ class SqliteInventory(InventoryStorage):
def __iter__(self): def __iter__(self):
with self.lock: with self.lock:
hashes = map(unhexlify, self._inventory.keys()[:]) hashes = map(unhexlify, self._inventory.keys()[:])
hashes += (unhexlify(x) for x, in sqlQuery('SELECT hash FROM inventory')) hashes += (x for x, in sqlQuery('SELECT hash FROM inventory'))
return hashes.__iter__() return hashes.__iter__()
def __len__(self): def __len__(self):