check ipfs connection before attempting to connect
This commit is contained in:
parent
2f828c72d1
commit
968b06860c
|
@ -8,6 +8,7 @@ const StorageProcessesLauncher = require('../../processes/storageProcesses/stora
|
|||
class IPFS {
|
||||
|
||||
constructor(embark, options) {
|
||||
const self = this;
|
||||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.buildDir = options.buildDir;
|
||||
|
@ -17,14 +18,21 @@ class IPFS {
|
|||
this.protocol = options.protocol || this.storageConfig.upload.protocol;
|
||||
this.embark = embark;
|
||||
|
||||
this.webServerConfig = embark.config.webServerConfig,
|
||||
this.webServerConfig = embark.config.webServerConfig
|
||||
this.blockchainConfig = embark.config.blockchainConfig
|
||||
|
||||
this.commandlineDeploy();
|
||||
this.setServiceCheck();
|
||||
this.addProviderToEmbarkJS();
|
||||
this.addObjectToConsole();
|
||||
this.startProcess(() => {});
|
||||
|
||||
this._checkService((err) => {
|
||||
if (!err) {
|
||||
return;
|
||||
}
|
||||
self.logger.info("IPFS node not found, attempting to start own node");
|
||||
self.startProcess(() => {});
|
||||
});
|
||||
}
|
||||
|
||||
commandlineDeploy() {
|
||||
|
@ -38,6 +46,7 @@ class IPFS {
|
|||
}
|
||||
|
||||
setServiceCheck() {
|
||||
console.dir("setServiceCheck");
|
||||
let self = this;
|
||||
|
||||
let storageConfig = this.storageConfig;
|
||||
|
@ -45,6 +54,7 @@ class IPFS {
|
|||
if (!storageConfig.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_.findWhere(this.storageConfig.dappConnection, {'provider': 'ipfs'}) === undefined && (storageConfig.upload.provider !== 'ipfs' || storageConfig.available_providers.indexOf("ipfs") < 0)) {
|
||||
return;
|
||||
}
|
||||
|
@ -58,28 +68,32 @@ class IPFS {
|
|||
});
|
||||
|
||||
self.events.request("services:register", 'IPFS', function (cb) {
|
||||
let url = (self.protocol || 'http') + '://' + self.host + ':' + self.port + '/api/v0/version';
|
||||
self.logger.trace(`Checking IPFS version on ${url}...`);
|
||||
if(self.protocol !== 'https'){
|
||||
utils.httpGetJson(url, versionCb);
|
||||
} else {
|
||||
utils.httpsGetJson(url, versionCb);
|
||||
}
|
||||
function versionCb(err, body) {
|
||||
self._checkService((err, body) => {
|
||||
if (err) {
|
||||
self.logger.trace("IPFS unavailable");
|
||||
self.logger.info("IPFS unavailable");
|
||||
return cb({name: "IPFS ", status: 'off'});
|
||||
}
|
||||
if (body.Version) {
|
||||
self.logger.trace("IPFS available");
|
||||
self.logger.info("IPFS available");
|
||||
return cb({name: ("IPFS " + body.Version), status: 'on'});
|
||||
}
|
||||
self.logger.trace("IPFS available");
|
||||
self.logger.info("IPFS available");
|
||||
return cb({name: "IPFS ", status: 'on'});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_checkService(cb) {
|
||||
const self = this;
|
||||
let url = (self.protocol || 'http') + '://' + self.host + ':' + self.port + '/api/v0/version';
|
||||
self.logger.info(`Checking IPFS version on ${url}...`);
|
||||
if (self.protocol !== 'https'){
|
||||
utils.httpGetJson(url, cb);
|
||||
} else {
|
||||
utils.httpsGetJson(url, cb);
|
||||
}
|
||||
}
|
||||
|
||||
addProviderToEmbarkJS() {
|
||||
const self = this;
|
||||
// TODO: make this a shouldAdd condition
|
||||
|
|
Loading…
Reference in New Issue