mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
Add pubsub.topic_validators
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
from collections import namedtuple
|
||||||
import time
|
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
|
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)
|
return (msg.seqno, msg.from_id)
|
||||||
|
|
||||||
|
|
||||||
|
TopicValidator = namedtuple("TopicValidator", ["validator", "is_async"])
|
||||||
|
|
||||||
|
|
||||||
class Pubsub:
|
class Pubsub:
|
||||||
|
|
||||||
host: IHost
|
host: IHost
|
||||||
@ -41,6 +45,8 @@ class Pubsub:
|
|||||||
peer_topics: Dict[str, List[ID]]
|
peer_topics: Dict[str, List[ID]]
|
||||||
peers: Dict[ID, INetStream]
|
peers: Dict[ID, INetStream]
|
||||||
|
|
||||||
|
topic_validators: Dict[str, TopicValidator]
|
||||||
|
|
||||||
# NOTE: Be sure it is increased atomically everytime.
|
# NOTE: Be sure it is increased atomically everytime.
|
||||||
counter: int # uint64
|
counter: int # uint64
|
||||||
|
|
||||||
@ -93,6 +99,9 @@ class Pubsub:
|
|||||||
# Create peers map, which maps peer_id (as string) to stream (to a given peer)
|
# Create peers map, which maps peer_id (as string) to stream (to a given peer)
|
||||||
self.peers = {}
|
self.peers = {}
|
||||||
|
|
||||||
|
# Map of topic to topic validator
|
||||||
|
self.topic_validators = {}
|
||||||
|
|
||||||
self.counter = time.time_ns()
|
self.counter = time.time_ns()
|
||||||
|
|
||||||
# Call handle peer to keep waiting for updates to peer queue
|
# Call handle peer to keep waiting for updates to peer queue
|
||||||
|
|||||||
Reference in New Issue
Block a user