Skip to content

Commit

Permalink
refactored :interfaces
Browse files Browse the repository at this point in the history
Co-authored-by: mystical-prog <[email protected]>
  • Loading branch information
Khwahish29 and mystical-prog committed Feb 12, 2025
1 parent 64e037e commit a5d5672
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 51 deletions.
4 changes: 1 addition & 3 deletions libp2p/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from libp2p.abc import (
IHost,
INetworkService,
IPeerRouting,
IPeerStore,
)
from libp2p.crypto.keys import (
Expand All @@ -29,9 +30,6 @@
from libp2p.peer.peerstore import (
PeerStore,
)
from libp2p.routing.interfaces import (
IPeerRouting,
)
from libp2p.security.insecure.transport import (
PLAINTEXT_PROTOCOL_ID,
InsecureTransport,
Expand Down
32 changes: 32 additions & 0 deletions libp2p/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
abstractmethod,
)
from collections.abc import (
Iterable,
Sequence,
)
from typing import (
Expand Down Expand Up @@ -780,3 +781,34 @@ async def negotiate(
:return: selected protocol name, handler function
:raise Exception: negotiation failed exception
"""


# interfaces


class IContentRouting(ABC):
@abstractmethod
def provide(self, cid: bytes, announce: bool = True) -> None:
"""
Provide adds the given cid to the content routing system.
If announce is True, it also announces it, otherwise it is just
kept in the local accounting of which objects are being
provided.
"""

@abstractmethod
def find_provider_iter(self, cid: bytes, count: int) -> Iterable[PeerInfo]:
"""
Search for peers who are able to provide a given key returns an
iterator of peer.PeerInfo.
"""


class IPeerRouting(ABC):
@abstractmethod
async def find_peer(self, peer_id: ID) -> PeerInfo:
"""
Find specific Peer FindPeer searches for a peer with given peer_id,
returns a peer.PeerInfo with relevant addresses.
"""
4 changes: 1 addition & 3 deletions libp2p/host/routed_host.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from libp2p.abc import (
INetworkService,
IPeerRouting,
)
from libp2p.host.basic_host import (
BasicHost,
Expand All @@ -10,9 +11,6 @@
from libp2p.peer.peerinfo import (
PeerInfo,
)
from libp2p.routing.interfaces import (
IPeerRouting,
)


# RoutedHost is a p2p Host that includes a routing system.
Expand Down
42 changes: 0 additions & 42 deletions libp2p/routing/interfaces.py

This file was deleted.

4 changes: 1 addition & 3 deletions libp2p/tools/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from libp2p.abc import (
IHost,
INetStream,
IPeerRouting,
IRawConnection,
ISecureConn,
)
Expand Down Expand Up @@ -78,9 +79,6 @@
Pubsub,
get_peer_and_seqno_msg_id,
)
from libp2p.routing.interfaces import (
IPeerRouting,
)
from libp2p.security.insecure.transport import (
PLAINTEXT_PROTOCOL_ID,
InsecureTransport,
Expand Down

0 comments on commit a5d5672

Please sign in to comment.