Python port of ShadowsocksR
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.6 KiB

#!/usr/bin/python
# -*- coding: utf-8 -*-
11 years ago
import sys
import os
import signal
import select
import time
from subprocess import Popen, PIPE
11 years ago
from shadowsocks import encrypt_salsa20
11 years ago
encrypt_salsa20.test()
print 'encryption test passed'
11 years ago
p1 = Popen(['python', 'shadowsocks/server.py', '-c', sys.argv[-1]], shell=False,
bufsize=0, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
p2 = Popen(['python', 'shadowsocks/local.py', '-c', sys.argv[-1]], shell=False,
bufsize=0, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
p3 = None
try:
11 years ago
local_ready = False
server_ready = False
fdset = [p1.stdout, p2.stdout, p1.stderr, p2.stderr]
while True:
r, w, e = select.select(fdset, [], fdset)
if e:
break
for fd in r:
line = fd.readline()
sys.stdout.write(line)
11 years ago
if line.find('starting local') >= 0:
local_ready = True
if line.find('starting server') >= 0:
server_ready = True
if local_ready and server_ready and p3 is None:
time.sleep(1)
p3 = Popen(['curl', 'http://www.example.com/', '-v', '-L',
11 years ago
'--socks5-hostname', '127.0.0.1:1081'], shell=False,
11 years ago
bufsize=0, close_fds=True)
break
if p3 is not None:
r = p3.wait()
if r == 0:
print 'test passed'
sys.exit(r)
11 years ago
finally:
for p in [p1, p2]:
try:
os.kill(p.pid, signal.SIGTERM)
except OSError:
pass
sys.exit(-1)