Skip to content

Commit

Permalink
Merge pull request #127 from zelcash/development
Browse files Browse the repository at this point in the history
v0.68.0
  • Loading branch information
TheTrunk authored Jul 29, 2020
2 parents 38491e5 + d52546e commit 2abddad
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 7 deletions.
9 changes: 9 additions & 0 deletions ZelBack/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,15 @@ module.exports = (app, expressWs) => {
app.get('/zelapps/installtemporarylocalapp/zelFoldingAtHome', (req, res) => {
zelappsService.temporaryZelAppRegisterFunctionForFoldingAtHome(req, res);
});
app.get('/zelapps/installtemporarylocalapp/dibi-UND', (req, res) => {
zelappsService.temporaryZelAppRegisterFunctionForDibiFetch(req, res);
});
app.get('/zelapps/installtemporarylocalapp/SuperMario', (req, res) => {
zelappsService.temporaryZelAppRegisterFunctionForSuperMario(req, res);
});
app.get('/zelapps/installtemporarylocalapp/PacMan', (req, res) => {
zelappsService.temporaryZelAppRegisterFunctionForPacMan(req, res);
});
app.get('/zelapps/createzelfluxnetwork', (req, res) => {
zelappsService.createZelFluxNetwork(req, res);
});
Expand Down
234 changes: 234 additions & 0 deletions ZelBack/src/services/zelappsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,14 @@ async function storeZelAppRunningMessage(message) {

const validTill = message.broadcastedAt + (3900 * 1000); // 3900 seconds

if (validTill < new Date().getTime()) {
// reject old message
return false;
}

const randomDelay = Math.floor((Math.random() * 1280)) + 240;
await serviceHelper.delay(randomDelay);

const db = serviceHelper.databaseConnection();
const database = db.db(config.database.zelappsglobal.database);
const newZelAppRunningMessage = {
Expand Down Expand Up @@ -2505,6 +2513,178 @@ async function temporaryZelAppRegisterFunctionForFoldingAtHome(req, res) {
}
}

async function temporaryZelAppRegisterFunctionForDibiFetch(req, res) {
try {
const authorized = await serviceHelper.verifyPrivilege('zelteam', req);
if (authorized) {
// ram is specified in MB, hdd specified in GB
const zelAppSpecifications = {
name: 'dibi-UND', // corresponds to docker name and this name is stored in zelapps mongo database
description: 'dibi fetch basic description',
repotag: 't1dev/dibi-fetch:latest',
owner: '1CbErtneaX2QVyUfwU7JGB7VzvPgrgc3uC',
port: 30003,
tiered: false,
cpu: 0.2, // true resource registered for app. If not tiered only this is available
ram: 200, // true resource registered for app
hdd: 1, // true resource registered for app
enviromentParameters: [],
commands: [],
containerPort: 80,
containerData: '/app',
hash: 'ahashofappmessage', // hash of app message
height: 2, // height of tx on which it was
};

// get our tier and adjust true resource registered
if (zelAppSpecifications.tiered) {
const tier = await zelnodeTier();
if (tier === 'basic') {
zelAppSpecifications.cpu = zelAppSpecifications.cpubasic || zelAppSpecifications.cpu;
zelAppSpecifications.ram = zelAppSpecifications.rambasic || zelAppSpecifications.ram;
} else if (tier === 'super') {
zelAppSpecifications.cpu = zelAppSpecifications.cpusuper || zelAppSpecifications.cpu;
zelAppSpecifications.ram = zelAppSpecifications.ramsuper || zelAppSpecifications.ram;
} else if (tier === 'bamf') {
zelAppSpecifications.cpu = zelAppSpecifications.cpubamf || zelAppSpecifications.cpu;
zelAppSpecifications.ram = zelAppSpecifications.rambamf || zelAppSpecifications.ram;
} else {
throw new Error('Unrecognised ZelNode tier');
}
}

res.setHeader('Content-Type', 'application/json');
registerZelAppLocally(zelAppSpecifications, res);
} else {
const errMessage = serviceHelper.errUnauthorizedMessage();
res.json(errMessage);
}
} catch (error) {
log.error(error);
const errorResponse = serviceHelper.createErrorMessage(
error.message || error,
error.name,
error.code,
);
res.json(errorResponse);
}
}


async function temporaryZelAppRegisterFunctionForSuperMario(req, res) {
try {
const authorized = await serviceHelper.verifyPrivilege('zelteam', req);
if (authorized) {
// ram is specified in MB, hdd specified in GB
const zelAppSpecifications = {
name: 'SuperMario', // corresponds to docker name and this name is stored in zelapps mongo database
description: 'LoL SuperMario',
repotag: 'pengbai/docker-supermario:latest',
owner: '1CbErtneaX2QVyUfwU7JGB7VzvPgrgc3uC',
port: 30001,
tiered: false,
cpu: 0.2, // true resource registered for app. If not tiered only this is available
ram: 200, // true resource registered for app
hdd: 1, // true resource registered for app
enviromentParameters: [],
commands: [],
containerPort: 8080,
containerData: '/tmp', // cannot be root todo in verification
hash: 'ahashofappmessage', // hash of app message
height: 3, // height of tx on which it was
};

// get our tier and adjust true resource registered
if (zelAppSpecifications.tiered) {
const tier = await zelnodeTier();
if (tier === 'basic') {
zelAppSpecifications.cpu = zelAppSpecifications.cpubasic || zelAppSpecifications.cpu;
zelAppSpecifications.ram = zelAppSpecifications.rambasic || zelAppSpecifications.ram;
} else if (tier === 'super') {
zelAppSpecifications.cpu = zelAppSpecifications.cpusuper || zelAppSpecifications.cpu;
zelAppSpecifications.ram = zelAppSpecifications.ramsuper || zelAppSpecifications.ram;
} else if (tier === 'bamf') {
zelAppSpecifications.cpu = zelAppSpecifications.cpubamf || zelAppSpecifications.cpu;
zelAppSpecifications.ram = zelAppSpecifications.rambamf || zelAppSpecifications.ram;
} else {
throw new Error('Unrecognised ZelNode tier');
}
}

res.setHeader('Content-Type', 'application/json');
registerZelAppLocally(zelAppSpecifications, res);
} else {
const errMessage = serviceHelper.errUnauthorizedMessage();
res.json(errMessage);
}
} catch (error) {
log.error(error);
const errorResponse = serviceHelper.createErrorMessage(
error.message || error,
error.name,
error.code,
);
res.json(errorResponse);
}
}

async function temporaryZelAppRegisterFunctionForPacMan(req, res) {
try {
const authorized = await serviceHelper.verifyPrivilege('zelteam', req);
if (authorized) {
// ram is specified in MB, hdd specified in GB
const zelAppSpecifications = {
name: 'PacMan', // corresponds to docker name and this name is stored in zelapps mongo database
description: 'LoL PacMan',
repotag: 'uzyexe/pacman:latest',
owner: '1CbErtneaX2QVyUfwU7JGB7VzvPgrgc3uC',
port: 30002,
tiered: false,
cpu: 0.2, // true resource registered for app. If not tiered only this is available
ram: 200, // true resource registered for app
hdd: 1, // true resource registered for app
enviromentParameters: [],
commands: [],
containerPort: 80,
containerData: '/tmp', // cannot be root todo in verification
hash: 'ahashofappmessage', // hash of app message
height: 4, // height of tx on which it was
};

// get our tier and adjust true resource registered
if (zelAppSpecifications.tiered) {
const tier = await zelnodeTier();
if (tier === 'basic') {
zelAppSpecifications.cpu = zelAppSpecifications.cpubasic || zelAppSpecifications.cpu;
zelAppSpecifications.ram = zelAppSpecifications.rambasic || zelAppSpecifications.ram;
} else if (tier === 'super') {
zelAppSpecifications.cpu = zelAppSpecifications.cpusuper || zelAppSpecifications.cpu;
zelAppSpecifications.ram = zelAppSpecifications.ramsuper || zelAppSpecifications.ram;
} else if (tier === 'bamf') {
zelAppSpecifications.cpu = zelAppSpecifications.cpubamf || zelAppSpecifications.cpu;
zelAppSpecifications.ram = zelAppSpecifications.rambamf || zelAppSpecifications.ram;
} else {
throw new Error('Unrecognised ZelNode tier');
}
}

res.setHeader('Content-Type', 'application/json');
registerZelAppLocally(zelAppSpecifications, res);
} else {
const errMessage = serviceHelper.errUnauthorizedMessage();
res.json(errMessage);
}
} catch (error) {
log.error(error);
const errorResponse = serviceHelper.createErrorMessage(
error.message || error,
error.name,
error.code,
);
res.json(errorResponse);
}
}

async function availableZelApps(req, res) {
// calls to global mongo db
// simulate a similar response
Expand Down Expand Up @@ -2540,6 +2720,57 @@ async function availableZelApps(req, res) {
hash: 'localappinstancehashABCDE', // hash of app message
height: 0, // height of tx on which it was
},
// {
// name: 'SuperMario', // corresponds to docker name and this name is stored in zelapps mongo database
// description: 'LoL SuperMario',
// repotag: 'pengbai/docker-supermario:latest',
// owner: '1CbErtneaX2QVyUfwU7JGB7VzvPgrgc3uC',
// port: 30001,
// tiered: false,
// cpu: 0.2, // true resource registered for app. If not tiered only this is available
// ram: 200, // true resource registered for app
// hdd: 1, // true resource registered for app
// enviromentParameters: [],
// commands: [],
// containerPort: 8080,
// containerData: '/tmp', // cannot be root todo in verification
// hash: 'ahashofappmessage', // hash of app message
// height: 3, // height of tx on which it was
// },
// {
// name: 'PacMan', // corresponds to docker name and this name is stored in zelapps mongo database
// description: 'LoL PacMan',
// repotag: 'uzyexe/pacman:latest',
// owner: '1CbErtneaX2QVyUfwU7JGB7VzvPgrgc3uC',
// port: 30002,
// tiered: false,
// cpu: 0.2, // true resource registered for app. If not tiered only this is available
// ram: 200, // true resource registered for app
// hdd: 1, // true resource registered for app
// enviromentParameters: [],
// commands: [],
// containerPort: 80,
// containerData: '/tmp', // cannot be root todo in verification
// hash: 'ahashofappmessage', // hash of app message
// height: 4, // height of tx on which it was
// },
// {
// name: 'dibi-UND', // corresponds to docker name and this name is stored in zelapps mongo database
// description: 'dibi fetch basic description',
// repotag: 't1dev/dibi-fetch:latest',
// owner: '1CbErtneaX2QVyUfwU7JGB7VzvPgrgc3uC',
// port: 30003,
// tiered: false,
// cpu: 0.2, // true resource registered for app. If not tiered only this is available
// ram: 200, // true resource registered for app
// hdd: 1, // true resource registered for app
// enviromentParameters: [],
// commands: [],
// containerPort: 80,
// containerData: '/app', // cannot be root todo in verification
// hash: 'ahashofappmessage', // hash of app message
// height: 2, // height of tx on which it was
// },
];

const dataResponse = serviceHelper.createDataMessage(zelapps);
Expand Down Expand Up @@ -3578,4 +3809,7 @@ module.exports = {
reindexGlobalAppsInformationAPI,
reindexGlobalAppsLocationAPI,
expireGlobalApplications,
temporaryZelAppRegisterFunctionForSuperMario,
temporaryZelAppRegisterFunctionForPacMan,
temporaryZelAppRegisterFunctionForDibiFetch,
};
18 changes: 12 additions & 6 deletions ZelBack/src/services/zelfluxCommunication.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,18 @@ async function verifyTimestampInFluxBroadcast(data, currentTimeStamp) {
return false;
}

function sendToAllPeers(data, wsList) {
async function sendToAllPeers(data, wsList) {
try {
let removals = [];
let ipremovals = [];
// console.log(data);
// wsList is always a sublist of outgoingConnections
const outConList = wsList || outgoingConnections;
outConList.forEach((client) => {
// eslint-disable-next-line no-restricted-syntax
for (const client of outConList) {
try {
// eslint-disable-next-line no-await-in-loop
await serviceHelper.delay(100);
client.send(data);
} catch (e) {
log.error(e);
Expand All @@ -207,7 +210,7 @@ function sendToAllPeers(data, wsList) {
log.error(err);
}
}
});
}

for (let i = 0; i < ipremovals.length; i += 1) {
const peerIndex = outgoingPeers.indexOf(ipremovals[i]);
Expand All @@ -228,15 +231,18 @@ function sendToAllPeers(data, wsList) {
}
}

function sendToAllIncomingConnections(data, wsList) {
async function sendToAllIncomingConnections(data, wsList) {
try {
let removals = [];
let ipremovals = [];
// console.log(data);
// wsList is always a sublist of incomingConnections
const incConList = wsList || incomingConnections;
incConList.forEach((client) => {
// eslint-disable-next-line no-restricted-syntax
for (const client of incConList) {
try {
// eslint-disable-next-line no-await-in-loop
await serviceHelper.delay(100);
client.send(data);
} catch (e) {
log.error(e);
Expand All @@ -249,7 +255,7 @@ function sendToAllIncomingConnections(data, wsList) {
log.error(err);
}
}
});
}

for (let i = 0; i < ipremovals.length; i += 1) {
const peerIndex = incomingPeers.indexOf(ipremovals[i]);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zelflux",
"version": "0.67.1",
"version": "0.68.0",
"description": "Flux - Node Daemon. The entrace to the Flux network.",
"repository": {
"type": "git",
Expand Down

0 comments on commit 2abddad

Please sign in to comment.