Skip to content

Commit

Permalink
INDY-1148 - It's possible to create several nodes with the same alias…
Browse files Browse the repository at this point in the history
… - change validation in pool_req_handler.

Signed-off-by: toktar <[email protected]>
  • Loading branch information
Toktar committed Mar 5, 2018
1 parent 859ba15 commit 366ca07
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions plenum/server/pool_req_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def authErrorWhileAddingNode(self, request):
origin)
if self.stewardHasNode(origin):
return "{} already has a node".format(origin)
if self.isNodeDataConflicting(
operation.get(DATA, request.operation.get(TARGET_NYM))):
if self.isNodeDataConflicting(data):
return "existing data has conflicts with " \
"request data {}".format(operation.get(DATA))

Expand Down Expand Up @@ -157,14 +156,14 @@ def isNodeDataSame(self, nodeNym, newData, isCommitted=True):
nodeInfo.pop(f.IDENTIFIER.nm, None)
return nodeInfo == newData

def isNodeDataConflicting(self, data, nodeNym=None):
def isNodeDataConflicting(self, data, updatingNym=None):
# Check if node's ALIAS or IPs or ports conflicts with other nodes,
# also, the node is not allowed to change its alias.

# Check ALIAS change
nodeData = {}
if nodeNym:
nodeData = self.getNodeData(nodeNym, isCommitted=False)
if updatingNym:
nodeData = self.getNodeData(updatingNym, isCommitted=False)
if nodeData.get(ALIAS) != data.get(ALIAS):
return True
else:
Expand All @@ -178,7 +177,7 @@ def isNodeDataConflicting(self, data, nodeNym=None):
otherNodeData = self.stateSerializer.deserialize(otherNodeData)
otherNodeData.pop(f.IDENTIFIER.nm, None)
otherNodeData.pop(SERVICES, None)
if not nodeNym or otherNode != nodeNym:
if not updatingNym or otherNode != updatingNym:
# The node's ip, port and alias shuuld be unique
bag = set()
for d in (nodeData, otherNodeData):
Expand All @@ -192,8 +191,8 @@ def isNodeDataConflicting(self, data, nodeNym=None):
if (not nodeData and len(bag) != 3) or (
nodeData and len(bag) != 6):
return True
if nodeData.get(ALIAS) == otherNodeData.get(
ALIAS) and not nodeNym or otherNode != nodeNym:
if data.get(ALIAS) == otherNodeData.get(
ALIAS) and not updatingNym:
return True

def dataErrorWhileValidatingUpdate(self, data, nodeNym):
Expand Down

0 comments on commit 366ca07

Please sign in to comment.