Apply PR feedback
This commit is contained in:
parent
76de01a17d
commit
5e215901c0
|
@ -67,7 +67,7 @@ class INetwork(ABC):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def listen(self, *args: Multiaddr) -> bool:
|
async def listen(self, *args: Sequence[Multiaddr]) -> bool:
|
||||||
"""
|
"""
|
||||||
:param *args: one or many multiaddrs to start listening on
|
:param *args: one or many multiaddrs to start listening on
|
||||||
:return: True if at least one success
|
:return: True if at least one success
|
||||||
|
|
|
@ -18,11 +18,11 @@ from libp2p.protocol_muxer.multiselect import Multiselect
|
||||||
from libp2p.protocol_muxer.multiselect_client import MultiselectClient
|
from libp2p.protocol_muxer.multiselect_client import MultiselectClient
|
||||||
from libp2p.routing.interfaces import IPeerRouting
|
from libp2p.routing.interfaces import IPeerRouting
|
||||||
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
||||||
|
from libp2p.stream_muxer.muxed_stream_interface import IMuxedStream
|
||||||
from libp2p.transport.upgrader import TransportUpgrader
|
from libp2p.transport.upgrader import TransportUpgrader
|
||||||
from libp2p.transport.transport_interface import ITransport
|
from libp2p.transport.transport_interface import ITransport
|
||||||
from libp2p.transport.listener_interface import IListener
|
from libp2p.transport.listener_interface import IListener
|
||||||
|
|
||||||
from libp2p.stream_muxer.mplex.mplex_stream import MplexStream
|
|
||||||
|
|
||||||
from .network_interface import INetwork
|
from .network_interface import INetwork
|
||||||
from .notifee_interface import INotifee
|
from .notifee_interface import INotifee
|
||||||
|
@ -168,7 +168,7 @@ class Swarm(INetwork):
|
||||||
|
|
||||||
return net_stream
|
return net_stream
|
||||||
|
|
||||||
async def listen(self, *args: Multiaddr) -> bool:
|
async def listen(self, *args: Sequence[Multiaddr]) -> bool:
|
||||||
"""
|
"""
|
||||||
:param *args: one or many multiaddrs to start listening on
|
:param *args: one or many multiaddrs to start listening on
|
||||||
:return: true if at least one success
|
:return: true if at least one success
|
||||||
|
@ -252,7 +252,7 @@ class Swarm(INetwork):
|
||||||
# TODO: `disconnect`?
|
# TODO: `disconnect`?
|
||||||
|
|
||||||
|
|
||||||
GenericProtocolHandlerFn = Callable[[MplexStream], Awaitable[None]]
|
GenericProtocolHandlerFn = Callable[[IMuxedStream], Awaitable[None]]
|
||||||
|
|
||||||
|
|
||||||
def create_generic_protocol_handler(swarm: Swarm) -> GenericProtocolHandlerFn:
|
def create_generic_protocol_handler(swarm: Swarm) -> GenericProtocolHandlerFn:
|
||||||
|
@ -264,7 +264,7 @@ def create_generic_protocol_handler(swarm: Swarm) -> GenericProtocolHandlerFn:
|
||||||
"""
|
"""
|
||||||
multiselect = swarm.multiselect
|
multiselect = swarm.multiselect
|
||||||
|
|
||||||
async def generic_protocol_handler(muxed_stream: MplexStream) -> None:
|
async def generic_protocol_handler(muxed_stream: IMuxedStream) -> None:
|
||||||
# Perform protocol muxing to determine protocol to use
|
# Perform protocol muxing to determine protocol to use
|
||||||
protocol, handler = await multiselect.negotiate(muxed_stream)
|
protocol, handler = await multiselect.negotiate(muxed_stream)
|
||||||
|
|
||||||
|
|
|
@ -20,16 +20,15 @@ MAX_INLINE_KEY_LENGTH = 42
|
||||||
|
|
||||||
class ID:
|
class ID:
|
||||||
|
|
||||||
_id_str: str
|
_id_str: bytes
|
||||||
|
|
||||||
def __init__(self, id_str: str) -> None:
|
def __init__(self, id_str: bytes) -> None:
|
||||||
self._id_str = id_str
|
self._id_str = id_str
|
||||||
|
|
||||||
# FIXME: Should return type `bytes`
|
def to_bytes(self) -> bytes:
|
||||||
def to_bytes(self) -> str:
|
|
||||||
return self._id_str
|
return self._id_str
|
||||||
|
|
||||||
def get_raw_id(self) -> str:
|
def get_raw_id(self) -> bytes:
|
||||||
return self._id_str
|
return self._id_str
|
||||||
|
|
||||||
def pretty(self) -> str:
|
def pretty(self) -> str:
|
||||||
|
@ -86,6 +85,6 @@ def id_from_private_key(key: RsaKey) -> ID:
|
||||||
return id_from_public_key(key.publickey())
|
return id_from_public_key(key.publickey())
|
||||||
|
|
||||||
def digest(data: Union[str, bytes]) -> bytes:
|
def digest(data: Union[str, bytes]) -> bytes:
|
||||||
if not isinstance(data, bytes):
|
if isinstance(data, str):
|
||||||
data = str(data).encode('utf8')
|
data = data.encode('utf8')
|
||||||
return hashlib.sha1(data).digest()
|
return hashlib.sha1(data).digest()
|
||||||
|
|
|
@ -31,7 +31,7 @@ class PeerData(IPeerData):
|
||||||
self.protocols = list(protocols)
|
self.protocols = list(protocols)
|
||||||
|
|
||||||
def add_addrs(self, addrs: Sequence[Multiaddr]) -> None:
|
def add_addrs(self, addrs: Sequence[Multiaddr]) -> None:
|
||||||
self.addrs.extend(list(addrs))
|
self.addrs.extend(addrs)
|
||||||
|
|
||||||
def get_addrs(self) -> List[Multiaddr]:
|
def get_addrs(self) -> List[Multiaddr]:
|
||||||
return self.addrs
|
return self.addrs
|
||||||
|
|
|
@ -533,6 +533,7 @@ class GossipSub(IPubsubRouter):
|
||||||
from_id_str = sender_peer_id
|
from_id_str = sender_peer_id
|
||||||
|
|
||||||
# FIXME: Update type of message ID
|
# FIXME: Update type of message ID
|
||||||
|
# FIXME: Find a better way to parse the msg ids
|
||||||
msg_ids: List[Any] = [literal_eval(msg) for msg in iwant_msg.messageIDs]
|
msg_ids: List[Any] = [literal_eval(msg) for msg in iwant_msg.messageIDs]
|
||||||
msgs_to_forward: List[rpc_pb2.Message] = []
|
msgs_to_forward: List[rpc_pb2.Message] = []
|
||||||
for msg_id_iwant in msg_ids:
|
for msg_id_iwant in msg_ids:
|
||||||
|
|
|
@ -373,6 +373,6 @@ class Pubsub:
|
||||||
self.seen_messages[msg_id] = 1
|
self.seen_messages[msg_id] = 1
|
||||||
|
|
||||||
def _is_subscribed_to_msg(self, msg: rpc_pb2.Message) -> bool:
|
def _is_subscribed_to_msg(self, msg: rpc_pb2.Message) -> bool:
|
||||||
if not bool(self.my_topics):
|
if not self.my_topics:
|
||||||
return False
|
return False
|
||||||
return all([topic in self.my_topics for topic in msg.topicIDs])
|
return all([topic in self.my_topics for topic in msg.topicIDs])
|
||||||
|
|
|
@ -2,17 +2,13 @@ from abc import (
|
||||||
ABC,
|
ABC,
|
||||||
abstractmethod,
|
abstractmethod,
|
||||||
)
|
)
|
||||||
from typing import (
|
|
||||||
TYPE_CHECKING,
|
|
||||||
)
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
from libp2p.stream_muxer.muxed_connection_interface import IMuxedConn
|
||||||
from libp2p.stream_muxer.mplex.mplex import Mplex
|
|
||||||
|
|
||||||
|
|
||||||
class IMuxedStream(ABC):
|
class IMuxedStream(ABC):
|
||||||
|
|
||||||
mplex_conn: 'Mplex'
|
mplex_conn: IMuxedConn
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def read(self):
|
def read(self):
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -19,5 +19,6 @@ basepython =
|
||||||
basepython = python3
|
basepython = python3
|
||||||
extras = dev
|
extras = dev
|
||||||
commands =
|
commands =
|
||||||
|
# TODO: Add the tests/ folder back to pylint
|
||||||
pylint --rcfile={toxinidir}/.pylintrc libp2p examples
|
pylint --rcfile={toxinidir}/.pylintrc libp2p examples
|
||||||
mypy -p libp2p -p examples --config-file {toxinidir}/mypy.ini
|
mypy -p libp2p -p examples --config-file {toxinidir}/mypy.ini
|
||||||
|
|
Loading…
Reference in New Issue
Block a user