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