updated logic for creating tunnel keys to use a consistent hashing method, since the builtin hash is not guaranteed in python3 as it was before in python2

This commit is contained in:
Blake Harnden 2019-06-20 13:22:20 -07:00
parent 338c3a1fa1
commit a5f26e664a
2 changed files with 20 additions and 1 deletions

View file

@ -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.