From 48c35d8148c92268e8c38eb620a538f40d802fa8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 5 Nov 2021 12:44:58 +0100 Subject: [PATCH] 3 Network Nodes Running in Debug Mode --- .vscode/Network-Node-1.code-workspace | 10 +++++++ .vscode/Network-Node-2.code-workspace | 10 +++++++ .vscode/Network-Node-3.code-workspace | 10 +++++++ Desktop/DesktopApp.js | 8 +++--- Network/NetwokNode.js | 18 +++++++------ NetworkRoot.js | 6 ++++- .../Network/NT/Modules/WebSocketsInterface.js | 4 ++- Projects/Network/SA/Modules/P2PNetwork.js | 3 +++ .../Network/SA/Modules/P2PNetworkPeers.js | 26 +++++++++++++++++++ network-node-1.js | 16 ++++++++++++ network-node-2.js | 16 ++++++++++++ network-node-3.js | 16 ++++++++++++ 12 files changed, 129 insertions(+), 14 deletions(-) create mode 100644 .vscode/Network-Node-1.code-workspace create mode 100644 .vscode/Network-Node-2.code-workspace create mode 100644 .vscode/Network-Node-3.code-workspace create mode 100644 Projects/Network/SA/Modules/P2PNetworkPeers.js create mode 100644 network-node-1.js create mode 100644 network-node-2.js create mode 100644 network-node-3.js diff --git a/.vscode/Network-Node-1.code-workspace b/.vscode/Network-Node-1.code-workspace new file mode 100644 index 000000000..97e2d4c8f --- /dev/null +++ b/.vscode/Network-Node-1.code-workspace @@ -0,0 +1,10 @@ +{ + "folders": [ + { + "path": "C:\\Superalgos" + } + ], + "settings": { + "search.maintainFileSearchCache": true + } +} \ No newline at end of file diff --git a/.vscode/Network-Node-2.code-workspace b/.vscode/Network-Node-2.code-workspace new file mode 100644 index 000000000..97e2d4c8f --- /dev/null +++ b/.vscode/Network-Node-2.code-workspace @@ -0,0 +1,10 @@ +{ + "folders": [ + { + "path": "C:\\Superalgos" + } + ], + "settings": { + "search.maintainFileSearchCache": true + } +} \ No newline at end of file diff --git a/.vscode/Network-Node-3.code-workspace b/.vscode/Network-Node-3.code-workspace new file mode 100644 index 000000000..97e2d4c8f --- /dev/null +++ b/.vscode/Network-Node-3.code-workspace @@ -0,0 +1,10 @@ +{ + "folders": [ + { + "path": "C:\\Superalgos" + } + ], + "settings": { + "search.maintainFileSearchCache": true + } +} \ No newline at end of file diff --git a/Desktop/DesktopApp.js b/Desktop/DesktopApp.js index df7d7f570..2be0b2ac6 100644 --- a/Desktop/DesktopApp.js +++ b/Desktop/DesktopApp.js @@ -2,7 +2,7 @@ exports.newDesktopApp = function newDesktopApp() { let thisObject = { socialGraph: undefined, - p2pMetwork: undefined, + p2pNetwork: undefined, webSocketsClient: undefined, webSocketsInterface: undefined, run: run @@ -21,12 +21,12 @@ exports.newDesktopApp = function newDesktopApp() { /* We can join now the P2P Network as a client app. */ - thisObject.p2pMetwork = SA.projects.network.modules.p2pNetwork.newNetworkModulesP2PNetwork() - await thisObject.p2pMetwork.initialize('Network Client') + thisObject.p2pNetwork = SA.projects.network.modules.p2pNetwork.newNetworkModulesP2PNetwork() + await thisObject.p2pNetwork.initialize('Network Client') /* Here we will pick a Network Node from all users profiles available that do have a Network Node running. */ - let selectedNetworkNode = thisObject.p2pMetwork.p2pNodesToConnect[0] + let selectedNetworkNode = thisObject.p2pNetwork.p2pNodesToConnect[0] /* This is the Web Sockets client that interacts with the Superalgos Network. */ diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index d3c300e2e..26763ca92 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -4,7 +4,7 @@ exports.newNetworkNode = function newNetworkNode() { webSocketsInterface: undefined, socialGraphService: undefined, storage: undefined, - p2pMetwork: undefined, + p2pNetwork: undefined, run: run } @@ -13,11 +13,6 @@ exports.newNetworkNode = function newNetworkNode() { return thisObject async function run() { - /* - Other Network Nodes and Client Apps will communicate with this Network Node via it's Websocket Interface. - */ - thisObject.webSocketsInterface = NT.projects.network.modules.webSocketsInterface.newNetworkModulesWebSocketsInterface() - thisObject.webSocketsInterface.initialize() /* The Social Graph Service is the first and for now, the only service this Network Node provides. */ @@ -31,7 +26,14 @@ exports.newNetworkNode = function newNetworkNode() { /* We can join now the P2P Network as a new peer there. */ - thisObject.p2pMetwork = SA.projects.network.modules.p2pNetwork.newNetworkModulesP2PNetwork() - await thisObject.p2pMetwork.initialize('Network Peer') + thisObject.p2pNetwork = SA.projects.network.modules.p2pNetwork.newNetworkModulesP2PNetwork() + await thisObject.p2pNetwork.initialize('Network Peer') + /* + Other Network Nodes and Client Apps will communicate with this Network Node via it's Websocket Interface. + */ + thisObject.webSocketsInterface = NT.projects.network.modules.webSocketsInterface.newNetworkModulesWebSocketsInterface() + thisObject.webSocketsInterface.initialize() + console.log('Network Node Web Sockets Interface ....................................... Listening at port ' + JSON.parse(NT.networkNode.p2pNetwork.thisNetworkNode.node.config).webSocketsPort) + } } diff --git a/NetworkRoot.js b/NetworkRoot.js index daa007839..a09e3cd62 100644 --- a/NetworkRoot.js +++ b/NetworkRoot.js @@ -10,7 +10,7 @@ exports.newNetworkRoot = function newNetworkRoot() { return thisObject - async function run() { + async function run(debugSettings) { /* The NT object is accessible everywhere at the Superalgos Network. It provides access to all modules built for this Network. @@ -25,6 +25,10 @@ exports.newNetworkRoot = function newNetworkRoot() { let ENVIRONMENT = require('./Environment.js'); let ENVIRONMENT_MODULE = ENVIRONMENT.newEnvironment() global.env = ENVIRONMENT_MODULE + + if (debugSettings !== undefined && debugSettings.P2P_NETWORK_NODE_SIGNING_ACCOUNT !== undefined) { + global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT = debugSettings.P2P_NETWORK_NODE_SIGNING_ACCOUNT + } /* First thing is to load the project schema file. */ diff --git a/Projects/Network/NT/Modules/WebSocketsInterface.js b/Projects/Network/NT/Modules/WebSocketsInterface.js index e79a51bb2..7374e869e 100644 --- a/Projects/Network/NT/Modules/WebSocketsInterface.js +++ b/Projects/Network/NT/Modules/WebSocketsInterface.js @@ -40,7 +40,9 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock } function initialize() { - socketServer = new SA.nodeModules.ws.Server({ port: global.env.NETWORK_WEB_SOCKETS_INTERFACE_PORT }) + let port = JSON.parse(NT.networkNode.p2pNetwork.thisNetworkNode.node.config).webSocketsPort + + socketServer = new SA.nodeModules.ws.Server({ port: port }) clientInterface = NT.projects.socialTrading.modules.clientInterface.newSocialTradingModulesClientInterface() peerInterface = NT.projects.socialTrading.modules.peerInterface.newSocialTradingModulesPeerInterface() diff --git a/Projects/Network/SA/Modules/P2PNetwork.js b/Projects/Network/SA/Modules/P2PNetwork.js index 61ae16c87..131f82e60 100644 --- a/Projects/Network/SA/Modules/P2PNetwork.js +++ b/Projects/Network/SA/Modules/P2PNetwork.js @@ -6,6 +6,7 @@ exports.newNetworkModulesP2PNetwork = function newNetworkModulesP2PNetwork() { let thisObject = { joinTheNetworkAsNetworkPeer: joinTheNetworkAsNetworkPeer, p2pNodesToConnect: undefined, + thisNetworkNode: undefined, /* Framework Functions */ initialize: initialize, finalize: finalize @@ -37,6 +38,8 @@ exports.newNetworkModulesP2PNetwork = function newNetworkModulesP2PNetwork() { let p2pNetworkNode = SA.projects.network.globals.memory.arrays.P2P_NETWORK_NODES[i] if (thisP2PNodeId !== p2pNetworkNode.node.id) { thisObject.p2pNodesToConnect.push(p2pNetworkNode) + } else { + thisObject.thisNetworkNode = p2pNetworkNode } } break diff --git a/Projects/Network/SA/Modules/P2PNetworkPeers.js b/Projects/Network/SA/Modules/P2PNetworkPeers.js new file mode 100644 index 000000000..2e40bd9ca --- /dev/null +++ b/Projects/Network/SA/Modules/P2PNetworkPeers.js @@ -0,0 +1,26 @@ +exports.newNetworkModulesP2PNetworkPeers = function newNetworkModulesP2PNetworkPeers() { + /* + This module represents the P2P Nodes we are connected to. + */ + let thisObject = { + + /* Framework Functions */ + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + + } + + async function initialize() { + /* + On a first iteration, we will try to connect to 2 Network Peers, one upstream and one downstream, + meaning one with higher ranking that us, and the other with lower ranking than us. + */ + + + } +} \ No newline at end of file diff --git a/network-node-1.js b/network-node-1.js new file mode 100644 index 000000000..ffb2ccd1e --- /dev/null +++ b/network-node-1.js @@ -0,0 +1,16 @@ +/* +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.. + +*/ + +let APP_ROOT = require('./NetworkRoot.js') +let APP_ROOT_MODULE = APP_ROOT.newNetworkRoot() +APP_ROOT_MODULE.run({P2P_NETWORK_NODE_SIGNING_ACCOUNT: 'P2P-Network-Node-1'}) \ No newline at end of file diff --git a/network-node-2.js b/network-node-2.js new file mode 100644 index 000000000..0f36a5e2d --- /dev/null +++ b/network-node-2.js @@ -0,0 +1,16 @@ +/* +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.. + +*/ + +let APP_ROOT = require('./NetworkRoot.js') +let APP_ROOT_MODULE = APP_ROOT.newNetworkRoot() +APP_ROOT_MODULE.run({P2P_NETWORK_NODE_SIGNING_ACCOUNT: 'P2P-Network-Node-2'}) \ No newline at end of file diff --git a/network-node-3.js b/network-node-3.js new file mode 100644 index 000000000..f8a3ac41e --- /dev/null +++ b/network-node-3.js @@ -0,0 +1,16 @@ +/* +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.. + +*/ + +let APP_ROOT = require('./NetworkRoot.js') +let APP_ROOT_MODULE = APP_ROOT.newNetworkRoot() +APP_ROOT_MODULE.run({P2P_NETWORK_NODE_SIGNING_ACCOUNT: 'P2P-Network-Node-3'}) \ No newline at end of file