async def start_communities(): bootstrap_ips = [] for i in range(2): # We start two bootstrap nodes bootstrap_endpoint = SimulationEndpoint() await bootstrap_endpoint.open() bootstrap_overlay = EndpointServer(bootstrap_endpoint) # We assume all peers in our simulation have a public WAN IP (to avoid conflicts with our SimulationEndpoint) bootstrap_overlay.my_estimated_lan = ("0.0.0.0", 0) bootstrap_overlay.my_estimated_wan = bootstrap_endpoint.wan_address bootstrap_ips.append(bootstrap_endpoint.wan_address) instances = [] for i in range(20): builder = ConfigBuilder().clear_keys().clear_overlays() builder.add_key("my peer", "medium", f"ec{i}.pem") bootstrappers = [ BootstrapperDefinition(Bootstrapper.DispersyBootstrapper, { "ip_addresses": bootstrap_ips, "dns_addresses": [] }) ] walkers = [WalkerDefinition(Strategy.RandomWalk, 10, {'timeout': 3.0})] builder.add_overlay("SimpleCommunity", "my peer", walkers, bootstrappers, {'id': i}, [('started', )]) endpoint = SimulationEndpoint() instance = IPv8(builder.finalize(), endpoint_override=endpoint, extra_communities={'SimpleCommunity': SimpleCommunity}) # We assume all peers in our simulation have a public WAN IP (to avoid conflicts with our SimulationEndpoint) instance.overlays[0].my_estimated_lan = ("0.0.0.0", 0) instance.overlays[0].my_estimated_wan = endpoint.wan_address await instance.start() instances.append(instance)
async def start_communities(): for i in [1, 2, 3]: builder = ConfigBuilder().clear_keys().clear_overlays() builder.add_key("my peer", "medium", f"ec{i}.pem") builder.add_overlay( "MyCommunity", "my peer", [WalkerDefinition(Strategy.RandomWalk, 10, {'timeout': 3.0})], default_bootstrap_defs, {}, [('started', )]) await IPv8(builder.finalize(), extra_communities={ 'MyCommunity': MyCommunity }).start()
async def start_communities(): for i in [1, 2]: builder = ConfigBuilder().clear_keys().clear_overlays() builder.add_key("my peer", "medium", f"ec{i}.pem") # We provide the 'started' function to the 'on_start'. # We will call the overlay's 'started' function without any # arguments once IPv8 is initialized. builder.add_overlay( "MyCommunity", "my peer", [WalkerDefinition(Strategy.RandomWalk, 10, {'timeout': 3.0})], default_bootstrap_defs, {}, [('started', )]) await IPv8(builder.finalize(), extra_communities={ 'MyCommunity': MyCommunity }).start()
async def start_communities(): for i in [1, 2]: builder = ConfigBuilder().clear_keys().clear_overlays() # If we actually want to communicate between two different peers # we need to assign them different keys. # We will generate an EC key called 'my peer' which has 'medium' # security and will be stored in file 'ecI.pem' where 'I' is replaced # by the peer number (1 or 2). builder.add_key("my peer", "medium", f"ec{i}.pem") # Instruct IPv8 to load our custom overlay, registered in _COMMUNITIES. # We use the 'my peer' key, which we registered before. # We will attempt to find other peers in this overlay using the # RandomWalk strategy, until we find 10 peers. # We do not provide additional startup arguments or a function to run # once the overlay has been initialized. builder.add_overlay( "MyCommunity", "my peer", [WalkerDefinition(Strategy.RandomWalk, 10, {'timeout': 3.0})], default_bootstrap_defs, {}, []) ipv8 = IPv8(builder.finalize(), extra_communities={'MyCommunity': MyCommunity}) await ipv8.start()
async def start_communities(): instances = [] for i in [1, 2]: builder = ConfigBuilder().clear_keys().clear_overlays() builder.add_key("my peer", "medium", f"ec{i}.pem") builder.add_overlay("PingPongCommunity", "my peer", [], [], {}, [('started', )]) endpoint = SimulationEndpoint() instance = IPv8( builder.finalize(), endpoint_override=endpoint, extra_communities={'PingPongCommunity': PingPongCommunity}) await instance.start() instances.append(instance) # Introduce peers to each other for from_instance in instances: for to_instance in instances: if from_instance == to_instance: continue from_instance.overlays[0].walk_to(to_instance.endpoint.wan_address)