-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.py
35 lines (24 loc) · 872 Bytes
/
Node.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
import threading
import _thread
import time
import math
class Node:
def __init__(self, network, power=1):
self.network = network
self.id = network.nodes_count
self.network.nodes_count += 1
self.power = power
self.delay = 1 / power
self.calls = 0
self.blocks_to_go = 0
def run(self, blocks, time):
self.blocks_to_go = blocks
thread = threading.Thread(target=self.work, args=[time])
thread.start()
def send_broadcast(self, data):
for node in self.network.nodes:
node.receive_broadcast(data)
def receive_broadcast(self, data):
raise Exception("Node is a abstract class. receive_broadcast() must be overwritten in subclasses")
def work(self):
raise Exception("Node is a abstract class. work() must be overwritten in subclasses")