diff --git a/daemon/core/api/tlv/broker.py b/daemon/core/api/tlv/broker.py index 2021bb4c..b7b24746 100644 --- a/daemon/core/api/tlv/broker.py +++ b/daemon/core/api/tlv/broker.py @@ -10,6 +10,7 @@ import select import socket import threading +from core import utils from core.api.tlv import coreapi from core.nodes.base import CoreNodeBase, CoreNetworkBase from core.emulator.enumerations import ConfigDataTypes @@ -387,12 +388,13 @@ class CoreBroker(object): :return: tunnel key for the node pair :rtype: int """ + logging.debug("creating tunnel key for: %s, %s", n1num, n2num) sid = self.session_id_master if sid is None: # this is the master session sid = self.session.id - key = (sid << 16) ^ hash(n1num) ^ (hash(n2num) << 8) + key = (sid << 16) ^ utils.hash(n1num) ^ (utils.hash(n2num) << 8) return key & 0xFFFFFFFF def addtunnel(self, remoteip, n1num, n2num, localnum): diff --git a/daemon/core/utils.py b/daemon/core/utils.py index ac76e693..89c8aa71 100644 --- a/daemon/core/utils.py +++ b/daemon/core/utils.py @@ -3,6 +3,7 @@ Miscellaneous utility functions, wrappers around some subprocess procedures. """ import fcntl +import hashlib import importlib import inspect import logging @@ -17,6 +18,22 @@ from core import CoreCommandError DEVNULL = open(os.devnull, "wb") +def hash(value): + """ + Provide a consistent hash that can be used in place + of the builtin hash, that no longer behaves consistently + in python3. + + :param str/int value: value to hash + :return: hash value + :rtype: int + """ + if isinstance(value, int): + value = str(value) + value = value.encode("utf-8") + return int(hashlib.sha256(value).hexdigest(), 16) + + def _detach_init(): """ Fork a child process and exit.