Browse Source

add gevent

1.4
clowwindy 12 years ago
parent
commit
12173a66d1
  1. 6
      README.md
  2. 13
      local.py
  3. 13
      server.py

6
README.md

@ -13,6 +13,7 @@ First, make sure you have Python 2.6 or 2.7.
$ python --version $ python --version
Python 2.6.8 Python 2.6.8
Then edit `config.json`, change the following values: Then edit `config.json`, change the following values:
server your server ip or hostname server your server ip or hostname
@ -36,7 +37,10 @@ You can use args to override settings from `config.json`.
python local.py -s server_name -p server_port -l local_port -k password python local.py -s server_name -p server_port -l local_port -k password
python server.py -p server_port -k password python server.py -p server_port -k password
You may want to install gevent for better performance.
$ sudo easy_install gevent
troubleshooting troubleshooting
--------------- ---------------

13
local.py

@ -20,6 +20,14 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
import sys
try:
import gevent, gevent.monkey
gevent.monkey.patch_all(dns=gevent.version_info[0]>=1)
except ImportError:
gevent = None
print >>sys.stderr, 'warning: gevent not found, using threading instead'
import socket import socket
import select import select
@ -27,7 +35,6 @@ import SocketServer
import struct import struct
import string import string
import hashlib import hashlib
import sys
import os import os
import json import json
import logging import logging
@ -58,13 +65,13 @@ class Socks5Server(SocketServer.StreamRequestHandler):
data = sock.recv(4096) data = sock.recv(4096)
if data <= 0: if data <= 0:
break break
if remote.sendall(self.encrypt(data)) is not None: if remote.send(self.encrypt(data)) <= 0:
break break
if remote in r: if remote in r:
data = remote.recv(4096) data = remote.recv(4096)
if data <= 0: if data <= 0:
break break
if sock.sendall(self.decrypt(data)) is not None: if sock.send(self.decrypt(data)) <= 0:
break break
finally: finally:
sock.close() sock.close()

13
server.py

@ -20,6 +20,14 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
import sys
try:
import gevent, gevent.monkey
gevent.monkey.patch_all(dns=gevent.version_info[0]>=1)
except ImportError:
gevent = None
print >>sys.stderr, 'warning: gevent not found, using threading instead'
import socket import socket
import select import select
@ -27,7 +35,6 @@ import SocketServer
import struct import struct
import string import string
import hashlib import hashlib
import sys
import os import os
import json import json
import logging import logging
@ -58,13 +65,13 @@ class Socks5Server(SocketServer.StreamRequestHandler):
data = sock.recv(4096) data = sock.recv(4096)
if data <= 0: if data <= 0:
break break
if remote.sendall(self.decrypt(data)) is not None: if remote.send(self.decrypt(data)) <= 0:
break break
if remote in r: if remote in r:
data = remote.recv(4096) data = remote.recv(4096)
if data <= 0: if data <= 0:
break break
if sock.sendall(self.encrypt(data)) is not None: if sock.send(self.encrypt(data)) <= 0:
break break
finally: finally:
sock.close() sock.close()

Loading…
Cancel
Save