2020-07-25 09:10:43 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Shadowsocks API
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
var SHELL = require("lib/shell");
|
|
|
|
var SYS = require("lib/system");
|
|
|
|
|
|
|
|
exports.VERSIONINFO = "Shadowsocks Lib (shadowsocks.js) version 0.1";
|
|
|
|
exports.global = global;
|
|
|
|
exports.require = global.require;
|
|
|
|
|
|
|
|
var arch = SYS.getArch();
|
2020-07-25 09:11:05 +00:00
|
|
|
if(arch.indexOf("64") > -1) {
|
2020-07-25 09:10:43 +00:00
|
|
|
exports.binPath = "bin/shadowsocks-lib-mingw-x86_64/ss-local";
|
|
|
|
} else {
|
|
|
|
exports.binPath = "bin/shadowsocks-lib-mingw-x86/ss-local";
|
|
|
|
}
|
|
|
|
|
2020-07-26 11:40:25 +00:00
|
|
|
exports.getRandomInt = function(min, max) {
|
|
|
|
var x = Math.random();
|
|
|
|
return min + Math.floor((max - min) * x);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.connect = function() {
|
|
|
|
var port = exports.getRandomInt(49152, 65535);
|
|
|
|
|
|
|
|
SHELL.run([
|
|
|
|
exports.binPath,
|
|
|
|
"-s",
|
|
|
|
__config.shadowsocks.host,
|
|
|
|
"-p",
|
|
|
|
__config.shadowsocks.port,
|
|
|
|
"-l",
|
|
|
|
port,
|
|
|
|
"-k",
|
|
|
|
__config.shadowsocks.password,
|
|
|
|
"-m",
|
|
|
|
__config.shadowsocks.cipher
|
|
|
|
], true);
|
|
|
|
|
|
|
|
return port;
|
2020-07-25 09:10:43 +00:00
|
|
|
};
|