mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
Added tests for 'RoutedHost' and modified 'FindPeer'
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import json
|
||||
from typing import List, Sequence
|
||||
|
||||
import multiaddr
|
||||
@ -14,6 +15,17 @@ class PeerInfo:
|
||||
self.peer_id = peer_id
|
||||
self.addrs = list(addrs)
|
||||
|
||||
def to_string(self) -> str:
|
||||
return json.dumps([self.peer_id.to_string(), list(map(lambda a: str(a), self.addrs))])
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, PeerInfo) and self.peer_id == other.peer_id and self.addrs == other.addrs
|
||||
|
||||
@classmethod
|
||||
def info_from_string(cls, info: str) -> "PeerInfo":
|
||||
peer_id, raw_addrs = json.loads(info)
|
||||
return PeerInfo(ID.from_base58(peer_id), list(map(lambda a: multiaddr.Multiaddr(a), raw_addrs)))
|
||||
|
||||
|
||||
def info_from_p2p_addr(addr: multiaddr.Multiaddr) -> PeerInfo:
|
||||
if not addr:
|
||||
|
||||
Reference in New Issue
Block a user