mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Run black over repo
This commit is contained in:
@ -1,16 +1,13 @@
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Iterable
|
||||
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.peer.peerinfo import PeerInfo
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
|
||||
class IContentRouting(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def provide(self, cid: bytes, announce: bool = True) -> None:
|
||||
"""
|
||||
@ -28,7 +25,6 @@ class IContentRouting(ABC):
|
||||
|
||||
|
||||
class IPeerRouting(ABC):
|
||||
|
||||
@abstractmethod
|
||||
async def find_peer(self, peer_id: ID) -> PeerInfo:
|
||||
"""
|
||||
|
||||
@ -1,13 +1,10 @@
|
||||
from typing import (
|
||||
Iterable,
|
||||
)
|
||||
from typing import Iterable
|
||||
|
||||
from libp2p.peer.peerinfo import PeerInfo
|
||||
from libp2p.routing.interfaces import IContentRouting
|
||||
|
||||
|
||||
class KadmeliaContentRouter(IContentRouting):
|
||||
|
||||
def provide(self, cid: bytes, announce: bool = True) -> None:
|
||||
"""
|
||||
Provide adds the given cid to the content routing system. If announce is True,
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
import ast
|
||||
from typing import (
|
||||
Union,
|
||||
)
|
||||
from typing import Union
|
||||
|
||||
from libp2p.kademlia.kad_peerinfo import (
|
||||
KadPeerInfo,
|
||||
create_kad_peerinfo,
|
||||
)
|
||||
from libp2p.kademlia.kad_peerinfo import KadPeerInfo, create_kad_peerinfo
|
||||
from libp2p.kademlia.network import KademliaServer
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.routing.interfaces import IPeerRouting
|
||||
@ -31,6 +26,7 @@ class KadmeliaPeerRouter(IPeerRouting):
|
||||
value = await self.server.get(xor_id)
|
||||
return decode_peerinfo(value)
|
||||
|
||||
|
||||
def decode_peerinfo(encoded: Union[bytes, str]) -> KadPeerInfo:
|
||||
if isinstance(encoded, bytes):
|
||||
encoded = encoded.decode()
|
||||
@ -38,7 +34,7 @@ def decode_peerinfo(encoded: Union[bytes, str]) -> KadPeerInfo:
|
||||
lines = ast.literal_eval(encoded)
|
||||
except SyntaxError:
|
||||
return None
|
||||
ip = lines[1] # pylint: disable=invalid-name
|
||||
ip = lines[1] # pylint: disable=invalid-name
|
||||
port = lines[2]
|
||||
peer_id = lines[3]
|
||||
peer_info = create_kad_peerinfo(peer_id, ip, port)
|
||||
|
||||
Reference in New Issue
Block a user