fully working gossip protocol

parent 7ada539e
......@@ -62,6 +62,7 @@ class Node(SystemEntity):
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))
......@@ -75,7 +76,6 @@ class Node(SystemEntity):
# TODO check messages for duplicates and brodacast them : Done
if not (hashlib.sha256((str(payload[0])).encode('utf-8')).hexdigest() in self.messagesTillNow) :
self.messagesTillNow.append(hashlib.sha256((str(payload[0])).encode('utf-8')).hexdigest())
self.broadcast(time,payload[0])
self.uniqueReceivedMessages.append(payload[0])
......
......@@ -25,45 +25,45 @@ class OverlayNode(Node):
#increment round number
# # Checking if I am a Block Propser
# previousHash = hashlib.sha256(genesisBlock.encode('utf-8')).hexdigest()
# currentRound = 0
# step = 0
# blockHeight = 0
# seed = ( previousHash,currentRound,blockHeight )
# roleCount = 20
# role = "BLOCK_PROPOSER"
# w = self.weight
# badaW = 100
#
# hash, proof, j = Utility.sortition(self.sk,seed,roleCount, role, w, self.network.badaW, self.pk)
# print("I am the mighty J =",j)
# if j > 0 :
# min_sha_priority = None
# # min_sub_user_index = None
# # msg_to_broadcast = ( currentRound, hash , min_sub_user_index , min_sha_priority )
# print(w)
# print(range(w))
# for sub_user_index in range(w):
# input_to_SHA256 = (hash , sub_user_index,) # TODO : can concatenation means this
# sha256_hash = hashlib.sha256((str(input_to_SHA256)).encode('utf-8')).hexdigest()
# print(sha256_hash)
# if not min_sha_priority :
# min_sha_priority = sha256_hash
# min_sub_user_index = sub_user_index
# if sha256_hash < min_sha_priority:
# min_sha_priority = sha256_hash
# min_sub_user_index = sub_user_index
#
#
# msg_to_broadcast = ( currentRound, hash , min_sub_user_index , min_sha_priority )
# print(msg_to_broadcast)
# self.logger.info(msg_to_broadcast)
#
# print("i am before yield 1",self.id)
# Checking if I am a Block Propser
previousHash = hashlib.sha256(genesisBlock.encode('utf-8')).hexdigest()
currentRound = 0
step = 0
blockHeight = 0
seed = ( previousHash,currentRound,blockHeight )
roleCount = 20
role = "BLOCK_PROPOSER"
w = self.weight
badaW = 100
hash, proof, j = Utility.sortition(self.sk,seed,roleCount, role, w, self.network.badaW, self.pk)
print("I am the mighty J =",j)
if j > 0 :
min_sha_priority = None
# min_sub_user_index = None
# msg_to_broadcast = ( currentRound, hash , min_sub_user_index , min_sha_priority )
print(w)
print(range(w))
for sub_user_index in range(w):
input_to_SHA256 = (hash , sub_user_index,) # TODO : can concatenation means this
sha256_hash = hashlib.sha256((str(input_to_SHA256)).encode('utf-8')).hexdigest()
print(sha256_hash)
if not min_sha_priority :
min_sha_priority = sha256_hash
min_sub_user_index = sub_user_index
if sha256_hash < min_sha_priority:
min_sha_priority = sha256_hash
min_sub_user_index = sub_user_index
msg_to_broadcast = ( currentRound, hash , min_sub_user_index , min_sha_priority )
print(msg_to_broadcast)
self.logger.info(msg_to_broadcast)
print("i am before yield 1",self.id)
yield "resume"
# print("i am before yield 2", self.id)
# yield
print("i am before yield 2", self.id)
yield
'''
TODo check if node is selected as BLOCK_PROPOSER
......
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