python 3 port
This commit is contained in:
parent
f9c49fbeb3
commit
c41cff67ac
|
@ -14,8 +14,8 @@ try:
|
||||||
import state
|
import state
|
||||||
from singleton import Singleton
|
from singleton import Singleton
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from pybitmessage import state
|
from . import state
|
||||||
from pybitmessage.singleton import Singleton
|
from .singleton import Singleton
|
||||||
|
|
||||||
SafeConfigParser = configparser.SafeConfigParser
|
SafeConfigParser = configparser.SafeConfigParser
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,16 @@ High level cryptographic functions based on `.pyelliptic` OpenSSL bindings.
|
||||||
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
|
||||||
import pyelliptic
|
try:
|
||||||
from bmconfigparser import BMConfigParser
|
import pyelliptic
|
||||||
from pyelliptic import OpenSSL
|
from bmconfigparser import BMConfigParser
|
||||||
from pyelliptic import arithmetic as a
|
from pyelliptic import OpenSSL
|
||||||
|
from pyelliptic import arithmetic as a
|
||||||
|
except ImportError:
|
||||||
|
from . import pyelliptic
|
||||||
|
from .bmconfigparser import BMConfigParser
|
||||||
|
from .pyelliptic import OpenSSL
|
||||||
|
from .pyelliptic import arithmetic as a
|
||||||
|
|
||||||
|
|
||||||
def makeCryptor(privkey):
|
def makeCryptor(privkey):
|
||||||
|
|
|
@ -13,16 +13,30 @@ import time
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from struct import Struct, pack, unpack
|
from struct import Struct, pack, unpack
|
||||||
|
|
||||||
import defaults
|
try:
|
||||||
import highlevelcrypto
|
import defaults
|
||||||
import state
|
import highlevelcrypto
|
||||||
from addresses import (
|
import state
|
||||||
|
from addresses import (
|
||||||
encodeVarint, decodeVarint, decodeAddress, varintDecodeError)
|
encodeVarint, decodeVarint, decodeAddress, varintDecodeError)
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from debug import logger
|
from debug import logger
|
||||||
from fallback import RIPEMD160Hash
|
from fallback import RIPEMD160Hash
|
||||||
from helper_sql import sqlExecute
|
from helper_sql import sqlExecute
|
||||||
from version import softwareVersion
|
from version import softwareVersion
|
||||||
|
except ImportError:
|
||||||
|
from . import defaults
|
||||||
|
from . import highlevelcrypto
|
||||||
|
from . import state
|
||||||
|
from .addresses import (
|
||||||
|
encodeVarint, decodeVarint, decodeAddress, varintDecodeError)
|
||||||
|
from .bmconfigparser import BMConfigParser
|
||||||
|
from .debug import logger
|
||||||
|
from .fallback import RIPEMD160Hash
|
||||||
|
from .helper_sql import sqlExecute
|
||||||
|
from .version import softwareVersion
|
||||||
|
|
||||||
|
PY3 = sys.version_info[0] >= 3
|
||||||
|
|
||||||
# Service flags
|
# Service flags
|
||||||
#: This is a normal network node
|
#: This is a normal network node
|
||||||
|
@ -100,6 +114,11 @@ def encodeHost(host):
|
||||||
return '\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode(
|
return '\xfd\x87\xd8\x7e\xeb\x43' + base64.b32decode(
|
||||||
host.split(".")[0], True)
|
host.split(".")[0], True)
|
||||||
elif host.find(':') == -1:
|
elif host.find(':') == -1:
|
||||||
|
import pdb; pdb.set_trace()
|
||||||
|
if PY3:
|
||||||
|
return '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' + \
|
||||||
|
socket.inet_aton(host).decode('utf-8')
|
||||||
|
else:
|
||||||
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' + \
|
||||||
socket.inet_aton(host)
|
socket.inet_aton(host)
|
||||||
return socket.inet_pton(socket.AF_INET6, host)
|
return socket.inet_pton(socket.AF_INET6, host)
|
||||||
|
@ -210,7 +229,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(str(host[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)
|
||||||
|
|
|
@ -4,10 +4,6 @@ Tests for common protocol functions
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from .common import skip_python3
|
|
||||||
|
|
||||||
skip_python3()
|
|
||||||
|
|
||||||
|
|
||||||
class TestProtocol(unittest.TestCase):
|
class TestProtocol(unittest.TestCase):
|
||||||
"""Main protocol test case"""
|
"""Main protocol test case"""
|
||||||
|
@ -15,11 +11,12 @@ class TestProtocol(unittest.TestCase):
|
||||||
def test_check_local(self):
|
def test_check_local(self):
|
||||||
"""Check the logic of TCPConnection.local"""
|
"""Check the logic of TCPConnection.local"""
|
||||||
from pybitmessage import protocol, state
|
from pybitmessage import protocol, state
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
protocol.checkIPAddress(protocol.encodeHost('127.0.0.1'), True))
|
protocol.checkIPAddress(protocol.encodeHost('127.0.0.1').decode('ISO-8859-1'), True))
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
protocol.checkIPAddress(protocol.encodeHost('192.168.0.1'), True))
|
protocol.checkIPAddress(protocol.encodeHost('192.168.0.1').decode('ISO-8859-1'), True))
|
||||||
|
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
not protocol.checkSocksIP('127.0.0.1')
|
not protocol.checkSocksIP('127.0.0.1')
|
||||||
|
|
Reference in New Issue
Block a user