Skip to content

Commit

Permalink
Merge branch 'release/1.0'
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
  • Loading branch information
cyfdecyf committed May 17, 2013
2 parents 1254da5 + 8dddaf7 commit 61d94bc
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 43 deletions.
4 changes: 2 additions & 2 deletions 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).

Expand Down Expand Up @@ -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).
6 changes: 1 addition & 5 deletions cmd/shadowsocks-httpget/httpget.go
Expand Up @@ -93,18 +93,14 @@ func main() {
fmt.Printf("Usage: %s -s <server> -p <port> -k <password> <url>\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)
if !strings.HasPrefix(uri, "http://") {
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)
Expand Down
31 changes: 17 additions & 14 deletions cmd/shadowsocks-local/local.go
Expand Up @@ -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)
Expand All @@ -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
}
Expand All @@ -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)))
Expand Down
30 changes: 20 additions & 10 deletions cmd/shadowsocks-server/server.go
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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])
Expand Down
2 changes: 2 additions & 0 deletions deb/DEBIAN/conffiles
@@ -0,0 +1,2 @@
/etc/shadowsocks/config.json
/etc/init.d/shadowsocks
2 changes: 1 addition & 1 deletion deb/DEBIAN/control
@@ -1,5 +1,5 @@
Package: shadowsocks-go
Version: 0.6.1-1
Version: VER-1
Section: net
Priority: optional
Architecture: any
Expand Down
5 changes: 5 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
6 changes: 4 additions & 2 deletions deb/etc/init.d/shadowsocks
Expand Up @@ -8,15 +8,15 @@
# 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

# 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
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions script/build.sh
Expand Up @@ -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
Expand All @@ -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*
5 changes: 3 additions & 2 deletions script/createdeb.sh
Expand Up @@ -13,7 +13,7 @@ export GOOS=linux

arch=$1
case $arch in
i386)
386)
export GOARCH=386
;;
amd64)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions script/set-version.sh
Expand Up @@ -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

Binary file modified script/shadowsocks.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions script/upload.sh
Expand Up @@ -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

2 changes: 1 addition & 1 deletion shadowsocks/util.go
Expand Up @@ -7,7 +7,7 @@ import (
)

func PrintVersion() {
const version = "0.6.2"
const version = "1.0"
fmt.Println("shadowsocks-go version", version)
}

Expand Down

0 comments on commit 61d94bc

Please sign in to comment.