def stupid_sybil_border(graph): reset_ranks(graph) ranker = algorithms.SybilGroupRank(graph) ranker.rank() attacker = max(graph.nodes, key=lambda node: node.rank) attacker.groups.add('stupid_sybil') sybil1 = graphs.node.Node('stupid_sybil_1', 'Sybil', set(['stupid_sybil'])) sybil2 = graphs.node.Node('stupid_sybil_2', 'Sybil', set(['stupid_sybil'])) graph.add_edge(attacker, sybil1) graph.add_edge(attacker, sybil2) reset_ranks(graph) ranker = algorithms.SybilGroupRank(graph) ranker.rank() border = max(sybil1.raw_rank, sybil2.raw_rank) graph.remove_nodes_from([sybil1, sybil2]) attacker.groups.remove('stupid_sybil') reset_ranks(graph) return border
def load_default(): graph = load_graph('graph.json') ranker = algorithms.SybilGroupRank(graph, algorithm_options) ranker.rank() graph_info = edit_output(graph) return json.dumps({ 'success': True, 'graph': to_json(graph), 'graph_info': graph_info })
def add_sybils(): json_graph = request.form['json_graph'] sybils_defenition = request.form['sybils'] graph = from_json(json_graph) if sybils_defenition: add_sybils_to_graph(graph, sybils_defenition) ranker = algorithms.SybilGroupRank(graph, algorithm_options) ranker.rank() graph_info = edit_output(graph) json_graph = to_json(graph) return json.dumps({ 'success': True, 'graph': json_graph, 'graph_info': graph_info })
def process(fname): with open(fname) as f: json_graph = from_dump(f) graph = from_json(json_graph) border = stupid_sybil_border(graph) raw_ranks = [node.raw_rank for node in graph.nodes] print('''stupid border: {} max: {} min: {} avg: {}'''.format(border, max(raw_ranks), min(raw_ranks), sum(raw_ranks) / len(raw_ranks))) reset_ranks(graph) ranker = algorithms.SybilGroupRank(graph, {'stupid_sybil_border': border}) ranker.rank() draw_graph(ranker.graph, 'nodes.html') draw_graph(ranker.group_graph, 'groups.html') update(ranker.graph, ranker.group_graph)
def upload_graph_json(): file = request.files.get('graph_json_file', None) if not file: return json.dumps({'success': False}) ext = file.filename.rsplit('.', 1)[1] if ext == 'json': json_graph = file.stream.read() elif ext == 'zip': json_graph = from_dump(file.stream) else: return json.dumps({'success': False}) graph = from_json(json_graph) reset_ranks(graph) ranker = algorithms.SybilGroupRank(graph, algorithm_options) ranker.rank() graph_info = edit_output(graph) return json.dumps({ 'success': True, 'graph': to_json(graph), 'graph_info': graph_info })
def new_graph(): form_data = request.form graph = graphs.generators.group_based.generate({ 'num_groups': int(form_data['num_groups']), 'num_seed_groups': int(form_data['num_seed_groups']), 'min_group_nodes': int(form_data['min_group_nodes']), 'max_group_nodes': int(form_data['max_group_nodes']), 'max_known_ratio': float(form_data['max_known_ratio']), 'avg_known_ratio': float(form_data['avg_known_ratio']), 'min_known_ratio': float(form_data['min_known_ratio']), 'num_seed_nodes': int(form_data['num_seed_nodes']), 'num_attacker_to_num_honest': float(form_data['num_attacker_to_num_honest']), 'num_sybil_to_num_attacker': int(form_data['num_sybil_to_num_attacker']), 'sybil_to_attackers_con': float(form_data['sybil_to_attackers_con']), 'num_joint_node': int(form_data['num_joint_node']), 'num_inter_group_con': int(form_data['num_inter_group_con']) }) ranker = algorithms.SybilGroupRank(graph, algorithm_options) ranker.rank() graph_info = edit_output(graph) json_graph = to_json(graph) return json.dumps({ 'success': True, 'graph': json_graph, 'graph_info': graph_info })
attacker.groups.add('stupid_sybil') sybil1 = graphs.node.Node('stupid_sybil_1', 'Sybil', set(['stupid_sybil'])) sybil2 = graphs.node.Node('stupid_sybil_2', 'Sybil', set(['stupid_sybil'])) graph.add_edge(attacker, sybil1) graph.add_edge(attacker, sybil2) reset_ranks(graph) ranker = algorithms.SybilGroupRank(graph) ranker.rank() border = max(sybil1.raw_rank, sybil2.raw_rank) graph.remove_nodes_from([sybil1, sybil2]) attacker.groups.remove('stupid_sybil') reset_ranks(graph) return border if __name__ == '__main__': graph = load() border = stupid_sybil_border(graph) raw_ranks = [node.raw_rank for node in graph.nodes] print('''stupid border: {} max: {} min: {} avg: {}'''.format(border, max(raw_ranks), min(raw_ranks), sum(raw_ranks) / len(raw_ranks))) reset_ranks(graph) ranker = algorithms.SybilGroupRank(graph, {'stupid_sybil_border': border}) ranker.rank() draw_graph(ranker.graph, 'nodes.html') draw_graph(ranker.group_graph, 'groups.html') update(ranker.graph, ranker.group_graph)