Skip to content

Instantly share code, notes, and snippets.

@jackyyf
Last active August 29, 2015 14:14
Show Gist options
  • Save jackyyf/92c07398a61a0246a520 to your computer and use it in GitHub Desktop.
Save jackyyf/92c07398a61a0246a520 to your computer and use it in GitHub Desktop.
Gist by paste.py @ 2015-01-29 16:01:25.577710
diff --git a/cmd/shadowsocks-local/local.go b/cmd/shadowsocks-local/local.go
index 78d0995..089196c 100644
--- a/cmd/shadowsocks-local/local.go
+++ b/cmd/shadowsocks-local/local.go
@@ -5,7 +5,7 @@ import (
"errors"
"flag"
"fmt"
- ss "github.com/shadowsocks/shadowsocks-go/shadowsocks"
+ ss "shadowsocks"
"io"
"log"
"math/rand"
@@ -33,7 +33,7 @@ const (
)
func init() {
- rand.Seed(time.Now().Unix())
+ rand.Seed(time.Now().UnixNano())
}
func handShake(conn net.Conn) (err error) {
@@ -250,9 +250,10 @@ 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++ {
+ loop_order := rand.Perm(n)
+ for _, i := range loop_order {
// skip failed server, but try it with some probability
- if servers.failCnt[i] > 0 && rand.Intn(servers.failCnt[i]+baseFailCnt) != 0 {
+ if servers.failCnt[i] > 0 && rand.Intn(servers.failCnt[i]+baseFailCnt) < 5 {
skipped = append(skipped, i)
continue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment