mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Fix cyclic import and lint
This commit is contained in:
@ -60,9 +60,9 @@ class GossipSub(IPubsubRouter):
|
||||
degree_low: int,
|
||||
degree_high: int,
|
||||
time_to_live: int,
|
||||
gossip_window: int=3,
|
||||
gossip_history: int=5,
|
||||
heartbeat_interval: int=120) -> None:
|
||||
gossip_window: int = 3,
|
||||
gossip_history: int = 5,
|
||||
heartbeat_interval: int = 120) -> None:
|
||||
# pylint: disable=too-many-arguments
|
||||
self.protocols = list(protocols)
|
||||
self.pubsub = None
|
||||
@ -79,6 +79,9 @@ class GossipSub(IPubsubRouter):
|
||||
self.mesh = {}
|
||||
self.fanout = {}
|
||||
|
||||
# Create peer --> protocol mapping
|
||||
self.peers_to_protocol = {}
|
||||
|
||||
# Create topic --> time since last publish map
|
||||
self.time_since_last_publish = {}
|
||||
|
||||
@ -449,7 +452,9 @@ class GossipSub(IPubsubRouter):
|
||||
self.mcache.shift()
|
||||
|
||||
@staticmethod
|
||||
def select_from_minus(num_to_select: int, pool: Sequence[Any], minus: Sequence[Any]) -> List[Any]:
|
||||
def select_from_minus(num_to_select: int,
|
||||
pool: Sequence[Any],
|
||||
minus: Sequence[Any]) -> List[Any]:
|
||||
"""
|
||||
Select at most num_to_select subset of elements from the set (pool - minus) randomly.
|
||||
:param num_to_select: number of elements to randomly select
|
||||
@ -510,7 +515,7 @@ class GossipSub(IPubsubRouter):
|
||||
# Add all unknown message ids (ids that appear in ihave_msg but not in seen_seqnos) to list
|
||||
# of messages we want to request
|
||||
# FIXME: Update type of message ID
|
||||
msg_ids_wanted = [
|
||||
msg_ids_wanted: List[Any] = [
|
||||
msg_id
|
||||
for msg_id in ihave_msg.messageIDs
|
||||
if literal_eval(msg_id) not in seen_seqnos_and_peers
|
||||
|
||||
@ -6,6 +6,7 @@ from typing import (
|
||||
Dict,
|
||||
List,
|
||||
Tuple,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
from lru import LRU
|
||||
@ -17,7 +18,9 @@ from libp2p.network.stream.net_stream_interface import INetStream
|
||||
|
||||
from .pb import rpc_pb2
|
||||
from .pubsub_notifee import PubsubNotifee
|
||||
from .pubsub_router_interface import IPubsubRouter
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .pubsub_router_interface import IPubsubRouter
|
||||
|
||||
|
||||
def get_msg_id(msg: rpc_pb2.Message) -> Tuple[bytes, bytes]:
|
||||
@ -31,17 +34,19 @@ class Pubsub:
|
||||
host: IHost
|
||||
my_id: ID
|
||||
|
||||
router: IPubsubRouter
|
||||
router: 'IPubsubRouter'
|
||||
|
||||
peer_queue: asyncio.Queue[ID]
|
||||
peer_queue: asyncio.Queue
|
||||
|
||||
protocols: List[str]
|
||||
|
||||
incoming_msgs_from_peers: asyncio.Queue[rpc_pb2.Message]
|
||||
outgoing_messages: asyncio.Queue[rpc_pb2.Message]
|
||||
incoming_msgs_from_peers: asyncio.Queue
|
||||
outgoing_messages: asyncio.Queue
|
||||
|
||||
seen_messages: LRU
|
||||
|
||||
my_topics: Dict[str, asyncio.Queue]
|
||||
|
||||
# FIXME: Should be changed to `Dict[str, List[ID]]`
|
||||
peer_topics: Dict[str, List[str]]
|
||||
# FIXME: Should be changed to `Dict[ID, INetStream]`
|
||||
@ -52,7 +57,7 @@ class Pubsub:
|
||||
|
||||
def __init__(self,
|
||||
host: IHost,
|
||||
router: IPubsubRouter,
|
||||
router: 'IPubsubRouter',
|
||||
my_id: ID,
|
||||
cache_size: int = None) -> None:
|
||||
"""
|
||||
@ -247,7 +252,7 @@ class Pubsub:
|
||||
# for each topic
|
||||
await self.my_topics[topic].put(publish_message)
|
||||
|
||||
async def subscribe(self, topic_id: str) -> asyncio.Queue[rpc_pb2.Message]:
|
||||
async def subscribe(self, topic_id: str) -> asyncio.Queue:
|
||||
"""
|
||||
Subscribe ourself to a topic
|
||||
:param topic_id: topic_id to subscribe to
|
||||
|
||||
@ -1,11 +1,7 @@
|
||||
import asyncio
|
||||
from typing import (
|
||||
Sequence,
|
||||
)
|
||||
|
||||
from multiaddr import Multiaddr
|
||||
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.network.network_interface import INetwork
|
||||
from libp2p.network.notifee_interface import INotifee
|
||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
||||
@ -16,9 +12,9 @@ from libp2p.network.stream.net_stream_interface import INetStream
|
||||
class PubsubNotifee(INotifee):
|
||||
# pylint: disable=too-many-instance-attributes, cell-var-from-loop
|
||||
|
||||
initiator_peers_queue: asyncio.Queue[ID]
|
||||
initiator_peers_queue: asyncio.Queue
|
||||
|
||||
def __init__(self, initiator_peers_queue: asyncio.Queue[ID]) -> None:
|
||||
def __init__(self, initiator_peers_queue: asyncio.Queue) -> None:
|
||||
"""
|
||||
:param initiator_peers_queue: queue to add new peers to so that pubsub
|
||||
can process new peers after we connect to them
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import (
|
||||
List,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
from libp2p.peer.id import ID
|
||||
|
||||
from .pb import rpc_pb2
|
||||
from .pubsub import Pubsub
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .pubsub import Pubsub
|
||||
|
||||
class IPubsubRouter(ABC):
|
||||
|
||||
@ -17,7 +20,7 @@ class IPubsubRouter(ABC):
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def attach(self, pubsub: Pubsub) -> None:
|
||||
def attach(self, pubsub: 'Pubsub') -> None:
|
||||
"""
|
||||
Attach is invoked by the PubSub constructor to attach the router to a
|
||||
freshly initialized PubSub instance.
|
||||
|
||||
Reference in New Issue
Block a user