Exemple #1
0
    def testFlowManagement(self):
        print 80 * "-"
        print "  testFlowManagement"
        print 80 * "-"
        client1 = LocalAliceLink(threading.Event(), None, self.lh_config)
        client1.start()
        client1.ready.wait()
        client1.send_message("ping")
        flow1 = self.random_flow(self.localhost, self.ip)
        flow2 = Switzerland.flow_mirror(flow1)
        #self.assertEqual(flow2, (ip,port2_s,localhost, port_s, prot_s))
        client1.send_message("active_flows", [[(0, "hash00", flow1)], []])
        # This trick should get us two useable Alice IPs
        client2 = AliceLink(threading.Event(), None, self.net_config)
        client2.start()
        client2.ready.wait()
        client2.send_message("ping")
        client2.send_message("active_flows", [[(0, "hash00", flow1)], []])

        mm1 = (flow1[0], flow1[2], "hash00")
        mm2 = (flow2[0], flow2[2], "hash00")
        time.sleep(3)
        mm = self.server.mm
        mm.global_flow_lock.acquire()
        try:
            print "Global flow table", mm.flow_matchmaker
            # XXX fix these
            #self.assert_(mm.global_flow_table.has_key(flow1))
            print "Hunting for", mm1, "\nand", mm2
            self.assert_(mm.flow_matchmaker.has_key(mm1))
            #self.assert_(not mm.global_flow_table.has_key(flow2))
            self.assert_(not mm.flow_matchmaker.has_key(mm2))

        finally:
            mm.global_flow_lock.release()

        # Now tear things down
        client2.send_message("active_flows", [[], [0]])
        client1.send_message("active_flows", [[], [0]])

        time.sleep(2)
        mm.global_flow_lock.acquire()
        try:
            print "Global flow table", mm.flow_matchmaker
            #self.assertEqual(mm.global_flow_table, {})
            self.assertEqual(mm.flow_matchmaker, {})
        finally:
            mm.global_flow_lock.release()

        nmf = lambda m: m[0] == "new-members"
        new_member_counts = [
            len(filter(nmf, c.in_log)) for c in [client1, client2]
        ]
        print "nmc:", new_member_counts
        self.assert_(1 in new_member_counts)
        self.assert_(2 in new_member_counts)
  def testFlowManagement(self):
    print 80 * "-"
    print "  testFlowManagement"
    print 80 * "-"
    client1 = LocalAliceLink(threading.Event(), None, self.lh_config)
    client1.start()
    client1.ready.wait()
    client1.send_message("ping")
    flow1 = self.random_flow(self.localhost, self.ip)
    flow2 = Switzerland.flow_mirror(flow1)
    #self.assertEqual(flow2, (ip,port2_s,localhost, port_s, prot_s))
    client1.send_message("active_flows", [[(0, "hash00", flow1)], []])
    # This trick should get us two useable Alice IPs
    client2 = AliceLink(threading.Event(), None, self.net_config)
    client2.start()
    client2.ready.wait()
    client2.send_message("ping")
    client2.send_message("active_flows", [[(0, "hash00", flow1)], []])
    
    mm1 = (flow1[0], flow1[2], "hash00")
    mm2 = (flow2[0], flow2[2], "hash00")
    time.sleep(3)
    mm = self.server.mm
    mm.global_flow_lock.acquire()
    try:
      print "Global flow table", mm.flow_matchmaker
      # XXX fix these
      #self.assert_(mm.global_flow_table.has_key(flow1))
      print "Hunting for", mm1, "\nand",  mm2
      self.assert_(mm.flow_matchmaker.has_key(mm1))
      #self.assert_(not mm.global_flow_table.has_key(flow2))
      self.assert_(not mm.flow_matchmaker.has_key(mm2))

    finally:
      mm.global_flow_lock.release()

    # Now tear things down
    client2.send_message("active_flows", [[], [0]])
    client1.send_message("active_flows", [[], [0]])

    time.sleep(2)
    mm.global_flow_lock.acquire()
    try:
      print "Global flow table", mm.flow_matchmaker
      #self.assertEqual(mm.global_flow_table, {})
      self.assertEqual(mm.flow_matchmaker, {})
    finally:
      mm.global_flow_lock.release()

    nmf = lambda m : m[0] == "new-members"
    new_member_counts = [len(filter(nmf, c.in_log)) for c in [client1, client2]]
    print "nmc:", new_member_counts
    self.assert_(1 in new_member_counts)
    self.assert_(2 in new_member_counts)
Exemple #3
0
    def testForgedReplies(self):
        print 80 * "-"
        print "  testForgedReplies"
        print 80 * "-"
        client1 = AliceLink(threading.Event(), None, self.lh_config)
        client1.handle_forged_in = client1.dummy_handle_forged_in
        client1.start()
        client1.ready.wait()
        client2 = AliceLink(threading.Event(), None, self.net_config)
        client2.handle_forged_in = client2.dummy_handle_forged_in
        client2.start()
        client2.ready.wait()
        server_thread1, server_thread2 = self.server.threads  # XXX not safe!!!
        # This interface is undocumented
        for t in self.server.threads:
            t.real_fi_handler = t.handle_fi_context
            t.handle_fi_context = t.hook_handle
        self.callback_count = 0
        contexts = {}
        for n in range(5):
            hash = Protocol.hash_length * chr(n)
            contexts[hash] = [repr(n)] * 3
        forgeries = contexts.keys()
        timestamps = [1, 2, 3, 4, 5]
        forgeries = zip(timestamps, forgeries)
        rec = self.random_reconciliator(server_thread1, server_thread2)
        frogs = (forgeries, rec)

        def callback(link, args, seq_no, reply_seq_no):
            self.assertEqual(link, server_thread1)
            meta = args[0]
            data = args[1]
            replying_to = meta[0]
            remembered = meta[1]
            self.assertEqual(replying_to, "forged-in")
            self.assertEqual(remembered, frogs)
            self.callback_count += 1
            # okay, we've finished testing, now call the real method:
            link.real_fi_handler(args, seq_no, reply_seq_no)

        for l in self.server.threads:
            l.hook_callback = callback
        client1.send_message("ping")

        server_thread1.send_message("forged-in", [0] + [forgeries],
                                    data_for_reply=frogs)
        time.sleep(1)
        client1.send_message("signoff")
        time.sleep(1)
        self.assertEqual(self.callback_count, 1)
  def testForgedReplies(self):
    print 80 * "-"
    print "  testForgedReplies"
    print 80 * "-"
    client1 = AliceLink(threading.Event(), None, self.lh_config)
    client1.handle_forged_in = client1.dummy_handle_forged_in
    client1.start()
    client1.ready.wait()
    client2 = AliceLink(threading.Event(), None, self.net_config)
    client2.handle_forged_in = client2.dummy_handle_forged_in
    client2.start()
    client2.ready.wait()
    server_thread1, server_thread2 = self.server.threads  # XXX not safe!!!
    # This interface is undocumented
    for t in self.server.threads:
      t.real_fi_handler = t.handle_fi_context
      t.handle_fi_context = t.hook_handle
    self.callback_count = 0
    contexts = {}
    for n in range(5):
      hash = Protocol.hash_length * chr(n)
      contexts[hash] = [repr(n)] * 3
    forgeries = contexts.keys()
    timestamps=[1,2,3,4,5]
    forgeries = zip(timestamps, forgeries)
    rec = self.random_reconciliator(server_thread1, server_thread2)
    frogs = (forgeries, rec)
    def callback(link, args, seq_no, reply_seq_no):
      self.assertEqual(link, server_thread1)
      meta = args[0]
      data = args[1]
      replying_to = meta[0]
      remembered = meta[1]
      self.assertEqual(replying_to, "forged-in")
      self.assertEqual(remembered, frogs)
      self.callback_count += 1
      # okay, we've finished testing, now call the real method:
      link.real_fi_handler(args, seq_no, reply_seq_no)
    for l in self.server.threads:
      l.hook_callback = callback
    client1.send_message("ping")

    server_thread1.send_message("forged-in", [0] + [forgeries], data_for_reply = frogs)
    time.sleep(1)
    client1.send_message("signoff")
    time.sleep(1)
    self.assertEqual(self.callback_count, 1)
Exemple #5
0
    def testProtocolBasics(self):
        print 80 * "-"
        print "  testProtocolBasics"
        print 80 * "-"
        client = AliceLink(threading.Event(), None, self.lh_config)
        client.start()
        client.ready.wait()

        server_thread = self.server.threads[-1]  # XXX not safe!!!
        client.send_message("ping")
        client.send_message("test", [1, 0, [1, 2, 4]])
        client.send_message("test", [2, 0, [1, 2, 5]])
        client.send_message("test", [3, 0, [1, 2, 6]])
        client.send_message("ping")
        client.send_message("ping")
        client.send_message("ping")
        time.sleep(1)
        client.send_message("signoff")
        time.sleep(1)

        #print "Server in:"
        #print "\n".join(map(repr, server_thread.in_log))
        server_thread.status_lock.acquire()
        # adding one for the firewall mss now in Protocol.setup(), and one more
        # for the default new-members message in Switzerland.new_link() and its
        # ack

        self.assertEqual(server_thread.messages_in, 8 + 2)
        self.assertEqual(server_thread.messages_out,
                         4 + 2)  # just for the pings
        self.assert_(server_thread.closed)
        self.assertEqual(client.messages_out, 8 + 2)
        self.assertEqual(client.messages_in, 4 + 2)
        self.assert_(["test", 3, 0, [1, 2, 6]] in client.out_log)
        self.assert_(["test", 3, 0, [1, 2, 6]] in server_thread.in_log)
        if local_ip.get_local_ip() != "127.0.0.1":
            #self.assert_(['you-are-firewalled', 0, '127.0.0.1'] in server_thread.out_log)
            #self.assert_(['you-are-firewalled', 0, '127.0.0.1'] in client.in_log)
            self.assert_(
                ['public-ip', 0, '127.0.0.1'] in server_thread.out_log)
            self.assert_(['public-ip', 0, '127.0.0.1'] in client.in_log)
        server_thread.status_lock.release()
  def testProtocolBasics(self):
    print 80 * "-"
    print "  testProtocolBasics"
    print 80 * "-"
    client = AliceLink(threading.Event(), None, self.lh_config)
    client.start()
    client.ready.wait()

    server_thread = self.server.threads[-1]  # XXX not safe!!!
    client.send_message("ping")
    client.send_message("test", [1,0,[1,2,4]])
    client.send_message("test", [2,0,[1,2,5]])
    client.send_message("test", [3,0,[1,2,6]])
    client.send_message("ping")
    client.send_message("ping")
    client.send_message("ping")
    time.sleep(1)
    client.send_message("signoff")
    time.sleep(1)

    #print "Server in:"
    #print "\n".join(map(repr, server_thread.in_log))
    server_thread.status_lock.acquire()
    # adding one for the firewall mss now in Protocol.setup(), and one more
    # for the default new-members message in Switzerland.new_link() and its
    # ack
    
    self.assertEqual(server_thread.messages_in, 8+2)
    self.assertEqual(server_thread.messages_out, 4+2)  # just for the pings
    self.assert_(server_thread.closed)
    self.assertEqual(client.messages_out,8+2)
    self.assertEqual(client.messages_in,4+2)
    self.assert_(["test", 3, 0, [1,2,6]] in client.out_log)
    self.assert_(["test", 3, 0, [1,2,6]] in server_thread.in_log)
    if local_ip.get_local_ip() != "127.0.0.1":
      #self.assert_(['you-are-firewalled', 0, '127.0.0.1'] in server_thread.out_log)
      #self.assert_(['you-are-firewalled', 0, '127.0.0.1'] in client.in_log)
      self.assert_(['public-ip', 0, '127.0.0.1'] in server_thread.out_log)
      self.assert_(['public-ip', 0, '127.0.0.1'] in client.in_log)
    server_thread.status_lock.release()