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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
35664759
Commit
35664759
authored
Nov 24, 2016
by
Julien Muchembled
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
master: fix crashes in identification due to buggy nodes
- check address conflicts - on invalid values, reject peer instead of dying
parent
54e819ff
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
20 deletions
+34
-20
neo/master/handlers/__init__.py
neo/master/handlers/__init__.py
+4
-5
neo/master/handlers/election.py
neo/master/handlers/election.py
+2
-2
neo/master/handlers/identification.py
neo/master/handlers/identification.py
+28
-13
No files found.
neo/master/handlers/__init__.py
View file @
35664759
...
@@ -18,7 +18,7 @@ from neo.lib import logging
...
@@ -18,7 +18,7 @@ from neo.lib import logging
from
neo.lib.exception
import
StoppedOperation
from
neo.lib.exception
import
StoppedOperation
from
neo.lib.handler
import
EventHandler
from
neo.lib.handler
import
EventHandler
from
neo.lib.protocol
import
(
uuid_str
,
NodeTypes
,
NodeStates
,
Packets
,
from
neo.lib.protocol
import
(
uuid_str
,
NodeTypes
,
NodeStates
,
Packets
,
BrokenNodeDisallowedError
,
BrokenNodeDisallowedError
,
ProtocolError
,
)
)
class
MasterHandler
(
EventHandler
):
class
MasterHandler
(
EventHandler
):
...
@@ -33,12 +33,11 @@ class MasterHandler(EventHandler):
...
@@ -33,12 +33,11 @@ class MasterHandler(EventHandler):
app
=
self
.
app
app
=
self
.
app
node
=
app
.
nm
.
getByUUID
(
uuid
)
node
=
app
.
nm
.
getByUUID
(
uuid
)
if
node
:
if
node
:
assert
node_type
is
not
NodeTypes
.
MASTER
or
node
.
getAddress
()
in
(
if
node_type
is
NodeTypes
.
MASTER
and
not
(
address
,
None
),
(
node
,
address
)
None
!=
address
==
node
.
getAddress
()):
raise
ProtocolError
if
node
.
isBroken
():
if
node
.
isBroken
():
raise
BrokenNodeDisallowedError
raise
BrokenNodeDisallowedError
else
:
node
=
app
.
nm
.
getByAddress
(
address
)
peer_uuid
=
self
.
_setupNode
(
conn
,
node_type
,
uuid
,
address
,
node
)
peer_uuid
=
self
.
_setupNode
(
conn
,
node_type
,
uuid
,
address
,
node
)
if
app
.
primary
:
if
app
.
primary
:
primary_address
=
app
.
server
primary_address
=
app
.
server
...
...
neo/master/handlers/election.py
View file @
35664759
...
@@ -126,8 +126,8 @@ class ServerElectionHandler(BaseElectionHandler, MasterHandler):
...
@@ -126,8 +126,8 @@ class ServerElectionHandler(BaseElectionHandler, MasterHandler):
logging
.
info
(
'reject a connection from a non-master'
)
logging
.
info
(
'reject a connection from a non-master'
)
raise
NotReadyError
raise
NotReadyError
if
node
is
None
:
if
node
is
None
is
app
.
nm
.
getByAddress
(
address
)
:
node
=
app
.
nm
.
createMaster
(
address
=
address
)
app
.
nm
.
createMaster
(
address
=
address
)
self
.
elect
(
conn
,
address
)
self
.
elect
(
conn
,
address
)
return
uuid
return
uuid
...
...
neo/master/handlers/identification.py
View file @
35664759
...
@@ -30,18 +30,32 @@ class IdentificationHandler(MasterHandler):
...
@@ -30,18 +30,32 @@ class IdentificationHandler(MasterHandler):
def
_setupNode
(
self
,
conn
,
node_type
,
uuid
,
address
,
node
):
def
_setupNode
(
self
,
conn
,
node_type
,
uuid
,
address
,
node
):
app
=
self
.
app
app
=
self
.
app
if
node
:
by_addr
=
address
and
app
.
nm
.
getByAddress
(
address
)
if
node
.
isRunning
():
while
1
:
if
uuid
>
0
:
if
by_addr
:
# cloned/evil/buggy node connecting to us
if
not
by_addr
.
isConnected
():
raise
ProtocolError
(
'already connected'
)
if
node
is
by_addr
:
# The peer wants a temporary id that's already assigned.
break
# Let's give it another one.
if
not
node
or
uuid
<
0
:
node
=
uuid
=
None
# In case of address conflict for a peer with temporary
# ids, we'll generate a new id.
node
=
by_addr
break
elif
node
:
if
node
.
isConnected
():
if
uuid
<
0
:
# The peer wants a temporary id that's already assigned.
# Let's give it another one.
node
=
uuid
=
None
break
else
:
node
.
setAddress
(
address
)
break
# Id conflict for a storage node.
else
:
else
:
assert
not
node
.
isConnected
()
break
node
.
setAddress
(
address
)
# cloned/evil/buggy node connecting to us
node
.
setRunning
(
)
raise
ProtocolError
(
'already connected'
)
state
=
NodeStates
.
RUNNING
state
=
NodeStates
.
RUNNING
if
node_type
==
NodeTypes
.
CLIENT
:
if
node_type
==
NodeTypes
.
CLIENT
:
...
@@ -68,14 +82,15 @@ class IdentificationHandler(MasterHandler):
...
@@ -68,14 +82,15 @@ class IdentificationHandler(MasterHandler):
handler
=
app
.
administration_handler
handler
=
app
.
administration_handler
human_readable_node_type
=
'n admin '
human_readable_node_type
=
'n admin '
else
:
else
:
raise
NotImplementedError
(
node_type
)
raise
ProtocolError
uuid
=
app
.
getNewUUID
(
uuid
,
address
,
node_type
)
uuid
=
app
.
getNewUUID
(
uuid
,
address
,
node_type
)
logging
.
info
(
'Accept a'
+
human_readable_node_type
+
uuid_str
(
uuid
))
logging
.
info
(
'Accept a'
+
human_readable_node_type
+
uuid_str
(
uuid
))
if
node
is
None
:
if
node
is
None
:
node
=
app
.
nm
.
createFromNodeType
(
node_type
,
node
=
app
.
nm
.
createFromNodeType
(
node_type
,
uuid
=
uuid
,
address
=
address
)
uuid
=
uuid
,
address
=
address
)
node
.
setUUID
(
uuid
)
else
:
node
.
setUUID
(
uuid
)
node
.
setState
(
state
)
node
.
setState
(
state
)
node
.
setConnection
(
conn
)
node
.
setConnection
(
conn
)
conn
.
setHandler
(
handler
)
conn
.
setHandler
(
handler
)
...
...
Kirill Smelkov
@kirr
·
Nov 28, 2016
Owner
@jm
tests?
@jm tests?
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