Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

build
bin
.DS_Store
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

80 changes: 41 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
UNAME := $(shell uname)

RTFLAGS=-lrt
ifeq ($(UNAME), Darwin)
RTFLAGS=-framework CoreServices
endif
OLEVEL=-O2 -DNDEBUG
CFLAGS=-Wall $(OLEVEL) -I libuv/include -std=gnu99
FILES=server.c utils.c encrypt.c md5.c rc4.c
APP=server

all: $(FILES) libuv/libuv.a
$(CC) $(CFLAGS) -o \
$(APP) $(FILES) \
libuv/libuv.a -lpthread -lcrypto -lm $(RTFLAGS)

libuv/libuv.a:
$(MAKE) -C libuv

valgrind: OLEVEL=-O0 -g
valgrind: all
valgrind --leak-check=full ./server

debug: OLEVEL=-O0 -g
debug: all

gprof: OLEVEL=-O0 -g -pg
gprof: all

test: OLEVEL=-O0 -g
test: FILES=tests.c encrypt.c md5.c rc4.c
test: APP=test
test: all
./test
cd pytest; python test.py
# compile
CFLAGS = -Wall -g -I/usr/local/opt/openssl/include -Iinclude
LDFLAGS = -lcrypto -luv -L/usr/local/opt/openssl/lib
# compiler
CC = gcc

# files
SRC = $(shell find src -name "*.c" -type f)
OBJ = $(patsubst src/%.c, build/%.o, $(SRC))
DEP = $(OBJ:.o=.d)
BIN = local

# target
all: $(patsubst %, bin/ss-%, $(BIN))

bin/ss-%: $(OBJ) $(DEP) build/ss-%.o build/ss-%.d
@mkdir -p $(dir $@)
$(CC) $(filter %.o, $(^)) $(LDFLAGS) $(CFLAGS) -o $@

define build-object
@mkdir -p $(dir $@)
$(CC) $< -c $(CFLAGS) -o $@
endef

define build-depend
@mkdir -p $(dir $@)
@$(CC) -MM $(CFLAGS) $< | sed 's#\($(notdir $*)\)\.o[ :]*#build/$*.o $@: #g' > $@
endef

build/ss-%.o: %.c
$(build-object)
build/ss-%.d: %.c
$(build-depend)

build/%.o: src/%.c
$(build-object)
build/%.d: src/%.c
$(build-depend)

clean:
$(MAKE) -C libuv clean
rm -f server
rm -rf *.dSYM
rm -rf test
$(RM) -r bin build

sinclude $(DEP)
173 changes: 89 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,123 +4,128 @@ shadowsocks-libuv

Shadowsocks is a lightweight tunnel proxy to help you get through firewalls.

Protocol made by [clowwindy](https://raw.github.com/clowwindy/), libuv port by [dndx](https://github.com/dndx)
Protocol made by [clowwindy](https://raw.github.com/clowwindy/), libuv port by [dndx](https://github.com/dndx), modified by [cube](https://github.com/cuber)

This is only a **server**, it should work with any shadowsocks client.
All code are reconstructed, Only **loacl** supported, most encrypt methods are supported.
It's an unfinished version, i'm trying my best to do it.

Current version: 0.2
~~This is only a **server**, it should work with any shadowsocks client.~~

This is an [Open Source](http://opensource.org/licenses/MIT) project and released under [The MIT License](http://opensource.org/licenses/MIT)
~~Current version: 0.2~~

## Features
* Super fast and low resource consumption (thanks to [libuv](https://github.com/joyent/libuv)), it runs smoothly on almost any VPS.
* Fully compatible with other ports of shadowsocks.
* Supports the latest RC4 encryption method.
* Fully IPv6 Ready
~~This is an [Open Source](http://opensource.org/licenses/MIT) project and released under [The MIT License](http://opensource.org/licenses/MIT)~~

## About IPv6 Support
Instead of creating two separate file descriptors for IPv4 and IPv6, shadowsocks-libuv only creates one. It works because it uses the Linux kernel 2.4.21 and 2.6, and we can use `IN6ADDR_ANY` (aka. `::0`) to accept connections from both the IPv4 and IPv6 stacks. Those connections come from the IPv4 stack will be mapped to [IPv4-mapped IPv6 addresses](https://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses) automatically. For example, IPv4 address `192.168.1.2` will be mapped to `::ffff:192:168:1:2` and will work whether your machine has an IPv6 link or not.
~~## Features~~
~~* Super fast and low resource consumption (thanks to [libuv](https://github.com/joyent/libuv)), it runs smoothly on almost any VPS.~~
~~* Fully compatible with other ports of shadowsocks.~~
~~* Supports the latest RC4 encryption method.~~
~~* Fully IPv6 Ready~~

If you want your shadowsocks to listen on a specific IPv4 address, listen using `::ffff:192:168:1:2`.
~~## About IPv6 Support~~
~~Instead of creating two separate file descriptors for IPv4 and IPv6, shadowsocks-libuv only creates one. It works because it uses the Linux kernel 2.4.21 and 2.6, and we can use `IN6ADDR_ANY` (aka. `::0`) to accept connections from both the IPv4 and IPv6 stacks. Those connections come from the IPv4 stack will be mapped to [IPv4-mapped IPv6 addresses](https://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses) automatically. For example,~~IPv4 address `192.168.1.2` will be mapped to `::ffff:192:168:1:2` and will work whether your machine has an IPv6 link or not.~~

When connecting to a remote server, shadowsocks prefers to use an IPv6 address if both your server and remote supports IPv6. This will work even if your connection to the server is using IPv4. Thus you can use shadowsocks as an IPv4 to IPv6 or IPv6 to IPv4 tunnel.
~~If you want your shadowsocks to listen on a specific IPv4 address, listen using `::ffff:192:168:1:2`.~~

### Diagram
~~When connecting to a remote server, shadowsocks prefers to use an IPv6 address if both your server and remote supports IPv6. This will work even ifyour connection to the server is using IPv4. Thus you can use shadowsocks as an IPv4 to IPv6 or IPv6 to IPv4 tunnel.~~

+------+ IPv4 +------+ IPv4 +------+
|Client| <---OR---> |Server| <---OR---> |Remote|
+------+ IPv6 +------+ IPv6 +------+
~~### Diagram~~

Client is any compatible shadowsocks client
~~+------+ IPv4 +------+ IPv4 +------+~~
~~|Client| <---OR---> |Server| <---OR---> |Remote|~~
~~+------+ IPv6 +------+ IPv6 +------+~~

Server is shadowsocks-libuv or other compatible server
~~Client is any compatible shadowsocks client~~

Remote is the service you are trying to access
~~Server is shadowsocks-libuv or other compatible server~~

## Attention
Please open an issue if you encounter any bugs. Be sure to attach the error message so I can identify it.
~~Remote is the service you are trying to access~~

## How to Build
$ yum install openssl-devel
$ git clone --recursive https://github.com/dndx/shadowsocks-libuv.git
$ cd shadowsocks-libuv/
$ vim config.h
$ make
~~## Attention~~
~~Please open an issue if you encounter any bugs. Be sure to attach the error message so I can identify it.~~

Note that you need to rebuild it every time you modify config.h, just run `make` again and it will do rest of the work.
~~## How to Build~~
~~$ yum install openssl-devel~~
~~$ git clone --recursive https://github.com/dndx/shadowsocks-libuv.git~~
~~$ cd shadowsocks-libuv/~~
~~$ vim config.h~~
~~$ make~~

Tested and confirmed to work on:
~~Note that you need to rebuild it every time you modify config.h, just run `make` again and it will do rest of the work.~~

* Mac OS X 10.8.2 x64 using Clang 4.1
* CentOS 5.8 x86 using GCC 4.1.2
* CentOS 6.3 x64 using GCC 4.4.6
* Ubuntu Linux 12.04 using GCC 4.6.x and Clang 3.1.x (Travis Environment)
~~Tested and confirmed to work on:~~

## How to Use
After you build shadowsocks successfully, you can rename the file `server` and move it to anywhere you want.
~~* Mac OS X 10.8.2 x64 using Clang 4.1~~
~~* CentOS 5.8 x86 using GCC 4.1.2~~
~~* CentOS 6.3 x64 using GCC 4.4.6~~
~~* Ubuntu Linux 12.04 using GCC 4.6.x and Clang 3.1.x (Travis Environment)~~

Also there are command line options that can be used to override settings in config.h:
~~## How to Use~~
~~After you build shadowsocks successfully, you can rename the file `server` and move it to anywhere you want.~~

$ ./server -?
./server: invalid option -- ?
Shadowsocks Version:0.2 libuv(0.9) Written by Dndx(idndx.com)
Usage: ./server [-l listen] [-p port] [-k keyfile] [-f pidfile] [-m rc4|shadow]
~~Also there are command line options that can be used to override settings in config.h:~~

Options:
-l : Override the listening IP
-p : Override the listening port
-k : Override the listening password
-f : Override the pidfile path
-m : Override the encryption method
If you want to run server in background, you can:
~~$ ./server -?~~
~~./server: invalid option -- ?~~
~~Shadowsocks Version:0.2 libuv(0.9) Written by Dndx(idndx.com)~~
~~Usage: ./server [-l listen] [-p port] [-k keyfile] [-f pidfile] [-m rc4|shadow]~~

$ nohup /path/to/server &
~~Options:~~
~~-l : Override the listening IP~~
~~-p : Override the listening port~~
~~-k : Override the listening password~~
~~-f : Override the pidfile path~~
~~-m : Override the encryption method~~
~~If you want to run server in background, you can:~~

Note this will redirect all logs generated by program to `nohup.out`. If you do not want logs to be saved, you can run:
~~$ nohup /path/to/server &~~

$ nohup /path/to/server > /dev/null 2>&1 &
~~Note this will redirect all logs generated by program to `nohup.out`. If you do not want logs to be saved, you can run:~~

This will delete all messages.
~~$ nohup /path/to/server > /dev/null 2>&1 &~~

If your program does not run as expected, log files will help identify the bug.
~~This will delete all messages.~~

## Known Issues
### Build Failed
src/unix/linux/syscalls.h:74: error: expected specifier-qualifier-list before ‘__u64’
1. First, make sure you have the latest kernel-headers by running `yum install kernel-headers`
2. Try make again, if it still complains, see next
3. `cd` to shadowsocks-libuv and `$ vim libuv/config-unix.mk`
4. At about line 22, you will see `CSTDFLAG=--std=c89 -pedantic -Wall -Wextra -Wno-unused-parameter`
5. Change it to `CSTDFLAG=--std=gnu99 -pedantic -Wall -Wextra -Wno-unused-parameter`
6. Save the file and run `make` again
~~If your program does not run as expected, log files will help identify the bug.~~

### Can not using static link
Thanks to [@cyfdecy](https://github.com/cyfdecyf)
~~## Known Issues~~
~~### Build Failed~~
~~src/unix/linux/syscalls.h:74: error: expected specifier-qualifier-list before ‘__u64’~~
~~1. First, make sure you have the latest kernel-headers by running `yum install kernel-headers`~~
~~2. Try make again, if it still complains, see next~~
~~3. `cd` to shadowsocks-libuv and `$ vim libuv/config-unix.mk`~~
~~4. At about line 22, you will see `CSTDFLAG=--std=c89 -pedantic -Wall -Wextra -Wno-unused-parameter`~~
~~5. Change it to `CSTDFLAG=--std=gnu99 -pedantic -Wall -Wextra -Wno-unused-parameter`~~
~~6. Save the file and run `make` again~~

Do not use `-static` to compile this project. The problem is that `libuv` is using `pthread` and `getaddrinfo(3)` for async DNS resolve. But this will cause `getaddrinfo(3)` Segment Fault.
~~### Can not using static link~~
~~Thanks to [@cyfdecy](https://github.com/cyfdecyf)~~

More information can be found at [issue #3](https://github.com/dndx/shadowsocks-libuv/issues/3)
~~Do not use `-static` to compile this project. The problem is that `libuv` is using `pthread` and `getaddrinfo(3)` for async DNS resolve. But this~~
~~ll cause `getaddrinfo(3)` Segment Fault.~~

### CPU 100%
There is a possibility that the process will sometimes consume 100% of CPU and can not be restored. The cause of problem is not clear but I am working for a solution. Including re-design the way connection is handled, please stay tuned.
~~More information can be found at [issue #3](https://github.com/dndx/shadowsocks-libuv/issues/3)~~

~~### CPU 100%~~
~~There is a possibility that the process will sometimes consume 100% of CPU and can not be restored. The cause of problem is not clear but I am~~
~~rking for a solution. Including re-design the way connection is handled, please stay tuned.~~

## Performance
I did not fully benchmark it yet, but according to my use on [TinyVZ](http://tinyvz.com/) (OpenVZ 128M RAM and CentOS 5.8 x86). When streaming YouTube 1080p vedio at about 20Mbit/s bandwidth, it use at most 3% of RAM (RSS about 7500) and almost no CPU time. While browsing it uses less than 0.7% RAM (RSS about 1164).

##Contributors
* [@messense](https://github.com/messense) Logger Color
* [@clowwindy](https://github.com/clowwindy)
* Test Case and Protol Maker of shadowsocks
* [getopt(3) issue](https://github.com/dndx/shadowsocks-libuv/pull/4)
* [@cyfdecyf](https://github.com/cyfdecyf) Warning about static link in [issue #3](https://github.com/dndx/shadowsocks-libuv/issues/3)
* [@madeye](https://github.com/madeye) [IPv6 Support](https://github.com/dndx/shadowsocks-libuv/pull/8)
~~## Performance~~
~~I did not fully benchmark it yet, but according to my use on [TinyVZ](http://tinyvz.com/) (OpenVZ 128M RAM and CentOS 5.8 x86). When streaming YouTube 1080p vedio at about 20Mbit/s bandwidth, it use at most 3% of RAM (RSS about 7500) and almost no CPU time. While browsing it uses less than~~0.7% RAM (RSS about 1164).~~

I appreciate all the people who have made this project better. Contribution is always welcome!
~~##Contributors~~
~~* [@messense](https://github.com/messense) Logger Color~~
~~* [@clowwindy](https://github.com/clowwindy)~~
~~* Test Case and Protol Maker of shadowsocks~~
~~* [getopt(3) issue](https://github.com/dndx/shadowsocks-libuv/pull/4)~~
~~* [@cyfdecyf](https://github.com/cyfdecyf) Warning about static link in [issue #3](https://github.com/dndx/shadowsocks-libuv/issues/3)~~
~~* [@madeye](https://github.com/madeye) [IPv6 Support](https://github.com/dndx/shadowsocks-libuv/pull/8)~~

## TODO List
* ~~Fully IPv6 Support~~ (accomplished)
* ~~RC4 Crypto Support~~ (accomplished)
* Multi Port Support
* Client Implement
* …to be continued…
~~I appreciate all the people who have made this project better. Contribution is always welcome!~~

~~## TODO List~~
~~*~~Fully IPv6 Support~~ (accomplished)~~
~~*~~RC4 Crypto Support~~ (accomplished)~~
~~* Multi Port Support~~
~~* Client Implement~~
~~* …to be continued…~~
45 changes: 0 additions & 45 deletions config.h

This file was deleted.

Loading