mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-11 15:40:54 +00:00
Add validators to push_msg
This commit is contained in:
@ -21,6 +21,7 @@ from libp2p.peer.id import ID
|
|||||||
|
|
||||||
from .pb import rpc_pb2
|
from .pb import rpc_pb2
|
||||||
from .pubsub_notifee import PubsubNotifee
|
from .pubsub_notifee import PubsubNotifee
|
||||||
|
from .validators import signature_validator
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .pubsub_router_interface import IPubsubRouter
|
from .pubsub_router_interface import IPubsubRouter
|
||||||
@ -392,8 +393,11 @@ class Pubsub:
|
|||||||
|
|
||||||
# TODO: Implement throttle on async validators
|
# TODO: Implement throttle on async validators
|
||||||
|
|
||||||
results = await asyncio.gather(*async_topic_validator_futures)
|
if len(async_topic_validator_futures) > 0:
|
||||||
return all(results)
|
results = await asyncio.gather(*async_topic_validator_futures)
|
||||||
|
return all(results)
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
async def push_msg(self, msg_forwarder: ID, msg: rpc_pb2.Message) -> None:
|
async def push_msg(self, msg_forwarder: ID, msg: rpc_pb2.Message) -> None:
|
||||||
"""
|
"""
|
||||||
@ -411,6 +415,14 @@ class Pubsub:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# TODO: - Validate the message. If failed, reject it.
|
# TODO: - Validate the message. If failed, reject it.
|
||||||
|
# Validate the signature of the message
|
||||||
|
# FIXME: `signature_validator` is currently a stub.
|
||||||
|
if not signature_validator(msg.key, msg.SerializeToString()):
|
||||||
|
return
|
||||||
|
# Validate the message with registered topic validators
|
||||||
|
is_validation_passed = await self.validate_msg(msg_forwarder, msg)
|
||||||
|
if not is_validation_passed:
|
||||||
|
return
|
||||||
|
|
||||||
self._mark_msg_seen(msg)
|
self._mark_msg_seen(msg)
|
||||||
await self.handle_talk(msg)
|
await self.handle_talk(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user