def main(): network = Network.get_instance() nodes = ["Alice", "Bob"] network.x_error_rate = 0 network.delay = 0.5 network.start(nodes) host_alice = Host('Alice') host_alice.add_connection('Bob') host_alice.max_ack_wait = 10 host_alice.delay = 0.2 host_alice.start() host_bob = Host('Bob') host_bob.max_ack_wait = 10 host_bob.delay = 0.2 host_bob.add_connection('Alice') host_bob.start() network.add_host(host_alice) network.add_host(host_bob) q_size = 6 host_alice.run_protocol(qudp_sender, (q_size, host_bob.host_id)) host_bob.run_protocol(qudp_receiver, (q_size, host_alice.host_id)) start_time = time.time() while time.time() - start_time < 50: pass network.stop(stop_hosts=True)
def main(): network = Network.get_instance() # backend = ProjectQBackend() backend = CQCBackend() nodes = ['A', 'B', 'C'] network.start(nodes, backend) network.delay = 0.1 host_A = Host('A', backend) host_A.add_connection('B') host_A.delay = 0 host_A.start() host_B = Host('B', backend) host_B.add_connections(['A', 'C']) host_B.delay = 0 host_B.start() host_C = Host('C', backend) host_C.add_connection('B') host_C.delay = 0 host_C.start() network.add_host(host_A) network.add_host(host_B) network.add_host(host_C) t1 = host_A.run_protocol(protocol_1, (host_C.host_id, )) t2 = host_C.run_protocol(protocol_2, (host_A.host_id, )) t1.join() t2.join() network.stop(True)
def main(): network = Network.get_instance() nodes = ["Alice", "Bob", "Eve"] network.start(nodes) network.delay = 0.1 host_alice = Host('Alice') host_alice.add_connection('Bob') host_alice.start() host_bob = Host('Bob') host_bob.add_connections(['Alice', 'Eve']) host_bob.start() host_eve = Host('Eve') host_eve.add_connection('Bob') host_eve.start() network.add_hosts([host_alice, host_bob, host_eve]) host_bob.q_relay_sniffing = True host_bob.q_relay_sniffing_fn = bob_sniffing_quantum host_bob.c_relay_sniffing = True host_bob.c_relay_sniffing_fn = bob_sniffing_classical t1 = host_alice.run_protocol(alice) t2 = host_eve.run_protocol(eve) t1.join() t2.join() network.stop(True) exit()
def main(): # Initialize a network network = Network.get_instance() backend = EQSNBackend() # Define the host IDs in the network nodes = ['Alice', 'Bob'] network.delay = 0.0 # Start the network with the defined hosts network.start(nodes, backend) # Initialize the host Alice host_alice = Host('Alice', backend) # Add a one-way connection (classical and quantum) to Bob host_alice.add_connection('Bob') host_alice.delay = 0.0 # Start listening host_alice.start() host_bob = Host('Bob', backend) # Bob adds his own one-way connection to Alice host_bob.add_connection('Alice') host_bob.delay = 0.0 host_bob.start() # Add the hosts to the network # The network is: Alice <--> Bob network.add_host(host_alice) network.add_host(host_bob) # Generate random key key_size = 20 # the size of the key in bit secret_key = np.random.randint(2, size=key_size) # Concatentate functions def alice_func(alice): msg_buff = [] alice_qkd(alice, msg_buff, secret_key, host_bob.host_id) alice_send_message(alice, secret_key, host_bob.host_id) def bob_func(eve): msg_buff = [] eve_key = eve_qkd(eve, msg_buff, key_size, host_alice.host_id) eve_receive_message(eve, msg_buff, eve_key, host_alice.host_id) # Run Bob and Alice host_alice.run_protocol(alice_func, ()) host_bob.run_protocol(bob_func, (), blocking=True) time.sleep(1) network.stop(True)
def main(): network = Network.get_instance() nodes = ['Alice', 'Bob', 'Eve'] network.delay = 0.2 network.start(nodes) host_alice = Host('Alice') host_bob = Host('Bob') host_eve = Host('Eve') host_alice.add_connection('Bob') host_bob.add_connection('Alice') host_bob.add_connection('Eve') host_eve.add_connection('Bob') host_alice.start() host_bob.start() host_eve.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) q = Qubit(host_alice) q.X() host_alice.send_teleport('Eve', q, await_ack=True) q_eve = host_eve.get_data_qubit(host_alice.host_id, q.id, wait=5) assert q_eve is not None print('Eve measures: %d' % q_eve.measure())
def main(): # Initialize a network network = Network.get_instance() nodes = ['Alice', 'Bob', 'Eve'] network.delay = 0.0 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) print('Starting transfer') t1 = host_alice.run_protocol(banker_protocol, (host_eve.host_id, )) t2 = host_eve.run_protocol(customer_protocol, (host_alice.host_id, )) t1.join() t2.join() network.stop(True)
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(): Y = 2 M = 2 network = Network.get_instance() nodes = ['Alice','C0','Bob'] network.use_ent_swap = True network.start(nodes) #0.01549 alice = Host('Alice') alice.add_connection('C0', 100) alice.coherence_time = 1 alice.max_ack_wait = 5 alice.start() repeater0 = Host('C0') repeater0.add_connection('Alice', 100) repeater0.add_connection('Bob', 100) repeater0.coherence_time = 1 repeater0.max_ack_wait = 5 repeater0.start() # repeater1 = Host('C1') # repeater1.add_connection('C0') # repeater1.add_connection('C2') # repeater1.max_ack_wait = 5 # repeater1.start() # repeater2 = Host('C2') # repeater2.add_connection('C1') # repeater2.add_connection('Bob') # repeater2.max_ack_wait = 5 # repeater2.start() bob = Host('Bob') bob.add_connection('C0', 100) bob.coherence_time = 1 bob.max_ack_wait = 5 bob.start() network.add_host(alice) network.add_host(repeater0) #network.add_host(repeater1) #network.add_host(repeater2) network.add_host(bob) t1 = alice.run_protocol(AliceProtocol, (repeater0.host_id, Y, M)) t2 = repeater0.run_protocol(RepeaterProtocol, (alice.host_id, bob.host_id, 0, 1, Y, M)) #repeater1.run_protocol(RepeaterProtocol, (repeater0.host_id, repeater2.host_id, 1, 2, Y, M)) #repeater2.run_protocol(RepeaterProtocol, (repeater1.host_id, bob.host_id, 2, 2, Y, M)) t3 = bob.run_protocol(BobProtocol, (repeater0.host_id, Y, M)) t1.join() t2.join() t3.join() network.stop(True)
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('')
def main(): # Initialize a network network = Network.get_instance() # Define the host IDs in the network nodes = ['Alice', 'Bob', 'Eve'] network.delay = 0.0 # Start the network with the defined hosts network.start(nodes) # Initialize the host Alice host_alice = Host('Alice') # Add a one-way connection (classical and quantum) to Bob host_alice.add_connection('Bob') # Start listening host_alice.start() host_bob = Host('Bob') # Bob adds his own one-way connection to Alice and Eve 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() # Add the hosts to the network # The network is: Alice <--> Bob <--> Eve network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) # Generate random key key_size = 8 # the size of the key in bit hosts = {'Alice': host_alice, 'Bob': host_bob, 'Eve': host_eve} # Run Alice and Eve host_alice.send_key(host_eve.host_id, key_size) start_time = time.time() while time.time() - start_time < 60: pass print('SENDER KEYS') print(host_alice.qkd_keys) print('RECEIVER KEYS') print(host_eve.qkd_keys) for h in hosts.values(): h.stop() network.stop()
def main(): network = Network.get_instance() network.start() network.delay = 0.2 host_alice = Host('Alice', backend) host_alice.add_connection('Bob') host_alice.start() host_bob = Host('Bob', backend) host_bob.add_connections(['Alice', 'Eve']) host_bob.start() host_eve = Host('Eve', backend) host_eve.add_connections(['Bob', 'Dean']) host_eve.start() host_dean = Host('Dean', backend) host_dean.add_connection('Eve') host_dean.start() network.add_hosts([host_alice, host_bob, host_eve, host_dean]) print('alice sends message') host_alice.send_classical('Bob', 'hello1') host_alice.send_classical('Bob', 'hello2') host_alice.send_classical('Bob', 'hello3') host_alice.send_classical('Bob', 'hello4') host_alice.send_classical('Bob', 'hello5') host_alice.send_classical('Bob', 'hello6') host_alice.send_classical('Bob', 'hello7') host_alice.send_classical('Bob', 'hello8') host_alice.send_classical('Bob', 'hello9') host_alice.send_classical('Bob', 'hello10') start_time = time.time() while time.time() - start_time < 10: pass network.stop(True) exit()
def main(): network = Network.get_instance() nodes = ['A', 'B', 'C'] network.start(nodes) network.delay = 0.1 host_A = Host('A') host_A.add_connection('B') host_A.start() host_B = Host('B') host_B.add_connection('A') host_B.add_connection('C') host_B.start() host_C = Host('C') host_C.add_connection('B') host_C.start() network.add_host(host_A) network.add_host(host_B) network.add_host(host_C) host_A.run_protocol(protocol_1, (host_C.host_id,)) host_C.run_protocol(protocol_2, (host_A.host_id,))
def main(): network = Network.get_instance() # backend = ProjectQBackend() # backend = CQCBackend() backend = EQSNBackend() nodes = ['A', 'B'] network.delay = 0.1 network.start(nodes, backend) host_A = Host('A', backend) host_A.add_connection('B') host_A.delay = 0 host_A.start() host_B = Host('B', backend) host_B.add_connection('A') host_B.delay = 0 host_B.start() network.add_host(host_A) network.add_host(host_B) m = 2 n = 4 rot_angle = np.pi / 9 t1 = host_A.run_protocol(quantum_coin_flipping, arguments=(m, n, host_B.host_id, rot_angle)) t2 = host_B.run_protocol(quantum_coin_flipping, arguments=(m, n, host_A.host_id, rot_angle)) t1.join() t2.join() network.stop(True)
def main() : network = Network.get_instance() nodes = ['Alice', 'R', 'Bob'] network.use_ent_swap = True network.delay = 0 network.start(nodes) alice = Host('Alice') alice.add_connection('R', 100) alice.max_ack_wait = 5 #alice.coherence_time = 0.0003 alice.start() repeater = Host('R') repeater.add_connection('Alice', 100) repeater.add_connection('Bob', 100) repeater.max_ack_wait = 5 #repeater.coherence_time = 0.0003 repeater.start() bob = Host('Bob') bob.add_connection('R', 100) bob.max_ack_wait = 5 #bob.coherence_time = 0.0003 bob.start() network.add_host(alice) network.add_host(repeater) network.add_host(bob) t1 = alice.run_protocol(AliceProtocol, (repeater.host_id,)) t2 = repeater.run_protocol(RepeaterProtocol, (alice.host_id, bob.host_id)) t3 = bob.run_protocol(BobProtocol, (repeater.host_id,)) t1.join() t2.join() t3.join() network.stop(True) sys.exit()
def main(): # Initialize a network network = Network.get_instance() # Define the host IDs in the network nodes = ['Alice', 'Bob', 'Eve'] # Start the network with the defined hosts network.start(nodes) # Initialize the host Alice host_alice = Host('Alice') # Add a one-way connection (classical and quantum) to Bob host_alice.add_connection('Bob') # Start listening host_alice.start() host_bob = Host('Bob') # Bob adds his own one-way connection to Alice and Eve 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() # Add the hosts to the network # The network is: Alice <--> Bob <--> Eve network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) # Run Bob and Alice DaemonThread(Alice_func) DaemonThread(Eve_func)
def main(): # Initialize a network network = Network.get_instance() nodes = ['Bank', 'Customer', 'Eve'] network.delay = 0.2 network.start(nodes) host_bank = Host('Bank') host_bank.add_connection('Eve') host_bank.delay = 0.3 host_bank.start() host_eve = Host('Eve') host_eve.add_connection('Bank') host_eve.add_connection('Customer') host_eve.start() host_customer = Host('Customer') host_customer.add_connection('Eve') host_customer.delay = 0.3 host_customer.start() network.add_host(host_bank) network.add_host(host_eve) network.add_host(host_customer) host_eve.q_relay_sniffing = True host_eve.q_relay_sniffing_fn = sniffing_quantum print('Starting transfer') t = host_customer.run_protocol(customer_protocol, (host_bank.host_id, )) host_bank.run_protocol(banker_protocol, (host_customer.host_id, ), blocking=True) t.join() network.stop(True)
def main(): network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes) network.delay = 0.5 host_alice = Host('Alice') host_alice.add_connection('Bob') host_alice.max_ack_wait = 30 host_alice.delay = 0.2 host_alice.start() host_bob = Host('Bob') host_bob.max_ack_wait = 30 host_bob.delay = 0.2 host_bob.add_connection('Alice') host_bob.add_connection('Eve') host_bob.start() host_eve = Host('Eve') host_eve.max_ack_wait = 30 host_eve.delay = 0.2 host_eve.add_connection('Bob') host_eve.add_connection('Dean') host_eve.start() host_dean = Host('Dean') host_dean.max_ack_wait = 30 host_dean.delay = 0.2 host_dean.add_connection('Eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) network.x_error_rate = 0 network.packet_drop_rate = 0 q_size = 6 checksum_per_qubit = 2 host_alice.run_protocol(checksum_sender, (q_size, host_dean.host_id, checksum_per_qubit)) host_dean.run_protocol(checksum_receiver, (q_size, host_alice.host_id, checksum_per_qubit)) start_time = time.time() while time.time() - start_time < 150: pass network.stop(stop_hosts=True) exit()
def main(): network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes) network.delay = 0.1 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.add_connection('Dean') host_eve.start() host_dean = Host('Dean') host_dean.add_connection('Eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) # Create a qubit owned by Alice q = Qubit(host_alice) # Put the qubit in the excited state q.X() # Send the qubit and await an ACK from Dean q_id, _ = host_alice.send_qubit('Dean', q, await_ack=True) # Get the qubit on Dean's side from Alice q_rec = host_dean.get_data_qubit('Alice', q_id) # Ensure the qubit arrived and then measure and print the results. if q_rec is not None: m = q_rec.measure() print("Results of the measurements for q_id are ", str(m)) else: print('q_rec is none') network.stop(True) exit()
def main(): # Initialize a network network = Network.get_instance() # Define the host IDs in the network nodes = ['Alice', 'Bob', 'Eve'] network.delay = 0.0 # Start the network with the defined hosts network.start(nodes) # Initialize the host Alice host_alice = Host('Alice') # Add a one-way connection (classical and quantum) to Bob host_alice.add_connection('Bob') host_alice.delay = 0 # Start listening host_alice.start() host_bob = Host('Bob') # Bob adds his own one-way connection to Alice and Eve host_bob.add_connection('Alice') host_bob.add_connection('Eve') host_bob.delay = 0 host_bob.start() host_eve = Host('Eve') host_eve.add_connection('Bob') host_eve.delay = 0 host_eve.start() # Add the hosts to the network # The network is: Alice <--> Bob <--> Eve network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) # Generate random key key_size = 8 # the size of the key in bit secret_key = np.random.randint(2, size=key_size) # Concatentate functions def alice_func(alice): msg_buff = [] alice_qkd(alice, msg_buff, secret_key, host_eve.host_id) alice_send_message(alice, secret_key, host_eve.host_id) def eve_func(eve): msg_buff = [] eve_key = eve_qkd(eve, msg_buff, key_size, host_alice.host_id) eve_receive_message(eve, msg_buff, eve_key, host_alice.host_id) # Run Bob and Alice t1 = host_alice.run_protocol(alice_func, ()) t2 = host_eve.run_protocol(eve_func, ()) t1.join() t2.join()
def main(): global thread_1_return global thread_2_return network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes) network.delay = 0.5 host_alice = Host('alice') host_alice.add_connection('bob') host_alice.max_ack_wait = 30 host_alice.delay = 0.2 host_alice.start() host_bob = Host('bob') host_bob.max_ack_wait = 30 host_bob.delay = 0.2 host_bob.add_connection('alice') host_bob.add_connection('eve') host_bob.start() host_eve = Host('eve') host_eve.max_ack_wait = 30 host_eve.delay = 0.2 host_eve.add_connection('bob') host_eve.add_connection('dean') host_eve.start() host_dean = Host('dean') host_dean.max_ack_wait = 30 host_dean.delay = 0.2 host_dean.add_connection('eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) host_alice.run_protocol(retransmission_sender, (host_dean.host_id, MAX_TRIAL_NUM)) host_dean.run_protocol(retransmission_receiver, (host_alice.host_id, MAX_TRIAL_NUM)) start_time = time.time() while time.time() - start_time < 150: pass network.stop(stop_hosts=True) exit()
# Initialize a network network = Network.get_instance() # Define the host IDs in the network nodes = ['Alice', 'Bob', 'Eve'] # Start the network with the defined hosts network.start(nodes) # Initialize the host Alice host_alice = Host('Alice') # Add a one-way connection (classical and quantum) to Bob host_alice.add_connection('Bob') # Start listening host_alice.start() host_bob = Host('Bob') # Bob adds his own one-way connection to Alice and Eve 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() # Add the hosts to the network
def main(): network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] backend = CQCBackend() network.start(nodes, backend) network.delay = 0.2 network.packet_drop_rate = 0 print('') host_alice = Host('Alice', backend) host_alice.add_connection('Bob') host_alice.start() host_bob = Host('Bob', backend) host_bob.add_connection('Alice') host_bob.add_connection('Eve') host_bob.start() host_eve = Host('Eve', backend) host_eve.add_connection('Bob') host_eve.add_connection('Dean') host_eve.start() host_dean = Host('Dean', backend) host_dean.add_connection('Eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) print('alice sends message') host_alice.send_classical('Bob', 'hello1') host_alice.send_classical('Bob', 'hello2') host_alice.send_classical('Bob', 'hello3') host_alice.send_classical('Bob', 'hello4') host_alice.send_classical('Bob', 'hello5') host_alice.send_classical('Bob', 'hello6') host_alice.send_classical('Bob', 'hello7') host_alice.send_classical('Bob', 'hello8') host_alice.send_classical('Bob', 'hello9') host_alice.send_classical('Bob', 'hello10') start_time = time.time() while time.time() - start_time < 10: pass network.stop(True) exit()
def qunetsim(): from components.host import Host from components.network import Network from objects.qubit import Qubit network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes) network.delay = 0.1 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.add_connection('Dean') host_eve.start() host_dean = Host('Dean') host_dean.add_connection('Eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) from mappings.qunetsim import mapping #return host_alice, host_bob, host_eve, network def source_protocol(source_host, target_host_id): _ = qpz_atomics.lib(mapping, source_host) for i in range(5): q = _.PREP() q = _.H(q) print("sending"), _.DISP(q) _.SEND(q, target_host_id) def target_protocol(target_host, source_host_id): _ = qpz_atomics.lib(mapping, target_host) for i in range(5): print(source_host_id) q = _.RECV(source_host_id) print("recieved"), _.DISP(q) host_alice.run_protocol(source_protocol, (host_bob.host_id, )) host_bob.run_protocol(target_protocol, (host_alice.host_id, ))
def main(): # Initialize a network network = Network.get_instance() # Define the host IDs in the network nodes = ['Alice', 'Bob', 'Eve'] network.delay = 0.0 # Start the network with the defined hosts network.start(nodes) # Initialize the host Alice host_alice = Host('Alice') # Add a one-way connection (classical and quantum) to Bob host_alice.add_connection('Bob') # Start listening host_alice.start() host_bob = Host('Bob') # Bob adds his own one-way connection to Alice and Eve 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() # Add the hosts to the network # The network is: Alice <--> Bob <--> Eve network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) # Generate random key key_size = 8 # the size of the key in bit secret_key = np.random.randint(2, size=key_size) hosts = {'Alice': host_alice, 'Bob': host_bob, 'Eve': host_eve} # Concatentate functions def Alice_func(alice=host_alice): msg_buff = [] Alice_qkd(alice, msg_buff, secret_key, hosts) Alice_send_message(alice, msg_buff, secret_key, hosts) def Eve_func(eve=host_eve): msg_buff = [] eve_key = Eve_qkd(eve, msg_buff, key_size, hosts) Eve_receive_message(eve, msg_buff, eve_key, hosts) # Run Bob and Alice thread_alice = DaemonThread(Alice_func) thread_eve = DaemonThread(Eve_func) thread_alice.join() thread_eve.join() for h in hosts.values(): h.stop() network.stop()
def main(): global thread_1_return global thread_2_return network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes) network.delay = 0.5 host_alice = Host('Alice') host_alice.add_connection('bob') host_alice.max_ack_wait = 30 host_alice.delay = 0.2 host_alice.start() host_bob = Host('Bob') host_bob.max_ack_wait = 30 host_bob.delay = 0.2 host_bob.add_connection('Alice') host_bob.add_connection('Eve') host_bob.start() host_eve = Host('Eve') host_eve.max_ack_wait = 30 host_eve.delay = 0.2 host_eve.add_connection('Bob') host_eve.add_connection('Dean') host_eve.start() host_dean = Host('Dean') host_dean.max_ack_wait = 30 host_dean.delay = 0.2 host_dean.add_connection('Eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) network.x_error_rate = 0 network.packet_drop_rate = 0 q_size = 6 checksum_per_qubit = 2 host_alice.run_protocol(qtcp_sender, (q_size, host_dean.host_id, checksum_per_qubit)) host_dean.run_protocol(qtcp_receiver, (q_size, host_alice.host_id, checksum_per_qubit)) while thread_1_return is None or thread_2_return is None: if thread_1_return is False or thread_2_return is False: Logger.get_instance().log( 'TCP Connection not successful : EXITING') sys.exit(1) pass thread_1_return = None thread_2_return = None Logger.get_instance().log('PACKET 1') host_alice.run_protocol(qtcp_sender, (q_size, host_dean.host_id, checksum_per_qubit)) host_dean.run_protocol(qtcp_receiver, (q_size, host_alice.host_id, checksum_per_qubit)) while thread_1_return is None or thread_2_return is None: if thread_1_return is False or thread_2_return is False: Logger.get_instance().log( 'TCP Connection not successful : EXITING') sys.exit(1) pass Logger.get_instance().log('PACKET 2') host_alice.run_protocol(qtcp_sender, (q_size, host_dean.host_id, checksum_per_qubit)) host_dean.run_protocol(qtcp_receiver, (q_size, host_alice.host_id, checksum_per_qubit)) while thread_1_return is None or thread_2_return is None: if thread_1_return is False or thread_2_return is False: Logger.get_instance().log( 'TCP Connection not successful : EXITING') sys.exit(1) pass start_time = time.time() while time.time() - start_time < 150: pass network.stop(stop_hosts=True) exit()
def main(): network = Network.get_instance() backend = ProjectQBackend() # backend = EQSNBackend() nodes = ['A', 'B', 'C'] network.delay = 0.1 network.start(nodes, backend) host_A = Host('A', backend) host_A.add_c_connection('C') host_A.delay = 0 host_A.start() host_B = Host('B', backend) host_B.add_c_connection('C') host_B.delay = 0 host_B.start() host_C = Host('C', backend) host_C.add_c_connections(['A', 'B']) host_C.delay = 0 host_C.start() network.add_host(host_C) # To generate entanglement host_A.add_connection('B') host_B.add_connection('A') network.add_host(host_A) network.add_host(host_B) # strategy = 'CLASSICAL' strategy = 'QUANTUM' host_A.delay = 0.0 host_B.delay = 0.0 host_C.delay = 0.0 print('Starting game. Strategy: %s' % strategy) if strategy == 'QUANTUM': print('Generating initial entanglement...') for i in range(PLAYS): host_A.send_epr('B', await_ack=True) print('created %d EPR pairs' % (i + 1)) print('Done generating initial entanglement') else: network.delay = 0.0 # Remove the connection from Alice and Bob host_A.remove_connection('B') host_B.remove_connection('A') network.update_host(host_A) network.update_host(host_B) # Play the game classically if strategy == 'CLASSICAL': host_A.run_protocol(alice_classical, (host_C.host_id, )) host_B.run_protocol( bob_classical, (host_C.host_id, ), ) # Play the game quantumly if strategy == 'QUANTUM': host_A.run_protocol(alice_quantum, (host_C.host_id, host_B.host_id)) host_B.run_protocol(bob_quantum, (host_C.host_id, host_A.host_id)) host_C.run_protocol(referee, (host_A.host_id, host_B.host_id), blocking=True) network.stop(True)
def main(): network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] network.start(nodes) network.delay = 0.1 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.add_connection('Dean') host_eve.start() host_dean = Host('Dean') host_dean.add_connection('Eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) q_id1, _ = host_alice.send_epr('Dean', await_ack=True) q1 = host_alice.get_epr('Dean', q_id1) q2 = host_dean.get_epr('Alice', q_id1) if q1 is not None and q2 is not None: m1 = q1.measure() m2 = q2.measure() print("Results of the measurements for the entangled pair are %d %d" % (m1, m2)) else: if q1 is None: print('q1 is none') if q2 is None: print('q2 is none') network.stop(True) exit()
def main(): network = Network.get_instance() nodes = ["Alice", "Bob", "Eve", "Dean"] back = ProjectQBackend() network.start(nodes, back) network.delay = 0.1 host_alice = Host('Alice', back) host_alice.add_connection('Bob') host_alice.add_connection('Eve') host_alice.start() host_bob = Host('Bob', back) host_bob.add_connection('Alice') host_bob.add_connection('Eve') host_bob.start() host_eve = Host('Eve', back) host_eve.add_connection('Bob') host_eve.add_connection('Dean') host_eve.add_connection('Alice') host_eve.start() host_dean = Host('Dean', back) host_dean.add_connection('Eve') host_dean.start() network.add_host(host_alice) network.add_host(host_bob) network.add_host(host_eve) network.add_host(host_dean) share_list = ["Bob", "Eve", "Dean"] q_id1, ack_received = host_alice.send_ghz(share_list, await_ack=True) print("Alice received ACK from all? " + str(ack_received)) q1 = host_alice.get_ghz('Alice', q_id1, wait=10) q2 = host_bob.get_ghz('Alice', q_id1, wait=10) q3 = host_eve.get_ghz('Alice', q_id1, wait=10) q4 = host_dean.get_ghz('Alice', q_id1, wait=10) if q1 is None: raise ValueError("Q1 is none") if q2 is None: raise ValueError("Q2 is none") if q3 is None: raise ValueError("Q3 is none") if q4 is None: raise ValueError("Q4 is none") m1 = q1.measure() m2 = q2.measure() m3 = q3.measure() m4 = q4.measure() print("results of measurements are %d, %d, %d, and %d." % (m1, m2, m3, m4)) network.stop(True) exit()