mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
refactored routedhost into router passed to swarm
This commit is contained in:
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user