diff --git a/CHANGELOG b/CHANGELOG index 1bc2e43..4b6cf94 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ -0.6.1 (2013-03-15) +0.6.3 (not released) + * Support IPv6 server + +0.6.2 (2013-03-15) * Connect to multiple servers in the order specified in config * More information in server error log to help error diagnosing diff --git a/cmd/shadowsocks-local/local.go b/cmd/shadowsocks-local/local.go index 2bbbc11..98b23ad 100644 --- a/cmd/shadowsocks-local/local.go +++ b/cmd/shadowsocks-local/local.go @@ -139,7 +139,7 @@ func getRequest(conn net.Conn) (rawaddr []byte, host string, err error) { host = addrIp.String() } port := binary.BigEndian.Uint16(buf[reqLen-2 : reqLen]) - host += ":" + strconv.Itoa(int(port)) + host = net.JoinHostPort(host, strconv.Itoa(int(port))) } return @@ -156,6 +156,14 @@ var servers struct { } func parseServerConfig(config *ss.Config) { + hasPort := func(s string) bool { + _, port, err := net.SplitHostPort(s) + if err != nil { + return false + } + return port != "" + } + if len(config.ServerPassword) == 0 { // only one encryption table cipher, err := ss.NewCipher(config.Method, config.Password) @@ -168,11 +176,11 @@ func parseServerConfig(config *ss.Config) { servers.srvCipher = make([]*ServerCipher, n) for i, s := range srvArr { - if ss.HasPort(s) { + if hasPort(s) { log.Println("ignore server_port option for server", s) servers.srvCipher[i] = &ServerCipher{s, cipher} } else { - servers.srvCipher[i] = &ServerCipher{s + ":" + srvPort, cipher} + servers.srvCipher[i] = &ServerCipher{net.JoinHostPort(s, srvPort), cipher} } } } else { @@ -192,8 +200,8 @@ func parseServerConfig(config *ss.Config) { if len(serverInfo) == 3 { encmethod = serverInfo[2] } - if !ss.HasPort(server) { - log.Fatalf("no port for server %s, please specify port in the form of %s:port\n", server, server) + if !hasPort(server) { + log.Fatalf("no port for server %s\n", server) } cipher, ok := cipherCache[passwd] if !ok { diff --git a/script/test.sh b/script/test.sh index 8263a1c..af92149 100755 --- a/script/test.sh +++ b/script/test.sh @@ -5,6 +5,38 @@ LOCAL_PORT="1090" SOCKS="127.0.0.1:$LOCAL_PORT" test_get() { + local url + url=$1 + target=$2 + code=$3 + + if [[ -z $code ]]; then + code="200" + fi + + # get 5 times + for i in {1..2}; do + # -s silent to disable progress meter, but enable --show-error + # -i to include http header + # -L to follow redirect so we should always get HTTP 200 + cont=`curl --socks5 $SOCKS -s --show-error -i -L $url 2>&1` + ok=`echo $cont | grep -E -o "HTTP/1\.1 +$code"` + html=`echo $cont | grep -E -o -i "$target"` + if [[ -z $ok || -z $html ]] ; then + echo "==============================" + echo "GET $url FAILED!!!" + echo "$ok" + echo "$html" + echo $cont + echo "==============================" + return 1 + fi + sleep 0.3 + done + return 0 +} + +test_shadowsocks() { local url local method local server_pid @@ -18,27 +50,24 @@ test_get() { local_pid=$! # wait server and client finish startup - sleep 0.5 + sleep 1 # get 5 times for i in {1..5}; do - if ! curl -s --socks5 $SOCKS $url >/dev/null 2>&1; then - echo "==============================" - echo "GET $url $method FAILED!!!" - echo "==============================" - kill -SIGINT $server_pid - kill -SIGINT $local_pid - exit 1 + if ! test_get $url " 0; i-- { - if s[i] == ':' { - return true - } - } - return false -}