mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-23 13:48:49 +00:00
check ipfs connection before attempting to connect
This commit is contained in:
parent
8384830066
commit
513659a53e
@ -8,6 +8,7 @@ const StorageProcessesLauncher = require('../../processes/storageProcesses/stora
|
|||||||
class IPFS {
|
class IPFS {
|
||||||
|
|
||||||
constructor(embark, options) {
|
constructor(embark, options) {
|
||||||
|
const self = this;
|
||||||
this.logger = embark.logger;
|
this.logger = embark.logger;
|
||||||
this.events = embark.events;
|
this.events = embark.events;
|
||||||
this.buildDir = options.buildDir;
|
this.buildDir = options.buildDir;
|
||||||
@ -17,14 +18,21 @@ class IPFS {
|
|||||||
this.protocol = options.protocol || this.storageConfig.upload.protocol;
|
this.protocol = options.protocol || this.storageConfig.upload.protocol;
|
||||||
this.embark = embark;
|
this.embark = embark;
|
||||||
|
|
||||||
this.webServerConfig = embark.config.webServerConfig,
|
this.webServerConfig = embark.config.webServerConfig
|
||||||
this.blockchainConfig = embark.config.blockchainConfig
|
this.blockchainConfig = embark.config.blockchainConfig
|
||||||
|
|
||||||
this.commandlineDeploy();
|
this.commandlineDeploy();
|
||||||
this.setServiceCheck();
|
this.setServiceCheck();
|
||||||
this.addProviderToEmbarkJS();
|
this.addProviderToEmbarkJS();
|
||||||
this.addObjectToConsole();
|
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() {
|
commandlineDeploy() {
|
||||||
@ -38,6 +46,7 @@ class IPFS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setServiceCheck() {
|
setServiceCheck() {
|
||||||
|
console.dir("setServiceCheck");
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
let storageConfig = this.storageConfig;
|
let storageConfig = this.storageConfig;
|
||||||
@ -45,6 +54,7 @@ class IPFS {
|
|||||||
if (!storageConfig.enabled) {
|
if (!storageConfig.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.findWhere(this.storageConfig.dappConnection, {'provider': 'ipfs'}) === undefined && (storageConfig.upload.provider !== 'ipfs' || storageConfig.available_providers.indexOf("ipfs") < 0)) {
|
if (_.findWhere(this.storageConfig.dappConnection, {'provider': 'ipfs'}) === undefined && (storageConfig.upload.provider !== 'ipfs' || storageConfig.available_providers.indexOf("ipfs") < 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -58,28 +68,32 @@ class IPFS {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.events.request("services:register", 'IPFS', function (cb) {
|
self.events.request("services:register", 'IPFS', function (cb) {
|
||||||
let url = (self.protocol || 'http') + '://' + self.host + ':' + self.port + '/api/v0/version';
|
self._checkService((err, body) => {
|
||||||
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) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
self.logger.trace("IPFS unavailable");
|
self.logger.info("IPFS unavailable");
|
||||||
return cb({name: "IPFS ", status: 'off'});
|
return cb({name: "IPFS ", status: 'off'});
|
||||||
}
|
}
|
||||||
if (body.Version) {
|
if (body.Version) {
|
||||||
self.logger.trace("IPFS available");
|
self.logger.info("IPFS available");
|
||||||
return cb({name: ("IPFS " + body.Version), status: 'on'});
|
return cb({name: ("IPFS " + body.Version), status: 'on'});
|
||||||
}
|
}
|
||||||
self.logger.trace("IPFS available");
|
self.logger.info("IPFS available");
|
||||||
return cb({name: "IPFS ", status: 'on'});
|
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() {
|
addProviderToEmbarkJS() {
|
||||||
const self = this;
|
const self = this;
|
||||||
// TODO: make this a shouldAdd condition
|
// TODO: make this a shouldAdd condition
|
||||||
|
Loading…
x
Reference in New Issue
Block a user