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
6201ad94
Commit
6201ad94
authored
Apr 09, 2019
by
THAKARE AKSHAY HARIBHAU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created Overlay node
parent
bc94379c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
133 additions
and
28 deletions
+133
-28
Link.py
Link.py
+5
-5
Network.py
Network.py
+1
-1
Node.py
Node.py
+22
-19
OverlayNode.py
OverlayNode.py
+103
-0
Starter.py
Starter.py
+0
-3
todolist.dat
todolist.dat
+2
-0
No files found.
Link.py
View file @
6201ad94
from
SystemEntity
import
SystemEntity
from
Node
import
Node
import
logging
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -15,6 +14,7 @@ class Link(SystemEntity):
'''
SystemEntity
.
__init__
(
self
,
network
)
self
.
logger
=
logging
.
getLogger
(
__name__
+
"-"
+
str
(
link
))
self
.
upNode
=
link
[
0
]
self
.
downNode
=
link
[
1
]
...
...
@@ -39,10 +39,10 @@ class Link(SystemEntity):
:return:
'''
node
=
self
.
network
.
nodes
.
get
(
params
[
0
])
node
.
enqueMessge
((
time
,
params
[
1
]))
node
.
enqueMess
a
ge
((
time
,
params
[
1
]))
pass
def
enqueMessge
(
self
,
message
):
def
enqueMess
a
ge
(
self
,
message
):
'''
:param message: (timestamp , payload) --- timestamp is the tick value at which node has inserted this message in queue
...
...
@@ -54,7 +54,7 @@ class Link(SystemEntity):
self
.
messageQueue
.
append
(
message
)
print
(
"message enqued"
)
def
dequeMessge
(
self
):
def
dequeMess
a
ge
(
self
):
return
self
.
messageQueue
.
pop
(
0
)
def
scheduleMessageDelievery
(
self
,
time
,
payload
):
...
...
@@ -65,7 +65,7 @@ class Link(SystemEntity):
def
simulate
(
self
,
time
):
# logger.info("simulating .. ")
#
self.
logger.info("simulating .. ")
'''
Process message first then process task in todo-list
...
...
Network.py
View file @
6201ad94
...
...
@@ -50,7 +50,7 @@ class Network():
def
simulate
(
self
,
time
):
logger
.
info
(
"simulating .. "
)
#
logger.info("simulating .. ")
self
.
networkClockTime
=
time
# Note links should be simulated before nodes
# in order to receive the messge which is supposed to be received in this tick
...
...
Node.py
View file @
6201ad94
from
SystemEntity
import
SystemEntity
import
logging
logger
=
logging
.
getLogger
(
__name__
)
class
Node
(
SystemEntity
):
def
__init__
(
self
,
id
,
network
):
SystemEntity
.
__init__
(
self
,
network
)
self
.
logger
=
logging
.
getLogger
(
__name__
+
"-"
+
str
(
id
))
self
.
id
=
id
self
.
adjacentNodes
=
[]
self
.
messageQueue
=
[]
'''make sure methods included here are not overriddenn'''
self
.
commands
=
{
"sendMessage"
:
self
.
sendMessage
,
}
def
enqueMessge
(
self
,
message
):
def
enqueMessage
(
self
,
message
):
'''
:param message: (timestamp , payload) --- timestamp is the tick value at which node has inserted this message in queue
...
...
@@ -25,7 +26,7 @@ class Node(SystemEntity):
self
.
messageQueue
.
append
(
message
)
print
(
"message enqued"
)
def
dequeMessge
(
self
):
def
dequeMess
a
ge
(
self
):
return
self
.
messageQueue
.
pop
(
0
)
...
...
@@ -37,15 +38,19 @@ class Node(SystemEntity):
:return:
'''
link
=
self
.
network
.
links
.
get
((
params
[
0
],
params
[
1
]))
link
.
enqueMessge
((
time
,
params
))
logger
.
info
(
"Sending Message
: "
+
str
((
time
,
params
)))
link
.
enqueMess
a
ge
((
time
,
params
))
self
.
logger
.
info
(
"Sending
: "
+
str
((
time
,
params
)))
pass
def
processMessage
(
self
,
time
,
payload
):
print
(
"fianlly reachec : "
+
str
(
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
def
simulate
(
self
,
time
):
# logger.info("simulating .. ")
#
self.
logger.info("simulating .. ")
'''
Process message first then process task in todo list
Here it is just intuition , i don`t what should be processing sequence
...
...
@@ -56,8 +61,10 @@ class Node(SystemEntity):
'''
# todo process messages in queue
# generate tasks for todolist based on messges
for
message
in
self
.
messageQueue
:
self
.
processMessage
(
message
[
0
],
message
[
1
])
# message : (time,(payload))
for
message
in
list
(
self
.
messageQueue
):
#this creates adupliacte list and iterate over it while making changes to original queue
self
.
processMessage
(
message
[
0
],
list
(
message
[
1
]))
# message : (time,(payload))
self
.
logger
.
info
(
"received : "
+
str
(
message
))
self
.
dequeMessage
()
# TODO : perform task from todolist which are relevant for current tick
...
...
@@ -77,17 +84,13 @@ if __name__ == '__main__':
# node = Node('1')
# cmd = node.commands.get("sendMessage")
# cmd("1 ","2 "," : Hello world")
x
=
[
1
,
2
,
3
,
4
,
5
,
6
]
for
i
in
list
(
x
):
y
=
x
.
pop
(
0
)
print
(
y
)
from
collections
import
defaultdict
# when accessing a key, if it has no value - create a list by default
d
=
defaultdict
(
list
)
d
[
"key"
]
.
append
(
"a value"
)
d
[
"key"
]
.
append
(
"another value"
)
print
(
d
)
x
=
d
.
pop
(
"key2"
)
print
(
x
)
print
(
d
.
get
(
"key2"
))
...
...
OverlayNode.py
0 → 100644
View file @
6201ad94
from
Node
import
Node
import
logging
class
OverlayNode
(
Node
):
def
__init__
(
self
,
id
,
network
):
Node
.
__init__
(
self
,
id
,
network
)
self
.
commands
.
update
({})
def
processMessage
(
self
,
time
,
payload
):
super
(
OverlayNode
,
self
)
.
processMessage
(
time
,
payload
)
print
(
"from overlay node : "
+
str
(
payload
))
class
A
(
object
):
def
__init__
(
self
,
id
):
self
.
id
=
id
self
.
commands
=
{
"sendMessage"
:
self
.
sendMessage
,
}
def
sendMessage
(
self
):
pass
def
process
(
self
,
param
):
print
(
"from A "
+
str
(
param
)
)
param
.
pop
(
0
)
param
.
pop
(
0
)
class
B
(
A
):
def
__init__
(
self
,
id
):
A
.
__init__
(
self
,
id
)
self
.
commands
.
update
({
"hello"
:
self
.
working
})
def
working
(
self
):
pass
def
process
(
self
,
param
):
super
(
B
,
self
)
.
process
(
param
)
print
(
"from B"
+
str
(
param
))
if
__name__
==
'__main__'
:
l
=
(
1
,
2
,
tuple
(
str
(
'3|4|5'
)
.
split
(
'|'
)))
x
=
B
(
2
)
print
(
x
.
commands
)
x
.
process
(
list
(
l
))
Starter.py
View file @
6201ad94
...
...
@@ -8,9 +8,6 @@ logging.basicConfig(filename='ASim.log', level=logging.INFO)
logger
=
logging
.
getLogger
(
__name__
)
def
simulateThis
(
time
):
logger
.
info
(
"ticking time"
+
str
(
time
))
if
__name__
==
'__main__'
:
metronome
=
TimeSimulator
()
network
=
Network
()
...
...
todolist.dat
View file @
6201ad94
1 5 sendMessage 1 2 hello2
2 3 sendMessage 2 3 hello3
4 5 sendMessage 4 1 hello1
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