Improvements to config manager + run checks for config files and write them before executing the router subprocess
This commit is contained in:
@ -10,13 +10,13 @@ try { Cu.import("resource://gre/modules/ctypes.jsm") } catch(e) {}
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm")
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "LauncherUtil", "resource://i2pbutton/modules/launcher-util.jsm")
|
||||
//XPCOMUtils.defineLazyModuleGetter(this, "I2PLauncherLogger", "resource://i2pbutton/modules/tl-logger.jsm")
|
||||
|
||||
//let observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService)
|
||||
|
||||
function I2PProcessService()
|
||||
{
|
||||
this._logger = Cc["@geti2p.net/i2pbutton-logger;1"].getService(Ci.nsISupports).wrappedJSObject
|
||||
this._config_checker = Cc["@geti2p.net/i2pbutton-router-config-mgr;1"].getService(Ci.nsISupports).wrappedJSObject
|
||||
this._logger.log(3, "I2pbutton I2P Router Process Service initialized")
|
||||
this.wrappedJSObject = this
|
||||
}
|
||||
@ -34,7 +34,7 @@ I2PProcessService.prototype =
|
||||
|
||||
kInitialControlConnDelayMS: 25,
|
||||
kMaxControlConnRetryMS: 2000, // Retry at least every 2 seconds.
|
||||
kControlConnTimeoutMS: 5*60*1000, // Wait at most 5 minutes for tor to start.
|
||||
kControlConnTimeoutMS: 5*60*1000, // Wait at most 5 minutes for i2p to start.
|
||||
|
||||
kStatusUnknown: 0, // I2P process status.
|
||||
kStatusStarting: 1,
|
||||
@ -98,8 +98,11 @@ I2PProcessService.prototype =
|
||||
this._isConsoleRunning(function(res) {
|
||||
if (res!=4) {
|
||||
// Yes, 4 is success
|
||||
self._logger.log(3, 'Starting the router')
|
||||
self.I2PStartAndControlI2P(true)
|
||||
let canStartPromise = this._config_checker.ensure_config()
|
||||
canStartPromise.then(() => {
|
||||
self._logger.log(3, 'Starting the router')
|
||||
self.I2PStartAndControlI2P(true)
|
||||
})
|
||||
} else {
|
||||
self._logger.log(3, 'Already found a router, won\'t launch.')
|
||||
}
|
||||
|
@ -145,9 +145,20 @@ RouterConfigManager.prototype = {
|
||||
_logger: null,
|
||||
state: {},
|
||||
|
||||
// State
|
||||
mDoesRouterConfigExists: false,
|
||||
mDoesClientsConfigExists: false,
|
||||
mDoesTunnelConfigExists: false,
|
||||
mHasChecksStarted: false,
|
||||
mIsChecksDone: false,
|
||||
|
||||
|
||||
// nsISupports implementation.
|
||||
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupports]),
|
||||
|
||||
canRouterStart: function() {
|
||||
return (this.mDoesRouterConfigExists && this.mDoesClientsConfigExists && this.mDoesTunnelConfigExists)
|
||||
},
|
||||
|
||||
|
||||
_write_router_config: function(configfile,onComplete) {
|
||||
@ -170,31 +181,78 @@ RouterConfigManager.prototype = {
|
||||
},
|
||||
|
||||
|
||||
ensure_config: function(onCompleteCallback) {
|
||||
ensure_config: async function(onCompleteCallback) {
|
||||
this.mHasChecksStarted = true
|
||||
|
||||
let configDirectory = LauncherUtil.getI2PConfigPath(true)
|
||||
let routerConfigFile = configDirectory.clone()
|
||||
routerConfigFile.append('router.config')
|
||||
let tunnelConfigFIle = configDirectory.clone()
|
||||
tunnelConfigFIle.append('i2ptunnel.config')
|
||||
let clientsConfigFIle = configDirectory.clone()
|
||||
clientsConfigFIle.append('clients.config')
|
||||
let tunnelConfigFile = configDirectory.clone()
|
||||
tunnelConfigFile.append('i2ptunnel.config')
|
||||
let clientsConfigFile = configDirectory.clone()
|
||||
clientsConfigFile.append('clients.config')
|
||||
|
||||
// Ensure they exists
|
||||
if (!routerConfigFile.exists) {
|
||||
this._write_router_config(routerConfigFile, file => {
|
||||
if (typeof onCompleteCallback === 'function') onCompleteCallback(file)
|
||||
const self = this
|
||||
|
||||
this.ensureRouterConfigPromise = () => {
|
||||
return new Promise(resolve => {
|
||||
if (!routerConfigFile.exists()) {
|
||||
self._write_router_config(routerConfigFile, file => {
|
||||
self.mDoesRouterConfigExists = true
|
||||
self._logger.log(3, 'Wrote router.config')
|
||||
if (typeof onCompleteCallback === 'function') onCompleteCallback(file)
|
||||
resolve(routerConfigFile)
|
||||
})
|
||||
} else {
|
||||
self._logger.log(3, 'Found router.config from earlier')
|
||||
self.mDoesRouterConfigExists = true
|
||||
resolve(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
if (!tunnelConfigFIle.exits) {
|
||||
this._write_tunnel_config(tunnelConfigFIle, tfile => {
|
||||
if (typeof onCompleteCallback === 'function') onCompleteCallback(tfile)
|
||||
|
||||
this.ensureTunnelConfigPromise = () => {
|
||||
return new Promise(resolve => {
|
||||
if (!tunnelConfigFile.exists()) {
|
||||
self._write_tunnel_config(tunnelConfigFile, tfile => {
|
||||
self._logger.log(3, 'Wrote i2ptunnel.config')
|
||||
self.mDoesTunnelConfigExists = true
|
||||
if (typeof onCompleteCallback === 'function') onCompleteCallback(tfile)
|
||||
resolve(tunnelConfigFile)
|
||||
})
|
||||
} else {
|
||||
self._logger.log(3, 'Found i2ptunnel.config from earlier')
|
||||
self.mDoesTunnelConfigExists = true
|
||||
resolve(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
if (!clientsConfigFIle.exits) {
|
||||
this._write_tunnel_config(tunnelConfigFIle, tfile => {
|
||||
if (typeof onCompleteCallback === 'function') onCompleteCallback(tfile)
|
||||
|
||||
this.ensureClientsConfigPromise = () => {
|
||||
return new Promise(resolve => {
|
||||
if (!clientsConfigFile.exists()) {
|
||||
self._write_tunnel_config(tunnelConfigFile, tfile => {
|
||||
self._logger.log(3, 'Wrote clients.config')
|
||||
self.mDoesClientsConfigExists = true
|
||||
if (typeof onCompleteCallback === 'function') onCompleteCallback(tfile)
|
||||
resolve(clientsConfigFile)
|
||||
})
|
||||
} else {
|
||||
self._logger.log(3, 'Found clients.config from earlier')
|
||||
self.mDoesClientsConfigExists = true
|
||||
resolve(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Promises are not done but at least done here.
|
||||
this.mIsChecksDone = true
|
||||
return Promise.all([
|
||||
this.ensureRouterConfigPromise(),
|
||||
this.ensureTunnelConfigPromise(),
|
||||
this.ensureClientsConfigPromise(),
|
||||
])
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user