Esempio n. 1
0
    def test_check_pong(self):
        circuit = Circuit(42L)
        ping_request_cache = PingRequestCache(self.tunnel_community, circuit)
        ping_num = self.tunnel_community.request_cache.add(ping_request_cache).number
        meta = self.tunnel_community.get_meta_message(u"ping")
        msg1 = meta.impl(distribution=(self.tunnel_community.global_time,),
                         candidate=Candidate(("127.0.0.1", 1234), False), payload=(42, ping_num - 1))
        msg2 = meta.impl(distribution=(self.tunnel_community.global_time,),
                         candidate=Candidate(("127.0.0.1", 1234), False), payload=(42, ping_num))

        # Invalid ping identifier
        for i in self.tunnel_community.check_pong([msg1]):
            self.assertIsInstance(i, DropMessage)

        for i in self.tunnel_community.check_pong([msg2]):
            self.assertIsInstance(i, type(msg2))

        self.tunnel_community.request_cache.pop(u"ping", ping_num)
Esempio n. 2
0
    def test_ping_request_cache(self):
        circuit = Circuit(42L)
        ping_request_cache = PingRequestCache(self.tunnel_community, circuit)
        self.assertGreater(ping_request_cache.timeout_delay, 0)
        self.tunnel_community.circuits[42] = circuit

        circuit.last_incoming = time.time() + 1000
        ping_request_cache.on_timeout()
        self.assertIn(42, self.tunnel_community.circuits)

        circuit.last_incoming = time.time() - ping_request_cache.timeout_delay - 200
        ping_request_cache.on_timeout()
        self.assertNotIn(42, self.tunnel_community.circuits)