-
Notifications
You must be signed in to change notification settings - Fork 1
/
broadcast.py
30 lines (28 loc) · 1.09 KB
/
broadcast.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
def broadcast(
env, object, objectType, source, neighbourList, params, pipes="", nodes=""
):
"""Broadcasts the object from the source to destination"""
if objectType == "Transaction":
"""Broadcast a transaction to all neighbours"""
for neighbour in neighbourList:
sourceLocation = "Ireland"
env.process(
nodes[neighbour].transactionPool.putTransaction(object, sourceLocation)
)
elif objectType == "Block":
"""Broadcast a block to all neighbours"""
if not pipes:
raise RuntimeError("There are no output pipes.")
events = []
for neighbour in neighbourList:
# Obtain transmission delay
sourceLocation = nodes[neighbour].location
store = pipes[neighbour]
events.append(store.put(object, sourceLocation))
if bool(params["verbose"]):
print(
"%7.4f" % env.now
+ " : "
+ "Node %s propagated Block %s" % (source, object.identifier)
)
return env.all_of(events)