def test_relay_link(self): bob = DHT(networking=0) alice = DHT(networking=0) bob.add_relay_link(alice) alice.add_relay_link(bob) msg = u"test" bob.send_direct_message(alice.get_id(), msg) assert(alice.has_messages()) assert(alice.get_messages()[0][u"message"] == msg)
def test_relay_link(self): bob = DHT(networking=0) alice = DHT(networking=0) alice.protocol.messages_received = Queue() bob.protocol.messages_received = Queue() bob.add_relay_link(alice) alice.add_relay_link(bob) msg = u"test" bob.send_direct_message(alice.get_id(), msg) assert (alice.has_messages()) assert (alice.get_messages()[0] == msg)
def test_relay_link(self): bob = DHT(networking=0) alice = DHT(networking=0) alice.protocol.messages_received = Queue() bob.protocol.messages_received = Queue() bob.add_relay_link(alice) alice.add_relay_link(bob) msg = u"test" bob.send_direct_message(alice.get_id(), msg) assert alice.has_messages() assert alice.get_messages()[0] == msg
def test_reverse_connect(self): # Setup Alice as master. alice_dht = DHT() bob_dht = DHT() alice_dht.protocol.messages_received = Queue() bob_dht.protocol.messages_received = Queue() bob_dht.add_relay_link(alice_dht) alice_dht.add_relay_link(bob_dht) alice_direct = Net( net_type="direct", node_type="passive", nat_type="preserving", passive_port=0, dht_node=alice_dht, debug=1 ).start() assert(alice_direct.node_type == "passive") # Setup Bob as slave. bob_direct = Net( net_type="direct", node_type="active", nat_type="preserving", passive_port=0, dht_node=bob_dht, debug=1 ).start() assert(bob_direct.node_type == "active") # Setup connection handlers. def success_builder(): def success(con): print("IN SUCCESS HANDLER \a") global found_con found_con = 1 return success events = { "success": success_builder() } # Make Bob connect back to Alice. alice_direct.unl.connect(bob_direct.unl.value, events, hairpin=0) # Process connections. end_time = time.time() + 15 while time.time() < end_time: for direct in [alice_direct, bob_direct]: direct.dht_node.get_messages() for con in direct: print(con) for reply in con: print("Reply in con = ") print(reply) time.sleep(0.5) print("Found con = " + str(found_con)) assert(found_con == 1) assert(len(alice_direct.pending_reverse_queries) == 0) # Close networking. for direct in [alice_direct, bob_direct]: direct.stop()