Minor changes

- config.json and param.json moved to args/
- param-default.json will be used by default if param.json is not generated by the user
- Renamed launch.js to start.js
- Minor bug fixes
This commit is contained in:
sairajzero 2021-07-29 20:34:29 +05:30
parent 9001b21b07
commit 25a342a2db
12 changed files with 105 additions and 56 deletions

8
.gitignore vendored
View File

@ -1,4 +1,4 @@
node_modules/ /node_modules/
package-lock.json /package-lock.json
config.json /args/config.json
param.json /args/param.json

View File

@ -22,7 +22,11 @@ npm install
### Configuration ### Configuration
#### General Configuration #### General Configuration
Copy `config-sample.json` to `config.json` and Edit the values as required. In `args/` directory, Copy `config-sample.json` to `config.json`.
```
cp args/config-sample.json args/config.json
```
Edit the values in `args/config.json` as required.
``` ```
{ {
"privateKey": "<private-key>", "privateKey": "<private-key>",
@ -43,10 +47,10 @@ Copy `config-sample.json` to `config.json` and Edit the values as required.
***Recommended*** *(optional)* Create and use a MySQL user instead of root. Remember to give access to the database to the user. ***Recommended*** *(optional)* Create and use a MySQL user instead of root. Remember to give access to the database to the user.
#### Parameter Generation #### Parameter Generation *(Optional)*
Open `gen-param.html` in a browser and download `param.json` to `SuperNodeStorage` directory. Open `args/gen-param.html` in a browser and download `param.json` to `SuperNodeStorage/args` directory.
*Note: param.json is used for controlled random values used by SecureRandom in Cryptography* *Note: `param.json` is used for controlled random values used by SecureRandom in Cryptography. If this step is skipped, `param-default.json` will be used as default parameter*
## Starting the Server ## Starting the Server
After successful installation and configuration using the above steps, SuperNodeStorage can be started using: After successful installation and configuration using the above steps, SuperNodeStorage can be started using:

37
args/param-default.json Normal file
View File

@ -0,0 +1,37 @@
{
"screen": {
"height": 1160,
"width": 2000,
"colorDepth": 24,
"availHeight": 1080,
"availWidth": 1920,
"pixelDepth": 24
},
"navigator": {
"userAgent": "Node/14.17.3 (Linux; aarch64; arm)",
"plugins": [{
"name": "MySQL",
"filename": "mysql",
"description": "A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed."
}, {
"name": "WebSocket",
"filename": "ws",
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js"
}, {
"name": "Node fetch",
"filename": "node-fetch",
"description": "A light-weight module that brings window.fetch to node.js"
}],
"mimeTypes": [{
"description": "",
"type": "application/pdf",
"suffixes": "pdf"
}],
"cookieEnabled": true,
"language": "en-US"
},
"history": {
"length": 512
},
"location": "protocol://subdomain.example.domain/path"
}

11
args/post-install.js Normal file
View File

@ -0,0 +1,11 @@
let message =
`SupernodeStorage is installed.
To complete the setup:
1. Copy args/config-sample.json to args/config.json and Edit the values as required
2. (Optional) Open args/gen-param.html and Download param.json to args/ directory
To start the node, Run:
npm start
`;
console.log(message);

View File

@ -10,8 +10,8 @@
}, },
"devDependencies": {}, "devDependencies": {},
"scripts": { "scripts": {
"postinstall": "node post-install.js", "postinstall": "node args/post-install.js",
"start": "node launch.js" "start": "node start.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -1,11 +0,0 @@
let message =
`SupernodeStorage is installed.
To complete the setup:
1. Open gen-param.html and Download param.json to this directory
2. Copy config-sample.json to config.json and Edit the values
To start the node, Run:
npm start
`;
console.log(message);

View File

@ -125,7 +125,7 @@ _prevNode.onclose = evt => _prevNode.close();
//Packet processing //Packet processing
const packet_ = {}; const packet_ = {};
packet_.constuct = function(message) { packet_.construct = function(message) {
const packet = { const packet = {
from: myFloID, from: myFloID,
message: message, message: message,
@ -189,7 +189,7 @@ function connectToNextNode() {
let nextNodeID = kBucket.nextNode(myFloID); let nextNodeID = kBucket.nextNode(myFloID);
connectToActiveNode(nextNodeID).then(ws => { connectToActiveNode(nextNodeID).then(ws => {
_nextNode.set(nextNodeID, ws); _nextNode.set(nextNodeID, ws);
_nextNode.send(packet_.constuct({ _nextNode.send(packet_.construct({
type: BACKUP_HANDSHAKE_INIT type: BACKUP_HANDSHAKE_INIT
})); }));
resolve("BACKUP_HANDSHAKE_INIT: " + nextNodeID); resolve("BACKUP_HANDSHAKE_INIT: " + nextNodeID);
@ -247,7 +247,7 @@ function processTaskFromNextNode(packet) {
dataSyncIndication(task.id, task.status, from); dataSyncIndication(task.id, task.status, from);
break; break;
case STORE_BACKUP_DATA: case STORE_BACKUP_DATA:
storeBackupData(task.data); storeBackupData(task.data, from, packet);
break; break;
default: default:
console.log("Invalid task type:" + task.type + "from next-node"); console.log("Invalid task type:" + task.type + "from next-node");
@ -324,18 +324,18 @@ function handshakeMid(id, ws) {
if (_prevNode.id && _prevNode.id in floGlobals.supernodes) { if (_prevNode.id && _prevNode.id in floGlobals.supernodes) {
if (kBucket.innerNodes(_prevNode.id, myFloID).includes(id)) { if (kBucket.innerNodes(_prevNode.id, myFloID).includes(id)) {
//close existing prev-node connection //close existing prev-node connection
_prevNode.send(packet_.constuct({ _prevNode.send(packet_.construct({
type: RECONNECT_NEXT_NODE type: RECONNECT_NEXT_NODE
})); }));
_prevNode.close(); _prevNode.close();
//set the new prev-node connection //set the new prev-node connection
_prevNode.set(id, ws); _prevNode.set(id, ws);
_prevNode.send(packet_.constuct({ _prevNode.send(packet_.construct({
type: BACKUP_HANDSHAKE_END type: BACKUP_HANDSHAKE_END
})); }));
} else { } else {
//Incorrect order, existing prev-node is already after the incoming node //Incorrect order, existing prev-node is already after the incoming node
ws.send(packet_.constuct({ ws.send(packet_.construct({
type: RECONNECT_NEXT_NODE type: RECONNECT_NEXT_NODE
})); }));
return; return;
@ -343,7 +343,7 @@ function handshakeMid(id, ws) {
} else { } else {
//set the new prev-node connection //set the new prev-node connection
_prevNode.set(id, ws); _prevNode.set(id, ws);
_prevNode.send(packet_.constuct({ _prevNode.send(packet_.construct({
type: BACKUP_HANDSHAKE_END type: BACKUP_HANDSHAKE_END
})); }));
}; };
@ -404,7 +404,7 @@ handshakeMid.requestData = function(req_sync, new_order) {
type: ORDER_BACKUP, type: ORDER_BACKUP,
order: _list.get(order) order: _list.get(order)
}); });
_nextNode.send(packet_.constuct(tasks)); _nextNode.send(packet_.construct(tasks));
if (failed.length) if (failed.length)
handshakeMid.timeout = setTimeout(_ => handshakeMid.requestData(failed, failed_order), RETRY_TIMEOUT); handshakeMid.timeout = setTimeout(_ => handshakeMid.requestData(failed, failed_order), RETRY_TIMEOUT);
}); });
@ -413,7 +413,7 @@ handshakeMid.requestData = function(req_sync, new_order) {
//Complete handshake //Complete handshake
function handshakeEnd() { function handshakeEnd() {
console.log("Backup connected: " + _nextNode.id); console.log("Backup connected: " + _nextNode.id);
_nextNode.send(packet_.constuct({ _nextNode.send(packet_.construct({
type: ORDER_BACKUP, type: ORDER_BACKUP,
order: _list.get() order: _list.get()
})); }));
@ -478,7 +478,7 @@ orderBackup.requestData = function(req_sync, new_order) {
failed.push(s); failed.push(s);
}); });
if (Object.keys(lastlogs).length) if (Object.keys(lastlogs).length)
_prevNode.send(packet_.constuct({ _prevNode.send(packet_.construct({
type: DATA_REQUEST, type: DATA_REQUEST,
nodes: lastlogs nodes: lastlogs
})); }));
@ -489,7 +489,7 @@ orderBackup.requestData = function(req_sync, new_order) {
order.push(n); order.push(n);
}); });
if (order.length) //TODO: maybe should wait for sync to finish? if (order.length) //TODO: maybe should wait for sync to finish?
_nextNode.send(packet_.constuct({ _nextNode.send(packet_.construct({
type: ORDER_BACKUP, type: ORDER_BACKUP,
order: _list.get(order) order: _list.get(order)
})); }));
@ -503,19 +503,19 @@ function sendStoredData(lastlogs, node) {
for (let n in lastlogs) { for (let n in lastlogs) {
if (_list.stored.includes(n)) { if (_list.stored.includes(n)) {
DB.getData(n, lastlogs[n]).then(result => { DB.getData(n, lastlogs[n]).then(result => {
node.send(packet_.constuct({ node.send(packet_.construct({
type: DATA_SYNC, type: DATA_SYNC,
id: n, id: n,
status: true status: true
})); }));
console.log(`START: ${n} data sync(send) to ${node.id}`); console.log(`START: ${n} data sync(send) to ${node.id}`);
//TODO: efficiently handle large number of data instead of loading all into memory //TODO: efficiently handle large number of data instead of loading all into memory
result.forEach(d => node.send(packet_.constuct({ result.forEach(d => node.send(packet_.construct({
type: STORE_BACKUP_DATA, type: STORE_BACKUP_DATA,
data: d data: d
}))); })));
console.log(`END: ${n} data sync(send) to ${node.id}`); console.log(`END: ${n} data sync(send) to ${node.id}`);
node.send(packet_.constuct({ node.send(packet_.construct({
type: DATA_SYNC, type: DATA_SYNC,
id: n, id: n,
status: false status: false
@ -555,7 +555,7 @@ function storeMigratedData(data) {
let closestNode = kBucket.closestNode(data.receiverID); let closestNode = kBucket.closestNode(data.receiverID);
if (_list.serving.includes(closestNode)) { if (_list.serving.includes(closestNode)) {
DB.storeData(closestNode, data); DB.storeData(closestNode, data);
_nextNode.send(packet_.constuct({ _nextNode.send(packet_.construct({
type: STORE_BACKUP_DATA, type: STORE_BACKUP_DATA,
data: data data: data
})); }));
@ -563,11 +563,11 @@ function storeMigratedData(data) {
}; };
//Delete (migrated) data //Delete (migrated) data
function deleteMigratedData(old_sn, vectorClock, receiverID, from, packet) { function deleteMigratedData(data, from, packet) {
let closestNode = kBucket.closestNode(receiverID); let closestNode = kBucket.closestNode(data.receiverID);
if (old_sn !== closestNode && _list.stored.includes(old_sn)) { if (data.snID !== closestNode && _list.stored.includes(data.snID)) {
DB.deleteData(old_sn, vectorClock); DB.deleteData(data.snID, data.vectorClock);
if (_list[old_sn] < floGlobals.sn_config.backupDepth && _nextNode.id !== from) if (_list[data.snID] < floGlobals.sn_config.backupDepth && _nextNode.id !== from)
_nextNode.send(packet); _nextNode.send(packet);
}; };
}; };
@ -583,7 +583,7 @@ function forwardToNextNode(mode, data) {
'DATA': STORE_BACKUP_DATA 'DATA': STORE_BACKUP_DATA
}; };
if (mode in modeMap && _nextNode.id) if (mode in modeMap && _nextNode.id)
_nextNode.send(packet_.constuct({ _nextNode.send(packet_.construct({
type: modeMap[mode], type: modeMap[mode],
data: data data: data
})); }));
@ -635,12 +635,12 @@ dataMigration.process_del = async function(del_nodes) {
let closest = kBucket.closestNode(d.receiverID); let closest = kBucket.closestNode(d.receiverID);
if (_list.serving.includes(closest)) { if (_list.serving.includes(closest)) {
DB.storeData(closest, d); DB.storeData(closest, d);
_nextNode.send(packet_.constuct({ _nextNode.send(packet_.construct({
type: STORE_BACKUP_DATA, type: STORE_BACKUP_DATA,
data: d data: d
})); }));
} else } else
ws_connections[closest].send(packet_.constuct({ ws_connections[closest].send(packet_.construct({
type: STORE_MIGRATED_DATA, type: STORE_MIGRATED_DATA,
data: d data: d
})); }));
@ -684,20 +684,22 @@ dataMigration.process_new = async function(new_nodes) {
if (new_nodes.includes(closest)) { if (new_nodes.includes(closest)) {
if (_list.serving.includes(closest)) { if (_list.serving.includes(closest)) {
DB.storeData(closest, d); DB.storeData(closest, d);
_nextNode.send(packet_.constuct({ _nextNode.send(packet_.construct({
type: STORE_BACKUP_DATA, type: STORE_BACKUP_DATA,
data: d data: d
})); }));
} else } else
ws_connections[closest].send(packet_.constuct({ ws_connections[closest].send(packet_.construct({
type: STORE_MIGRATED_DATA, type: STORE_MIGRATED_DATA,
data: d data: d
})); }));
_nextNode.send(packet_.constuct({ _nextNode.send(packet_.construct({
type: DELETE_MIGRATED_DATA, type: DELETE_MIGRATED_DATA,
vectorClock: d.vectorClock, data: {
receiverID: d.receiverID, vectorClock: d.vectorClock,
snID: n receiverID: d.receiverID,
snID: n
}
})); }));
}; };
}); });
@ -717,7 +719,7 @@ dataMigration.process_new = async function(new_nodes) {
dataMigration.intimateAllNodes = function() { dataMigration.intimateAllNodes = function() {
connectToAliveNodes().then(ws_connections => { connectToAliveNodes().then(ws_connections => {
let packet = packet_.constuct({ let packet = packet_.construct({
type: INITIATE_REFRESH type: INITIATE_REFRESH
}); });
for (let n in ws_connections) for (let n in ws_connections)

View File

@ -1,4 +1,4 @@
const config = require("../config.json"); const config = require('../args/config.json');
global.floGlobals = require("./floGlobals"); global.floGlobals = require("./floGlobals");
require('./set_globals'); require('./set_globals');
require('./lib'); require('./lib');

View File

@ -2,7 +2,13 @@
//fetch for node js (used in floBlockchainAPI.js) //fetch for node js (used in floBlockchainAPI.js)
global.fetch = require("node-fetch"); global.fetch = require("node-fetch");
//Set browser paramaters from param.json //Set browser paramaters from param.json (or param-default.json)
const param = require('../param.json'); var param;
for(let p in param) try {
global[p] = param[p]; param = require('../args/param.json');
} catch {
param = require('../args/param-default.json');
} finally {
for (let p in param)
global[p] = param[p];
}

View File