Updated code quality binary operator next line changes in class_singleWorker.py

This commit is contained in:
kuldeep.k@cisinlabs.com 2021-08-16 22:09:16 +05:30
parent f997bca5e4
commit 4d1bca76a8
No known key found for this signature in database
GPG Key ID: AF4FB299BF7C7C2A

View File

@ -82,8 +82,8 @@ class singleWorker(StoppableThread):
state.neededPubkeys[toAddress] = 0 state.neededPubkeys[toAddress] = 0
elif toAddressVersionNumber >= 4: elif toAddressVersionNumber >= 4:
doubleHashOfAddressData = hashlib.sha512(hashlib.sha512( doubleHashOfAddressData = hashlib.sha512(hashlib.sha512(
encodeVarint(toAddressVersionNumber) + encodeVarint(toAddressVersionNumber)
encodeVarint(toStreamNumber) + toRipe + encodeVarint(toStreamNumber) + toRipe
).digest()).digest() ).digest()).digest()
# Note that this is the first half of the sha512 hash. # Note that this is the first half of the sha512 hash.
privEncryptionKey = doubleHashOfAddressData[:32] privEncryptionKey = doubleHashOfAddressData[:32]
@ -221,11 +221,11 @@ class singleWorker(StoppableThread):
log_time=False): log_time=False):
target = 2 ** 64 / ( target = 2 ** 64 / (
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * ( defaults.networkDefaultProofOfWorkNonceTrialsPerByte * (
len(payload) + 8 + len(payload) + 8
defaults.networkDefaultPayloadLengthExtraBytes + (( + defaults.networkDefaultPayloadLengthExtraBytes + ((
TTL * ( TTL * (
len(payload) + 8 + len(payload) + 8
defaults.networkDefaultPayloadLengthExtraBytes + defaults.networkDefaultPayloadLengthExtraBytes
)) / (2 ** 16)) )) / (2 ** 16))
)) ))
initialHash = hashlib.sha512(payload).digest() initialHash = hashlib.sha512(payload).digest()
@ -450,8 +450,8 @@ class singleWorker(StoppableThread):
# know which pubkey object to try to decrypt # know which pubkey object to try to decrypt
# when they want to send a message. # when they want to send a message.
doubleHashOfAddressData = hashlib.sha512(hashlib.sha512( doubleHashOfAddressData = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersionNumber) + encodeVarint(addressVersionNumber)
encodeVarint(streamNumber) + addressHash + encodeVarint(streamNumber) + addressHash
).digest()).digest() ).digest()).digest()
payload += doubleHashOfAddressData[32:] # the tag payload += doubleHashOfAddressData[32:] # the tag
signature = highlevelcrypto.sign( signature = highlevelcrypto.sign(
@ -614,8 +614,8 @@ class singleWorker(StoppableThread):
payload += encodeVarint(streamNumber) payload += encodeVarint(streamNumber)
if addressVersionNumber >= 4: if addressVersionNumber >= 4:
doubleHashOfAddressData = hashlib.sha512(hashlib.sha512( doubleHashOfAddressData = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersionNumber) + encodeVarint(addressVersionNumber)
encodeVarint(streamNumber) + ripe + encodeVarint(streamNumber) + ripe
).digest()).digest() ).digest()).digest()
tag = doubleHashOfAddressData[32:] tag = doubleHashOfAddressData[32:]
payload += tag payload += tag
@ -654,8 +654,8 @@ class singleWorker(StoppableThread):
# Internet connections and being stored on the disk of 3rd parties. # Internet connections and being stored on the disk of 3rd parties.
if addressVersionNumber <= 3: if addressVersionNumber <= 3:
privEncryptionKey = hashlib.sha512( privEncryptionKey = hashlib.sha512(
encodeVarint(addressVersionNumber) + encodeVarint(addressVersionNumber)
encodeVarint(streamNumber) + ripe + encodeVarint(streamNumber) + ripe
).digest()[:32] ).digest()[:32]
else: else:
privEncryptionKey = doubleHashOfAddressData[:32] privEncryptionKey = doubleHashOfAddressData[:32]
@ -796,8 +796,8 @@ class singleWorker(StoppableThread):
toTag = '' toTag = ''
else: else:
toTag = hashlib.sha512(hashlib.sha512( toTag = hashlib.sha512(hashlib.sha512(
encodeVarint(toAddressVersionNumber) + encodeVarint(toAddressVersionNumber)
encodeVarint(toStreamNumber) + toRipe + encodeVarint(toStreamNumber) + toRipe
).digest()).digest()[32:] ).digest()).digest()[32:]
if toaddress in state.neededPubkeys or \ if toaddress in state.neededPubkeys or \
toTag in state.neededPubkeys: toTag in state.neededPubkeys:
@ -1044,13 +1044,13 @@ class singleWorker(StoppableThread):
" and %2" " and %2"
).arg( ).arg(
str( str(
float(requiredAverageProofOfWorkNonceTrialsPerByte) / float(requiredAverageProofOfWorkNonceTrialsPerByte)
defaults.networkDefaultProofOfWorkNonceTrialsPerByte / defaults.networkDefaultProofOfWorkNonceTrialsPerByte
) )
).arg( ).arg(
str( str(
float(requiredPayloadLengthExtraBytes) / float(requiredPayloadLengthExtraBytes)
defaults.networkDefaultPayloadLengthExtraBytes / defaults.networkDefaultPayloadLengthExtraBytes
) )
) )
) )
@ -1083,11 +1083,11 @@ class singleWorker(StoppableThread):
" the recipient (%1 and %2) is" " the recipient (%1 and %2) is"
" more difficult than you are" " more difficult than you are"
" willing to do. %3" " willing to do. %3"
).arg(str(float(requiredAverageProofOfWorkNonceTrialsPerByte) / ).arg(str(float(requiredAverageProofOfWorkNonceTrialsPerByte)
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)).arg( / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
str(float(requiredPayloadLengthExtraBytes) / ).arg(str(float(requiredPayloadLengthExtraBytes)
defaults.networkDefaultPayloadLengthExtraBytes)).arg( / defaults.networkDefaultPayloadLengthExtraBytes)
l10n.formatTimestamp())))) ).arg(l10n.formatTimestamp()))))
continue continue
else: # if we are sending a message to ourselves or a chan.. else: # if we are sending a message to ourselves or a chan..
self.logger.info('Sending a message.') self.logger.info('Sending a message.')
@ -1255,20 +1255,20 @@ class singleWorker(StoppableThread):
encryptedPayload += encodeVarint(toStreamNumber) + encrypted encryptedPayload += encodeVarint(toStreamNumber) + encrypted
target = 2 ** 64 / ( target = 2 ** 64 / (
requiredAverageProofOfWorkNonceTrialsPerByte * ( requiredAverageProofOfWorkNonceTrialsPerByte * (
len(encryptedPayload) + 8 + len(encryptedPayload) + 8
requiredPayloadLengthExtraBytes + (( + requiredPayloadLengthExtraBytes + ((
TTL * ( TTL * (
len(encryptedPayload) + 8 + len(encryptedPayload) + 8
requiredPayloadLengthExtraBytes + requiredPayloadLengthExtraBytes
)) / (2 ** 16)) )) / (2 ** 16))
)) ))
self.logger.info( self.logger.info(
'(For msg message) Doing proof of work. Total required' '(For msg message) Doing proof of work. Total required'
' difficulty: %f. Required small message difficulty: %f.', ' difficulty: %f. Required small message difficulty: %f.',
float(requiredAverageProofOfWorkNonceTrialsPerByte) / float(requiredAverageProofOfWorkNonceTrialsPerByte)
defaults.networkDefaultProofOfWorkNonceTrialsPerByte, / defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
float(requiredPayloadLengthExtraBytes) / float(requiredPayloadLengthExtraBytes)
defaults.networkDefaultPayloadLengthExtraBytes / defaults.networkDefaultPayloadLengthExtraBytes
) )
powStartTime = time.time() powStartTime = time.time()
@ -1409,13 +1409,13 @@ class singleWorker(StoppableThread):
# Note that this is the first half of the sha512 hash. # Note that this is the first half of the sha512 hash.
privEncryptionKey = hashlib.sha512(hashlib.sha512( privEncryptionKey = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersionNumber) + encodeVarint(addressVersionNumber)
encodeVarint(streamNumber) + ripe + encodeVarint(streamNumber) + ripe
).digest()).digest()[:32] ).digest()).digest()[:32]
# Note that this is the second half of the sha512 hash. # Note that this is the second half of the sha512 hash.
tag = hashlib.sha512(hashlib.sha512( tag = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersionNumber) + encodeVarint(addressVersionNumber)
encodeVarint(streamNumber) + ripe + encodeVarint(streamNumber) + ripe
).digest()).digest()[32:] ).digest()).digest()[32:]
if tag not in state.neededPubkeys: if tag not in state.neededPubkeys:
# We'll need this for when we receive a pubkey reply: # We'll need this for when we receive a pubkey reply: