libp2p.tools.pubsub package
Submodules
libp2p.tools.pubsub.dummy_account_node module
- class libp2p.tools.pubsub.dummy_account_node.DummyAccountNode(pubsub: Pubsub)
Bases:
Service
Node which has an internal balance mapping, meant to serve as a dummy crypto blockchain.
There is no actual blockchain, just a simple map indicating how much crypto each user in the mappings holds
- classmethod create(number: int) AsyncIterator[Tuple[DummyAccountNode, ...]]
Create a new DummyAccountNode and attach a libp2p node, a floodsub, and a pubsub instance to this new node.
We use create as this serves as a factory function and allows us to use async await, unlike the init function
- get_balance(user: str) int
Get balance in crypto for a particular user.
- Parameters:
user – user to get balance for
- Returns:
balance of user
- handle_send_crypto(source_user: str, dest_user: str, amount: int) None
Handle incoming send_crypto message.
- Parameters:
source_user – user to send crypto from
dest_user – user to send crypto to
amount – amount of crypto to send
- handle_set_crypto(dest_user: str, amount: int) None
Handle incoming set_crypto message.
- Parameters:
dest_user – user to set crypto for
amount – amount of crypto
- async publish_send_crypto(source_user: str, dest_user: str, amount: int) None
Create a send crypto message and publish that message to all other nodes.
- Parameters:
source_user – user to send crypto from
dest_user – user to send crypto to
amount – amount of crypto to send
libp2p.tools.pubsub.floodsub_integration_test_settings module
- async libp2p.tools.pubsub.floodsub_integration_test_settings.perform_test_from_obj(obj, pubsub_factory) None
Perform pubsub tests from a test object, which is composed as follows:
{ "supported_protocols": ["supported/protocol/1.0.0",...], "adj_list": { "node1": ["neighbor1_of_node1", "neighbor2_of_node1", ...], "node2": ["neighbor1_of_node2", "neighbor2_of_node2", ...], ... }, "topic_map": { "topic1": ["node1_subscribed_to_topic1", "node2_subscribed_to_topic1", ...] }, "messages": [ { "topics": ["topic1_for_message", "topic2_for_message", ...], "data": b"some contents of the message (newlines are not supported)", "node_id": "message sender node id" }, ... ] }
Note
In adj_list, for any neighbors A and B, only list B as a neighbor of A or B as a neighbor of A once. Do NOT list both A: [“B”] and B:[“A”] as the behavior is undefined (even if it may work)