Fixed: Responded to PR comments
This commit is contained in:
parent
ab1dd319e3
commit
e1c2e8ec46
|
@ -11,6 +11,7 @@ from __future__ import absolute_import
|
||||||
import base64
|
import base64
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import os
|
||||||
import random
|
import random
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
|
@ -88,6 +89,9 @@ def isBitSetWithinBitfield(fourByteString, n):
|
||||||
return x & 2**n != 0
|
return x & 2**n != 0
|
||||||
|
|
||||||
|
|
||||||
|
# ip addresses
|
||||||
|
|
||||||
|
|
||||||
def encodeHost(host):
|
def encodeHost(host):
|
||||||
"""Encode a given host to be used in low-level socket operations"""
|
"""Encode a given host to be used in low-level socket operations"""
|
||||||
if host.find('.onion') > -1:
|
if host.find('.onion') > -1:
|
||||||
|
@ -214,6 +218,9 @@ def isProofOfWorkSufficient(data,
|
||||||
((TTL * (len(data) + payloadLengthExtraBytes)) / (2 ** 16))))
|
((TTL * (len(data) + payloadLengthExtraBytes)) / (2 ** 16))))
|
||||||
|
|
||||||
|
|
||||||
|
# Packet creation
|
||||||
|
|
||||||
|
|
||||||
def CreatePacket(command, payload=''):
|
def CreatePacket(command, payload=''):
|
||||||
"""Construct and return a number of bytes from a payload"""
|
"""Construct and return a number of bytes from a payload"""
|
||||||
payload_length = len(payload)
|
payload_length = len(payload)
|
||||||
|
@ -299,6 +306,9 @@ def assembleErrorMessage(fatal=0, banTime=0, inventoryVector='', errorText=''):
|
||||||
return CreatePacket('error', payload)
|
return CreatePacket('error', payload)
|
||||||
|
|
||||||
|
|
||||||
|
# Packet decoding
|
||||||
|
|
||||||
|
|
||||||
def decryptAndCheckPubkeyPayload(data, address):
|
def decryptAndCheckPubkeyPayload(data, address):
|
||||||
"""
|
"""
|
||||||
Version 4 pubkeys are encrypted. This function is run when we already have the
|
Version 4 pubkeys are encrypted. This function is run when we already have the
|
||||||
|
@ -335,8 +345,8 @@ def decryptAndCheckPubkeyPayload(data, address):
|
||||||
toAddress, cryptorObject = state.neededPubkeys[tag]
|
toAddress, cryptorObject = state.neededPubkeys[tag]
|
||||||
if toAddress != address:
|
if toAddress != address:
|
||||||
logger.critical(
|
logger.critical(
|
||||||
('decryptAndCheckPubkeyPayload failed due to toAddress mismatch. '
|
'decryptAndCheckPubkeyPayload failed due to toAddress mismatch.'
|
||||||
'This is very peculiar. toAddress: %s, address %s'),
|
' This is very peculiar. toAddress: %s, address %s',
|
||||||
toAddress,
|
toAddress,
|
||||||
address)
|
address)
|
||||||
# the only way I can think that this could happen is if someone encodes their address data two different
|
# the only way I can think that this could happen is if someone encodes their address data two different
|
||||||
|
@ -393,14 +403,13 @@ def decryptAndCheckPubkeyPayload(data, address):
|
||||||
# Everything checked out. Insert it into the pubkeys table.
|
# Everything checked out. Insert it into the pubkeys table.
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
'within decryptAndCheckPubkeyPayload, addressVersion: %s, streamNumber: %s \n\
|
os.linesep.join([
|
||||||
ripe %s\n\
|
'within decryptAndCheckPubkeyPayload,'
|
||||||
publicSigningKey in hex: %s\n\
|
' addressVersion: %s, streamNumber: %s' % addressVersion, streamNumber,
|
||||||
publicEncryptionKey in hex: %s', addressVersion,
|
'ripe %s' % hexlify(ripe),
|
||||||
streamNumber,
|
'publicSigningKey in hex: %s' % hexlify(publicSigningKey),
|
||||||
hexlify(ripe),
|
'publicEncryptionKey in hex: %s' % hexlify(publicEncryptionKey),
|
||||||
hexlify(publicSigningKey),
|
])
|
||||||
hexlify(publicEncryptionKey)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
t = (address, addressVersion, storedData, int(time.time()), 'yes')
|
t = (address, addressVersion, storedData, int(time.time()), 'yes')
|
||||||
|
@ -459,14 +468,14 @@ def checkAndShareObjectWithPeers(data):
|
||||||
return 0.6
|
return 0.6
|
||||||
except varintDecodeError as err:
|
except varintDecodeError as err:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
("There was a problem with a varint while checking to see whether it was appropriate to share an object "
|
"There was a problem with a varint while checking to see whether it was appropriate to share an object"
|
||||||
"with peers. Some details: %s"),
|
" with peers. Some details: %s", err
|
||||||
err)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.critical(
|
logger.critical(
|
||||||
('There was a problem while checking to see whether it was appropriate to share an object with peers. '
|
'There was a problem while checking to see whether it was appropriate to share an object with peers.'
|
||||||
'This is definitely a bug! \n%s'),
|
' This is definitely a bug! %s%s' % os.linesep, traceback.format_exc()
|
||||||
traceback.format_exc())
|
)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user