Exemplo n.º 1
0
    def test_on_tunnel_in(self):
        """
        Test whether no data is sent to the SOCKS5 server when we receive data from the tunnels
        """
        mock_circuit = MockObject()
        mock_circuit.goal_hops = 300
        mock_circuit.circuit_id = b'a'
        mock_circuit.ctype = CIRCUIT_TYPE_DATA
        origin = ("0.0.0.0", 1024)
        self.assertFalse(
            self.dispatcher.on_incoming_from_tunnel(self.mock_tunnel_community,
                                                    mock_circuit, origin,
                                                    b'a'))

        mock_circuit.goal_hops = 1
        mock_sock_server = MockObject()
        mock_session = MockObject()
        mock_session._udp_socket = None
        mock_sock_server.sessions = [mock_session]
        self.dispatcher.set_socks_servers([mock_sock_server])
        self.dispatcher.destinations[1] = {b'a': mock_circuit}
        self.assertFalse(
            self.dispatcher.on_incoming_from_tunnel(self.mock_tunnel_community,
                                                    mock_circuit, origin,
                                                    b'a'))

        mock_session._udp_socket = MockObject()
        mock_session._udp_socket.sendDatagram = lambda _: True
        self.assertTrue(
            self.dispatcher.on_incoming_from_tunnel(self.mock_tunnel_community,
                                                    mock_circuit, origin,
                                                    b'a'))
Exemplo n.º 2
0
    def test_monitor_downloads_stop_ip(self):
        """
        Test whether we stop building IPs when a download doesn't exist anymore
        """
        mock_circuit = MockObject()
        mock_circuit.circuit_id = 0
        mock_circuit.ctype = 'IP_SEEDER'
        mock_circuit.state = 'READY'
        mock_circuit.info_hash = b'a'
        mock_circuit.goal_hops = 1
        mock_circuit.last_activity = 0

        self.nodes[0].overlay.remove_circuit = Mock()
        self.nodes[0].overlay.circuits[0] = mock_circuit
        self.nodes[0].overlay.join_swarm(b'a', 1)
        self.nodes[0].overlay.download_states[b'a'] = 3
        self.nodes[0].overlay.monitor_downloads([])
        self.nodes[0].overlay.remove_circuit.assert_called_with(
            0, 'leaving hidden swarm', destroy=5)
Exemplo n.º 3
0
    def test_monitor_downloads_stop_ip(self):
        """
        Test whether we stop building IPs when a download doesn't exist anymore
        """
        def mocked_remove_circuit(circuit_id, *_, **__):
            mocked_remove_circuit.circuit_id = circuit_id

        mocked_remove_circuit.circuit_id = -1

        mock_circuit = MockObject()
        mock_circuit.circuit_id = 0
        mock_circuit.ctype = 'IP_SEEDER'
        mock_circuit.state = 'READY'
        mock_circuit.info_hash = b'a'
        mock_circuit.goal_hops = 1

        self.nodes[0].overlay.remove_circuit = mocked_remove_circuit
        self.nodes[0].overlay.circuits[0] = mock_circuit
        self.nodes[0].overlay.join_swarm(b'a', 1)
        self.nodes[0].overlay.download_states[b'a'] = 3
        self.nodes[0].overlay.monitor_downloads([])
        self.assertEqual(mocked_remove_circuit.circuit_id, 0)
Exemplo n.º 4
0
    def test_monitor_downloads_stop_all(self):
        """
        Test whether circuits are removed when all downloads are stopped
        """
        def mocked_remove_circuit(circuit_id, *_, **__):
            mocked_remove_circuit.circuit_id = circuit_id

        mocked_remove_circuit.circuit_id = -1

        mock_circuit = MockObject()
        mock_circuit.circuit_id = 0
        mock_circuit.ctype = 'DATA'
        mock_circuit.state = 'READY'
        mock_circuit.info_hash = b'a'
        mock_circuit.goal_hops = 1
        mock_circuit.last_activity = 0

        self.nodes[0].overlay.remove_circuit = mocked_remove_circuit
        self.nodes[0].overlay.circuits[0] = mock_circuit
        self.nodes[0].overlay.join_swarm(b'a', 1)
        self.nodes[0].overlay.download_states[b'a'] = 3
        self.nodes[0].overlay.monitor_downloads([])
        self.assertEqual(mocked_remove_circuit.circuit_id, 0)
Exemplo n.º 5
0
    def test_monitor_downloads_intro(self):
        """
        Test whether rendezvous points are removed when a download is stopped
        """
        def mocked_remove_circuit(circuit_id, *_, **__):
            mocked_remove_circuit.circuit_id = circuit_id

        mocked_remove_circuit.circuit_id = -1

        mock_circuit = MockObject()
        mock_circuit.circuit_id = 0
        mock_circuit.ctype = 'RP_DOWNLOADER'
        mock_circuit.state = 'READY'
        mock_circuit.info_hash = b'a'
        mock_circuit.goal_hops = 1

        self.nodes[0].overlay.remove_circuit = mocked_remove_circuit
        self.nodes[0].overlay.circuits[0] = mock_circuit
        self.nodes[0].overlay.join_swarm(b'a', 1)
        self.nodes[0].overlay.swarms[b'a'].add_connection(mock_circuit, None)
        self.nodes[0].overlay.download_states[b'a'] = 3
        self.nodes[0].overlay.monitor_downloads([])
        self.assertEqual(mocked_remove_circuit.circuit_id, 0)