made sock5 enable-able from the config

This commit is contained in:
tigerbot 2017-08-04 15:23:15 -06:00
parent 188869b83e
commit fee0df3ec9
2 changed files with 20 additions and 4 deletions

View File

@ -398,6 +398,16 @@ npm install -g git+https://git.daplie.com/Daplie/mdig.git
mdig _cloud._tcp.local mdig _cloud._tcp.local
``` ```
### socks5
Run a Socks5 proxy server.
```yaml
socks5:
enable: true
port: 1080
```
### api ### api
See [API.md](/API.md) See [API.md](/API.md)

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
module.exports.create = function () { module.exports.create = function (deps, config) {
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var server; var server;
@ -15,7 +15,7 @@ module.exports.create = function () {
}); });
} }
function start() { function start(port) {
if (server) { if (server) {
return curState(); return curState();
} }
@ -35,14 +35,14 @@ module.exports.create = function () {
return new PromiseA(function (resolve, reject) { return new PromiseA(function (resolve, reject) {
server.on('error', function (err) { server.on('error', function (err) {
if (err.code === 'EADDRINUSE') { if (!port && err.code === 'EADDRINUSE') {
server.listen(0); server.listen(0);
} else { } else {
server = null; server = null;
reject(err); reject(err);
} }
}); });
server.listen(1080, function () { server.listen(port || 1080, function () {
resolve(curState()); resolve(curState());
}); });
}); });
@ -63,6 +63,12 @@ module.exports.create = function () {
}); });
} }
if (config.socks5 && config.socks5.enabled) {
start(config.socks5.port).catch(function (err) {
console.error('failed to start Socks5 proxy', err);
});
}
return { return {
curState: curState curState: curState
, start: start , start: start