-
Notifications
You must be signed in to change notification settings - Fork 0
/
SynHerdingBenchmarkAttacker.py
57 lines (51 loc) · 1.97 KB
/
SynHerdingBenchmarkAttacker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import random
from Messages.Message import Message
from Util.Util import *
class SynHerdingBenchmarkAttacker:
name = "Synchronous Herding Benchmark Attacker"
def __init__(self, **kargs):
self.env = kargs["env"]
self.pki = kargs["pki"]
self.con = kargs["con"]
self.pki.register(self)
self.input = None
self._lambda = kargs["lambda"]
self.buckets = [[], []]
self.bar = self.env.get_k() * self._lambda * self._lambda
self.my_mine = kargs["mine"]
self.called = 0
self.corrupt_node_list = list(
filter(lambda x: self.env.check_corrupt(x), range(self.env.get_n())))
self.chameleon_dict = {}
self.represent = None
self.represent_id = self.env.get_n()-1
for node in self.con.node_id.keys():
if node.env.get_id(node) == self.represent_id:
self.represent_node = node
break
def run_node(self):
self.called += 1
if (self.called % self.con.f) != 1:
return
round = self.env.get_round()
if round == 0:
pass
elif round < self.bar-1:
for i in range(2):
for id in self.corrupt_node_list:
my_pow = self.my_mine.POW(round, id, i)
if my_pow:
new_block = self.pki.sign(
self.represent_node, Block(round, id, i))
self.buckets[i].append(new_block)
break
elif round == self.bar-1:
for i in range(self.env.get_n()):
if self.env.check_corrupt(i):
pass
else:
if self.buckets[i % 2]:
self.represent_node.env.put_packet(self.represent_node, self.represent_node.pki.sign(
self.represent_node, Message(self.represent_id, self.buckets[i % 2])), i)
else:
pass