Task Server connecting itself to the p2p Network
This commit is contained in:
1 parent
dfca398d7a
commit
524c9ec28a
5 files changed
+88
-32
No files matched your search
@@ -32,6 +32,7 @@ exports.newEnvironment = function () {
|
||||
PATH_TO_FONTS: path.join(basePath, './Platform/WebServer/Fonts'),
|
||||
DESKTOP_APP_SIGNING_ACCOUNT: 'Social-Trading-Desktop-App-1',
|
||||
DESKTOP_APP_MAX_OUTGOING_PEERS: 1,
|
||||
TASK_SERVER_APP_MAX_OUTGOING_PEERS: 1,
|
||||
MOBILE_APP_SIGNING_ACCOUNT: 'Social-Trading-Mobile-App-1',
|
||||
SERVER_APP_SIGNING_ACCOUNT: 'Social-Trading-Server-App-1',
|
||||
PLATFORM_APP_SIGNING_ACCOUNT: 'Algo-Traders-Platform-1',
|
||||
|
||||
@@ -9,6 +9,7 @@ exports.newFoundationsGlobalsTaskConstants = function () {
|
||||
PROJECT_DEFINITION_NODE: undefined,
|
||||
PROJECTS_SCHEMA: undefined,
|
||||
EVENT_SERVER_CLIENT_MODULE_OBJECT: undefined, // This is an instance of the Event Server Client pointing to the localhost server
|
||||
P2P_NETWORK: undefined,
|
||||
TASK_HEARTBEAT_INTERVAL_HANDLER: undefined
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ function newFoundationsFunctionLibraryTaskFunctions() {
|
||||
}
|
||||
|
||||
let taskLightingPath = '->Task->' +
|
||||
'Task Server App Reference->Signing Account->'
|
||||
'Task Server App Reference->Task Server App->Signing Account->' +
|
||||
'Sensor Bot Instance->' +
|
||||
'API Data Fetcher Bot Instance->' +
|
||||
'Indicator Bot Instance->' +
|
||||
|
||||
+74
-31
@@ -82,10 +82,12 @@ exports.newTaskServer = function newTaskServer() {
|
||||
}
|
||||
}
|
||||
|
||||
function bootingProcess() {
|
||||
async function bootingProcess() {
|
||||
try {
|
||||
initializeProjectDefinitionNode()
|
||||
await setupNetwork()
|
||||
setupTaskHeartbeats()
|
||||
startProcesses()
|
||||
|
||||
function initializeProjectDefinitionNode() {
|
||||
TS.projects.foundations.globals.taskConstants.PROJECT_DEFINITION_NODE = SA.projects.visualScripting.utilities.nodeFunctions.findNodeInNodeMesh(TS.projects.foundations.globals.taskConstants.TASK_NODE, 'Project Definition')
|
||||
@@ -109,6 +111,45 @@ exports.newTaskServer = function newTaskServer() {
|
||||
}
|
||||
}
|
||||
|
||||
async function setupNetwork() {
|
||||
/*
|
||||
If we received a App Server Reference Node and a Signing Account, then we will connect to the P2P Network
|
||||
*/
|
||||
if (
|
||||
TS.projects.foundations.globals.taskConstants.TASK_NODE.taskServerAppReference === undefined ||
|
||||
TS.projects.foundations.globals.taskConstants.TASK_NODE.taskServerAppReference.referenceParent === undefined ||
|
||||
TS.projects.foundations.globals.taskConstants.TASK_NODE.taskServerAppReference.referenceParent.signingAccount === undefined
|
||||
) {
|
||||
return
|
||||
}
|
||||
TS.projects.foundations.globals.taskConstants.P2P_NETWORK = {}
|
||||
/*
|
||||
We set up ourselves as a Network Client.
|
||||
*/
|
||||
TS.projects.foundations.globals.taskConstants.P2P_NETWORK.p2pNetworkClient = SA.projects.network.modules.p2pNetworkClient.newNetworkModulesP2PNetworkClient()
|
||||
await TS.projects.foundations.globals.taskConstants.P2P_NETWORK.p2pNetworkClient.initialize()
|
||||
/*
|
||||
We will read all user profiles plugins and get from there our network identity.
|
||||
*/
|
||||
TS.projects.foundations.globals.taskConstants.P2P_NETWORK.userProfiles = SA.projects.network.modules.userProfiles.newNetworkModulesUserProfiles()
|
||||
await TS.projects.foundations.globals.taskConstants.P2P_NETWORK.userProfiles.initialize(TS.projects.foundations.globals.taskConstants.TASK_NODE.taskServerAppReference.referenceParent.config.codeName, TS.projects.foundations.globals.taskConstants.P2P_NETWORK.p2pNetworkClient)
|
||||
/*
|
||||
We set up the P2P Network.
|
||||
*/
|
||||
TS.projects.foundations.globals.taskConstants.P2P_NETWORK.p2pNetwork = SA.projects.network.modules.p2pNetwork.newNetworkModulesP2PNetwork()
|
||||
await TS.projects.foundations.globals.taskConstants.P2P_NETWORK.p2pNetwork.initialize('Network Client')
|
||||
/*
|
||||
Set up the connections to network nodes.
|
||||
*/
|
||||
TS.projects.foundations.globals.taskConstants.P2P_NETWORK.p2pNetworkPeers = SA.projects.network.modules.p2pNetworkPeers.newNetworkModulesP2PNetworkPeers()
|
||||
await TS.projects.foundations.globals.taskConstants.P2P_NETWORK.p2pNetworkPeers.initialize(
|
||||
'Network Client',
|
||||
TS.projects.foundations.globals.taskConstants.P2P_NETWORK.p2pNetworkClient,
|
||||
TS.projects.foundations.globals.taskConstants.P2P_NETWORK.p2pNetwork,
|
||||
global.env.TASK_SERVER_APP_MAX_OUTGOING_PEERS
|
||||
)
|
||||
}
|
||||
|
||||
function setupTaskHeartbeats() {
|
||||
/*
|
||||
Heartbeat sent to the UI
|
||||
@@ -129,42 +170,44 @@ exports.newTaskServer = function newTaskServer() {
|
||||
}
|
||||
}
|
||||
|
||||
for (let processIndex = 0; processIndex < TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes.length; processIndex++) {
|
||||
/*
|
||||
Here we will validate that the process is connected all the way to a Mine
|
||||
and that nodes in the middle have whatever config is mandatory.
|
||||
*/
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Process Instance without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex]));
|
||||
continue
|
||||
}
|
||||
function startProcesses() {
|
||||
for (let processIndex = 0; processIndex < TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes.length; processIndex++) {
|
||||
/*
|
||||
Here we will validate that the process is connected all the way to a Mine
|
||||
and that nodes in the middle have whatever config is mandatory.
|
||||
*/
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Process Instance without a Reference Parent. This process will not be executed. -> Process Instance = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex]));
|
||||
continue
|
||||
}
|
||||
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Process Definition without parent Bot Definition. -> Process Definition = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent));
|
||||
continue
|
||||
}
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Process Definition without parent Bot Definition. -> Process Definition = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent));
|
||||
continue
|
||||
}
|
||||
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Bot Definition without parent Mine. -> Bot Definition = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode));
|
||||
continue
|
||||
}
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Bot Definition without parent Mine. -> Bot Definition = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode));
|
||||
continue
|
||||
}
|
||||
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Process Definition without a codeName defined. -> Process Definition = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent));
|
||||
continue
|
||||
}
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.config.codeName === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Process Definition without a codeName defined. -> Process Definition = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent));
|
||||
continue
|
||||
}
|
||||
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.config.codeName === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Bot Definition without a codeName defined. -> Bot Definition = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode));
|
||||
continue
|
||||
}
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.config.codeName === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Bot Definition without a codeName defined. -> Bot Definition = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode));
|
||||
continue
|
||||
}
|
||||
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Mine without a codeName defined. -> Mine Definition = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode));
|
||||
continue
|
||||
}
|
||||
if (TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode.config.codeName === undefined) {
|
||||
console.log("[ERROR] Task Server -> Task -> bootingProcess -> Mine without a codeName defined. -> Mine Definition = " + JSON.stringify(TS.projects.foundations.globals.taskConstants.TASK_NODE.bot.processes[processIndex].referenceParent.parentNode.parentNode));
|
||||
continue
|
||||
}
|
||||
|
||||
startProcessInstance(processIndex);
|
||||
startProcessInstance(processIndex);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('[ERROR] Task Server -> Task -> bootingProcess -> Fatal Error. Can not run this task. -> ' + err.stack)
|
||||
|
||||
@@ -55,6 +55,17 @@ SA.nodeModules = {
|
||||
lookpath: require('lookpath'),
|
||||
twitter: require('twitter')
|
||||
}
|
||||
/*
|
||||
Setting up Secrets.
|
||||
*/
|
||||
SA.secrets = {
|
||||
array: require('./My-Secrets/Secrets.json').secrets,
|
||||
map: new Map()
|
||||
}
|
||||
for (let i = 0; i < SA.secrets.array.length; i++) {
|
||||
let secret = SA.secrets.array[i]
|
||||
SA.secrets.map.set(secret.nodeCodeName, secret)
|
||||
}
|
||||
|
||||
run()
|
||||
|
||||
|
||||
Reference in new issue
Block a user