added ability to detect config changes to the socks5 module

This commit is contained in:
tigerbot 2017-10-26 16:55:16 -06:00
parent 5534ba2ef1
commit c637671c78
1 changed files with 20 additions and 7 deletions

View File

@ -63,15 +63,28 @@ module.exports.create = function (deps, config) {
});
}
if (config.socks5 && config.socks5.enabled) {
start(config.socks5.port).catch(function (err) {
console.error('failed to start Socks5 proxy', err);
});
var configEnabled = false;
function updateConf() {
var wanted = config.socks5 && config.socks5.enabled;
if (configEnabled && !wanted) {
stop().catch(function (err) {
console.error('failed to stop socks5 proxy on config change', err);
});
configEnabled = false;
}
if (wanted && !configEnabled) {
start(config.socks5.port).catch(function (err) {
console.error('failed to start Socks5 proxy', err);
});
configEnabled = true;
}
}
return {
curState: curState
, start: start
, stop: stop
curState
, start
, stop
, updateConf
};
};