Skip to content

Commit

Permalink
Client now support multiple server ports and multiple server/port pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Oct 29, 2013
1 parent 7beccb3 commit 50b2acb
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 40 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.4.2 2013-10-29
- Client now support multiple server ports and multiple server/port pairs. See test/config-client-*.json for example

1.4.1 2013-07-30
- Change default cipher to AES-256-CFB in config.json
- Fix a typo in local
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
shadowsocks-nodejs
===========

Current version: 1.4.1
Current version: 1.4.2
[![Build Status](https://travis-ci.org/clowwindy/shadowsocks-nodejs.png)](https://travis-ci.org/clowwindy/shadowsocks-nodejs)

shadowsocks-nodejs is a lightweight tunnel proxy which can help you get through
Expand Down
24 changes: 17 additions & 7 deletions lib/shadowsocks/local.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/shadowsocks/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "a tunnel proxy that help you get through firewalls",
"keywords": ["shadowsocks", "proxy", "socks5"],
"author": "clowwindy",
"version": "1.4.1",
"version": "1.4.2",
"licenses": [{
"type": "MIT",
"url": "https://raw.github.com/clowwindy/shadowsocks-nodejs/master/LICENSE"
Expand Down
23 changes: 17 additions & 6 deletions src/local.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,21 @@ createServer = (serverAddr, serverPort, port, key, method, timeout)->
udpServer = udpRelay.createServer(null, port, serverAddr, serverPort, key, method, timeout, true)

getServer = ->
aPort = serverPort
aServer = serverAddr
if serverPort instanceof Array
# support config like "server_port": [8081, 8082]
aPort = serverPort[Math.floor(Math.random() * serverPort .length)]
if serverAddr instanceof Array
serverAddr[Math.floor(Math.random() * serverAddr .length)]
else
serverAddr
# support config like "server": ["123.123.123.1", "123.123.123.2"]
aServer = serverAddr[Math.floor(Math.random() * serverAddr .length)]
r = /^(.*)\:(\d+)$/.exec(aServer)
# support config like "server": "123.123.123.1:8381"
# or "server": ["123.123.123.1:8381", "123.123.123.2:8381", "123.123.123.2:8382"]
if r?
aServer = r[1]
aPort = +r[2]
return [aServer, aPort]

server = net.createServer((connection) ->
connections += 1
Expand Down Expand Up @@ -149,9 +160,9 @@ createServer = (serverAddr, serverPort, port, key, method, timeout)->
buf.writeInt16BE 2222, 8
connection.write buf
# connect remote server
aServer = getServer()
remote = net.connect(serverPort, aServer, ->
utils.info "connecting #{remoteAddr}:#{remotePort}"
[aServer, aPort] = getServer()
utils.info "connecting #{aServer}:#{aPort}"
remote = net.connect(aPort, aServer, ->
if not encryptor
remote.destroy() if remote
return
Expand Down
2 changes: 1 addition & 1 deletion src/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ exports.checkConfig = (config) ->
if (config.method or '').toLowerCase() == 'rc4'
exports.warn 'RC4 is not safe; please use a safer cipher, like AES-256-CFB'

exports.version = "shadowsocks-nodejs v1.4.1"
exports.version = "shadowsocks-nodejs v1.4.2"

exports.EVERYTHING = 0
exports.DEBUG = 1
Expand Down
8 changes: 8 additions & 0 deletions test/config-client-multi-port.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"server": "123.123.123.1",
"server_port":[8380, 8381, 8382, 8383],
"local_port":1081,
"password":"barfoo!",
"timeout":60,
"method":"aes-256-cfb"
}
8 changes: 8 additions & 0 deletions test/config-client-multi-server-port.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"server": ["123.123.123.1:8381", "123.123.123.2:8381", "123.123.123.2:8382"],
"server_port":8380,
"local_port":1081,
"password":"barfoo!",
"timeout":60,
"method":"aes-256-cfb"
}
8 changes: 8 additions & 0 deletions test/config-client-multi-server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"server": ["123.123.123.1", "123.123.123.2", "123.123.123.3"],
"server_port":8380,
"local_port":1081,
"password":"barfoo!",
"timeout":60,
"method":"aes-256-cfb"
}
21 changes: 0 additions & 21 deletions test/config-multi-passwd.json

This file was deleted.

22 changes: 22 additions & 0 deletions test/config-server-multi-passwd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"server":"127.0.0.1",
"server_port":8380,
"local_port":1081,
"password":"barfoo!",
"port_password": {
"8381": "foobar1",
"8382": "foobar2",
"8383": "foobar3",
"8384": "foobar4",
"8385": "foobar5",
"8386": "foobar6",
"8387": "foobar7",
"8388": "foobar8",
"8389": "foobar9",
"8390": "foobar10",
"8391": "foobar11",
"8392": "foobar12"
},
"timeout":60,
"method":"aes-256-cfb"
}
18 changes: 18 additions & 0 deletions test/config-server-multi-port.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"server":"127.0.0.1",
"server_port":8380,
"local_port":1081,
"password":"barfoo!",
"port_password": {
"8380": "barfoo!",
"8381": "barfoo!",
"8382": "barfoo!",
"8383": "barfoo!",
"8384": "barfoo!",
"8385": "barfoo!",
"8386": "barfoo!",
"8387": "barfoo!"
},
"timeout":60,
"method":"aes-256-cfb"
}
4 changes: 2 additions & 2 deletions test/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"server":["127.0.0.1", "127.0.0.1"],
"server":"127.0.0.1",
"server_port":8388,
"local_port":1080,
"password":"barfoo!",
"timeout":60,
"method":"rc4"
"method":"aes-256-cfb"
}

0 comments on commit 50b2acb

Please sign in to comment.