Move to swarmjs and await geth ready

Move to swarmjs library (in embark-framework).

Wait for geth to start before start of swarm check.
This commit is contained in:
emizzle 2018-09-05 16:07:30 +10:00
parent b5e8546ebd
commit fcb75dee11
3 changed files with 2544 additions and 1947 deletions

View File

@ -1,9 +1,10 @@
const UploadSwarm = require('./upload.js'); const UploadSwarm = require('./upload.js');
const utils = require('../../utils/utils.js'); const utils = require('../../utils/utils.js');
const fs = require('../../core/fs.js'); const fs = require('../../core/fs.js');
const SwarmGW = require('swarmgw'); const SwarmJS = require('swarmjs');
// TODO: not great, breaks module isolation // TODO: not great, breaks module isolation
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher'); const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
const constants = require('../../constants.json');
class Swarm { class Swarm {
@ -26,20 +27,26 @@ class Swarm {
if (!this.isSwarmEnabledInTheConfig()) { if (!this.isSwarmEnabledInTheConfig()) {
return; return;
} }
this.swarm = new SwarmGW({gateway: this.providerUrl}); console.dir('STARTING SWARMJS');
this.swarm = new SwarmJS({gateway: this.providerUrl});
this.setServiceCheck(); this.setServiceCheck();
this.addProviderToEmbarkJS(); this.addProviderToEmbarkJS();
// TODO add check to see if we need to start process
this.startProcess(() => {});
this.registerUploadCommand(); this.registerUploadCommand();
this._checkService((err) => { // swarm needs geth to be running first
if (!err) { this.events.once(constants.blockchain.blockchainReady, () => {
return; this.swarm.isAvailable((err, isAvailable) => {
} if (err) return this.logger.error('Error checking swarm availability', err);
self.logger.info("Swarm node not found, attempting to start own node"); if (isAvailable) {
self.startProcess(() => {}); this.logger.info("Swarm node found, using currently running node");
return;
}
this.logger.info("SWARM: Swarm node not found, attempting to start own node");
return this.startProcess(() => {});
});
}); });
} }
@ -54,15 +61,15 @@ class Swarm {
self.logger.info(__('Swarm node is offline...')); self.logger.info(__('Swarm node is offline...'));
}); });
self.events.request("services:register", 'Swarm', function(cb){ self.events.request("services:register", 'Swarm', function (cb) {
self.logger.trace(`Checking Swarm availability on ${self.providerUrl}...`); self.logger.trace(`Checking Swarm availability on ${self.providerUrl}...`);
self._checkService((err, result) => { self._checkService((err, result) => {
if (err) { if (err) {
self.logger.trace("Check Swarm availability error: " + err); self.logger.trace("Check Swarm availability error: " + err);
return cb({name: "Swarm ", status: 'off'}); return cb({name: "Swarm ", status: 'off'});
} }
self.logger.trace("Swarm " + (result ? '':'on') + "available"); self.logger.trace("Swarm " + (result ? '' : 'on') + "available");
return cb({name: "Swarm ", status: result ? 'on':'off'}); return cb({name: "Swarm ", status: result ? 'on' : 'off'});
}); });
}); });
} }

4456
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -81,7 +81,7 @@
"solc": "0.4.24", "solc": "0.4.24",
"string-replace-async": "^1.2.1", "string-replace-async": "^1.2.1",
"style-loader": "^0.19.0", "style-loader": "^0.19.0",
"swarmgw": "file:../swarmgw", "swarmjs": "file:../swarmjs",
"tar": "^3.1.5", "tar": "^3.1.5",
"toposort": "^1.0.0", "toposort": "^1.0.0",
"underscore": "^1.9.0", "underscore": "^1.9.0",