mirror of https://github.com/poanetwork/quorum.git
Merge branch '1812-permission-rpc-api' of https://github.com/vsmk98/quorum into 1812-permission-rpc-api
merge for LRU cache implementation
This commit is contained in:
commit
e3112a05ac
|
@ -43,11 +43,15 @@ type PermissionCtrl struct {
|
|||
isRaft bool
|
||||
key *ecdsa.PrivateKey
|
||||
dataDir string
|
||||
pm *pbind.Permissions
|
||||
pm *pbind.Permissions
|
||||
}
|
||||
|
||||
// Creates the controls structure for permissions
|
||||
func NewQuorumPermissionCtrl(stack *node.Node, isRaft bool) (*PermissionCtrl, error) {
|
||||
if types.AcctMapErr != nil {
|
||||
log.Error("error initializing account access map", "err", types.AcctMapErr)
|
||||
return nil, types.AcctMapErr
|
||||
}
|
||||
// Create a new ethclient to for interfacing with the contract
|
||||
stateReader, e, err := controls.CreateEthClient(stack)
|
||||
if err != nil {
|
||||
|
@ -115,7 +119,7 @@ func (p *PermissionCtrl) manageNodePermissions() {
|
|||
//monitor for nodes deletiin via smart contract
|
||||
go p.monitorNodeDeactivation()
|
||||
|
||||
//monitor for nodes activation from deactivation status
|
||||
//monitor for nodes activation from deactivation status
|
||||
go p.monitorNodeActivation()
|
||||
|
||||
//monitor for nodes blacklisting via smart contract
|
||||
|
@ -210,6 +214,7 @@ func (p *PermissionCtrl) monitorNodeBlacklisting() {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
//this function populates the new node information into the permissioned-nodes.json file
|
||||
func (p *PermissionCtrl) updatePermissionedNodes(enodeId, ipAddrPort, discPort, raftPort string, operation NodeOperation) {
|
||||
newEnodeId := p.formatEnodeId(enodeId, ipAddrPort, discPort, raftPort)
|
||||
|
@ -427,7 +432,7 @@ func (p *PermissionCtrl) populateInitPermission() error {
|
|||
return err
|
||||
}
|
||||
|
||||
// populate the initial node list from static-nodes.json
|
||||
// populate the initial node list from static-nodes.json
|
||||
err := p.populateStaticNodesToContract(permissionsSession)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -442,9 +447,8 @@ func (p *PermissionCtrl) populateInitPermission() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
// Reads the node list from static-nodes.json and populates into the contract
|
||||
func (p *PermissionCtrl) populateStaticNodesToContract( permissionsSession *pbind.PermissionsSession ) error {
|
||||
func (p *PermissionCtrl) populateStaticNodesToContract(permissionsSession *pbind.PermissionsSession) error {
|
||||
nodes := p2p.ParsePermissionedNodes(p.dataDir)
|
||||
for _, node := range nodes {
|
||||
|
||||
|
@ -489,7 +493,7 @@ func (p *PermissionCtrl) populateInitAccountAccess(permissionsSession *pbind.Per
|
|||
}
|
||||
|
||||
// update network boot status to true
|
||||
func (p *PermissionCtrl) updateNetworkStatus( permissionsSession *pbind.PermissionsSession ) error {
|
||||
func (p *PermissionCtrl) updateNetworkStatus(permissionsSession *pbind.PermissionsSession) error {
|
||||
nonce := p.eth.TxPool().Nonce(permissionsSession.TransactOpts.From)
|
||||
permissionsSession.TransactOpts.Nonce = new(big.Int).SetUint64(nonce)
|
||||
_, err := permissionsSession.UpdateNetworkBootStatus()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package types
|
||||
import (
|
||||
"sync"
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/hashicorp/golang-lru"
|
||||
)
|
||||
|
||||
type AccessType uint8
|
||||
|
@ -15,91 +15,70 @@ const (
|
|||
)
|
||||
|
||||
type PermStruct struct {
|
||||
AcctId common.Address
|
||||
AcctId common.Address
|
||||
AcctAccess AccessType
|
||||
}
|
||||
type OrgStruct struct {
|
||||
OrgId string
|
||||
Keys []string
|
||||
Keys []string
|
||||
}
|
||||
|
||||
type PermAccountsMap map[common.Address][] *PermStruct
|
||||
var AcctMap, AcctMapErr = lru.NewARC(100)
|
||||
|
||||
type PermOrgKeyMap map[string][] *OrgStruct
|
||||
var OrgKeyMap, OrgKeyMapErr = lru.NewARC(100)
|
||||
|
||||
var AcctMap = make(map[common.Address] *PermStruct)
|
||||
|
||||
var OrgKeyMap = make(map[string] *OrgStruct)
|
||||
|
||||
func AddAccountAccess(acctId common.Address, access uint8) {
|
||||
mu := sync.RWMutex{}
|
||||
|
||||
mu.Lock()
|
||||
AcctMap[acctId] = &PermStruct {AcctId : acctId, AcctAccess : AccessType(access)}
|
||||
mu.Unlock()
|
||||
func AddAccountAccess(acctId common.Address, access uint8) {
|
||||
AcctMap.Add(acctId, &PermStruct{AcctId: acctId, AcctAccess: AccessType(access)})
|
||||
}
|
||||
|
||||
func GetAcctAccess(acctId common.Address) AccessType {
|
||||
mu := sync.RWMutex{}
|
||||
if len(AcctMap) != 0 {
|
||||
if _, ok := AcctMap[acctId]; ok {
|
||||
mu.RLock()
|
||||
acctAccess := AcctMap[acctId].AcctAccess
|
||||
mu.RUnlock()
|
||||
return acctAccess
|
||||
if AcctMap.Len() != 0 {
|
||||
if val, ok := AcctMap.Get(acctId); ok {
|
||||
vo := val.(*PermStruct)
|
||||
return vo.AcctAccess
|
||||
}
|
||||
}
|
||||
if len(AcctMap) == 0 {
|
||||
if AcctMap.Len() == 0 {
|
||||
return FullAccess
|
||||
} else {
|
||||
return ReadOnly
|
||||
}
|
||||
}
|
||||
|
||||
func AddOrgKey(orgId string, keys string){
|
||||
|
||||
if len(OrgKeyMap) != 0 {
|
||||
if _, ok := OrgKeyMap[orgId]; ok {
|
||||
func AddOrgKey(orgId string, key string) {
|
||||
if OrgKeyMap.Len() != 0 {
|
||||
if val, ok := OrgKeyMap.Get(orgId); ok {
|
||||
// Org record exists. Append the key only
|
||||
OrgKeyMap[orgId].Keys = append (OrgKeyMap[orgId].Keys, keys)
|
||||
vo := val.(*OrgStruct)
|
||||
vo.Keys = append(vo.Keys, key)
|
||||
return
|
||||
}
|
||||
}
|
||||
// first record into the map or firts record for the org
|
||||
var locKeys []string
|
||||
locKeys = append(locKeys, keys);
|
||||
OrgKeyMap[orgId] = &OrgStruct {OrgId : orgId, Keys : locKeys}
|
||||
OrgKeyMap.Add(orgId, &OrgStruct{OrgId: orgId, Keys: []string{key}})
|
||||
}
|
||||
|
||||
func DeleteOrgKey(orgId string, keys string){
|
||||
|
||||
if len(OrgKeyMap) != 0 {
|
||||
if _, ok := OrgKeyMap[orgId]; ok {
|
||||
for i, keyVal := range OrgKeyMap[orgId].Keys{
|
||||
if keyVal == keys {
|
||||
OrgKeyMap[orgId].Keys = append(OrgKeyMap[orgId].Keys[:i], OrgKeyMap[orgId].Keys[i+1:]...)
|
||||
break
|
||||
}
|
||||
func DeleteOrgKey(orgId string, key string) {
|
||||
if val, ok := OrgKeyMap.Get(orgId); ok {
|
||||
vo := val.(*OrgStruct)
|
||||
for i, keyVal := range vo.Keys {
|
||||
if keyVal == key {
|
||||
vo.Keys = append(vo.Keys[:i], vo.Keys[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ResolvePrivateForKeys(orgId string ) []string {
|
||||
func ResolvePrivateForKeys(orgId string) []string {
|
||||
var keys []string
|
||||
mu := sync.RWMutex{}
|
||||
|
||||
if len(OrgKeyMap) != 0 {
|
||||
if _, ok := OrgKeyMap[orgId]; ok {
|
||||
if len(OrgKeyMap[orgId].Keys) > 0{
|
||||
mu.RLock()
|
||||
keys = OrgKeyMap[orgId].Keys
|
||||
mu.RUnlock()
|
||||
} else {
|
||||
keys = append(keys, orgId)
|
||||
}
|
||||
return keys
|
||||
if val, ok := OrgKeyMap.Get(orgId); ok {
|
||||
vo := val.(*OrgStruct)
|
||||
if len(vo.Keys) > 0 {
|
||||
keys = vo.Keys
|
||||
} else {
|
||||
keys = append(keys, orgId)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
keys = append(keys, orgId)
|
||||
return keys
|
||||
|
|
Loading…
Reference in New Issue