예제 #1
0
def selectExitNode(bw_weights, bwweightscale, cons_rel_stats, descriptors,
                   fast, stable, internal, port):
    exits = filterExits(cons_rel_stats, descriptors, fast, stable, internal,
                        port)

    if len(exits) == 0:
        raise ValueError("No usable exit nodes for requested path.")

    if len(exits) == 1:
        return exits[0]

    weight_pos = 'm' if internal is True else 'e'
    weights = path_util.getPositionWeights(exits, cons_rel_stats, weight_pos,
                                           bw_weights, bwweightscale)
    weighted_exits = path_util.getWeightedNodes(exits, weights)

    return path_util.selectWeightedNode(weighted_exits)
예제 #2
0
def selectMiddleNode(bw_weights, bwweightscale, cons_rel_stats, descriptors,
                     fast, stable, exit_desc, exit_status_entry, guard_desc,
                     guard_status_entry):
    middles = filterMiddles(cons_rel_stats, descriptors, fast, stable,
                            exit_desc, exit_status_entry, guard_desc,
                            guard_status_entry)

    if len(middles) == 0:
        raise ValueError("No usable middle nodes for requested path.")

    if len(middles) == 1:
        return middles[0]

    weights = path_util.getPositionWeights(middles, cons_rel_stats, 'm',
                                           bw_weights, bwweightscale)
    weighted_middles = path_util.getWeightedNodes(middles, weights)
    return path_util.selectWeightedNode(weighted_middles)
예제 #3
0
파일: path.py 프로젝트: nskinkel/oppy
def selectExitNode(bw_weights, bwweightscale, cons_rel_stats, descriptors,
                   fast, stable, internal, port):
    exits = filterExits(cons_rel_stats, descriptors, fast, stable, internal,
                        port)

    if len(exits) == 0:
        raise ValueError("No usable exit nodes for requested path.")

    if len(exits) == 1:
        return exits[0]

    weight_pos = 'm' if internal is True else 'e'
    weights = path_util.getPositionWeights(exits, cons_rel_stats, weight_pos,
                                           bw_weights, bwweightscale)
    weighted_exits = path_util.getWeightedNodes(exits, weights)

    return path_util.selectWeightedNode(weighted_exits)
예제 #4
0
파일: path.py 프로젝트: nskinkel/oppy
def selectMiddleNode(bw_weights, bwweightscale, cons_rel_stats, descriptors,
                     fast, stable, exit_desc, exit_status_entry, guard_desc,
                     guard_status_entry):
    middles = filterMiddles(cons_rel_stats, descriptors, fast, stable,
                            exit_desc, exit_status_entry, guard_desc,
                            guard_status_entry)

    if len(middles) == 0:
        raise ValueError("No usable middle nodes for requested path.")

    if len(middles) == 1:
        return middles[0]

    weights = path_util.getPositionWeights(middles, cons_rel_stats, 'm',
                                           bw_weights, bwweightscale)
    weighted_middles = path_util.getWeightedNodes(middles, weights)
    return path_util.selectWeightedNode(weighted_middles)
예제 #5
0
파일: test_util.py 프로젝트: zyk2290/oppy
    def test_getPositionWeights(self, mock_getBwweight):
        from oppy.path.path import DEFAULT_BWWEIGHTSCALE

        mock_getBwweight.return_value = 5

        mock_flags = mock.Mock()
        mock_bwweights = mock.Mock()
        mock_node = mock.Mock()
        mock_node.bandwidth = 100
        mock_rel_stats = {mock_node: mock_node}
        mock_nodes = [mock_node]

        ret = path_util.getPositionWeights(mock_nodes, mock_rel_stats, 'g',
                                           mock_bwweights,
                                           DEFAULT_BWWEIGHTSCALE)

        expected = (5.0 / DEFAULT_BWWEIGHTSCALE) * 100

        self.assertTrue(isinstance(ret[mock_node], float))
        self.assertEqual(ret[mock_node], expected)
        self.assertTrue(mock_getBwweight.call_count, 1)
        self.assertTrue(mock_getBwweight.call_args_list,
                        [mock.call(mock_flags, 'g', mock_bwweights)])
예제 #6
0
파일: test_util.py 프로젝트: nskinkel/oppy
    def test_getPositionWeights(self, mock_getBwweight):
        from oppy.path.path import DEFAULT_BWWEIGHTSCALE

        mock_getBwweight.return_value = 5

        mock_flags = mock.Mock()
        mock_bwweights = mock.Mock()
        mock_node = mock.Mock()
        mock_node.bandwidth = 100
        mock_rel_stats = {mock_node: mock_node}
        mock_nodes = [mock_node]

        ret = path_util.getPositionWeights(mock_nodes, mock_rel_stats, 'g',
                                           mock_bwweights,
                                           DEFAULT_BWWEIGHTSCALE)

        expected = (5.0 / DEFAULT_BWWEIGHTSCALE) * 100

        self.assertTrue(isinstance(ret[mock_node], float))
        self.assertEqual(ret[mock_node], expected)
        self.assertTrue(mock_getBwweight.call_count, 1)
        self.assertTrue(mock_getBwweight.call_args_list,
                        [mock.call(mock_flags, 'g', mock_bwweights)])