refactored routedhost into router passed to swarm

This commit is contained in:
Alex Haynes
2019-04-24 22:11:54 -04:00
parent fc4fc74b87
commit 6c5bac53d7
13 changed files with 48 additions and 50 deletions

View File

@ -1,5 +1,6 @@
import base58
import multihash
import hashlib
# MaxInlineKeyLength is the maximum length a key can be for it to be inlined in
# the peer ID.
@ -21,6 +22,9 @@ class ID:
def pretty(self):
return base58.b58encode(self._id_str).decode()
def get_xor_id(self):
return int(digest(self.get_raw_id()).hex(), 16)
def __str__(self):
pid = self.pretty()
if len(pid) <= 10:
@ -67,3 +71,8 @@ def id_from_public_key(key):
def id_from_private_key(key):
return id_from_public_key(key.publickey())
def digest(string):
if not isinstance(string, bytes):
string = str(string).encode('utf8')
return hashlib.sha1(string).digest()