示例#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)
示例#2
0
文件: path.py 项目: nskinkel/oppy
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)
示例#3
0
文件: test_util.py 项目: zyk2290/oppy
    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)
示例#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)
示例#5
0
文件: test_util.py 项目: zyk2290/oppy
    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)
示例#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)
示例#7
0
文件: path.py 项目: nskinkel/oppy
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)
示例#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)