From 3345eff34720b980d4bc1b17640d8441fb34b980 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 22 Oct 2021 15:46:56 +0200 Subject: [PATCH] Splitting Memory and changing it to Network Project --- .../NT/Globals/Memory.js | 5 +-- .../Network/NT/Modules/WebSocketsInterface.js | 2 +- Projects/Network/SA/Globals/Memory.js | 16 ++++++++ .../Network/SA/Utilities/NetworkNodePicker.js | 12 ++++++ Projects/ProjectsSchema.json | 39 +++++++++++++------ .../Social-Trading/NT/Modules/Bootstrap.js | 8 ++-- .../NT/Modules/ClientInterface.js | 6 +-- Projects/Social-Trading/NT/Modules/Event.js | 4 +- .../NT/Modules/Queries/BotProfileStats.js | 4 +- .../NT/Modules/Queries/Events.js | 10 ++--- .../Modules/Queries/UnfollowedUserProfiles.js | 4 +- .../NT/Modules/Queries/UserProfileStats.js | 4 +- .../NT/Modules/Queries/UserProfiles.js | 2 +- .../NT/Modules/Social-Graph/Post.js | 2 +- Projects/Social-Trading/NT/Modules/Storage.js | 10 ++--- .../NT/Utilities/QueriesValidations.js | 4 +- 16 files changed, 86 insertions(+), 46 deletions(-) rename Projects/{Social-Trading => Network}/NT/Globals/Memory.js (64%) create mode 100644 Projects/Network/SA/Globals/Memory.js create mode 100644 Projects/Network/SA/Utilities/NetworkNodePicker.js diff --git a/Projects/Social-Trading/NT/Globals/Memory.js b/Projects/Network/NT/Globals/Memory.js similarity index 64% rename from Projects/Social-Trading/NT/Globals/Memory.js rename to Projects/Network/NT/Globals/Memory.js index b0b2b9458..560d7ad6f 100644 --- a/Projects/Social-Trading/NT/Globals/Memory.js +++ b/Projects/Network/NT/Globals/Memory.js @@ -1,12 +1,9 @@ -exports.newSocialTradingGlobalsMemory = function () { +exports.newNetworkGlobalsMemory = function () { /* Here is the Data we are going to keep in memory. */ let thisObject = { 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. EVENTS: new Map() // This is the registry of all events received that prevents processing them more than once. }, arrays: { diff --git a/Projects/Network/NT/Modules/WebSocketsInterface.js b/Projects/Network/NT/Modules/WebSocketsInterface.js index 63c192f76..ebad1b2cc 100644 --- a/Projects/Network/NT/Modules/WebSocketsInterface.js +++ b/Projects/Network/NT/Modules/WebSocketsInterface.js @@ -304,7 +304,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock /* The signature gives us the blockchain account, and the account the user profile. */ - let witnessUserProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_BLOCHAIN_ACCOUNT.get(caller.blockchainAccount) + let witnessUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOCHAIN_ACCOUNT.get(caller.blockchainAccount) if (witnessUserProfile === undefined) { let response = { diff --git a/Projects/Network/SA/Globals/Memory.js b/Projects/Network/SA/Globals/Memory.js new file mode 100644 index 000000000..7c86e1224 --- /dev/null +++ b/Projects/Network/SA/Globals/Memory.js @@ -0,0 +1,16 @@ +exports.newNetworkGlobalsMemory = function () { + /* + Here is the Data we are going to keep in memory. + */ + let thisObject = { + 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. + }, + arrays: { + } + } + + return thisObject +} \ No newline at end of file diff --git a/Projects/Network/SA/Utilities/NetworkNodePicker.js b/Projects/Network/SA/Utilities/NetworkNodePicker.js new file mode 100644 index 000000000..a80bc58e4 --- /dev/null +++ b/Projects/Network/SA/Utilities/NetworkNodePicker.js @@ -0,0 +1,12 @@ +exports.newNetworkNetworkNodePicker = function newNetworkNetworkNodePicker () { + let thisObject = { + pickOneNetworkNode: pickOneNetworkNode + } + + return thisObject + + function pickOneNetworkNode() { + + + } +} \ No newline at end of file diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index b8209b59c..1f033bcc4 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -311,7 +311,8 @@ "name": "Load Save Frame", "propertyName": "loadSaveFrame", "functionName": "newVisualScriptingUtilitiesLoadSaveFrame" - }, { + }, + { "name": "Meshes", "propertyName": "meshes", "functionName": "newVisualScriptingUtilitiesMeshes" @@ -1350,7 +1351,14 @@ "name": "Network", "propertyName": "network", "NT": { - "globals": [], + "globals": [ + { + "name": "Memory", + "propertyName": "memory", + "functionName": "newNetworkGlobalsMemory", + "fileName": "Memory.js" + } + ], "modules": [ { "name": "Web Sockets Interface", @@ -1368,7 +1376,14 @@ "utilities": [] }, "SA": { - "globals": [], + "globals": [ + { + "name": "Memory", + "propertyName": "memory", + "functionName": "newNetworkGlobalsMemory", + "fileName": "Memory.js" + } + ], "modules": [ { "name": "Web Sockets App Client", @@ -1377,21 +1392,21 @@ "fileName": "WebSocketsAppClient.js" } ], - "utilities": [] + "utilities": [ + { + "name": "Network Node Picker", + "propertyName": "networkNodePicker", + "functionName": "newNetworkNetworkNodePicker", + "fileName": "NetworkNodePicker.js" + } + ] } }, { "name": "Social-Trading", "propertyName": "socialTrading", "NT": { - "globals": [ - { - "name": "Memory", - "propertyName": "memory", - "functionName": "newSocialTradingGlobalsMemory", - "fileName": "Memory.js" - } - ], + "globals": [], "modules": [ { "name": "User Profiles", diff --git a/Projects/Social-Trading/NT/Modules/Bootstrap.js b/Projects/Social-Trading/NT/Modules/Bootstrap.js index d0b5fb2a6..45c5dad80 100644 --- a/Projects/Social-Trading/NT/Modules/Bootstrap.js +++ b/Projects/Social-Trading/NT/Modules/Bootstrap.js @@ -56,9 +56,9 @@ exports.newBootstrap = function newBootstrap() { ranking ) - NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.set(userProfileId, userProfile) - NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_HANDLE.set(userHandle, userProfile) - NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_BLOCHAIN_ACCOUNT.set(blockchainAccount, userProfile) + 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) /* Each User Profile might have Signing Accounts, meaning accounts that can be siging on behalf of the User Profile. @@ -70,7 +70,7 @@ exports.newBootstrap = function newBootstrap() { let signatureObject = config.signature let web3 = new SA.nodeModules.web3() let blockchainAccount = web3.eth.accounts.recover(signatureObject) - NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_BLOCHAIN_ACCOUNT.set(blockchainAccount, userProfile) + SA.projects.network.globals.memory.maps.USER_PROFILES_BY_BLOCHAIN_ACCOUNT.set(blockchainAccount, userProfile) } } } diff --git a/Projects/Social-Trading/NT/Modules/ClientInterface.js b/Projects/Social-Trading/NT/Modules/ClientInterface.js index b1791258a..60cc1be33 100644 --- a/Projects/Social-Trading/NT/Modules/ClientInterface.js +++ b/Projects/Social-Trading/NT/Modules/ClientInterface.js @@ -120,7 +120,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule We will not accept events that have already been processed. */ - if (NT.projects.socialTrading.globals.memory.maps.EVENTS.get(eventReceived.eventId) !== undefined) { + if (NT.projects.network.globals.memory.maps.EVENTS.get(eventReceived.eventId) !== undefined) { let response = { result: 'Error', message: 'Client Interface Event Already Exists.' @@ -133,8 +133,8 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule try { let event = NT.projects.socialTrading.modules.event.newSocialTradingModulesEvent() event.initialize(eventReceived) - NT.projects.socialTrading.globals.memory.maps.EVENTS.set(eventReceived.eventId, event) - NT.projects.socialTrading.globals.memory.arrays.EVENTS.push(event) + NT.projects.network.globals.memory.maps.EVENTS.set(eventReceived.eventId, event) + NT.projects.network.globals.memory.arrays.EVENTS.push(event) let response = { result: 'Ok', diff --git a/Projects/Social-Trading/NT/Modules/Event.js b/Projects/Social-Trading/NT/Modules/Event.js index f0bf34040..47c5fd45d 100644 --- a/Projects/Social-Trading/NT/Modules/Event.js +++ b/Projects/Social-Trading/NT/Modules/Event.js @@ -64,7 +64,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { if (thisObject.emitterUserProfileId === undefined) { throw ('Emitter User Profile Id Not Provided.') } - emitterUserProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) + emitterUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.emitterUserProfileId) if (emitterUserProfile === undefined) { throw ('Emitter User Profile Not Found.') } @@ -72,7 +72,7 @@ exports.newSocialTradingModulesEvent = function newSocialTradingModulesEvent() { Validate Target User Profile. */ if (thisObject.targetUserProfileId !== undefined) { - targetUserProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) + targetUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) if (targetUserProfile === undefined) { throw ('Target User Profile Not Found.') } diff --git a/Projects/Social-Trading/NT/Modules/Queries/BotProfileStats.js b/Projects/Social-Trading/NT/Modules/Queries/BotProfileStats.js index 2db10f72b..720f6e804 100644 --- a/Projects/Social-Trading/NT/Modules/Queries/BotProfileStats.js +++ b/Projects/Social-Trading/NT/Modules/Queries/BotProfileStats.js @@ -19,9 +19,9 @@ exports.newSocialTradingModulesQueriesBotProfileStats = function newSocialTradin */ let userProfile if (queryReceived.targetUserProfileId !== undefined) { - userProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + userProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } else { - userProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) + userProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) } if (userProfile === undefined) { diff --git a/Projects/Social-Trading/NT/Modules/Queries/Events.js b/Projects/Social-Trading/NT/Modules/Queries/Events.js index 352954b92..28d45def2 100644 --- a/Projects/Social-Trading/NT/Modules/Queries/Events.js +++ b/Projects/Social-Trading/NT/Modules/Queries/Events.js @@ -22,7 +22,7 @@ exports.newSocialTradingModulesQueriesEvents = function newSocialTradingModulesQ function initialize(queryReceived) { NT.projects.socialTrading.utilities.queriesValidations.profilesValidations(queryReceived, thisObject) - NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, NT.projects.socialTrading.globals.memory.arrays.EVENTS) + NT.projects.socialTrading.utilities.queriesValidations.arrayValidations(queryReceived, thisObject, NT.projects.network.globals.memory.arrays.EVENTS) } @@ -31,7 +31,7 @@ exports.newSocialTradingModulesQueriesEvents = function newSocialTradingModulesQ switch (thisObject.direction) { case SA.projects.socialTrading.globals.queryConstants.DIRECTION_FUTURE: { for (let i = thisObject.initialIndex; i < thisObject.initialIndex + thisObject.amountRequested; i++) { - let event = NT.projects.socialTrading.globals.memory.arrays.EVENTS[i] + let event = NT.projects.network.globals.memory.arrays.EVENTS[i] if (event === undefined) { break } checkEventContext(event) } @@ -39,7 +39,7 @@ exports.newSocialTradingModulesQueriesEvents = function newSocialTradingModulesQ } case SA.projects.socialTrading.globals.queryConstants.DIRECTION_PAST: { for (let i = thisObject.initialIndex; i > thisObject.initialIndex - thisObject.amountRequested; i--) { - let event = NT.projects.socialTrading.globals.memory.arrays.EVENTS[i] + let event = NT.projects.network.globals.memory.arrays.EVENTS[i] if (event === undefined) { break } checkEventContext(event) } @@ -59,11 +59,11 @@ exports.newSocialTradingModulesQueriesEvents = function newSocialTradingModulesQ Any of the above happening, means that indeed it is related. */ - let emitterUserProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(event.emitterUserProfileId) + let emitterUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(event.emitterUserProfileId) let emitterBotProfile = emitterUserProfile.bots.get(event.emitterBotProfileId) let emitterPost = emitterUserProfile.posts.get(event.emitterPostHash) - let targetUserProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(event.targetUserProfileId) + let targetUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(event.targetUserProfileId) let targetBotProfile let targetPost diff --git a/Projects/Social-Trading/NT/Modules/Queries/UnfollowedUserProfiles.js b/Projects/Social-Trading/NT/Modules/Queries/UnfollowedUserProfiles.js index 51a9b0d23..fc01a7e60 100644 --- a/Projects/Social-Trading/NT/Modules/Queries/UnfollowedUserProfiles.js +++ b/Projects/Social-Trading/NT/Modules/Queries/UnfollowedUserProfiles.js @@ -24,13 +24,13 @@ exports.newSocialTradingModulesQueriesUnfollowedUserProfiles = function newSocia function initialize(queryReceived) { - thisObject.emitterUserProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.emitterUserProfileId) + thisObject.emitterUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.emitterUserProfileId) if (thisObject.emitterUserProfile === undefined) { throw ('Emitter User Profile Not Found.') } thisObject.profiles = Array.from( - NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID, + SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID, x => x[1] ) thisObject.profiles.sort((a, b) => (a["ranking"] > b["ranking"]) ? 1 : -1) diff --git a/Projects/Social-Trading/NT/Modules/Queries/UserProfileStats.js b/Projects/Social-Trading/NT/Modules/Queries/UserProfileStats.js index 5825be95f..75e3ab41f 100644 --- a/Projects/Social-Trading/NT/Modules/Queries/UserProfileStats.js +++ b/Projects/Social-Trading/NT/Modules/Queries/UserProfileStats.js @@ -18,9 +18,9 @@ exports.newSocialTradingModulesQueriesUserProfileStats = function newSocialTradi Validate User Profile */ if (queryReceived.targetUserProfileId !== undefined) { - thisObject.profile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + thisObject.profile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) } else { - thisObject.profile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) + thisObject.profile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_HANDLE.get(queryReceived.targetUserProfileHandle) } if (thisObject.profile === undefined) { diff --git a/Projects/Social-Trading/NT/Modules/Queries/UserProfiles.js b/Projects/Social-Trading/NT/Modules/Queries/UserProfiles.js index 57b93bd74..f52467202 100644 --- a/Projects/Social-Trading/NT/Modules/Queries/UserProfiles.js +++ b/Projects/Social-Trading/NT/Modules/Queries/UserProfiles.js @@ -23,7 +23,7 @@ exports.newSocialTradingModulesQueriesUserProfiles = function newSocialTradingMo function initialize(queryReceived) { thisObject.profiles = Array.from( - NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID, + SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID, x => x[1] ) thisObject.profiles.sort((a, b) => (a["ranking"] > b["ranking"]) ? 1 : -1) diff --git a/Projects/Social-Trading/NT/Modules/Social-Graph/Post.js b/Projects/Social-Trading/NT/Modules/Social-Graph/Post.js index d462cab83..4975b2c50 100644 --- a/Projects/Social-Trading/NT/Modules/Social-Graph/Post.js +++ b/Projects/Social-Trading/NT/Modules/Social-Graph/Post.js @@ -99,7 +99,7 @@ exports.newSocialTradingModulesSocialGraphPost = function newSocialTradingModule /* Validate Target User Profile. */ - let targetUserProfile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) + let targetUserProfile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(thisObject.targetUserProfileId) if (targetUserProfile === undefined) { throw ('Target User Profile Not Found.') } diff --git a/Projects/Social-Trading/NT/Modules/Storage.js b/Projects/Social-Trading/NT/Modules/Storage.js index fa59b092e..105815bb9 100644 --- a/Projects/Social-Trading/NT/Modules/Storage.js +++ b/Projects/Social-Trading/NT/Modules/Storage.js @@ -54,9 +54,9 @@ exports.newSocialTradingModulesStorage = function newSocialTradingModulesStorage try { let event = NT.projects.socialTrading.modules.event.newSocialTradingModulesEvent() event.initialize(storedEvent) - NT.projects.socialTrading.globals.memory.maps.EVENTS.set(storedEvent.eventId, event) - NT.projects.socialTrading.globals.memory.arrays.EVENTS.push(event) - indexLastSavedEvent = NT.projects.socialTrading.globals.memory.arrays.EVENTS.length - 1 + NT.projects.network.globals.memory.maps.EVENTS.set(storedEvent.eventId, event) + NT.projects.network.globals.memory.arrays.EVENTS.push(event) + indexLastSavedEvent = NT.projects.network.globals.memory.arrays.EVENTS.length - 1 } catch (err) { if (err.stack !== undefined) { console.log('[ERROR] Client Interface -> err.stack = ' + err.stack) @@ -94,8 +94,8 @@ exports.newSocialTradingModulesStorage = function newSocialTradingModulesStorage let eventsToSave = [] let minuteToSave - for (let i = indexLastSavedEvent + 1; i < NT.projects.socialTrading.globals.memory.arrays.EVENTS.length; i++) { - let event = NT.projects.socialTrading.globals.memory.arrays.EVENTS[i] + for (let i = indexLastSavedEvent + 1; i < NT.projects.network.globals.memory.arrays.EVENTS.length; i++) { + let event = NT.projects.network.globals.memory.arrays.EVENTS[i] let currentMinute = Math.trunc((new Date()).valueOf() / SA.projects.foundations.globals.timeConstants.ONE_MIN_IN_MILISECONDS) let eventMinute = Math.trunc(event.timestamp / SA.projects.foundations.globals.timeConstants.ONE_MIN_IN_MILISECONDS) diff --git a/Projects/Social-Trading/NT/Utilities/QueriesValidations.js b/Projects/Social-Trading/NT/Utilities/QueriesValidations.js index 7f2e6f566..ffb20ecbd 100644 --- a/Projects/Social-Trading/NT/Utilities/QueriesValidations.js +++ b/Projects/Social-Trading/NT/Utilities/QueriesValidations.js @@ -15,14 +15,14 @@ exports.newSocialTradingUtilitiesQueriesValidations = function newSocialTradingU Validate User Profile */ if (queryReceived.emitterUserProfileId !== undefined) { - thisObject.profile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.emitterUserProfileId) + thisObject.profile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.emitterUserProfileId) if (thisObject.profile === undefined) { throw ('Emitter User Profile Not Found.') } } if (queryReceived.targetUserProfileId !== undefined) { - thisObject.profile = NT.projects.socialTrading.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) + thisObject.profile = SA.projects.network.globals.memory.maps.USER_PROFILES_BY_ID.get(queryReceived.targetUserProfileId) if (thisObject.profile === undefined) { throw ('Target User Profile Not Found.') }