def main(): network = Network.get_instance() network.delay = 0.1 nodes = ["Alice", "Bob", "Eve"] network.start(nodes) host_alice = Host('Alice', ) host_alice.add_connection('Bob') host_alice.start() host_bob = Host('Bob') host_bob.add_connection('Alice') host_bob.add_connection('Eve') host_bob.start() host_eve = Host('Eve') host_eve.add_connection('Bob') host_eve.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) host_alice.send_superdense('Eve', '11') host_alice.send_superdense('Eve', '10') host_alice.send_superdense('Eve', '00') time.sleep(5) messages = host_eve.get_classical('Alice') for m in messages: print('----') print(m) print('----')
def main(): # network.classical_routing_algo = routing_algorithm nodes = ['A', 'node_1', 'node_2', 'B'] network.use_hop_by_hop = False network.set_delay = 0.1 network.start(nodes) A = Host('A') A.add_connection('node_1') A.add_connection('node_2') A.start() node_1 = Host('node_1') node_1.add_connection('A') node_1.add_connection('B') node_1.start() node_2 = Host('node_2') node_2.add_connection('A') node_2.add_connection('B') node_2.start() B = Host('B') B.add_connection('node_1') B.add_connection('node_2') B.start() hosts = [A, node_1, node_2, B] for h in hosts: network.add_host(h) node_1.run_protocol(generate_entanglement) node_2.run_protocol(generate_entanglement) print('---- BUILDING ENTANGLEMENT ----') # Let the network build up entanglement for i in range(10): print('building...') time.sleep(1) print('---- DONE BUILDING ENTANGLEMENT ----') network.quantum_routing_algo = routing_algorithm choices = ['00', '11', '10', '01'] for _ in range(5): print('---- sending superdense ----') A.send_superdense(B.host_id, random.choice(choices), await_ack=True) time.sleep(1) print('stopping') try: network.stop(stop_hosts=True) except Exception: print('')