p2p Network Node implemented
This commit is contained in:
1 parent
1bcd24e442
commit
80f7ffaa8e
7 files changed
+95
-4
No files matched your search
@@ -0,0 +1,35 @@
|
||||
exports.newNetworkModulesP2PNetwork = function newNetworkModulesP2PNetwork() {
|
||||
/*
|
||||
This module represents the P2P Network and it is needed to enable the connection
|
||||
of this current node to other peers.
|
||||
*/
|
||||
let thisObject = {
|
||||
joinTheNetworkAsPeer: joinTheNetworkAsPeer,
|
||||
/* Framework Functions */
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
|
||||
}
|
||||
|
||||
async function initialize() {
|
||||
/*
|
||||
We will setup here the maps and arryas we will need to operate within the P2P Network.
|
||||
*/
|
||||
let thisP2PNodeId = SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).signingAccountNodeId
|
||||
for (let i = 0; i < SA.projects.network.globals.memory.arrays.P2P_NETWORK_NODES.length; i++) {
|
||||
let p2pNetworkNode = SA.projects.network.globals.memory.arrays.P2P_NETWORK_NODES[i]
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function joinTheNetworkAsPeer() {
|
||||
/*
|
||||
To join the network we will need to thorugh the list of Network Nodes and pick one to connect to.
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
exports.newNetworkModulesP2PNetworkNode = function newNetworkModulesP2PNetworkNode() {
|
||||
/*
|
||||
This module represents the P2P Network Node.
|
||||
*/
|
||||
let thisObject = {
|
||||
|
||||
node: undefined,
|
||||
userPofile: undefined,
|
||||
|
||||
/* Framework Functions */
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
thisObject.node = undefined
|
||||
thisObject.userPofile = undefined
|
||||
}
|
||||
|
||||
async function initialize(node, userPofile) {
|
||||
/*
|
||||
We will setup here the maps and arryas we will need to operate within the P2P Network.
|
||||
*/
|
||||
thisObject.node = node
|
||||
thisObject.userPofile = userPofile
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ exports.newNetworkModulesUserProfiles = function newNetworkModulesUserProfiles()
|
||||
|
||||
SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.set(userProfileId, userProfile)
|
||||
SA.projects.network.globals.memory.maps.USER_PROFILES_BY_HANDLE.set(userHandle, userProfile)
|
||||
SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOCHAIN_ACCOUNT.set(blockchainAccount, userProfile)
|
||||
SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOKCHAIN_ACCOUNT.set(blockchainAccount, userProfile)
|
||||
/*
|
||||
Each User Profile might have Signing Accounts, meaning
|
||||
accounts that can be siging on behalf of the User Profile.
|
||||
@@ -65,7 +65,15 @@ exports.newNetworkModulesUserProfiles = function newNetworkModulesUserProfiles()
|
||||
let signatureObject = config.signature
|
||||
let web3 = new SA.nodeModules.web3()
|
||||
let blockchainAccount = web3.eth.accounts.recover(signatureObject)
|
||||
SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOCHAIN_ACCOUNT.set(blockchainAccount, userProfile)
|
||||
SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOKCHAIN_ACCOUNT.set(blockchainAccount, userProfile)
|
||||
/*
|
||||
If the Signing Account is for a P2P node, we will add the node to the array of available nodes at the p2p network.
|
||||
*/
|
||||
if (signingAccount.signingAccountChild.type === "P2P Network Node") {
|
||||
p2pNetworkNode = SA.projects.network.modules.p2pMetworkNode.newNetworkModulesP2PNetworkNode()
|
||||
p2pMetworkNode.initialize(signingAccount.signingAccountChild, userPofile)
|
||||
SA.projects.network.globals.memory.arrays.P2P_NETWORK_NODES.push(p2pNetworkNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user