Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
algorand
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nilak
algorand
Commits
e6b3b384
Commit
e6b3b384
authored
Apr 22, 2019
by
THAKARE AKSHAY HARIBHAU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fully working gossip protocol
parent
7ada539e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
39 deletions
+39
-39
Node.py
Node.py
+1
-1
OverlayNode.py
OverlayNode.py
+38
-38
No files found.
Node.py
View file @
e6b3b384
...
@@ -62,6 +62,7 @@ class Node(SystemEntity):
...
@@ -62,6 +62,7 @@ class Node(SystemEntity):
broadcast and processMessage together makes it gossip protocol
broadcast and processMessage together makes it gossip protocol
'''
'''
self
.
messagesTillNow
.
append
(
hashlib
.
sha256
((
str
(
gossipPayload
))
.
encode
(
'utf-8'
))
.
hexdigest
())
for
nodeid
in
self
.
adjacentNodes
:
for
nodeid
in
self
.
adjacentNodes
:
node
=
self
.
network
.
nodes
.
get
(
nodeid
)
node
=
self
.
network
.
nodes
.
get
(
nodeid
)
link
=
self
.
network
.
getLink
((
self
.
id
,
node
.
id
))
link
=
self
.
network
.
getLink
((
self
.
id
,
node
.
id
))
...
@@ -75,7 +76,6 @@ class Node(SystemEntity):
...
@@ -75,7 +76,6 @@ class Node(SystemEntity):
# TODO check messages for duplicates and brodacast them : Done
# TODO check messages for duplicates and brodacast them : Done
if
not
(
hashlib
.
sha256
((
str
(
payload
[
0
]))
.
encode
(
'utf-8'
))
.
hexdigest
()
in
self
.
messagesTillNow
)
:
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
.
broadcast
(
time
,
payload
[
0
])
self
.
uniqueReceivedMessages
.
append
(
payload
[
0
])
self
.
uniqueReceivedMessages
.
append
(
payload
[
0
])
...
...
OverlayNode.py
View file @
e6b3b384
...
@@ -25,45 +25,45 @@ class OverlayNode(Node):
...
@@ -25,45 +25,45 @@ class OverlayNode(Node):
#increment round number
#increment round number
#
#
Checking if I am a Block Propser
# Checking if I am a Block Propser
#
previousHash = hashlib.sha256(genesisBlock.encode('utf-8')).hexdigest()
previousHash
=
hashlib
.
sha256
(
genesisBlock
.
encode
(
'utf-8'
))
.
hexdigest
()
#
currentRound = 0
currentRound
=
0
#
step = 0
step
=
0
#
blockHeight = 0
blockHeight
=
0
#
seed = ( previousHash,currentRound,blockHeight )
seed
=
(
previousHash
,
currentRound
,
blockHeight
)
#
roleCount = 20
roleCount
=
20
#
role = "BLOCK_PROPOSER"
role
=
"BLOCK_PROPOSER"
#
w = self.weight
w
=
self
.
weight
#
badaW = 100
badaW
=
100
#
#
hash, proof, j = Utility.sortition(self.sk,seed,roleCount, role, w, self.network.badaW, self.pk)
hash
,
proof
,
j
=
Utility
.
sortition
(
self
.
sk
,
seed
,
roleCount
,
role
,
w
,
self
.
network
.
badaW
,
self
.
pk
)
#
print("I am the mighty J =",j)
print
(
"I am the mighty J ="
,
j
)
#
if j > 0 :
if
j
>
0
:
#
min_sha_priority = None
min_sha_priority
=
None
#
# min_sub_user_index = None
# min_sub_user_index = None
#
# msg_to_broadcast = ( currentRound, hash , min_sub_user_index , min_sha_priority )
# msg_to_broadcast = ( currentRound, hash , min_sub_user_index , min_sha_priority )
#
print(w)
print
(
w
)
#
print(range(w))
print
(
range
(
w
))
#
for sub_user_index in range(w):
for
sub_user_index
in
range
(
w
):
#
input_to_SHA256 = (hash , sub_user_index,) # TODO : can concatenation means this
input_to_SHA256
=
(
hash
,
sub_user_index
,)
# TODO : can concatenation means this
#
sha256_hash = hashlib.sha256((str(input_to_SHA256)).encode('utf-8')).hexdigest()
sha256_hash
=
hashlib
.
sha256
((
str
(
input_to_SHA256
))
.
encode
(
'utf-8'
))
.
hexdigest
()
#
print(sha256_hash)
print
(
sha256_hash
)
#
if not min_sha_priority :
if
not
min_sha_priority
:
#
min_sha_priority = sha256_hash
min_sha_priority
=
sha256_hash
#
min_sub_user_index = sub_user_index
min_sub_user_index
=
sub_user_index
#
if sha256_hash < min_sha_priority:
if
sha256_hash
<
min_sha_priority
:
#
min_sha_priority = sha256_hash
min_sha_priority
=
sha256_hash
#
min_sub_user_index = sub_user_index
min_sub_user_index
=
sub_user_index
#
#
#
msg_to_broadcast = ( currentRound, hash , min_sub_user_index , min_sha_priority )
msg_to_broadcast
=
(
currentRound
,
hash
,
min_sub_user_index
,
min_sha_priority
)
#
print(msg_to_broadcast)
print
(
msg_to_broadcast
)
#
self.logger.info(msg_to_broadcast)
self
.
logger
.
info
(
msg_to_broadcast
)
#
#
print("i am before yield 1",self.id)
print
(
"i am before yield 1"
,
self
.
id
)
yield
"resume"
yield
"resume"
#
print("i am before yield 2", self.id)
print
(
"i am before yield 2"
,
self
.
id
)
#
yield
yield
'''
'''
TODo check if node is selected as BLOCK_PROPOSER
TODo check if node is selected as BLOCK_PROPOSER
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment