Skip to content

Commit

Permalink
Merge pull request #4328 from Luis-Fernando-Molina/develop
Browse files Browse the repository at this point in the history
Contribution: Minimun SA Tokens Required for User Profiles connecting to Network Nodes.
  • Loading branch information
Luis-Fernando-Molina authored Sep 10, 2022
2 parents 1d0b18e + 9f33e09 commit bdb0260
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Network/NetwokApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ exports.newNetworkApp = function newNetworkApp() {
setupNetworkInterfaces()

console.log('Network Node User Profile Code Name .......................................... ' + thisObject.p2pNetworkNode.userProfile.config.codeName)
console.log('Network Node User Profile Balance ............................................ ' + SA.projects.governance.utilities.balances.toSABalanceString(thisObject.p2pNetworkNode.userProfile.balance))
console.log('Network Node Code Name ....................................................... ' + thisObject.p2pNetworkNode.node.config.codeName)
console.log('Minimun User Profile Balance Required to Connect to this Network Node ........ ' + SA.projects.governance.utilities.balances.toSABalanceString(thisObject.p2pNetworkNode.node.config.clientMinimunBalance))
console.log('Network Node Version ......................................................... ' + NETWORK_NODE_VERSION)
console.log('Network Type ................................................................. ' + thisObject.p2pNetworkNode.node.p2pNetworkReference.referenceParent.type)
console.log('Network Code Name ............................................................ ' + thisObject.p2pNetworkNode.node.p2pNetworkReference.referenceParent.config.codeName)
Expand Down
12 changes: 12 additions & 0 deletions Projects/Governance/SA/Utilities/Balances.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exports.newGovernanceUtilitiesBalances = function newGovernanceUtilitiesBalances() {

let thisObject = {
toSABalanceString: toSABalanceString
}

return thisObject

function toSABalanceString(balance) {
return Math.trunc(balance).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ' SA'
}
}
34 changes: 34 additions & 0 deletions Projects/Network/NT/Modules/SocketInterfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,40 @@ exports.newNetworkModulesSocketInterfaces = function newNetworkModulesSocketInte
console.log((new Date()).toISOString(), '[WARN] Socket Interfaces -> handshakeStepTwo -> userAppBlockchainAccount not associated with userProfile -> userAppBlockchainAccount = ' + caller.userAppBlockchainAccount)
return
}
/*
We will verify that the caller's User Profile has the minimun SA Balance required to connect to this Netork Node
*/
switch (caller.role) {
case 'Network Client': {
let clientMinimunBalance = NT.networkApp.p2pNetworkNode.node.config.clientMinimunBalance | 0
if (userProfileByBlockchainAccount.balance < clientMinimunBalance) {
let response = {
result: 'Error',
message: 'Network Client User Profile ' + userProfileByBlockchainAccount.config.codeName + ' has a Balance of ' + SA.projects.governance.utilities.balances.toSABalanceString(userProfileByBlockchainAccount.balance) + ' while the Minimun Balance Required to connect to this Network Node "' + NT.networkApp.p2pNetworkNode.userProfile.config.codeName + '/' + NT.networkApp.p2pNetworkNode.node.config.codeName + '" is ' + SA.projects.governance.utilities.balances.toSABalanceString(clientMinimunBalance)
}
caller.socket.send(JSON.stringify(response))
caller.socket.close()
return
}
break
}
case 'Network Peer': {
let clientMinimunBalance = NT.networkApp.p2pNetworkNode.node.config.peerMinimunBalance | 0
if (userProfileByBlockchainAccount.balance < clientMinimunBalance) {
let response = {
result: 'Error',
message: 'Network Peer User Profile ' + userProfileByBlockchainAccount.config.codeName + ' has a Balance of ' + SA.projects.governance.utilities.balances.toSABalanceString(userProfileByBlockchainAccount.balance) + ' while the Minimun Balance Required to connect to this Network Node "' + NT.networkApp.p2pNetworkNode.userProfile.config.codeName + '/' + NT.networkApp.p2pNetworkNode.node.config.codeName + '" is ' + SA.projects.governance.utilities.balances.toSABalanceString(clientMinimunBalance)
}
caller.socket.send(JSON.stringify(response))
caller.socket.close()
return
}
break
}
}
/*
Parse the signed Message
*/
let signedMessage = JSON.parse(signature.message)
/*
We will verify that the signature belongs to the signature.message.
Expand Down
50 changes: 45 additions & 5 deletions Projects/Network/SA/Modules/AppBootstrapingProcess.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion Projects/Network/SA/Modules/P2PNetworkClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ exports.newNetworkModulesP2PNetworkClient = function newNetworkModulesP2PNetwork
thisObject.p2pNetworkClientIdentity,
false
)
console.log('Network Client User Profile Code Name ........................................ ' + thisObject.p2pNetworkClientIdentity.userProfile.config.codeName)
console.log('Network Client User Profile Balance .......................................... ' + SA.projects.governance.utilities.balances.toSABalanceString(thisObject.p2pNetworkClientIdentity.userProfile.balance))
console.log('')
/*
We set up the P2P Network reacheable nodes. This means that we will filter out all the network nodes that do not have the
network services this Task requires or the Network Interfaces this Task can speak to.
Expand All @@ -62,7 +65,9 @@ exports.newNetworkModulesP2PNetworkClient = function newNetworkModulesP2PNetwork
targetNetworkCodeName,
targetNetworkType,
thisObject.p2pNetworkClientIdentity,
p2pNetworkClientNode
p2pNetworkClientNode,
thisObject.p2pNetworkClientIdentity.userProfile.config.codeName,
thisObject.p2pNetworkClientIdentity.userProfile.balance
)
/*
Set up the connections to network nodes. These are websockets connections and in order to do this,
Expand Down
16 changes: 14 additions & 2 deletions Projects/Network/SA/Modules/P2PNetworkReachableNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ exports.newNetworkModulesP2PNetworkReachableNodes = function newNetworkModulesP2
networkCodeName,
networkType,
p2pNetworkClientIdentity,
p2pNetworkClientNode
p2pNetworkClientNode,
userProfileCodeName,
userProfileBalance
) {
thisObject.networkCodeName = networkCodeName
thisObject.networkType = networkType
Expand Down Expand Up @@ -56,11 +58,21 @@ exports.newNetworkModulesP2PNetworkReachableNodes = function newNetworkModulesP2
if (p2pNetworkNode.node.networkInterfaces.websocketsNetworkInterface === undefined && p2pNetworkClientNode.networkInterfaces.websocketsNetworkInterface !== undefined) { continue }
if (p2pNetworkNode.node.networkInterfaces.webrtcNetworkInterface === undefined && p2pNetworkClientNode.networkInterfaces.webrtcNetworkInterface !== undefined) { continue }
if (p2pNetworkNode.node.networkInterfaces.httpNetworkInterface === undefined && p2pNetworkClientNode.networkInterfaces.httpNetworkInterface !== undefined) { continue }
/*
Check that we have enough User Profile Balance to connect to this Network Node.
*/
let clientMinimunBalance = p2pNetworkNode.node.config.clientMinimunBalance | 0
if (userProfileBalance < clientMinimunBalance) {
console.log('')
console.log((new Date()).toISOString(), '[INFO] Network Client User Profile ' + userProfileCodeName + ' has a Balance of ' + SA.projects.governance.utilities.balances.toSABalanceString(userProfileBalance) + ' while the Minimun Balance Required to connect to the Network Node "' + p2pNetworkNode.userProfile.config.codeName + '/' + p2pNetworkNode.node.config.codeName + '" is ' + SA.projects.governance.utilities.balances.toSABalanceString(clientMinimunBalance) + '. If you want to be able to connect to this Network Node you will need to earn or buy more SA tokens and try again.')
console.log('')
continue
}

checkForPermissions(p2pNetworkNode)
}

console.log((new Date()).toISOString(), '[INFO] These are the P2P Network Nodes we can connect to: all nodes that do not have the network services and network interfaces defined required by the Network Client were filtered out. ')
console.log((new Date()).toISOString(), '[INFO] These are the P2P Network Nodes we can connect to: all nodes that do not have the network services and network interfaces defined required by the Network Client were filtered out. Network nodes that requires a minimun User Profile Balance than the one you have also been filtered out.')
console.log('')
for (let i = 0; i < thisObject.p2pNodesToConnect.length; i++) {
console.log(i + ' - ' + thisObject.p2pNodesToConnect[i].userProfile.config.codeName + ' - ' + thisObject.p2pNodesToConnect[i].node.config.codeName)
Expand Down
2 changes: 1 addition & 1 deletion Projects/Network/Schemas/App-Schema/p2p-network-node.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"config": true
},
"initialValues": {
"config": "{ \n\"codeName\": \"\", \n\"host\": \"localhost\" \n}"
"config": "{ \n\"codeName\": \"\", \n\"host\": \"localhost\", \n\"clientMinimunBalance\": 0, \n\"clientMinimunBalance\": 0 \n}"
},
"addLeftIcons": true,
"level": 1,
Expand Down
12 changes: 9 additions & 3 deletions Projects/ProjectsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,12 @@
"propertyName": "signingAccounts",
"functionName": "newGovernanceUtilitiesSigningAccounts",
"fileName": "SigningAccounts.js"
},
{
"name": "Balances",
"propertyName": "balances",
"functionName": "newGovernanceUtilitiesBalances",
"fileName": "Balances.js"
}
]
},
Expand Down Expand Up @@ -2394,7 +2400,7 @@
]
},
"TS": {
"botModules":[
"botModules": [
{
"name": "Forecast-Client",
"propertyName": "forecastClient",
Expand Down Expand Up @@ -2452,7 +2458,7 @@
"folderName": "Test-Server"
}
],
"utilities":[
"utilities": [
{
"name": "Miscellaneous",
"propertyName": "miscellaneous",
Expand All @@ -2463,7 +2469,7 @@
]
},
"NT": {
"modules":[
"modules": [
{
"name": "Machine Learning Network Service",
"propertyName": "machineLearningNetworkService",
Expand Down
11 changes: 1 addition & 10 deletions network.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
/*
The Superalgos Network offers 3 types of services:
* Social Graph Service
* Search Index Service
* Private Message Service
Users can decide which services to run at their node.(TODO)
This module represents the Nodejs command that users have to start the Network Node..
This module represents the Nodejs command that users use to start the Network Node.
*/

let APP_ROOT = require('./NetworkRoot.js')
Expand Down

0 comments on commit bdb0260

Please sign in to comment.