Пример #1
0
def _make_pubsubs(hosts, pubsub_routers, cache_size):
    if len(pubsub_routers) != len(hosts):
        raise ValueError(
            f"lenght of pubsub_routers={pubsub_routers} should be equaled to the "
            f"length of hosts={len(hosts)}")
    return tuple(
        PubsubFactory(host=host, router=router, cache_size=cache_size)
        for host, router in zip(hosts, pubsub_routers))
Пример #2
0
def pubsubs(num_hosts, hosts, is_gossipsub):
    if is_gossipsub:
        routers = GossipsubFactory.create_batch(num_hosts, **GOSSIPSUB_PARAMS._asdict())
    else:
        routers = FloodsubFactory.create_batch(num_hosts)
    _pubsubs = tuple(
        PubsubFactory(host=host, router=router) for host, router in zip(hosts, routers)
    )
    yield _pubsubs
Пример #3
0
    async def create(cls) -> "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
        """

        pubsub = PubsubFactory(router=FloodsubFactory())
        await pubsub.host.get_network().listen(LISTEN_MADDR)
        return cls(libp2p_node=pubsub.host,
                   pubsub=pubsub,
                   floodsub=pubsub.router)
 async def add_node(node_id_str: str):
     pubsub_router = router_factory(protocols=obj["supported_protocols"])
     pubsub = PubsubFactory(router=pubsub_router)
     await pubsub.host.get_network().listen(LISTEN_MADDR)
     node_map[node_id_str] = pubsub.host
     pubsub_map[node_id_str] = pubsub