diff --git a/Environment.js b/Environment.js index a599d095e..78846c598 100644 --- a/Environment.js +++ b/Environment.js @@ -17,6 +17,7 @@ exports.newEnvironment = function () { DESKTOP_WEB_SOCKETS_INTERFACE_HOST: 'localhost', PLATFORM_HTTP_INTERFACE_PORT: 34248, DESKTOP_HTTP_INTERFACE_PORT: 33248, + NETWORK_HTTP_INTERFACE_PORT: 31248, PATH_TO_DATA_STORAGE: path.join(basePath, './Platform/My-Data-Storage'), PATH_TO_PROJECTS: path.join(basePath, './Projects'), PATH_TO_LOG_FILES: path.join(basePath, './Platform/My-Log-Files'), diff --git a/Network/NetwokNode.js b/Network/NetwokNode.js index 4bd5f705c..c4301e112 100644 --- a/Network/NetwokNode.js +++ b/Network/NetwokNode.js @@ -6,6 +6,7 @@ exports.newNetworkNode = function newNetworkNode() { p2pNetworkPeers: undefined, p2pNetworkNode: undefined, webSocketsInterface: undefined, + httpInterface: undefined, socialGraphService: undefined, storage: undefined, run: run @@ -65,6 +66,12 @@ exports.newNetworkNode = function newNetworkNode() { 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.p2pNetworkNode.node.config).webSocketsPort) + /* + Other Network Nodes and Client Apps will communicate with this Network Node via it's HTTP Interface. + */ + thisObject.webSocketsInterface = NT.projects.network.modules.webHttpInterface.newNetworkModulesHttpInterface() + thisObject.webSocketsInterface.initialize() + console.log('Network Node Http Interface .................................................. Listening at port ' + JSON.parse(NT.networkNode.p2pNetworkNode.node.config).webPort) } } } diff --git a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json index 14668a46b..a60755b4f 100644 --- a/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json +++ b/Projects/Governance/Plugins/User-Profiles/Luis-Fernando-Molina.json @@ -17236,7 +17236,7 @@ "signingAccountChild": { "type": "P2P Network Node", "name": "P2P Network Node # 1", - "config": "{\n \"codeName\": \"P2P-Network-Node-1\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18042\"\n}", + "config": "{\n \"codeName\": \"P2P-Network-Node-1\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18042\",\n \"webPort\": \"31248\"\n}", "project": "Governance", "id": "bb0f0417-9dfb-47a3-941f-dcfa82fbaea1", "savedPayload": { @@ -17292,7 +17292,7 @@ "signingAccountChild": { "type": "P2P Network Node", "name": "P2P Network Node # 2", - "config": "{\n \"codeName\": \"P2P-Network-Node-2\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18043\"\n}", + "config": "{\n \"codeName\": \"P2P-Network-Node-2\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18043\",\n \"webPort\": \"31248\"\n}", "project": "Governance", "id": "76fa8a24-9ab4-4eaf-82f2-458ba557b204", "savedPayload": { @@ -17348,7 +17348,7 @@ "signingAccountChild": { "type": "P2P Network Node", "name": "P2P Network Node # 3", - "config": "{\n \"codeName\": \"P2P-Network-Node-3\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18044\"\n}", + "config": "{\n \"codeName\": \"P2P-Network-Node-3\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18044\",\n \"webPort\": \"31248\"\n}", "project": "Governance", "id": "297e57c2-3c1a-4170-b710-d2705804205b", "savedPayload": { diff --git a/Projects/Governance/Schemas/App-Schema/p2p-network-node.json b/Projects/Governance/Schemas/App-Schema/p2p-network-node.json index ae7aeb2d4..17f1a4838 100644 --- a/Projects/Governance/Schemas/App-Schema/p2p-network-node.json +++ b/Projects/Governance/Schemas/App-Schema/p2p-network-node.json @@ -25,7 +25,7 @@ "config": true }, "initialValues": { - "config": "{ \n\"codeName\": \"localhost\", \n\"host\": \"localhost\", \n\"webSocketsPort\": \"18042\"\n}" + "config": "{ \n\"codeName\": \"localhost\", \n\"host\": \"localhost\", \n\"webPort\": \"31248\", \n\"webSocketsPort\": \"18042\"\n}" }, "addLeftIcons": true, "level": 1, diff --git a/Projects/Network/NT/Modules/HttpInterface.js b/Projects/Network/NT/Modules/HttpInterface.js new file mode 100644 index 000000000..aed274b25 --- /dev/null +++ b/Projects/Network/NT/Modules/HttpInterface.js @@ -0,0 +1,52 @@ +exports.newNetworkModulesHttpInterface = function newNetworkModulesHttpInterface() { + /* + This module represent the HTTP API of the + NNetwork Node. All HTTP request are processed + by this module. + */ + let thisObject = { + initialize: initialize, + finalize: finalize + } + + return thisObject + + function finalize() { + } + + function initialize() { + let port = JSON.parse(NT.networkNode.p2pNetworkNode.node.config).webPort + /* + We will create an HTTP Server and leave it running forever. + */ + SA.nodeModules.http.createServer(onHttpRequest).listen(port) + } + + function onHttpRequest(httpRequest, httpResponse) { + try { + let requestPathAndParameters = httpRequest.url.split('?') // Remove version information + let requestPath = requestPathAndParameters[0].split('/') + let endpointOrFile = requestPath[1] + + switch (endpointOrFile) { + case 'Signal': + { + let message = requestPath[2] + let response = await thisObject.clientInterface.messageReceived(message) + SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(response), httpResponse) + } + break + case 'Stats': + { + SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify([]), httpResponse) + } + break + default: + { + } + } + } catch (err) { + console.log(err.stack) + } + } +} diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index 3fd1d2c7d..ca78a8f61 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -1389,6 +1389,12 @@ "propertyName": "webSocketsInterface", "functionName": "newNetworkModulesWebSocketsInterface", "fileName": "WebSocketsInterface.js" + }, + { + "name": "Http Interface", + "propertyName": "httpInterface", + "functionName": "newNetworkModulesHttpInterface", + "fileName": "HttpInterface.js" } ], "utilities": [] @@ -1629,7 +1635,7 @@ "name": "Http Interface", "propertyName": "httpInterface", "functionName": "newDesktopModulesHttpInterface", - "fileName": "httpInterface.js" + "fileName": "HttpInterface.js" }, { "name": "Web Sockets Interface", diff --git a/Projects/Social-Trading/NT/Modules/ClientInterface.js b/Projects/Social-Trading/NT/Modules/ClientInterface.js index 0da1aa0d4..e99344c1a 100644 --- a/Projects/Social-Trading/NT/Modules/ClientInterface.js +++ b/Projects/Social-Trading/NT/Modules/ClientInterface.js @@ -64,7 +64,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule return await eventReceived(messageHeader.eventMessage, userProfile) } case 'Signal': { - return await signalReceived(messageHeader.eventMessage, userProfile) + return await signalReceived(messageHeader.eventMessage) } } } @@ -245,7 +245,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule } } - async function signalReceived(signalMessage, userProfile) { + async function signalReceived(signalMessage) { /* We expect here a JSON string with some or all of the following properties: