mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Add pubsub.topic_validators
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
from collections import namedtuple
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Tuple
|
||||
from typing import Any, Awaitable, Callable, Dict, List, Tuple, Union, TYPE_CHECKING
|
||||
|
||||
from lru import LRU
|
||||
|
||||
@ -20,6 +21,9 @@ def get_msg_id(msg: rpc_pb2.Message) -> Tuple[bytes, bytes]:
|
||||
return (msg.seqno, msg.from_id)
|
||||
|
||||
|
||||
TopicValidator = namedtuple("TopicValidator", ["validator", "is_async"])
|
||||
|
||||
|
||||
class Pubsub:
|
||||
|
||||
host: IHost
|
||||
@ -41,6 +45,8 @@ class Pubsub:
|
||||
peer_topics: Dict[str, List[ID]]
|
||||
peers: Dict[ID, INetStream]
|
||||
|
||||
topic_validators: Dict[str, TopicValidator]
|
||||
|
||||
# NOTE: Be sure it is increased atomically everytime.
|
||||
counter: int # uint64
|
||||
|
||||
@ -93,6 +99,9 @@ class Pubsub:
|
||||
# Create peers map, which maps peer_id (as string) to stream (to a given peer)
|
||||
self.peers = {}
|
||||
|
||||
# Map of topic to topic validator
|
||||
self.topic_validators = {}
|
||||
|
||||
self.counter = time.time_ns()
|
||||
|
||||
# Call handle peer to keep waiting for updates to peer queue
|
||||
|
||||
Reference in New Issue
Block a user