mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Modify pubsub to have seen message check incorporate seqno and node id
This commit is contained in:
@ -2,7 +2,6 @@ import asyncio
|
||||
|
||||
from .pb import rpc_pb2
|
||||
from .pubsub_notifee import PubsubNotifee
|
||||
from .read_only_queue import ReadOnlyQueue
|
||||
|
||||
|
||||
class Pubsub():
|
||||
@ -89,7 +88,7 @@ class Pubsub():
|
||||
for message in rpc_incoming.publish:
|
||||
if message.seqno not in self.seen_messages:
|
||||
should_publish = True
|
||||
self.seen_messages.append(message.seqno)
|
||||
self.seen_messages.append((message.seqno, message.from_id))
|
||||
await self.handle_talk(message)
|
||||
|
||||
if rpc_incoming.subscriptions:
|
||||
@ -188,9 +187,8 @@ class Pubsub():
|
||||
if topic in self.my_topics:
|
||||
# we are subscribed to a topic this message was sent for,
|
||||
# so add message to the subscription output queue
|
||||
# for each topic with priority being the message's seqno.
|
||||
# Note: asyncio.PriorityQueue item format is (priority, data)
|
||||
await self.my_topics[topic].put((publish_message.seqno, publish_message))
|
||||
# for each topic
|
||||
await self.my_topics[topic].put(publish_message)
|
||||
|
||||
async def subscribe(self, topic_id):
|
||||
"""
|
||||
@ -198,8 +196,8 @@ class Pubsub():
|
||||
:param topic_id: topic_id to subscribe to
|
||||
"""
|
||||
|
||||
# Map topic_id to a priority blocking queue
|
||||
self.my_topics[topic_id] = asyncio.PriorityQueue()
|
||||
# Map topic_id to blocking queue
|
||||
self.my_topics[topic_id] = asyncio.Queue()
|
||||
|
||||
# Create subscribe message
|
||||
packet = rpc_pb2.RPC()
|
||||
@ -214,8 +212,8 @@ class Pubsub():
|
||||
# Tell router we are joining this topic
|
||||
self.router.join(topic_id)
|
||||
|
||||
# Return the readonly queue for messages on this topic
|
||||
return ReadOnlyQueue(self.my_topics[topic_id])
|
||||
# Return the asyncio queue for messages on this topic
|
||||
return self.my_topics[topic_id]
|
||||
|
||||
async def unsubscribe(self, topic_id):
|
||||
"""
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
class ReadOnlyQueue():
|
||||
|
||||
def __init__(self, queue):
|
||||
self.queue = queue
|
||||
|
||||
async def get(self):
|
||||
"""
|
||||
Get the next item from queue, which has items in the format (priority, data)
|
||||
:return: next item from the queue
|
||||
"""
|
||||
return (await self.queue.get())[1]
|
||||
|
||||
Reference in New Issue
Block a user