Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manyuser #1

Open
wants to merge 50 commits into
base: manyuser
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0edae70
Add fail2ban filter.
jackyyf Jun 20, 2015
a2edd6a
Merge pull request #361 from jackyyf/master
clowwindy Jun 21, 2015
1a62694
add udp source port test
clowwindy Jul 10, 2015
c34c994
fix UDP source port issue
clowwindy Jul 10, 2015
99b4121
fix problem when UDP client requesting both IPv4 and IPv6
clowwindy Jul 10, 2015
13a6bb0
cache DNS results in UDPRelay
clowwindy Jul 10, 2015
f55bd03
update CHANGES
clowwindy Jul 10, 2015
f7d69db
bump
clowwindy Jul 10, 2015
1bb0e51
refine tests
clowwindy Jul 11, 2015
2555aa8
PEP8 indent
cicku Jul 27, 2015
d95e5ce
Merge pull request #388 from cicku/patch-1
clowwindy Jul 27, 2015
4a8d077
optimize performance for multiple ports
clowwindy Aug 1, 2015
80102f3
fix pyflakes
clowwindy Aug 1, 2015
d319fab
fix asyncdns unit test
clowwindy Aug 1, 2015
e8b2946
fix workers
clowwindy Aug 1, 2015
111acf6
fix graceful restart and add unit test
clowwindy Aug 2, 2015
02120e3
optimize eventloop
clowwindy Aug 2, 2015
b28de8e
fix pyflakes
clowwindy Aug 2, 2015
177c639
fix graceful restart test
clowwindy Aug 2, 2015
d946ac8
skip graceful restart test on Jenkins
clowwindy Aug 2, 2015
999a541
update CHANGES
clowwindy Aug 2, 2015
4211184
remove unnecessary overwrite
clowwindy Aug 2, 2015
baad209
bump
clowwindy Aug 2, 2015
58df1d8
close poll object after loop stopped
clowwindy Aug 3, 2015
956199e
add control manager
clowwindy Aug 5, 2015
e08845d
fix manager
clowwindy Aug 5, 2015
9c3af61
add statistics
clowwindy Aug 5, 2015
d20a071
allow manager to bind on unix socket
clowwindy Aug 5, 2015
4f948b2
fix password type in udprelay
clowwindy Aug 5, 2015
a8ae8ab
add unit test for manager
clowwindy Aug 5, 2015
30efc30
fix pyflakes
clowwindy Aug 5, 2015
249bcc0
refine unit test
clowwindy Aug 5, 2015
5ed73c1
bump 2.8
clowwindy Aug 5, 2015
583b54f
update CHANGES
clowwindy Aug 6, 2015
3576b30
support IPv6 on control socket
clowwindy Aug 6, 2015
77f9979
Update CONTRIBUTING.md
clowwindy Aug 6, 2015
c8b3f71
respond ok to add and remove commands
clowwindy Aug 6, 2015
f04e268
bump 2.8.1
clowwindy Aug 6, 2015
c5dd081
Update README.md
clowwindy Aug 8, 2015
3c11549
fix json unicode issue in manager
clowwindy Aug 9, 2015
a434eef
fix json decode issue
clowwindy Aug 10, 2015
7c08101
update CHANGES
clowwindy Aug 10, 2015
a2bc6e1
fix #414
clowwindy Aug 11, 2015
f19d0ea
fix #425
clowwindy Aug 15, 2015
eb033a8
Update README.md
clowwindy Aug 16, 2015
0c4f792
allow user to override system dnsserver with config.
May 11, 2015
ffed9b2
dns_server config test
Aug 17, 2015
e52aa9d
Merge pull request #335 from slayercat/master
clowwindy Aug 17, 2015
61a0b2d
Update README.md
clowwindy Aug 17, 2015
5b450ac
Update README.md
clowwindy Aug 20, 2015
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before_install:
- sudo dd if=/dev/urandom of=/usr/share/nginx/www/file bs=1M count=10
- sudo sh -c "echo '127.0.0.1 localhost' > /etc/hosts"
- sudo service nginx restart
- pip install pep8 pyflakes nose coverage
- pip install pep8 pyflakes nose coverage PySocks
- sudo tests/socksify/install.sh
- sudo tests/libsodium/install.sh
- sudo tests/setup_tc.sh
Expand Down
15 changes: 15 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2.8.2 2015-08-10
- Fix a encoding problem in manager

2.8.1 2015-08-06
- Respond ok to add and remove commands

2.8 2015-08-06
- Add Shadowsocks manager

2.7 2015-08-02
- Optimize speed for multiple ports

2.6.11 2015-07-10
- Fix a compatibility issue in UDP Relay

2.6.10 2015-06-08
- Optimize LRU cache
- Refine logging
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
How to Contribute
=================

Notice this is the repository for Shadowsocks Python version. If you have problems with Android / iOS / Windows etc clients, please post your questions in their issue trackers.

Pull Requests
-------------

Expand Down
63 changes: 8 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
shadowsocks
===========

[![PyPI version]][PyPI]
[![Build Status]][Travis CI]
[![Coverage Status]][Coverage]

A fast tunnel proxy that helps you bypass firewalls.

Features:
- TCP & UDP support
- User management API
- TCP Fast Open
- Workers and graceful restart
- Destination IP blacklist

Server
------

Expand Down Expand Up @@ -45,16 +48,6 @@ To check the log:
Check all the options via `-h`. You can also use a [Configuration] file
instead.

Client
------

* [Windows] / [OS X]
* [Android] / [iOS]
* [OpenWRT]

Use GUI clients on your local PC/phones. Check the README of your client
for more information.

Documentation
-------------

Expand All @@ -63,44 +56,4 @@ You can find all the documentation in the [Wiki].
License
-------

Copyright 2015 clowwindy

Licensed under the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License. You may obtain
a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.

Bugs and Issues
----------------

* [Troubleshooting]
* [Issue Tracker]
* [Mailing list]



[Android]: https://github.com/shadowsocks/shadowsocks-android
[Build Status]: https://img.shields.io/travis/shadowsocks/shadowsocks/master.svg?style=flat
[Configuration]: https://github.com/shadowsocks/shadowsocks/wiki/Configuration-via-Config-File
[Coverage Status]: https://jenkins.shadowvpn.org/result/shadowsocks
[Coverage]: https://jenkins.shadowvpn.org/job/Shadowsocks/ws/PYENV/py34/label/linux/htmlcov/index.html
[Debian sid]: https://packages.debian.org/unstable/python/shadowsocks
[iOS]: https://github.com/shadowsocks/shadowsocks-iOS/wiki/Help
[Issue Tracker]: https://github.com/shadowsocks/shadowsocks/issues?state=open
[Install Server on Windows]: https://github.com/shadowsocks/shadowsocks/wiki/Install-Shadowsocks-Server-on-Windows
[Mailing list]: https://groups.google.com/group/shadowsocks
[OpenWRT]: https://github.com/shadowsocks/openwrt-shadowsocks
[OS X]: https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-Help
[PyPI]: https://pypi.python.org/pypi/shadowsocks
[PyPI version]: https://img.shields.io/pypi/v/shadowsocks.svg?style=flat
[Travis CI]: https://travis-ci.org/shadowsocks/shadowsocks
[Troubleshooting]: https://github.com/shadowsocks/shadowsocks/wiki/Troubleshooting
[Wiki]: https://github.com/shadowsocks/shadowsocks/wiki
[Windows]: https://github.com/shadowsocks/shadowsocks-csharp
Apache License
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="shadowsocks",
version="2.6.11",
version="2.8.2",
license='http://www.apache.org/licenses/LICENSE-2.0',
description="A fast tunnel proxy that help you get through firewalls",
author='clowwindy',
Expand Down
69 changes: 35 additions & 34 deletions shadowsocks/asyncdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from __future__ import absolute_import, division, print_function, \
with_statement

import time
import os
import socket
import struct
Expand Down Expand Up @@ -249,17 +248,19 @@ def __str__(self):

class DNSResolver(object):

def __init__(self):
def __init__(self, server_list=None):
self._loop = None
self._hosts = {}
self._hostname_status = {}
self._hostname_to_cb = {}
self._cb_to_hostname = {}
self._cache = lru_cache.LRUCache(timeout=300)
self._last_time = time.time()
self._sock = None
self._servers = None
self._parse_resolv()
if server_list is None:
self._servers = None
self._parse_resolv()
else:
self._servers = server_list
self._parse_hosts()
# TODO monitor hosts change and reload hosts
# TODO parse /etc/gai.conf and follow its rules
Expand Down Expand Up @@ -304,16 +305,16 @@ def _parse_hosts(self):
except IOError:
self._hosts['localhost'] = '127.0.0.1'

def add_to_loop(self, loop, ref=False):
def add_to_loop(self, loop):
if self._loop:
raise Exception('already add to loop')
self._loop = loop
# TODO when dns server is IPv6
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)
self._sock.setblocking(False)
loop.add(self._sock, eventloop.POLL_IN)
loop.add_handler(self.handle_events, ref=ref)
loop.add(self._sock, eventloop.POLL_IN, self)
loop.add_periodic(self.handle_periodic)

def _call_callback(self, hostname, ip, error=None):
callbacks = self._hostname_to_cb.get(hostname, [])
Expand Down Expand Up @@ -354,30 +355,27 @@ def _handle_data(self, data):
self._call_callback(hostname, None)
break

def handle_events(self, events):
for sock, fd, event in events:
if sock != self._sock:
continue
if event & eventloop.POLL_ERR:
logging.error('dns socket err')
self._loop.remove(self._sock)
self._sock.close()
# TODO when dns server is IPv6
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)
self._sock.setblocking(False)
self._loop.add(self._sock, eventloop.POLL_IN)
else:
data, addr = sock.recvfrom(1024)
if addr[0] not in self._servers:
logging.warn('received a packet other than our dns')
break
self._handle_data(data)
break
now = time.time()
if now - self._last_time > CACHE_SWEEP_INTERVAL:
self._cache.sweep()
self._last_time = now
def handle_event(self, sock, fd, event):
if sock != self._sock:
return
if event & eventloop.POLL_ERR:
logging.error('dns socket err')
self._loop.remove(self._sock)
self._sock.close()
# TODO when dns server is IPv6
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)
self._sock.setblocking(False)
self._loop.add(self._sock, eventloop.POLL_IN, self)
else:
data, addr = sock.recvfrom(1024)
if addr[0] not in self._servers:
logging.warn('received a packet other than our dns')
return
self._handle_data(data)

def handle_periodic(self):
self._cache.sweep()

def remove_callback(self, callback):
hostname = self._cb_to_hostname.get(callback)
Expand Down Expand Up @@ -430,14 +428,17 @@ def resolve(self, hostname, callback):

def close(self):
if self._sock:
if self._loop:
self._loop.remove_periodic(self.handle_periodic)
self._loop.remove(self._sock)
self._sock.close()
self._sock = None


def test():
dns_resolver = DNSResolver()
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop, ref=True)
dns_resolver.add_to_loop(loop)

global counter
counter = 0
Expand All @@ -451,8 +452,8 @@ def callback(result, error):
print(result, error)
counter += 1
if counter == 9:
loop.remove_handler(dns_resolver.handle_events)
dns_resolver.close()
loop.stop()
a_callback = callback
return a_callback

Expand Down
2 changes: 1 addition & 1 deletion shadowsocks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def parse_header(data):
if len(data) >= 2 + addrlen:
dest_addr = data[2:2 + addrlen]
dest_port = struct.unpack('>H', data[2 + addrlen:4 +
addrlen])[0]
addrlen])[0]
header_length = 4 + addrlen
else:
logging.warn('header is too short')
Expand Down
2 changes: 1 addition & 1 deletion shadowsocks/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def handle_exit(signum, _):
sys.exit(1)

os.setsid()
signal.signal(signal.SIG_IGN, signal.SIGHUP)
signal.signal(signal.SIGHUP, signal.SIG_IGN)

print('started')
os.kill(ppid, signal.SIGTERM)
Expand Down
Loading