From fee0df3ec93cec9a1d0f439183f8c4e45380e376 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Fri, 4 Aug 2017 15:23:15 -0600 Subject: [PATCH] made sock5 enable-able from the config --- README.md | 10 ++++++++++ lib/socks5-server.js | 14 ++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 53d0fee..dae6727 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lib/socks5-server.js b/lib/socks5-server.js index 6ad9eb0..b717f8f 100644 --- a/lib/socks5-server.js +++ b/lib/socks5-server.js @@ -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