Exemple #1
0
def middleFilter(node,
                 cons_rel_stats,
                 descriptors,
                 exit_desc,
                 exit_status_entry,
                 guard_desc,
                 guard_status_entry,
                 fast=False,
                 stable=False):
    try:
        rel_stat = cons_rel_stats[node]
        node_desc = descriptors[rel_stat.digest]
    except KeyError:
        return False

    if node_desc.ntor_onion_key is None:
        return False
    # Note that we intentionally allow non-Valid routers for middle
    # as per path-spec.txt default config
    if Flag.RUNNING not in rel_stat.flags:
        return False
    if (fast is True) and (Flag.FAST not in rel_stat.flags):
        return False
    if (stable is True) and (Flag.STABLE not in rel_stat.flags):
        return False
    if path_util.nodeUsableWithOther(exit_desc, exit_status_entry, node_desc,
                                     rel_stat) is False:
        return False

    return path_util.nodeUsableWithOther(guard_desc, guard_status_entry,
                                         node_desc, rel_stat)
Exemple #2
0
def middleFilter(node, cons_rel_stats, descriptors, exit_desc,
                 exit_status_entry, guard_desc, guard_status_entry,
                 fast=False, stable=False):
    try:
        rel_stat = cons_rel_stats[node]
        node_desc = descriptors[rel_stat.digest]
    except KeyError:
        return False

    if node_desc.ntor_onion_key is None:
        return False
    # Note that we intentionally allow non-Valid routers for middle
    # as per path-spec.txt default config
    if Flag.RUNNING not in rel_stat.flags:
        return False
    if (fast is True) and (Flag.FAST not in rel_stat.flags):
        return False
    if (stable is True) and (Flag.STABLE not in rel_stat.flags):
        return False
    if path_util.nodeUsableWithOther(exit_desc, exit_status_entry, node_desc,
        rel_stat) is False:
        return False

    return path_util.nodeUsableWithOther(guard_desc, guard_status_entry,
                                         node_desc, rel_stat)
Exemple #3
0
    def test_NodeUsableWithOther_no_equal_nodes(self, mock_subnet,
                                                mock_family):

        desc1 = 'desc1'
        se1 = mock.Mock()
        se1.fingerprint = 'fprint1'
        desc2 = 'desc1'
        se2 = mock.Mock()
        se2.fingerprint = 'fprint1'

        self.assertFalse(path_util.nodeUsableWithOther(desc1, se1, desc2, se2))
        self.assertEqual(mock_subnet.call_count, 0)
        self.assertEqual(mock_family.call_count, 0)
Exemple #4
0
    def test_NodeUsableWithOther_no_equal_nodes(self, mock_subnet,
        mock_family):

        desc1 = 'desc1'
        se1 = mock.Mock()
        se1.fingerprint = 'fprint1'
        desc2 = 'desc1'
        se2 = mock.Mock()
        se2.fingerprint = 'fprint1'

        self.assertFalse(path_util.nodeUsableWithOther(
            desc1, se1, desc2, se2))
        self.assertEqual(mock_subnet.call_count, 0)
        self.assertEqual(mock_family.call_count, 0)
Exemple #5
0
    def test_nodeUsableWithOther_yes(self, mock_subnet, mock_family):
        desc1 = 'desc1'
        se1 = mock.Mock()
        se1.fingerprint = 'fprint1'
        desc2 = 'desc2'
        se2 = mock.Mock()
        se2.fingerprint = 'fprint2'

        mock_family.return_value = False
        mock_subnet.return_value = False

        self.assertTrue(path_util.nodeUsableWithOther(desc1, se1, desc2, se2))

        self.assertEqual(mock_family.call_count, 1)
        self.assertEqual(mock_subnet.call_count, 1)
Exemple #6
0
def guardFilter(guard, cons_rel_stats, descriptors, fast, stable, exit_desc,
                exit_status_entry):
    try:
        rel_stat = cons_rel_stats[guard]
        guard_desc = descriptors[rel_stat.digest]
    except KeyError:
        return False

    if (fast is True) and (Flag.FAST not in rel_stat.flags):
        return False
    if (stable is True) and (Flag.STABLE not in rel_stat.flags):
        return False

    return path_util.nodeUsableWithOther(guard_desc, rel_stat, exit_desc,
                                         exit_status_entry)
Exemple #7
0
def guardFilter(guard, cons_rel_stats, descriptors, fast, stable, exit_desc,
                exit_status_entry):
    try:
        rel_stat = cons_rel_stats[guard]
        guard_desc = descriptors[rel_stat.digest]
    except KeyError:
        return False

    if (fast is True) and (Flag.FAST not in rel_stat.flags):
        return False
    if (stable is True) and (Flag.STABLE not in rel_stat.flags):
        return False

    return path_util.nodeUsableWithOther(guard_desc, rel_stat,
                                         exit_desc, exit_status_entry)
Exemple #8
0
    def test_nodeUsableWithOther_yes(self, mock_subnet, mock_family):
        desc1 = 'desc1'
        se1 = mock.Mock()
        se1.fingerprint = 'fprint1'
        desc2 = 'desc2'
        se2 = mock.Mock()
        se2.fingerprint = 'fprint2'

        mock_family.return_value = False
        mock_subnet.return_value = False

        self.assertTrue(path_util.nodeUsableWithOther(
            desc1, se1, desc2, se2))

        self.assertEqual(mock_family.call_count, 1)
        self.assertEqual(mock_subnet.call_count, 1)