Commit 41e9287d authored by THAKARE AKSHAY HARIBHAU's avatar THAKARE AKSHAY HARIBHAU

Merge branch 'algorand' into 'Nalgo'

# Conflicts:
#   filegen.py
parents e2ab3569 6113f258
lambda_proposer = 3 # wait time for priority messages to be received
tou_proposer = 20 # proposer rolecount
ROLE_BLOCK_PROPOSER = 'BLOCK_PROPOSER'
tou_step = 3 # tou is expected number of users that sortition selects for committee
ROLE_COMMITEE_FOR_VOTE = 'committee'
lambda_block = 30 #seconds
lambda_step = 3
BLOCK_PROPOSAL_MSG_type = 'BLOCK_PROPOSAL_MSGs'
PRIORITY_MSG_type = 'PRIORITY_MSG'
COMMITTEE_VOTE_MSG_type = "COMMITTEE_VOTE"
TIMEOUT = "TIMEOUT"
T = 2/3 # T isa a fraction of expected committee size that defines BA*`s voting thershold
......@@ -2,3 +2,7 @@
2 3
3 4
4 1
3 5
2 6
3 7
7 4
\ No newline at end of file
This diff is collapsed.
......@@ -17,6 +17,7 @@ class Network():
self.links = {} #{(1,2):Link(1-2),(2,1):Link(2,1),(3,2):Link(3*2)} linkID = tuple(1,2)
self.networkClockTime = 0
self.pk_weight_map = {}
self.time = 0
def setupNetwork(self):
'''
......@@ -33,20 +34,26 @@ class Network():
w = randint(1, 51, 4) # 51 is excluded - range (1,50)
self.badaW = np.sum(w)
i = 0
with open('Nodes.dat', 'r') as f:
with open('Nodes1.dat', 'r') as f:
reader = csv.reader(f)
for row in reader:
node = row[0] # NOde id
node = row[0] # Node id
xnode = {node:OverlayNode(node,self,w[i])}
self.pk_weight_map.update({xnode[node].pk:w[i]})
self.nodes.update(xnode)#added node to network
# print(self.nodes.get('1')) #keys are strings
with open('Links.dat', 'r') as f:
with open('Links1.dat', 'r') as f:
reader = csv.reader(f)
for row in reader:
link = tuple(row[0].split()) # tuple of a link
tup = row[0].split()
link = None # tuple of a link
if int(tup[0]) < int(tup[1]):
link = (tup[0],tup[1])
else:
link = (tup[1],tup[0])
linkDelay = 1
self.links.update({link:Link(link,self,linkDelay)})
......@@ -58,11 +65,17 @@ class Network():
pass
def getLink(self,tup):
if int(tup[0]) < int(tup[1]) :
return self.links.get(tup)
else:
return self.links.get((tup[1],tup[0]))
def simulate(self,time):
self.time = time
# logger.info("simulating .. ")
self.networkClockTime = time
# Note links should be simulated before nodes
# Note links should be simulated before nodeself.ResumeTasks.append(("nextOn", self.startNodeLifeCycleGenerator,))s
# in order to receive the messge which is supposed to be received in this tick
for link in self.links.values():
link.simulate(time)
......
from SystemEntity import SystemEntity
import logging
import Utility
import hashlib
from collections import defaultdict
class Node(SystemEntity):
def __init__(self,id,network,weight):
......@@ -12,11 +14,14 @@ class Node(SystemEntity):
self.adjacentNodes = []
self.messageQueue = []
self.sk,self.pk = Utility.genratePublicPrivateKey()
self.ResumeTasks = defaultdict(list)
'''make sure methods included here are not overriddenn'''
self.commands={"sendMessage":self.sendMessage,
"nextOn":self.nextOn
}
self.messagesTillNow = [] # list of messages forwarded
self.uniqueReceivedMessages = defaultdict(list) #this is a list of messages in buffer which were not processed, expecting two list of 'BLOCK_PROPOSAL_MSG','PRIORITY_MSG'
def enqueMessage(self,message):
......@@ -42,25 +47,41 @@ class Node(SystemEntity):
:param params: ('1','2','hello2')
:return:
'''
link = self.network.links.get((params[0],params[1]))
link = self.network.getLink((params[0],params[1]))
link.enqueMessage((time,params))
self.logger.info("Sending : " + str((time,params)))
# any message going out is recorded as sent and will be checked for duplicates
self.messagesTillNow.append(hashlib.sha256((str(params[2])).encode('utf-8')).hexdigest())
###### self.logger.info("Sending : " + str((time,params)))#(time,(sender,receiver,payload))
pass
def broadcast(self,time,gossipPayload):
for node in self.adjacentNodes:
link = self.network.links.get((self.id, node.id))
'''
:param time:
:param gossipPayload:
:return:
broadcast and processMessage together makes it gossip protocol
'''
self.messagesTillNow.append(hashlib.sha256((str(gossipPayload)).encode('utf-8')).hexdigest())
for nodeid in self.adjacentNodes:
node = self.network.nodes.get(nodeid)
link = self.network.getLink((self.id, node.id))
link.enqueMessage((time, (self.id, node.id,gossipPayload)))
self.logger.info("Sending : " + str((time, (self.id, node.id,gossipPayload))))
###### self.logger.info("Sending : " + str((time, (self.id, node.id,gossipPayload))))#(time,(sender,receiver,payload))
def processMessage(self,time,payload):
print("fianlly reached : " + str(payload))
'''remove any extra headers like source and destination here '''
payload.pop(0) # removed source header
payload.pop(0) #removed destination header
# TODO check messages for duplicates and brodacast them : Done
if not (hashlib.sha256((str(payload[0])).encode('utf-8')).hexdigest() in self.messagesTillNow) :
self.broadcast(time,payload[0])
self.uniqueReceivedMessages[payload[0][0]].append(payload[0])
def nextOn(self,time,generator):
next(generator[0])
return next(generator[0])
def startNodeLifeCycle(self):
pass
......@@ -83,6 +104,28 @@ class Node(SystemEntity):
self.logger.info("received : "+str(message))
self.dequeMessage()
# check if main ba* has to be resumed or not
try:
ResumeTasks = self.ResumeTasks.pop(time)
for ResumeTask in ResumeTasks:
command = self.commands.get(ResumeTask[0])
ResumeOut = command(time,ResumeTask[1:])
'''
synatx for proper return commands
yield "resume",timeafter_which_to_resume
'''
if ResumeOut and ResumeOut[0] == "resume":
self.logger.info("resume has been called")
self.ResumeTasks[str(int(time)+int(ResumeOut[1]))].append(("nextOn", self.startNodeLifeCycleGenerator,))
except KeyError as ke:
# not task pending at this time
pass
except StopIteration as si:
pass
except IndexError as Ie:
self.logger.info("No resume task from ba*")
# TODO : perform task from todolist which are relevant for current tick
......@@ -91,14 +134,9 @@ class Node(SystemEntity):
for task in tasks:
command = self.commands.get(task[0])
out = command(time,task[1:])
if out and out[0] == "resume":
self.logger.info("resume has been called")
self.todoList[time+1].append(("nextOn", self.startNodeLifeCycleGenerator,))
except KeyError as ke:
# not task pending at this time
pass
except StopIteration as si:
pass
......
......@@ -2,3 +2,6 @@
2
3
4
5
6
7
\ No newline at end of file
......@@ -48,153 +48,3 @@
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
This diff is collapsed.
......@@ -12,6 +12,6 @@ if __name__ == '__main__':
metronome = TimeSimulator()
network = Network()
network.setupNetwork()
populateTodolist(network)
# populateTodolist(network)
metronome.startTicking(network.simulate)
pass
\ No newline at end of file
......@@ -22,3 +22,4 @@ class SystemEntity(object):
'''
pass
......@@ -18,11 +18,12 @@ def populateTodolist(net):
instruction = row[0].split() # tuple of a link
node = network.nodes.get(instruction[0])
node.todoList[instruction[1]].append(tuple(instruction[2:]))
for id, node in network.nodes.items():
node.todoList['0'].append(("nextOn",node.startNodeLifeCycleGenerator,))
# for id, node in network.nodes.items():
# node.todoList['0'].append(("nextOn",node.startNodeLifeCycleGenerator,))
for id,node in network.nodes.items():
logger.info(id +" : "+str(node.todoList))
# logger.info(id +" : "+str(node.todoList))
pass
def simulateNetwork(net):
if not net:
......@@ -41,6 +42,11 @@ def simulateNetwork(net):
if __name__ == '__main__':
logging.basicConfig(filename='TestCases.log', level=logging.INFO)
# populateTodolist(None)
simulateNetwork(None)
# simulateNetwork(None)
ak = ['hello','ramesh']
ak.append('rao')
if 'hello' in ak:
print("yay")
print(ak.pop())
pass
......@@ -155,6 +155,13 @@ class TestYieldSequence:
self.B()
self.C()
def gen():
for i in range(5):
yield 'ram', 'ganesh'
def testit():
for k1 in gen():
print(k1[1])
if __name__ == '__main__':
# testSortition()
......@@ -162,5 +169,5 @@ if __name__ == '__main__':
# testVerifySort(
# testclassLessGenerator()
# testGeneratorClass()
testSelfReferGen()
# testSelfReferGen()
testit()
......@@ -12,7 +12,7 @@ class TimeSimulator(object):
return "Time : "+ str(self._systemTime)
def startTicking(self,callback):
for i in range(10):
for i in range(10000):
self._systemTime = self._systemTime + 1
logger.info(self)
callback(str(self._systemTime))
......
......@@ -2,8 +2,6 @@ import hashlib
from numpy.random import randint
import sys
import networkx as nx
import numpy
import matplotlib.pyplot as plt
from networkx.algorithms import community
'''
......
1 5 sendMessage 1 2 hello2
2 3 sendMessage 2 3 hello3
4 5 sendMessage 4 1 hello1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment