Add pubsub.topic_validators

This commit is contained in:
NIC619
2019-08-03 18:44:40 +08:00
parent ccf4b62976
commit 3973f1d13c

View File

@ -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