added error message when a node not part of network is added is proposed for deactviation

This commit is contained in:
vsmk98 2019-02-07 12:45:29 +08:00
parent c0d48d90d4
commit 178d7629c4
5 changed files with 42 additions and 16 deletions

View File

@ -128,7 +128,12 @@ contract Permissions {
function getNodeDetails(string memory enodeId) public view returns (string memory _enodeId, string memory _ipAddrPort, string memory _discPort, string memory _raftPort, NodeStatus _nodeStatus)
{
uint nodeIndex = getNodeIndex(enodeId);
return (nodeList[nodeIndex].enodeId, nodeList[nodeIndex].ipAddrPort, nodeList[nodeIndex].discPort, nodeList[nodeIndex].raftPort, nodeList[nodeIndex].status);
if (nodeIdToIndex[keccak256(abi.encodePacked(enodeId))] != 0){
return (nodeList[nodeIndex].enodeId, nodeList[nodeIndex].ipAddrPort, nodeList[nodeIndex].discPort, nodeList[nodeIndex].raftPort, nodeList[nodeIndex].status);
}
else {
return (enodeId, "", "", "", NodeStatus.NotInList);
}
}
// Get node details given index
function getNodeDetailsFromIndex(uint nodeIndex) public view returns (string memory _enodeId, string memory _ipAddrPort, string memory _discPort, string memory _raftPort, NodeStatus _nodeStatus)

File diff suppressed because one or more lines are too long

View File

@ -475,11 +475,15 @@ func (p *PermissionCtrl) populateInitPermission() error {
return err
}
// update network status to boot completed
err = p.updateNetworkStatus(permissionsSession)
if err != nil {
return err
}
// set the default access to ReadOnly
types.SetDefaultAccess()
}
return nil
}

View File

@ -478,18 +478,36 @@ func checkNodeDetails(ps *pbind.PermissionsSession, nodeId string, action PermAc
enodeID, discPort, raftPort, ipAddrPort, err := getNodeDetailsFromEnode(nodeId)
cnode, err := ps.GetNodeDetails(enodeID)
if err == nil {
if !(strings.Compare(ipAddrPort, cnode.IpAddrPort) == 0 && strings.Compare(discPort, cnode.DiscPort) == 0 && strings.Compare(raftPort, cnode.RaftPort) == 0) {
return errors.New("Details Mismtach"), ErrNodeDetailsMismatch
}
nodeStatus := decodeNodeStatus(cnode.NodeStatus)
// if node status is Blacklisted no activities are allowed on the same.
if nodeStatus == "Blacklisted" {
return errors.New("Cannot propose blacklisted node"), ErrBlacklistedNode
}
if nodeStatus == "NotInNetwork" && (action == ProposeNodeDeactivation || action == ProposeNodeActivation){
return errors.New("operation cannot be performed"), ErrOpNotAllowed
}
newNode := false;
if nodeStatus == "NotInNetwork" && len(cnode.IpAddrPort) == 0{
newNode = true
}
detailsMatch := false;
if strings.Compare(ipAddrPort, cnode.IpAddrPort) == 0 && strings.Compare(discPort, cnode.DiscPort) == 0 && strings.Compare(raftPort, cnode.RaftPort) == 0 {
detailsMatch = true
}
// if the node is not in network and is being proposed for blacklisting or as a new node
// allow the operation. For anyother operation, the node will be in the network and all details
// should match
if action == ProposeNode || action == ProposeNodeBlacklisting {
if !newNode && !detailsMatch {
return errors.New("Details Mismtach"), ErrNodeDetailsMismatch
}
} else if !detailsMatch {
return errors.New("Details Mismtach"), ErrNodeDetailsMismatch
}
// if propose action, check if node status allows the operation
if ((action == ProposeNode && nodeStatus != "NotInNetwork") ||
(action == ProposeNodeDeactivation && nodeStatus != "Approved") ||
@ -518,9 +536,8 @@ func checkNodeDetails(ps *pbind.PermissionsSession, nodeId string, action PermAc
return errors.New("Node already proposed"), ErrNodeProposed
}
}
}
return nil, ExecSuccess
}
@ -666,7 +683,7 @@ func (s *QuorumControlsAPI) executePermAction(action PermAction, args txArgs) Ex
tx, err = ps.BlacklistNode(enodeID)
case SetAccountAccess:
if (args.accessType > 4){
if (args.accessType > 3){
return ErrInvalidAccountAccess
}
if !checkAccountAccess(args.txa.From, args.acctId, args.accessType) {

View File

@ -49,12 +49,12 @@ func GetAcctAccess(acctId common.Address) AccessType {
return vo.AcctAccess
}
}
// return DefaultAccess
if AcctMap.Len() == 0 {
return FullAccess
} else {
return ReadOnly
}
return DefaultAccess
// if AcctMap.Len() == 0 {
// return FullAccess
// } else {
// return ReadOnly
// }
}
func AddOrgKey(orgId string, key string) {