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
```
### socks5
Run a Socks5 proxy server.
```yaml
socks5:
enable: true
port: 1080
```
### api
See [API.md](/API.md)

View File

@ -1,6 +1,6 @@
'use strict';
module.exports.create = function () {
module.exports.create = function (deps, config) {
var PromiseA = require('bluebird');
var server;
@ -15,7 +15,7 @@ module.exports.create = function () {
});
}
function start() {
function start(port) {
if (server) {
return curState();
}
@ -35,14 +35,14 @@ module.exports.create = function () {
return new PromiseA(function (resolve, reject) {
server.on('error', function (err) {
if (err.code === 'EADDRINUSE') {
if (!port && err.code === 'EADDRINUSE') {
server.listen(0);
} else {
server = null;
reject(err);
}
});
server.listen(1080, function () {
server.listen(port || 1080, function () {
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 {
curState: curState
, start: start