p2p Network Node implemented
This commit is contained in:
1 parent
1bcd24e442
commit
80f7ffaa8e
7 files changed
+95
-4
No files matched your search
@@ -3,6 +3,7 @@ exports.newNetworkNode = function newNetworkNode() {
|
||||
let thisObject = {
|
||||
socialGraphService: undefined,
|
||||
storage: undefined,
|
||||
p2pMetwork: undefined,
|
||||
run: run
|
||||
}
|
||||
|
||||
@@ -24,5 +25,10 @@ exports.newNetworkNode = function newNetworkNode() {
|
||||
*/
|
||||
thisObject.storage = NT.projects.socialTrading.modules.storage.newSocialTradingModulesStorage()
|
||||
thisObject.storage.initialize()
|
||||
/*
|
||||
We can join now the P2P Network as a new peer there.
|
||||
*/
|
||||
thisObject.p2pMetwork = SA.projects.network.modules.p2pMetwork.newNetworkModulesP2PNetwork()
|
||||
await thisObject.p2pMetwork.initialize()
|
||||
}
|
||||
}
|
||||
@@ -304,7 +304,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock
|
||||
/*
|
||||
The signature gives us the blockchain account, and the account the user profile.
|
||||
*/
|
||||
let witnessUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOCHAIN_ACCOUNT.get(caller.blockchainAccount)
|
||||
let witnessUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOKCHAIN_ACCOUNT.get(caller.blockchainAccount)
|
||||
|
||||
if (witnessUserProfile === undefined) {
|
||||
let response = {
|
||||
|
||||
@@ -6,9 +6,10 @@ exports.newNetworkGlobalsMemory = function () {
|
||||
maps: {
|
||||
USER_PROFILES_BY_ID: new Map(), // Here we will store the user profiles by User Profile Id.
|
||||
USER_PROFILES_BY_HANDLE: new Map(), // Here we will store the user profiles by User Profile Handle.
|
||||
USER_PROFILES_BY_BLOCHAIN_ACCOUNT: new Map() // Here we will store the user profiles by Blockchain Account.
|
||||
USER_PROFILES_BY_BLOKCHAIN_ACCOUNT: new Map() // Here we will store the user profiles by Blockchain Account.
|
||||
},
|
||||
arrays: {
|
||||
P2P_NETWORK_NODES: [] // Here we will store the p2p nodes deined under Signing Account node types.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1407,6 +1407,18 @@
|
||||
"propertyName": "userProfiles",
|
||||
"functionName": "newNetworkModulesUserProfiles",
|
||||
"fileName": "UserProfiles.js"
|
||||
},
|
||||
{
|
||||
"name": "P2P Network",
|
||||
"propertyName": "p2pNetwork",
|
||||
"functionName": "newSocialTradingModulesP2PNetwork",
|
||||
"fileName": "P2PNetwork.js"
|
||||
},
|
||||
{
|
||||
"name": "P2P Network Node",
|
||||
"propertyName": "p2pNetworkNode",
|
||||
"functionName": "newSocialTradingModulesP2PNetworkNode",
|
||||
"fileName": "P2PNetworkNode.js"
|
||||
}
|
||||
],
|
||||
"utilities": [
|
||||
|
||||
Reference in new issue
Block a user