diff --git a/README.md b/README.md index 7169e37..549dfa2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # shadowsocks-go -Current version: 0.6.2 [![Build Status](https://travis-ci.org/shadowsocks/shadowsocks-go.png?branch=master)](https://travis-ci.org/shadowsocks/shadowsocks-go) +Current version: 1.0 [![Build Status](https://travis-ci.org/shadowsocks/shadowsocks-go.png?branch=master)](https://travis-ci.org/shadowsocks/shadowsocks-go) shadowsocks-go is a lightweight tunnel proxy which can help you get through firewalls. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). @@ -86,4 +86,4 @@ Edit the config file used to start the server, then send `SIGHUP` to the server **Use OpenVZ VM that supports vswap**. Otherwise, the OS will incorrectly account much more memory than actually used. shadowsocks-go on OpenVZ VM with vswap takes about 3MB memory after startup. (Refer to [this issue](https://github.com/shadowsocks/shadowsocks-go/issues/3) for more details.) -If vswap is not an option and memory usage is a problem for you, try [shadowsocks-libuv](https://github.com/dndx/shadowsocks-libuv). +If vswap is not an option and memory usage is a problem for you, try [shadowsocks-libev](https://github.com/madeye/shadowsocks-libev). diff --git a/cmd/shadowsocks-httpget/httpget.go b/cmd/shadowsocks-httpget/httpget.go index eb83d18..e7aaa15 100644 --- a/cmd/shadowsocks-httpget/httpget.go +++ b/cmd/shadowsocks-httpget/httpget.go @@ -93,10 +93,6 @@ func main() { fmt.Printf("Usage: %s -s -p -k \n", os.Args[0]) os.Exit(1) } - if err := ss.SetDefaultCipher(config.method); err != nil { - fmt.Println(err) - os.Exit(1) - } runtime.GOMAXPROCS(config.core) uri := flag.Arg(0) @@ -104,7 +100,7 @@ func main() { uri = "http://" + uri } - cipher, err := ss.NewCipher(config.passwd) + cipher, err := ss.NewCipher(config.method, config.passwd) if err != nil { fmt.Println("Error creating cipher:", err) os.Exit(1) diff --git a/cmd/shadowsocks-local/local.go b/cmd/shadowsocks-local/local.go index 98b23ad..e97c03c 100644 --- a/cmd/shadowsocks-local/local.go +++ b/cmd/shadowsocks-local/local.go @@ -85,8 +85,9 @@ func getRequest(conn net.Conn) (rawaddr []byte, host string, err error) { typeDm = 3 // type is domain address typeIPv6 = 4 // type is ipv6 address - lenIP = 3 + 1 + 4 + 2 // 3(ver+cmd+rsv) + 1addrType + 4ip + 2port - lenDmBase = 3 + 1 + 1 + 2 // 3 + 1addrType + 1addrLen + 2port, plus addrLen + lenIPv4 = 3 + 1 + net.IPv4len + 2 // 3(ver+cmd+rsv) + 1addrType + ipv4 + 2port + lenIPv6 = 3 + 1 + net.IPv6len + 2 // 3(ver+cmd+rsv) + 1addrType + ipv6 + 2port + lenDmBase = 3 + 1 + 1 + 2 // 3 + 1addrType + 1addrLen + 2port, plus addrLen ) // refer to getRequest in server.go for why set buffer size to 263 buf := make([]byte, 263) @@ -105,15 +106,15 @@ func getRequest(conn net.Conn) (rawaddr []byte, host string, err error) { return } - // Browsers seems always using domain name, so it's not urgent to support - // IPv6 address in the local socks server. - reqLen := lenIP - if buf[idType] == typeDm { + reqLen := -1 + switch buf[idType] { + case typeIPv4: + reqLen = lenIPv4 + case typeIPv6: + reqLen = lenIPv6 + case typeDm: reqLen = int(buf[idDmLen]) + lenDmBase - } else if buf[idType] != typeIPv4 { - if buf[idType] == typeIPv6 { - log.Println("IPv6 address type not supported in socks request") - } + default: err = errAddrType return } @@ -132,11 +133,13 @@ func getRequest(conn net.Conn) (rawaddr []byte, host string, err error) { rawaddr = buf[idType:reqLen] if debug { - if buf[idType] == typeDm { + switch buf[idType] { + case typeIPv4: + host = net.IP(buf[idIP0 : idIP0+net.IPv4len]).String() + case typeIPv6: + host = net.IP(buf[idIP0 : idIP0+net.IPv6len]).String() + case typeDm: host = string(buf[idDm0 : idDm0+buf[idDmLen]]) - } else if buf[idType] == typeIPv4 { - addrIp := net.IPv4(buf[idIP0], buf[idIP0+1], buf[idIP0+2], buf[idIP0+3]) - host = addrIp.String() } port := binary.BigEndian.Uint16(buf[reqLen-2 : reqLen]) host = net.JoinHostPort(host, strconv.Itoa(int(port))) diff --git a/cmd/shadowsocks-server/server.go b/cmd/shadowsocks-server/server.go index 294d526..8a0eae7 100644 --- a/cmd/shadowsocks-server/server.go +++ b/cmd/shadowsocks-server/server.go @@ -32,8 +32,9 @@ func getRequest(conn *ss.Conn) (host string, extra []byte, err error) { typeDm = 3 // type is domain address typeIPv6 = 4 // type is ipv6 address - lenIP = 1 + 4 + 2 // 1addrType + 4ip + 2port - lenDmBase = 1 + 1 + 2 // 1addrType + 1addrLen + 2port, plus addrLen + lenIPv4 = 1 + net.IPv4len + 2 // 1addrType + ipv4 + 2port + lenIPv6 = 1 + net.IPv6len + 2 // 1addrType + ipv6 + 2port + lenDmBase = 1 + 1 + 2 // 1addrType + 1addrLen + 2port, plus addrLen ) // buf size should at least have the same size with the largest possible @@ -47,11 +48,15 @@ func getRequest(conn *ss.Conn) (host string, extra []byte, err error) { return } - // Currently the client will not send request with ipv6 address. - reqLen := lenIP - if buf[idType] == typeDm { + reqLen := -1 + switch buf[idType] { + case typeIPv4: + reqLen = lenIPv4 + case typeIPv6: + reqLen = lenIPv6 + case typeDm: reqLen = int(buf[idDmLen]) + lenDmBase - } else if buf[idType] != typeIPv4 { + default: err = errors.New(fmt.Sprintf("addr type %d not supported", buf[idType])) return } @@ -66,11 +71,16 @@ func getRequest(conn *ss.Conn) (host string, extra []byte, err error) { extra = buf[reqLen:n] } - if buf[idType] == typeDm { + // Return string for typeIP is not most efficient, but browsers (Chrome, + // Safari, Firefox) all seems using typeDm exclusively. So this is not a + // big problem. + switch buf[idType] { + case typeIPv4: + host = net.IP(buf[idIP0 : idIP0+net.IPv4len]).String() + case typeIPv6: + host = net.IP(buf[idIP0 : idIP0+net.IPv6len]).String() + case typeDm: host = string(buf[idDm0 : idDm0+buf[idDmLen]]) - } else if buf[idType] == typeIPv4 { - addrIp := net.IPv4(buf[idIP0], buf[idIP0+1], buf[idIP0+2], buf[idIP0+3]) - host = addrIp.String() } // parse port port := binary.BigEndian.Uint16(buf[reqLen-2 : reqLen]) diff --git a/deb/DEBIAN/conffiles b/deb/DEBIAN/conffiles new file mode 100644 index 0000000..b41e606 --- /dev/null +++ b/deb/DEBIAN/conffiles @@ -0,0 +1,2 @@ +/etc/shadowsocks/config.json +/etc/init.d/shadowsocks diff --git a/deb/DEBIAN/control b/deb/DEBIAN/control index ce9cae2..ae2e234 100644 --- a/deb/DEBIAN/control +++ b/deb/DEBIAN/control @@ -1,5 +1,5 @@ Package: shadowsocks-go -Version: 0.6.1-1 +Version: VER-1 Section: net Priority: optional Architecture: any diff --git a/deb/DEBIAN/postinst b/deb/DEBIAN/postinst new file mode 100755 index 0000000..dc7e7a9 --- /dev/null +++ b/deb/DEBIAN/postinst @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +if [ -x "/etc/init.d/shadowsocks" ]; then + update-rc.d shadowsocks defaults >/dev/null +fi diff --git a/deb/DEBIAN/postrm b/deb/DEBIAN/postrm new file mode 100755 index 0000000..24af3a6 --- /dev/null +++ b/deb/DEBIAN/postrm @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +# Automatically added by dh_installinit +if [ "$1" = "purge" ] ; then + update-rc.d shadowsocks remove >/dev/null +fi +# End automatically added section diff --git a/deb/DEBIAN/prerm b/deb/DEBIAN/prerm new file mode 100755 index 0000000..82316e5 --- /dev/null +++ b/deb/DEBIAN/prerm @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +# Automatically added by dh_installinit +if [ -x "/etc/init.d/shadowsocks" ]; then + invoke-rc.d shadowsocks stop || exit $? +fi +# End automatically added section diff --git a/deb/etc/init.d/shadowsocks b/deb/etc/init.d/shadowsocks index ef3aaa2..99ae417 100755 --- a/deb/etc/init.d/shadowsocks +++ b/deb/etc/init.d/shadowsocks @@ -8,7 +8,7 @@ # Should-Start: # Should-Stop: # Default-Start: 2 3 4 5 -# Default-Stop: +# Default-Stop: 0 1 6 # Short-Description: shadowsocks is a lightweight tunneling proxy # Description: Modified from Linode's nginx fastcgi startup script ### END INIT INFO @@ -16,7 +16,7 @@ # Note: this script requires sudo in order to run shadowsocks as the specified # user. -BIN=/usr/bin/shadowsocks +BIN=/usr/bin/shadowsocks-server CONFIG_FILE=/etc/shadowsocks/config.json LOG_FILE=/var/log/shadowsocks USER=nobody @@ -25,6 +25,8 @@ PID_DIR=/var/run PID_FILE=$PID_DIR/shadowsocks.pid RET_VAL=0 +[ -x $BIN ] || exit 0 + check_running() { if [[ -r $PID_FILE ]]; then read PID <$PID_FILE diff --git a/script/build.sh b/script/build.sh index b94363c..cd8077b 100755 --- a/script/build.sh +++ b/script/build.sh @@ -24,8 +24,10 @@ build() { if [[ $1 == "windows" ]]; then mv $prog.exe $ROOT/script/ pushd $ROOT/script/ - zip $name.zip $prog.exe shadowsocks.exe - rm -f $prog.exe + cp $ROOT/config.json sample-config.json + cp $ROOT/sample-config/client-multi-server.json multi-server.json + zip $name.zip $prog.exe shadowsocks.exe sample-config.json multi-server.json + rm -f $prog.exe sample-config.json multi-server.json mv $name.zip $bindir popd else @@ -48,3 +50,7 @@ build linux 386 linux32 server #build windows amd64 win64 server #build windows 386 win32 server +script/createdeb.sh amd64 +script/createdeb.sh 386 +mv shadowsocks-go_$version-1-*.deb bin/ +rm -rf shadowsocks-go_$version-1* diff --git a/script/createdeb.sh b/script/createdeb.sh index 9818389..fb02278 100755 --- a/script/createdeb.sh +++ b/script/createdeb.sh @@ -13,7 +13,7 @@ export GOOS=linux arch=$1 case $arch in - i386) + 386) export GOARCH=386 ;; amd64) @@ -35,10 +35,11 @@ DEBDIR=shadowsocks-go_$ver-1-$arch rm -rf $DEBDIR cp -r deb $DEBDIR +sed -i -e "s/VER/$ver/" $DEBDIR/DEBIAN/control || exit 1 sed -i -e "s/^Architecture.*$/Architecture: $arch/" $DEBDIR/DEBIAN/control || exit 1 mkdir -p $DEBDIR/usr/bin -cp cmd/shadowsocks-server/shadowsocks-server $DEBDIR/usr/bin/shadowsocks +cp cmd/shadowsocks-server/shadowsocks-server $DEBDIR/usr/bin/ rm -f cmd/shadowsocks-server/shadowsocks-server fakeroot dpkg-deb --build $DEBDIR diff --git a/script/set-version.sh b/script/set-version.sh index ef88c15..df12b95 100755 --- a/script/set-version.sh +++ b/script/set-version.sh @@ -10,6 +10,6 @@ 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 +sed -i -e "s,\(\tconst version \+= \)\".*\"$,\1\"$version\"," shadowsocks/util.go +sed -i -e "s,^\(Current version: \)[^ ]\+,\1$version," README.md diff --git a/script/shadowsocks.exe b/script/shadowsocks.exe index 2b2e7b2..1a2ca9c 100755 Binary files a/script/shadowsocks.exe and b/script/shadowsocks.exe differ diff --git a/script/upload.sh b/script/upload.sh index 3c5a89c..6db4882 100755 --- a/script/upload.sh +++ b/script/upload.sh @@ -26,6 +26,6 @@ upload "$version Windows Client 32bit" bin/shadowsocks-local-win32-$version.zip upload "$version Linux Server 32bit" bin/shadowsocks-server-linux32-$version.gz upload "$version Linux Server 64bit" bin/shadowsocks-server-linux64-$version.gz -upload "$version Linux Server deb 32bit" bin/shadowsocks-go_0.6.1-1-i386.deb -upload "$version Linux Server deb 64bit" bin/shadowsocks-go_0.6.1-1-amd64.deb +upload "$version Linux Server deb 32bit" bin/shadowsocks-go_$version-1-i386.deb +upload "$version Linux Server deb 64bit" bin/shadowsocks-go_$version-1-amd64.deb diff --git a/shadowsocks/util.go b/shadowsocks/util.go index eb9396b..4a5ceab 100644 --- a/shadowsocks/util.go +++ b/shadowsocks/util.go @@ -7,7 +7,7 @@ import ( ) func PrintVersion() { - const version = "0.6.2" + const version = "1.0" fmt.Println("shadowsocks-go version", version) }