For the complete documentation index, see llms.txt. This page is also available as Markdown.

R

        async def handle_vote(from_peer_id: ID, message: rpc_pb2.Message) -> None:
            payload = message.data.decode("utf-8")
            ...

        def validate_vote(from_peer_id: ID, message: rpc_pb2.Message) -> bool:
            return bool(message.data)

        termination_event = trio.Event()
        receiver = GossipReceiverTemplate(
            pubsub=pubsub,
            termination_event=termination_event,
            topics_config=[
                GossipTopicConfig(
                    topic="votes",
                    topic_handler=handle_vote,
                    topic_validator=validate_vote,
                ),
                GossipTopicConfig(
                    topic="peer_state",
                    topic_handler=handle_peer_state,
                    topic_validator=None,
                ),
            ],
        )

        async with trio.open_nursery() as nursery:
            nursery.start_soon(receiver.run)
            ...
            termination_event.set()

Last updated