Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xavier Thompson
neoppod
Commits
d85b471d
Commit
d85b471d
authored
Jan 04, 2014
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client: refactor code to connect to master
parent
1e0c5efc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
26 deletions
+23
-26
neo/client/app.py
neo/client/app.py
+20
-26
neo/client/handlers/master.py
neo/client/handlers/master.py
+3
-0
No files found.
neo/client/app.py
View file @
d85b471d
...
@@ -254,20 +254,19 @@ class Application(object):
...
@@ -254,20 +254,19 @@ class Application(object):
Lookup for the current primary master node
Lookup for the current primary master node
"""
"""
logging
.
debug
(
'connecting to primary master...'
)
logging
.
debug
(
'connecting to primary master...'
)
ready
=
False
index
=
0
nm
=
self
.
nm
ask
=
self
.
_ask
while
not
ready
:
handler
=
self
.
primary_bootstrap_handler
while
1
:
# Get network connection to primary master
# Get network connection to primary master
index
=
0
while
1
:
connected
=
False
while
not
connected
:
if
self
.
primary_master_node
is
not
None
:
if
self
.
primary_master_node
is
not
None
:
# If I know a primary master node, pinpoint it.
# If I know a primary master node, pinpoint it.
self
.
trying_master_node
=
self
.
primary_master_node
self
.
trying_master_node
=
self
.
primary_master_node
self
.
primary_master_node
=
None
self
.
primary_master_node
=
None
else
:
else
:
# Otherwise, check one by one.
# Otherwise, check one by one.
master_list
=
nm
.
getMasterList
()
master_list
=
self
.
nm
.
getMasterList
()
try
:
try
:
self
.
trying_master_node
=
master_list
[
index
]
self
.
trying_master_node
=
master_list
[
index
]
except
IndexError
:
except
IndexError
:
...
@@ -288,37 +287,32 @@ class Application(object):
...
@@ -288,37 +287,32 @@ class Application(object):
self
.
trying_master_node
)
self
.
trying_master_node
)
continue
continue
try
:
try
:
self
.
_
ask
(
conn
,
Packets
.
RequestIdentification
(
ask
(
conn
,
Packets
.
RequestIdentification
(
NodeTypes
.
CLIENT
,
self
.
uuid
,
None
,
self
.
name
),
NodeTypes
.
CLIENT
,
self
.
uuid
,
None
,
self
.
name
),
handler
=
self
.
primary_bootstrap_
handler
)
handler
=
handler
)
except
ConnectionClosed
:
except
ConnectionClosed
:
continue
continue
# If we reached the primary master node, mark as connected
# If we reached the primary master node, mark as connected
connected
=
self
.
primary_master_node
is
not
None
and
\
if
self
.
primary_master_node
is
not
None
and
\
self
.
primary_master_node
is
self
.
trying_master_node
self
.
primary_master_node
is
self
.
trying_master_node
:
break
logging
.
info
(
'Connected to %s'
,
self
.
primary_master_node
)
logging
.
info
(
'Connected to %s'
,
self
.
primary_master_node
)
try
:
try
:
ready
=
self
.
identifyToPrimaryNode
(
conn
)
# Request identification and required informations to be
# operational. Might raise ConnectionClosed so that the new
# primary can be looked-up again.
logging
.
info
(
'Initializing from master'
)
ask
(
conn
,
Packets
.
AskNodeInformation
(),
handler
=
handler
)
ask
(
conn
,
Packets
.
AskPartitionTable
(),
handler
=
handler
)
ask
(
conn
,
Packets
.
AskLastTransaction
(),
handler
=
handler
)
if
self
.
pt
.
operational
():
break
except
ConnectionClosed
:
except
ConnectionClosed
:
logging
.
error
(
'Connection to %s lost'
,
self
.
trying_master_node
)
logging
.
error
(
'Connection to %s lost'
,
self
.
trying_master_node
)
self
.
primary_master_node
=
None
self
.
primary_master_node
=
None
logging
.
info
(
"Connected and ready"
)
logging
.
info
(
"Connected and ready"
)
return
conn
return
conn
def
identifyToPrimaryNode
(
self
,
conn
):
"""
Request identification and required informations to be operational.
Might raise ConnectionClosed so that the new primary can be
looked-up again.
"""
logging
.
info
(
'Initializing from master'
)
ask
=
self
.
_ask
handler
=
self
.
primary_bootstrap_handler
ask
(
conn
,
Packets
.
AskNodeInformation
(),
handler
=
handler
)
ask
(
conn
,
Packets
.
AskPartitionTable
(),
handler
=
handler
)
self
.
lastTransaction
()
return
self
.
pt
.
operational
()
def
registerDB
(
self
,
db
,
limit
):
def
registerDB
(
self
,
db
,
limit
):
self
.
_db
=
db
self
.
_db
=
db
...
...
neo/client/handlers/master.py
View file @
d85b471d
...
@@ -89,6 +89,9 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
...
@@ -89,6 +89,9 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
def
answerNodeInformation
(
self
,
conn
):
def
answerNodeInformation
(
self
,
conn
):
pass
pass
def
answerLastTransaction
(
self
,
conn
,
ltid
):
pass
class
PrimaryNotificationsHandler
(
BaseHandler
):
class
PrimaryNotificationsHandler
(
BaseHandler
):
""" Handler that process the notifications from the primary master """
""" Handler that process the notifications from the primary master """
...
...
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