fix assert error
This commit is contained in:
parent
c3e63110f4
commit
6b62c50925
|
@ -107,10 +107,16 @@ def isBitSetWithinBitfield(fourByteString, n):
|
||||||
|
|
||||||
|
|
||||||
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:
|
||||||
return '\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode(
|
try:
|
||||||
|
return '\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode(
|
||||||
host.split(".")[0], True)
|
host.split(".")[0], True)
|
||||||
|
except TypeError:
|
||||||
|
return '\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode(
|
||||||
|
host.split(".")[0], True).decode('utf-8', 'ignore')
|
||||||
elif host.find(':') == -1:
|
elif host.find(':') == -1:
|
||||||
try:
|
try:
|
||||||
return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \
|
return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \
|
||||||
|
@ -151,7 +157,7 @@ def network_group(host):
|
||||||
decoded_host = checkIPv6Address(raw_host, True)
|
decoded_host = checkIPv6Address(raw_host, True)
|
||||||
if decoded_host:
|
if decoded_host:
|
||||||
# /32 subnet
|
# /32 subnet
|
||||||
return raw_host[0:12]
|
return raw_host[0:12].decode()
|
||||||
else:
|
else:
|
||||||
# just host, e.g. for tor
|
# just host, e.g. for tor
|
||||||
return host
|
return host
|
||||||
|
@ -227,7 +233,7 @@ def checkIPv6Address(host, hostStandardFormat, private=False):
|
||||||
if not private:
|
if not private:
|
||||||
logger.debug('Ignoring local address: %s', hostStandardFormat)
|
logger.debug('Ignoring local address: %s', hostStandardFormat)
|
||||||
return hostStandardFormat if private else False
|
return hostStandardFormat if private else False
|
||||||
if (ord(host[0]) & 0xfe) == 0xfc:
|
if (ord(host.decode()[0]) & 0xfe) == 0xfc:
|
||||||
if not private:
|
if not private:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Ignoring unique local address: %s', hostStandardFormat)
|
'Ignoring unique local address: %s', hostStandardFormat)
|
||||||
|
|
|
@ -32,10 +32,10 @@ class TestNetworkGroup(unittest.TestCase):
|
||||||
'bootstrap8444.bitmessage.org',
|
'bootstrap8444.bitmessage.org',
|
||||||
network_group(test_ip))
|
network_group(test_ip))
|
||||||
|
|
||||||
# test_ip = 'quzwelsuziwqgpt2.onion'
|
test_ip = 'quzwelsuziwqgpt2.onion'
|
||||||
# self.assertEqual(
|
self.assertEqual(
|
||||||
# test_ip,
|
test_ip,
|
||||||
# network_group(test_ip))
|
network_group(test_ip))
|
||||||
|
|
||||||
test_ip = None
|
test_ip = None
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Reference in New Issue
Block a user