Skip to content

Commit

Permalink
Use smaller probability to retry failed server.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Mar 15, 2013
1 parent 12907cb commit 29d78c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions cmd/shadowsocks-local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]++
}
Expand All @@ -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
}
Expand Down

0 comments on commit 29d78c2

Please sign in to comment.