use binary literals for compatibility to Python3
This commit is contained in:
parent
3a04e351cc
commit
90236ee5ab
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
qt_resource_data = "\
|
qt_resource_data = b"\
|
||||||
\x00\x00\x03\x66\
|
\x00\x00\x03\x66\
|
||||||
\x89\
|
\x89\
|
||||||
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
|
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
|
||||||
|
@ -1534,7 +1534,7 @@ qt_resource_data = "\
|
||||||
\x82\
|
\x82\
|
||||||
"
|
"
|
||||||
|
|
||||||
qt_resource_name = "\
|
qt_resource_name = b"\
|
||||||
\x00\x09\
|
\x00\x09\
|
||||||
\x0c\x78\x54\x88\
|
\x0c\x78\x54\x88\
|
||||||
\x00\x6e\
|
\x00\x6e\
|
||||||
|
@ -1639,7 +1639,7 @@ qt_resource_name = "\
|
||||||
\x00\x70\x00\x6e\x00\x67\
|
\x00\x70\x00\x6e\x00\x67\
|
||||||
"
|
"
|
||||||
|
|
||||||
qt_resource_struct = "\
|
qt_resource_struct = b"\
|
||||||
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
|
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\
|
||||||
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
|
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\
|
||||||
\x00\x00\x00\x18\x00\x02\x00\x00\x00\x15\x00\x00\x00\x03\
|
\x00\x00\x00\x18\x00\x02\x00\x00\x00\x15\x00\x00\x00\x03\
|
||||||
|
|
|
@ -299,12 +299,12 @@ class objectProcessor(threading.Thread):
|
||||||
'(within processpubkey) payloadLength less than 146.'
|
'(within processpubkey) payloadLength less than 146.'
|
||||||
' Sanity check failed.')
|
' Sanity check failed.')
|
||||||
readPosition += 4
|
readPosition += 4
|
||||||
pubSigningKey = '\x04' + data[readPosition:readPosition + 64]
|
pubSigningKey = b'\x04' + data[readPosition:readPosition + 64]
|
||||||
# Is it possible for a public key to be invalid such that trying to
|
# Is it possible for a public key to be invalid such that trying to
|
||||||
# encrypt or sign with it will cause an error? If it is, it would
|
# encrypt or sign with it will cause an error? If it is, it would
|
||||||
# be easiest to test them here.
|
# be easiest to test them here.
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
pubEncryptionKey = '\x04' + data[readPosition:readPosition + 64]
|
pubEncryptionKey = b'\x04' + data[readPosition:readPosition + 64]
|
||||||
if len(pubEncryptionKey) < 65:
|
if len(pubEncryptionKey) < 65:
|
||||||
return logger.debug(
|
return logger.debug(
|
||||||
'publicEncryptionKey length less than 64. Sanity check'
|
'publicEncryptionKey length less than 64. Sanity check'
|
||||||
|
@ -350,9 +350,9 @@ class objectProcessor(threading.Thread):
|
||||||
' Sanity check failed.')
|
' Sanity check failed.')
|
||||||
return
|
return
|
||||||
readPosition += 4
|
readPosition += 4
|
||||||
pubSigningKey = '\x04' + data[readPosition:readPosition + 64]
|
pubSigningKey = b'\x04' + data[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
pubEncryptionKey = '\x04' + data[readPosition:readPosition + 64]
|
pubEncryptionKey = b'\x04' + data[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
specifiedNonceTrialsPerByteLength = decodeVarint(
|
specifiedNonceTrialsPerByteLength = decodeVarint(
|
||||||
data[readPosition:readPosition + 10])[1]
|
data[readPosition:readPosition + 10])[1]
|
||||||
|
@ -507,9 +507,9 @@ class objectProcessor(threading.Thread):
|
||||||
return
|
return
|
||||||
readPosition += sendersStreamNumberLength
|
readPosition += sendersStreamNumberLength
|
||||||
readPosition += 4
|
readPosition += 4
|
||||||
pubSigningKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
pubSigningKey = b'\x04' + decryptedData[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
pubEncryptionKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
pubEncryptionKey = b'\x04' + decryptedData[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
if sendersAddressVersionNumber >= 3:
|
if sendersAddressVersionNumber >= 3:
|
||||||
requiredAverageProofOfWorkNonceTrialsPerByte, varintLength = \
|
requiredAverageProofOfWorkNonceTrialsPerByte, varintLength = \
|
||||||
|
@ -854,10 +854,10 @@ class objectProcessor(threading.Thread):
|
||||||
)
|
)
|
||||||
readPosition += sendersStreamLength
|
readPosition += sendersStreamLength
|
||||||
readPosition += 4
|
readPosition += 4
|
||||||
sendersPubSigningKey = '\x04' + \
|
sendersPubSigningKey = b'\x04' + \
|
||||||
decryptedData[readPosition:readPosition + 64]
|
decryptedData[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
sendersPubEncryptionKey = '\x04' + \
|
sendersPubEncryptionKey = b'\x04' + \
|
||||||
decryptedData[readPosition:readPosition + 64]
|
decryptedData[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
if sendersAddressVersion >= 3:
|
if sendersAddressVersion >= 3:
|
||||||
|
@ -1047,7 +1047,7 @@ 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 != 'object':
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -105,7 +105,7 @@ class singleWorker(StoppableThread):
|
||||||
for oldack in state.ackdataForWhichImWatching:
|
for oldack in state.ackdataForWhichImWatching:
|
||||||
if len(oldack) == 32:
|
if len(oldack) == 32:
|
||||||
# attach legacy header, always constant (msg/1/1)
|
# attach legacy header, always constant (msg/1/1)
|
||||||
newack = '\x00\x00\x00\x02\x01\x01' + oldack
|
newack = b'\x00\x00\x00\x02\x01\x01' + oldack
|
||||||
state.ackdataForWhichImWatching[newack] = 0
|
state.ackdataForWhichImWatching[newack] = 0
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
'''UPDATE sent SET ackdata=? WHERE ackdata=? AND folder = 'sent' ''',
|
'''UPDATE sent SET ackdata=? WHERE ackdata=? AND folder = 'sent' ''',
|
||||||
|
@ -261,7 +261,7 @@ class singleWorker(StoppableThread):
|
||||||
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
|
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
|
||||||
embeddedTime = int(time.time() + TTL)
|
embeddedTime = int(time.time() + TTL)
|
||||||
payload = pack('>Q', (embeddedTime))
|
payload = pack('>Q', (embeddedTime))
|
||||||
payload += '\x00\x00\x00\x01' # object type: pubkey
|
payload += b'\x00\x00\x00\x01' # object type: pubkey
|
||||||
payload += encodeVarint(addressVersionNumber) # Address version number
|
payload += encodeVarint(addressVersionNumber) # Address version number
|
||||||
payload += encodeVarint(streamNumber)
|
payload += encodeVarint(streamNumber)
|
||||||
# bitfield of features supported by me (see the wiki).
|
# bitfield of features supported by me (see the wiki).
|
||||||
|
@ -338,7 +338,7 @@ class singleWorker(StoppableThread):
|
||||||
# expiresTime time.
|
# expiresTime time.
|
||||||
|
|
||||||
payload = pack('>Q', (embeddedTime))
|
payload = pack('>Q', (embeddedTime))
|
||||||
payload += '\x00\x00\x00\x01' # object type: pubkey
|
payload += b'\x00\x00\x00\x01' # object type: pubkey
|
||||||
payload += encodeVarint(addressVersionNumber) # Address version number
|
payload += encodeVarint(addressVersionNumber) # Address version number
|
||||||
payload += encodeVarint(streamNumber)
|
payload += encodeVarint(streamNumber)
|
||||||
# bitfield of features supported by me (see the wiki).
|
# bitfield of features supported by me (see the wiki).
|
||||||
|
@ -413,7 +413,7 @@ class singleWorker(StoppableThread):
|
||||||
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
|
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
|
||||||
embeddedTime = int(time.time() + TTL)
|
embeddedTime = int(time.time() + TTL)
|
||||||
payload = pack('>Q', (embeddedTime))
|
payload = pack('>Q', (embeddedTime))
|
||||||
payload += '\x00\x00\x00\x01' # object type: pubkey
|
payload += b'\x00\x00\x00\x01' # object type: pubkey
|
||||||
payload += encodeVarint(addressVersionNumber) # Address version number
|
payload += encodeVarint(addressVersionNumber) # Address version number
|
||||||
payload += encodeVarint(streamNumber)
|
payload += encodeVarint(streamNumber)
|
||||||
dataToEncrypt = protocol.getBitfield(myAddress)
|
dataToEncrypt = protocol.getBitfield(myAddress)
|
||||||
|
@ -599,7 +599,7 @@ class singleWorker(StoppableThread):
|
||||||
TTL = int(TTL + helper_random.randomrandrange(-300, 300))
|
TTL = int(TTL + helper_random.randomrandrange(-300, 300))
|
||||||
embeddedTime = int(time.time() + TTL)
|
embeddedTime = int(time.time() + TTL)
|
||||||
payload = pack('>Q', embeddedTime)
|
payload = pack('>Q', embeddedTime)
|
||||||
payload += '\x00\x00\x00\x03' # object type: broadcast
|
payload += b'\x00\x00\x00\x03' # object type: broadcast
|
||||||
|
|
||||||
if addressVersionNumber <= 3:
|
if addressVersionNumber <= 3:
|
||||||
payload += encodeVarint(4) # broadcast version
|
payload += encodeVarint(4) # broadcast version
|
||||||
|
@ -615,7 +615,7 @@ class singleWorker(StoppableThread):
|
||||||
tag = doubleHashOfAddressData[32:]
|
tag = doubleHashOfAddressData[32:]
|
||||||
payload += tag
|
payload += tag
|
||||||
else:
|
else:
|
||||||
tag = ''
|
tag = b''
|
||||||
|
|
||||||
dataToEncrypt = encodeVarint(addressVersionNumber)
|
dataToEncrypt = encodeVarint(addressVersionNumber)
|
||||||
dataToEncrypt += encodeVarint(streamNumber)
|
dataToEncrypt += encodeVarint(streamNumber)
|
||||||
|
@ -788,7 +788,7 @@ class singleWorker(StoppableThread):
|
||||||
# We don't have the needed pubkey in the pubkeys table already.
|
# We don't have the needed pubkey in the pubkeys table already.
|
||||||
else:
|
else:
|
||||||
if toAddressVersionNumber <= 3:
|
if toAddressVersionNumber <= 3:
|
||||||
toTag = ''
|
toTag = b''
|
||||||
else:
|
else:
|
||||||
toTag = highlevelcrypto.double_sha512(
|
toTag = highlevelcrypto.double_sha512(
|
||||||
encodeVarint(toAddressVersionNumber)
|
encodeVarint(toAddressVersionNumber)
|
||||||
|
@ -1201,14 +1201,14 @@ class singleWorker(StoppableThread):
|
||||||
'Not bothering to include ackdata because we are'
|
'Not bothering to include ackdata because we are'
|
||||||
' sending to ourselves or a chan.'
|
' sending to ourselves or a chan.'
|
||||||
)
|
)
|
||||||
fullAckPayload = ''
|
fullAckPayload = b''
|
||||||
elif not protocol.checkBitfield(
|
elif not protocol.checkBitfield(
|
||||||
behaviorBitfield, protocol.BITFIELD_DOESACK):
|
behaviorBitfield, protocol.BITFIELD_DOESACK):
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
'Not bothering to include ackdata because'
|
'Not bothering to include ackdata because'
|
||||||
' the receiver said that they won\'t relay it anyway.'
|
' the receiver said that they won\'t relay it anyway.'
|
||||||
)
|
)
|
||||||
fullAckPayload = ''
|
fullAckPayload = b''
|
||||||
else:
|
else:
|
||||||
# The fullAckPayload is a normal msg protocol message
|
# The fullAckPayload is a normal msg protocol message
|
||||||
# with the proof of work already completed that the
|
# with the proof of work already completed that the
|
||||||
|
@ -1217,7 +1217,7 @@ class singleWorker(StoppableThread):
|
||||||
ackdata, toStreamNumber, TTL)
|
ackdata, toStreamNumber, TTL)
|
||||||
payload += encodeVarint(len(fullAckPayload))
|
payload += encodeVarint(len(fullAckPayload))
|
||||||
payload += fullAckPayload
|
payload += fullAckPayload
|
||||||
dataToSign = pack('>Q', embeddedTime) + '\x00\x00\x00\x02' + \
|
dataToSign = pack('>Q', embeddedTime) + b'\x00\x00\x00\x02' + \
|
||||||
encodeVarint(1) + encodeVarint(toStreamNumber) + payload
|
encodeVarint(1) + encodeVarint(toStreamNumber) + payload
|
||||||
signature = highlevelcrypto.sign(
|
signature = highlevelcrypto.sign(
|
||||||
dataToSign, privSigningKeyHex, self.digestAlg)
|
dataToSign, privSigningKeyHex, self.digestAlg)
|
||||||
|
@ -1227,7 +1227,7 @@ class singleWorker(StoppableThread):
|
||||||
# We have assembled the data that will be encrypted.
|
# We have assembled the data that will be encrypted.
|
||||||
try:
|
try:
|
||||||
encrypted = highlevelcrypto.encrypt(
|
encrypted = highlevelcrypto.encrypt(
|
||||||
payload, "04" + hexlify(pubEncryptionKeyBase256)
|
payload, b"04" + hexlify(pubEncryptionKeyBase256)
|
||||||
)
|
)
|
||||||
except: # noqa:E722
|
except: # noqa:E722
|
||||||
self.logger.warning("highlevelcrypto.encrypt didn't work")
|
self.logger.warning("highlevelcrypto.encrypt didn't work")
|
||||||
|
@ -1247,7 +1247,7 @@ class singleWorker(StoppableThread):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
encryptedPayload = pack('>Q', embeddedTime)
|
encryptedPayload = pack('>Q', embeddedTime)
|
||||||
encryptedPayload += '\x00\x00\x00\x02' # object type: msg
|
encryptedPayload += b'\x00\x00\x00\x02' # object type: msg
|
||||||
encryptedPayload += encodeVarint(1) # msg version
|
encryptedPayload += encodeVarint(1) # msg version
|
||||||
encryptedPayload += encodeVarint(toStreamNumber) + encrypted
|
encryptedPayload += encodeVarint(toStreamNumber) + encrypted
|
||||||
target = 2 ** 64 / (
|
target = 2 ** 64 / (
|
||||||
|
@ -1429,7 +1429,7 @@ class singleWorker(StoppableThread):
|
||||||
TTL = TTL + helper_random.randomrandrange(-300, 300)
|
TTL = TTL + helper_random.randomrandrange(-300, 300)
|
||||||
embeddedTime = int(time.time() + TTL)
|
embeddedTime = int(time.time() + TTL)
|
||||||
payload = pack('>Q', embeddedTime)
|
payload = pack('>Q', embeddedTime)
|
||||||
payload += '\x00\x00\x00\x00' # object type: getpubkey
|
payload += b'\x00\x00\x00\x00' # object type: getpubkey
|
||||||
payload += encodeVarint(addressVersionNumber)
|
payload += encodeVarint(addressVersionNumber)
|
||||||
payload += encodeVarint(streamNumber)
|
payload += encodeVarint(streamNumber)
|
||||||
if addressVersionNumber <= 3:
|
if addressVersionNumber <= 3:
|
||||||
|
@ -1511,4 +1511,4 @@ class singleWorker(StoppableThread):
|
||||||
payload = self._doPOWDefaults(
|
payload = self._doPOWDefaults(
|
||||||
payload, TTL, log_prefix='(For ack message)', log_time=True)
|
payload, TTL, log_prefix='(For ack message)', log_time=True)
|
||||||
|
|
||||||
return protocol.CreatePacket('object', payload)
|
return protocol.CreatePacket(b'object', payload)
|
||||||
|
|
|
@ -19,17 +19,17 @@ def calculateBitcoinAddressFromPubkey(pubkey):
|
||||||
sha = hashlib.new('sha256')
|
sha = hashlib.new('sha256')
|
||||||
sha.update(pubkey)
|
sha.update(pubkey)
|
||||||
ripe.update(sha.digest())
|
ripe.update(sha.digest())
|
||||||
ripeWithProdnetPrefix = '\x00' + ripe.digest()
|
ripeWithProdnetPrefix = b'\x00' + ripe.digest()
|
||||||
|
|
||||||
checksum = hashlib.sha256(hashlib.sha256(
|
checksum = hashlib.sha256(hashlib.sha256(
|
||||||
ripeWithProdnetPrefix).digest()).digest()[:4]
|
ripeWithProdnetPrefix).digest()).digest()[:4]
|
||||||
binaryBitcoinAddress = ripeWithProdnetPrefix + checksum
|
binaryBitcoinAddress = ripeWithProdnetPrefix + checksum
|
||||||
numberOfZeroBytesOnBinaryBitcoinAddress = 0
|
numberOfZeroBytesOnBinaryBitcoinAddress = 0
|
||||||
while binaryBitcoinAddress[0] == '\x00':
|
while binaryBitcoinAddress[0] == b'\x00':
|
||||||
numberOfZeroBytesOnBinaryBitcoinAddress += 1
|
numberOfZeroBytesOnBinaryBitcoinAddress += 1
|
||||||
binaryBitcoinAddress = binaryBitcoinAddress[1:]
|
binaryBitcoinAddress = binaryBitcoinAddress[1:]
|
||||||
base58encoded = arithmetic.changebase(binaryBitcoinAddress, 256, 58)
|
base58encoded = arithmetic.changebase(binaryBitcoinAddress, 256, 58)
|
||||||
return "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
|
return b"1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
|
||||||
|
|
||||||
|
|
||||||
def calculateTestnetAddressFromPubkey(pubkey):
|
def calculateTestnetAddressFromPubkey(pubkey):
|
||||||
|
@ -43,14 +43,14 @@ def calculateTestnetAddressFromPubkey(pubkey):
|
||||||
sha = hashlib.new('sha256')
|
sha = hashlib.new('sha256')
|
||||||
sha.update(pubkey)
|
sha.update(pubkey)
|
||||||
ripe.update(sha.digest())
|
ripe.update(sha.digest())
|
||||||
ripeWithProdnetPrefix = '\x6F' + ripe.digest()
|
ripeWithProdnetPrefix = b'\x6F' + ripe.digest()
|
||||||
|
|
||||||
checksum = hashlib.sha256(hashlib.sha256(
|
checksum = hashlib.sha256(hashlib.sha256(
|
||||||
ripeWithProdnetPrefix).digest()).digest()[:4]
|
ripeWithProdnetPrefix).digest()).digest()[:4]
|
||||||
binaryBitcoinAddress = ripeWithProdnetPrefix + checksum
|
binaryBitcoinAddress = ripeWithProdnetPrefix + checksum
|
||||||
numberOfZeroBytesOnBinaryBitcoinAddress = 0
|
numberOfZeroBytesOnBinaryBitcoinAddress = 0
|
||||||
while binaryBitcoinAddress[0] == '\x00':
|
while binaryBitcoinAddress[0] == b'\x00':
|
||||||
numberOfZeroBytesOnBinaryBitcoinAddress += 1
|
numberOfZeroBytesOnBinaryBitcoinAddress += 1
|
||||||
binaryBitcoinAddress = binaryBitcoinAddress[1:]
|
binaryBitcoinAddress = binaryBitcoinAddress[1:]
|
||||||
base58encoded = arithmetic.changebase(binaryBitcoinAddress, 256, 58)
|
base58encoded = arithmetic.changebase(binaryBitcoinAddress, 256, 58)
|
||||||
return "1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
|
return b"1" * numberOfZeroBytesOnBinaryBitcoinAddress + base58encoded
|
||||||
|
|
|
@ -82,7 +82,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
"""Process incoming header"""
|
"""Process incoming header"""
|
||||||
self.magic, self.command, self.payloadLength, self.checksum = \
|
self.magic, self.command, self.payloadLength, self.checksum = \
|
||||||
protocol.Header.unpack(self.read_buf[:protocol.Header.size])
|
protocol.Header.unpack(self.read_buf[:protocol.Header.size])
|
||||||
self.command = self.command.rstrip('\x00')
|
self.command = self.command.rstrip(b'\x00')
|
||||||
if self.magic != protocol.magic:
|
if self.magic != protocol.magic:
|
||||||
# skip 1 byte in order to sync
|
# skip 1 byte in order to sync
|
||||||
self.set_state("bm_header", length=1)
|
self.set_state("bm_header", length=1)
|
||||||
|
@ -107,7 +107,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
self.invalid = True
|
self.invalid = True
|
||||||
retval = True
|
retval = True
|
||||||
if not self.fullyEstablished and self.command not in (
|
if not self.fullyEstablished and self.command not in (
|
||||||
"error", "version", "verack"):
|
b"error", b"version", b"verack"):
|
||||||
logger.error(
|
logger.error(
|
||||||
'Received command %s before connection was fully'
|
'Received command %s before connection was fully'
|
||||||
' established, ignoring', self.command)
|
' established, ignoring', self.command)
|
||||||
|
@ -168,14 +168,14 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
"""Decode node details from the payload"""
|
"""Decode node details from the payload"""
|
||||||
# protocol.checkIPAddress()
|
# protocol.checkIPAddress()
|
||||||
services, host, port = self.decode_payload_content("Q16sH")
|
services, host, port = self.decode_payload_content("Q16sH")
|
||||||
if host[0:12] == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF':
|
if host[0:12] == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF':
|
||||||
host = socket.inet_ntop(socket.AF_INET, str(host[12:16]))
|
host = socket.inet_ntop(socket.AF_INET, str(host[12:16]))
|
||||||
elif host[0:6] == '\xfd\x87\xd8\x7e\xeb\x43':
|
elif host[0:6] == b'\xfd\x87\xd8\x7e\xeb\x43':
|
||||||
# Onion, based on BMD/bitcoind
|
# Onion, based on BMD/bitcoind
|
||||||
host = base64.b32encode(host[6:]).lower() + ".onion"
|
host = base64.b32encode(host[6:]).lower() + b".onion"
|
||||||
else:
|
else:
|
||||||
host = socket.inet_ntop(socket.AF_INET6, str(host))
|
host = socket.inet_ntop(socket.AF_INET6, str(host))
|
||||||
if host == "":
|
if host == b"":
|
||||||
# This can happen on Windows systems which are not 64-bit
|
# This can happen on Windows systems which are not 64-bit
|
||||||
# compatible so let us drop the IPv6 address.
|
# compatible so let us drop the IPv6 address.
|
||||||
host = socket.inet_ntop(socket.AF_INET, str(host[12:16]))
|
host = socket.inet_ntop(socket.AF_INET, str(host[12:16]))
|
||||||
|
@ -477,7 +477,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
|
|
||||||
def bm_command_ping(self):
|
def bm_command_ping(self):
|
||||||
"""Incoming ping, respond to it."""
|
"""Incoming ping, respond to it."""
|
||||||
self.append_write_buf(protocol.CreatePacket('pong'))
|
self.append_write_buf(protocol.CreatePacket(b'pong'))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -531,12 +531,12 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
if not self.peerValidityChecks():
|
if not self.peerValidityChecks():
|
||||||
# ABORT afterwards
|
# ABORT afterwards
|
||||||
return True
|
return True
|
||||||
self.append_write_buf(protocol.CreatePacket('verack'))
|
self.append_write_buf(protocol.CreatePacket(b'verack'))
|
||||||
self.verackSent = True
|
self.verackSent = True
|
||||||
ua_valid = re.match(
|
ua_valid = re.match(
|
||||||
r'^/[a-zA-Z]+:[0-9]+\.?[\w\s\(\)\./:;-]*/$', self.userAgent)
|
r'^/[a-zA-Z]+:[0-9]+\.?[\w\s\(\)\./:;-]*/$', self.userAgent)
|
||||||
if not ua_valid:
|
if not ua_valid:
|
||||||
self.userAgent = '/INVALID:0/'
|
self.userAgent = b'/INVALID:0/'
|
||||||
if not self.isOutbound:
|
if not self.isOutbound:
|
||||||
self.append_write_buf(protocol.assembleVersionMessage(
|
self.append_write_buf(protocol.assembleVersionMessage(
|
||||||
self.destination.host, self.destination.port,
|
self.destination.host, self.destination.port,
|
||||||
|
|
|
@ -381,7 +381,7 @@ class BMConnectionPool(object):
|
||||||
minTx -= 300 - 20
|
minTx -= 300 - 20
|
||||||
if i.lastTx < minTx:
|
if i.lastTx < minTx:
|
||||||
if i.fullyEstablished:
|
if i.fullyEstablished:
|
||||||
i.append_write_buf(protocol.CreatePacket('ping'))
|
i.append_write_buf(protocol.CreatePacket(b'ping'))
|
||||||
else:
|
else:
|
||||||
i.close_reason = "Timeout (%is)" % (
|
i.close_reason = "Timeout (%is)" % (
|
||||||
time.time() - i.lastTx)
|
time.time() - i.lastTx)
|
||||||
|
|
|
@ -71,7 +71,7 @@ class DownloadThread(StoppableThread):
|
||||||
if not chunkCount:
|
if not chunkCount:
|
||||||
continue
|
continue
|
||||||
payload[0:0] = addresses.encodeVarint(chunkCount)
|
payload[0:0] = addresses.encodeVarint(chunkCount)
|
||||||
i.append_write_buf(protocol.CreatePacket('getdata', payload))
|
i.append_write_buf(protocol.CreatePacket(b'getdata', payload))
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
'%s:%i Requesting %i objects',
|
'%s:%i Requesting %i objects',
|
||||||
i.destination.host, i.destination.port, chunkCount)
|
i.destination.host, i.destination.port, chunkCount)
|
||||||
|
|
|
@ -90,15 +90,15 @@ class InvThread(StoppableThread):
|
||||||
if fluffs:
|
if fluffs:
|
||||||
random.shuffle(fluffs)
|
random.shuffle(fluffs)
|
||||||
connection.append_write_buf(protocol.CreatePacket(
|
connection.append_write_buf(protocol.CreatePacket(
|
||||||
'inv',
|
b'inv',
|
||||||
addresses.encodeVarint(
|
addresses.encodeVarint(
|
||||||
len(fluffs)) + ''.join(fluffs)))
|
len(fluffs)) + b''.join(fluffs)))
|
||||||
if stems:
|
if stems:
|
||||||
random.shuffle(stems)
|
random.shuffle(stems)
|
||||||
connection.append_write_buf(protocol.CreatePacket(
|
connection.append_write_buf(protocol.CreatePacket(
|
||||||
'dinv',
|
b'dinv',
|
||||||
addresses.encodeVarint(
|
addresses.encodeVarint(
|
||||||
len(stems)) + ''.join(stems)))
|
len(stems)) + b''.join(stems)))
|
||||||
|
|
||||||
invQueue.iterate()
|
invQueue.iterate()
|
||||||
for _ in range(len(chunk)):
|
for _ in range(len(chunk)):
|
||||||
|
|
|
@ -220,7 +220,7 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
'Sending huge inv message with %i objects to just this'
|
'Sending huge inv message with %i objects to just this'
|
||||||
' one peer', objectCount)
|
' one peer', objectCount)
|
||||||
self.append_write_buf(protocol.CreatePacket(
|
self.append_write_buf(protocol.CreatePacket(
|
||||||
'inv', addresses.encodeVarint(objectCount) + payload))
|
b'inv', addresses.encodeVarint(objectCount) + payload))
|
||||||
|
|
||||||
# Select all hashes for objects in this stream.
|
# Select all hashes for objects in this stream.
|
||||||
bigInvList = {}
|
bigInvList = {}
|
||||||
|
|
|
@ -34,7 +34,7 @@ else:
|
||||||
# ciphers
|
# ciphers
|
||||||
if (
|
if (
|
||||||
ssl.OPENSSL_VERSION_NUMBER >= 0x10100000
|
ssl.OPENSSL_VERSION_NUMBER >= 0x10100000
|
||||||
and not ssl.OPENSSL_VERSION.startswith(b"LibreSSL")
|
and not ssl.OPENSSL_VERSION.startswith("LibreSSL")
|
||||||
):
|
):
|
||||||
sslProtocolCiphers = "AECDH-AES256-SHA@SECLEVEL=0"
|
sslProtocolCiphers = "AECDH-AES256-SHA@SECLEVEL=0"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -49,7 +49,7 @@ class UploadThread(StoppableThread):
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
payload.extend(protocol.CreatePacket(
|
payload.extend(protocol.CreatePacket(
|
||||||
'object', state.Inventory[chunk].payload))
|
b'object', state.Inventory[chunk].payload))
|
||||||
chunk_count += 1
|
chunk_count += 1
|
||||||
except KeyError:
|
except KeyError:
|
||||||
i.antiIntersectionDelay()
|
i.antiIntersectionDelay()
|
||||||
|
|
|
@ -172,7 +172,7 @@ def checkIPAddress(host, private=False):
|
||||||
return checkIPv4Address(host[12:], hostStandardFormat, private)
|
return checkIPv4Address(host[12:], hostStandardFormat, private)
|
||||||
elif host[0:6] == b'\xfd\x87\xd8\x7e\xeb\x43':
|
elif host[0:6] == b'\xfd\x87\xd8\x7e\xeb\x43':
|
||||||
# Onion, based on BMD/bitcoind
|
# Onion, based on BMD/bitcoind
|
||||||
hostStandardFormat = base64.b32encode(host[6:]).lower() + ".onion"
|
hostStandardFormat = base64.b32encode(host[6:]).lower() + b".onion"
|
||||||
if private:
|
if private:
|
||||||
return False
|
return False
|
||||||
return hostStandardFormat
|
return hostStandardFormat
|
||||||
|
@ -511,9 +511,9 @@ def decryptAndCheckPubkeyPayload(data, address):
|
||||||
readPosition = 0
|
readPosition = 0
|
||||||
# bitfieldBehaviors = decryptedData[readPosition:readPosition + 4]
|
# bitfieldBehaviors = decryptedData[readPosition:readPosition + 4]
|
||||||
readPosition += 4
|
readPosition += 4
|
||||||
pubSigningKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
pubSigningKey = b'\x04' + decryptedData[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
pubEncryptionKey = '\x04' + decryptedData[readPosition:readPosition + 64]
|
pubEncryptionKey = b'\x04' + decryptedData[readPosition:readPosition + 64]
|
||||||
readPosition += 64
|
readPosition += 64
|
||||||
specifiedNonceTrialsPerByteLength = decodeVarint(
|
specifiedNonceTrialsPerByteLength = decodeVarint(
|
||||||
decryptedData[readPosition:readPosition + 10])[1]
|
decryptedData[readPosition:readPosition + 10])[1]
|
||||||
|
|
Reference in New Issue
Block a user