From d493836669ecabc256bb7fa73e2f9ec1487f6655 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Fri, 15 Mar 2013 19:08:34 +0800 Subject: [PATCH 1/5] Add script to set new version. --- script/set-version.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 script/set-version.sh diff --git a/script/set-version.sh b/script/set-version.sh new file mode 100755 index 0000000..ef88c15 --- /dev/null +++ b/script/set-version.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +cd "$( dirname "${BASH_SOURCE[0]}" )/.." + +if [ $# != 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +version=$1 +#echo $version + +sed -i -e "s,\(\tversion \+= \)\".*\"$,\1\"$version\"," shadowsocks/util.go +sed -i -e "s/Version:.*$/Version: $version-1/" deb/DEBIAN/control + From 868e9ae21481f9a3351c1458c648054d64e8e64e Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Fri, 15 Mar 2013 19:21:38 +0800 Subject: [PATCH 2/5] Update README for the new multi-server behavior. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2840a8f..aeb6bdd 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ server_password specify multiple server and password, server should be in the Here's a sample configuration [`client-multi-server.json`](https://github.com/shadowsocks/shadowsocks-go/blob/master/sample-config/client-multi-server.json). Given `server_password`, client program will ignore `server_port`, `server` and `password` options. -Servers are chosen in round robin fasion. If a server can't be connected, the client will try the next one. The client does not try to detect connection problems caused by incorrect password, this is intended for the user to notice the error. +Servers are chosen in the order specified in the config. If a server can't be connected (connection failure), the client will try the next one. (Client will retry failed server with some probability to discover server recovery.) ## Multiple users with different passwords on server From 42cc25de6c9c8ab2506bd841c2b560f5e876c11c Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Fri, 15 Mar 2013 19:24:08 +0800 Subject: [PATCH 3/5] Fix arch error in upload script. --- script/upload.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/upload.sh b/script/upload.sh index 15507e5..3c5a89c 100755 --- a/script/upload.sh +++ b/script/upload.sh @@ -20,7 +20,7 @@ upload() { upload "$version OS X Client 64bit" bin/shadowsocks-local-mac64-$version.gz upload "$version Linux Client 32bit" bin/shadowsocks-local-linux32-$version.gz upload "$version Linux Client 64bit" bin/shadowsocks-local-linux64-$version.gz -upload "$version Windows Client 32bit" bin/shadowsocks-local-win64-$version.zip +upload "$version Windows Client 64bit" bin/shadowsocks-local-win64-$version.zip upload "$version Windows Client 32bit" bin/shadowsocks-local-win32-$version.zip upload "$version Linux Server 32bit" bin/shadowsocks-server-linux32-$version.gz From 12907cb3f8084f2b234825241d25c58a0183d50b Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Fri, 15 Mar 2013 19:59:43 +0800 Subject: [PATCH 4/5] Seed random number generator for client. --- cmd/shadowsocks-local/local.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/shadowsocks-local/local.go b/cmd/shadowsocks-local/local.go index b997c19..5dfcc8b 100644 --- a/cmd/shadowsocks-local/local.go +++ b/cmd/shadowsocks-local/local.go @@ -13,6 +13,7 @@ import ( "os" "path" "strconv" + "time" ) var debug ss.DebugLog @@ -31,6 +32,10 @@ const ( socksCmdConnect = 1 ) +func init() { + rand.Seed(time.Now().Unix()) +} + func handShake(conn net.Conn) (err error) { const ( idVer = 0 From 29d78c2d7b032ba02f9aff971c58c037b99f5030 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Fri, 15 Mar 2013 21:59:44 +0800 Subject: [PATCH 5/5] Use smaller probability to retry failed server. --- Makefile | 6 +++--- cmd/shadowsocks-local/local.go | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 0557d5b..e776d8d 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ PREFIX := shadowsocks LOCAL := $(GOPATH)/bin/$(PREFIX)-local SERVER := $(GOPATH)/bin/$(PREFIX)-server -CGO := CGO_ENABLED=0 +CGO := CGO_ENABLED=1 all: $(LOCAL) $(SERVER) $(TEST) @@ -14,10 +14,10 @@ clean: # -a option is needed to ensure we disabled CGO $(LOCAL): shadowsocks/*.go cmd/$(PREFIX)-local/*.go - cd cmd/$(PREFIX)-local; $(CGO) go install -a + cd cmd/$(PREFIX)-local; $(CGO) go install $(SERVER): shadowsocks/*.go cmd/$(PREFIX)-server/*.go - cd cmd/$(PREFIX)-server; $(CGO) go install -a + cd cmd/$(PREFIX)-server; $(CGO) go install local: $(LOCAL) diff --git a/cmd/shadowsocks-local/local.go b/cmd/shadowsocks-local/local.go index 5dfcc8b..2bbbc11 100644 --- a/cmd/shadowsocks-local/local.go +++ b/cmd/shadowsocks-local/local.go @@ -220,7 +220,7 @@ func connectToServer(serverId int, rawaddr []byte, addr string) (remote *ss.Conn remote, err = ss.DialWithRawAddr(rawaddr, se.server, se.cipher.Copy()) if err != nil { log.Println("error connecting to shadowsocks server:", err) - const maxFailCnt = 50 + const maxFailCnt = 30 if servers.failCnt[serverId] < maxFailCnt { servers.failCnt[serverId]++ } @@ -236,11 +236,12 @@ func connectToServer(serverId int, rawaddr []byte, addr string) (remote *ss.Conn // some probability according to its fail count, so we can discover recovered // servers. func createServerConn(rawaddr []byte, addr string) (remote *ss.Conn, err error) { + const baseFailCnt = 20 n := len(servers.srvCipher) skipped := make([]int, 0) for i := 0; i < n; i++ { // skip failed server, but try it with some probability - if servers.failCnt[i] > 0 && rand.Intn(servers.failCnt[i]+1) != 0 { + if servers.failCnt[i] > 0 && rand.Intn(servers.failCnt[i]+baseFailCnt) != 0 { skipped = append(skipped, i) continue }